1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2022 Imagination Technologies Ltd. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 5bf215546Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal 6bf215546Sopenharmony_ci * in the Software without restriction, including without limitation the rights 7bf215546Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8bf215546Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is 9bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18bf215546Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include <assert.h> 25bf215546Sopenharmony_ci#include <stddef.h> 26bf215546Sopenharmony_ci#include <stdint.h> 27bf215546Sopenharmony_ci#include <vulkan/vulkan.h> 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "pvr_bo.h" 30bf215546Sopenharmony_ci#include "pvr_csb.h" 31bf215546Sopenharmony_ci#include "pvr_device_info.h" 32bf215546Sopenharmony_ci#include "pvr_private.h" 33bf215546Sopenharmony_ci#include "util/macros.h" 34bf215546Sopenharmony_ci#include "vk_log.h" 35bf215546Sopenharmony_ci#include "vk_object.h" 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ciVkResult pvr_CreateQueryPool(VkDevice _device, 38bf215546Sopenharmony_ci const VkQueryPoolCreateInfo *pCreateInfo, 39bf215546Sopenharmony_ci const VkAllocationCallbacks *pAllocator, 40bf215546Sopenharmony_ci VkQueryPool *pQueryPool) 41bf215546Sopenharmony_ci{ 42bf215546Sopenharmony_ci PVR_FROM_HANDLE(pvr_device, device, _device); 43bf215546Sopenharmony_ci const uint32_t core_count = device->pdevice->dev_runtime_info.core_count; 44bf215546Sopenharmony_ci const uint32_t query_size = pCreateInfo->queryCount * sizeof(uint32_t); 45bf215546Sopenharmony_ci struct pvr_query_pool *pool; 46bf215546Sopenharmony_ci uint64_t alloc_size; 47bf215546Sopenharmony_ci VkResult result; 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci /* Vulkan 1.0 supports only occlusion, timestamp, and pipeline statistics 50bf215546Sopenharmony_ci * query. 51bf215546Sopenharmony_ci * We don't currently support timestamp queries. 52bf215546Sopenharmony_ci * VkQueueFamilyProperties->timestampValidBits = 0. 53bf215546Sopenharmony_ci * We don't currently support pipeline statistics queries. 54bf215546Sopenharmony_ci * VkPhysicalDeviceFeatures->pipelineStatisticsQuery = false. 55bf215546Sopenharmony_ci */ 56bf215546Sopenharmony_ci assert(!device->features.pipelineStatisticsQuery); 57bf215546Sopenharmony_ci assert(pCreateInfo->queryType == VK_QUERY_TYPE_OCCLUSION); 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci pool = vk_object_alloc(&device->vk, 60bf215546Sopenharmony_ci pAllocator, 61bf215546Sopenharmony_ci sizeof(*pool), 62bf215546Sopenharmony_ci VK_OBJECT_TYPE_QUERY_POOL); 63bf215546Sopenharmony_ci if (!pool) 64bf215546Sopenharmony_ci return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci pool->result_stride = 67bf215546Sopenharmony_ci ALIGN_POT(query_size, PVRX(CR_ISP_OCLQRY_BASE_ADDR_ALIGNMENT)); 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci /* Each Phantom writes to a separate offset within the vis test heap so 70bf215546Sopenharmony_ci * allocate space for the total number of Phantoms. 71bf215546Sopenharmony_ci */ 72bf215546Sopenharmony_ci alloc_size = pool->result_stride * core_count; 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci result = pvr_bo_alloc(device, 75bf215546Sopenharmony_ci device->heaps.vis_test_heap, 76bf215546Sopenharmony_ci alloc_size, 77bf215546Sopenharmony_ci PVRX(CR_ISP_OCLQRY_BASE_ADDR_ALIGNMENT), 78bf215546Sopenharmony_ci PVR_BO_ALLOC_FLAG_CPU_MAPPED, 79bf215546Sopenharmony_ci &pool->result_buffer); 80bf215546Sopenharmony_ci if (result != VK_SUCCESS) 81bf215546Sopenharmony_ci goto err_free_pool; 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci result = pvr_bo_alloc(device, 84bf215546Sopenharmony_ci device->heaps.vis_test_heap, 85bf215546Sopenharmony_ci query_size, 86bf215546Sopenharmony_ci sizeof(uint32_t), 87bf215546Sopenharmony_ci PVR_BO_ALLOC_FLAG_CPU_MAPPED, 88bf215546Sopenharmony_ci &pool->availability_buffer); 89bf215546Sopenharmony_ci if (result != VK_SUCCESS) 90bf215546Sopenharmony_ci goto err_free_result_buffer; 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci *pQueryPool = pvr_query_pool_to_handle(pool); 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci return VK_SUCCESS; 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_cierr_free_result_buffer: 97bf215546Sopenharmony_ci pvr_bo_free(device, pool->result_buffer); 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_cierr_free_pool: 100bf215546Sopenharmony_ci vk_object_free(&device->vk, pAllocator, pool); 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci return result; 103bf215546Sopenharmony_ci} 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_civoid pvr_DestroyQueryPool(VkDevice _device, 106bf215546Sopenharmony_ci VkQueryPool queryPool, 107bf215546Sopenharmony_ci const VkAllocationCallbacks *pAllocator) 108bf215546Sopenharmony_ci{ 109bf215546Sopenharmony_ci PVR_FROM_HANDLE(pvr_query_pool, pool, queryPool); 110bf215546Sopenharmony_ci PVR_FROM_HANDLE(pvr_device, device, _device); 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci pvr_bo_free(device, pool->availability_buffer); 113bf215546Sopenharmony_ci pvr_bo_free(device, pool->result_buffer); 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci vk_object_free(&device->vk, pAllocator, pool); 116bf215546Sopenharmony_ci} 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ciVkResult pvr_GetQueryPoolResults(VkDevice _device, 119bf215546Sopenharmony_ci VkQueryPool queryPool, 120bf215546Sopenharmony_ci uint32_t firstQuery, 121bf215546Sopenharmony_ci uint32_t queryCount, 122bf215546Sopenharmony_ci size_t dataSize, 123bf215546Sopenharmony_ci void *pData, 124bf215546Sopenharmony_ci VkDeviceSize stride, 125bf215546Sopenharmony_ci VkQueryResultFlags flags) 126bf215546Sopenharmony_ci{ 127bf215546Sopenharmony_ci assert(!"Unimplemented"); 128bf215546Sopenharmony_ci return VK_SUCCESS; 129bf215546Sopenharmony_ci} 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_civoid pvr_CmdResetQueryPool(VkCommandBuffer commandBuffer, 132bf215546Sopenharmony_ci VkQueryPool queryPool, 133bf215546Sopenharmony_ci uint32_t firstQuery, 134bf215546Sopenharmony_ci uint32_t queryCount) 135bf215546Sopenharmony_ci{ 136bf215546Sopenharmony_ci assert(!"Unimplemented"); 137bf215546Sopenharmony_ci} 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_civoid pvr_CmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, 140bf215546Sopenharmony_ci VkQueryPool queryPool, 141bf215546Sopenharmony_ci uint32_t firstQuery, 142bf215546Sopenharmony_ci uint32_t queryCount, 143bf215546Sopenharmony_ci VkBuffer dstBuffer, 144bf215546Sopenharmony_ci VkDeviceSize dstOffset, 145bf215546Sopenharmony_ci VkDeviceSize stride, 146bf215546Sopenharmony_ci VkQueryResultFlags flags) 147bf215546Sopenharmony_ci{ 148bf215546Sopenharmony_ci assert(!"Unimplemented"); 149bf215546Sopenharmony_ci} 150bf215546Sopenharmony_ci 151bf215546Sopenharmony_civoid pvr_CmdBeginQuery(VkCommandBuffer commandBuffer, 152bf215546Sopenharmony_ci VkQueryPool queryPool, 153bf215546Sopenharmony_ci uint32_t query, 154bf215546Sopenharmony_ci VkQueryControlFlags flags) 155bf215546Sopenharmony_ci{ 156bf215546Sopenharmony_ci assert(!"Unimplemented"); 157bf215546Sopenharmony_ci} 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_civoid pvr_CmdEndQuery(VkCommandBuffer commandBuffer, 160bf215546Sopenharmony_ci VkQueryPool queryPool, 161bf215546Sopenharmony_ci uint32_t query) 162bf215546Sopenharmony_ci{ 163bf215546Sopenharmony_ci assert(!"Unimplemented"); 164bf215546Sopenharmony_ci} 165