From 79cbc900bcef2859b23e7617cb849345f3815246 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Wed, 23 Aug 2017 16:18:15 +0200 Subject: [PATCH] libs/vkd3d: Create Vulkan Query Pools for D3D12 Query Heaps. --- libs/vkd3d/device.c | 2 +- libs/vkd3d/resource.c | 60 +++++++++++++++++++++++++++++++++++++- libs/vkd3d/vkd3d_private.h | 3 +- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index dcabdb43..f3e82fd8 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -1419,7 +1419,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_device_CreateQueryHeap(ID3D12Device *ifac TRACE("iface %p, desc %p, iid %s, heap %p.\n", iface, desc, debugstr_guid(iid), heap); - if (FAILED(hr = d3d12_query_heap_create(device, &object))) + if (FAILED(hr = d3d12_query_heap_create(device, &object, desc))) return hr; return return_interface((IUnknown *)&object->ID3D12QueryHeap_iface, diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 0232dea8..c7abbad3 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -1636,6 +1636,9 @@ static ULONG STDMETHODCALLTYPE d3d12_query_heap_Release(ID3D12QueryHeap *iface) if (!refcount) { struct d3d12_device *device = heap->device; + const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; + + VK_CALL(vkDestroyQueryPool(device->vk_device, heap->vk_query_pool, NULL)); vkd3d_free(heap); @@ -1701,9 +1704,13 @@ static const struct ID3D12QueryHeapVtbl d3d12_query_heap_vtbl = d3d12_query_heap_GetDevice, }; -HRESULT d3d12_query_heap_create(struct d3d12_device *device, struct d3d12_query_heap **heap) +HRESULT d3d12_query_heap_create(struct d3d12_device *device, struct d3d12_query_heap **heap, + const D3D12_QUERY_HEAP_DESC *desc) { + const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; struct d3d12_query_heap *object; + VkQueryPoolCreateInfo pool_info; + VkResult vr; if (!(object = vkd3d_malloc(sizeof(*object)))) return E_OUTOFMEMORY; @@ -1711,6 +1718,57 @@ HRESULT d3d12_query_heap_create(struct d3d12_device *device, struct d3d12_query_ object->ID3D12QueryHeap_iface.lpVtbl = &d3d12_query_heap_vtbl; object->refcount = 1; object->device = device; + + pool_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; + pool_info.pNext = NULL; + pool_info.flags = 0; + pool_info.queryCount = desc->Count; + + switch (desc->Type) + { + case D3D12_QUERY_HEAP_TYPE_OCCLUSION: + pool_info.queryType = VK_QUERY_TYPE_OCCLUSION; + pool_info.pipelineStatistics = 0; + break; + + case D3D12_QUERY_HEAP_TYPE_TIMESTAMP: + pool_info.queryType = VK_QUERY_TYPE_TIMESTAMP; + pool_info.pipelineStatistics = 0; + break; + + case D3D12_QUERY_HEAP_TYPE_PIPELINE_STATISTICS: + pool_info.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS; + pool_info.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT + | VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT + | VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT + | VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT + | VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT + | VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT + | VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT + | VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT + | VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT + | VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT + | VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT; + break; + + case D3D12_QUERY_HEAP_TYPE_SO_STATISTICS: + WARN("Unsupported query heap type SO_STATISTICS.\n"); + vkd3d_free(object); + return E_NOTIMPL; + + default: + WARN("Invalid query heap type %u.\n", desc->Type); + vkd3d_free(object); + return E_INVALIDARG; + } + + if ((vr = VK_CALL(vkCreateQueryPool(device->vk_device, &pool_info, NULL, &object->vk_query_pool))) < 0) + { + WARN("Failed to create Vulkan query pool, vr %d.\n", vr); + vkd3d_free(object); + return hresult_from_vk_result(vr); + } + ID3D12Device_AddRef(&device->ID3D12Device_iface); TRACE("Created query heap %p.\n", object); diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index a8194aab..37f7bf23 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -257,12 +257,13 @@ struct d3d12_query_heap { ID3D12QueryHeap ID3D12QueryHeap_iface; LONG refcount; + VkQueryPool vk_query_pool; struct d3d12_device *device; }; HRESULT d3d12_query_heap_create(struct d3d12_device *device, - struct d3d12_query_heap **heap) DECLSPEC_HIDDEN; + struct d3d12_query_heap **heap, const D3D12_QUERY_HEAP_DESC *desc) DECLSPEC_HIDDEN; struct d3d12_root_descriptor_table_range {