From eef34d533aa8db2250ae01a83b9716e8b10a949d Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Mon, 30 Sep 2024 00:49:06 +0200 Subject: [PATCH] Implement query-set creation. --- .../Direct3D12/Sources/kope/direct3d12/device.cpp | 9 +++++++++ .../Sources/kope/direct3d12/device_functions.h | 2 ++ .../Sources/kope/direct3d12/device_structs.h | 5 +++++ Sources/kope/graphics5/device.c | 4 ++++ Sources/kope/graphics5/device.h | 13 ++++++++++++- 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp index 2bd49c363..59962e22d 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp @@ -733,6 +733,15 @@ void kope_d3d12_device_create_raytracing_hierarchy(kope_g5_device *device, kope_ kope_g5_device_create_buffer(device, &as_params, &hierarchy->d3d12.acceleration_structure); } +void kope_d3d12_device_create_query_set(kope_g5_device *device, const kope_g5_query_set_parameters *parameters, kope_g5_query_set *query_set) { + D3D12_QUERY_HEAP_DESC desc = {}; + desc.Type = parameters->type == KOPE_G5_QUERY_TYPE_OCCLUSION ? D3D12_QUERY_HEAP_TYPE_OCCLUSION : D3D12_QUERY_HEAP_TYPE_TIMESTAMP; + desc.Count = parameters->count; + desc.NodeMask = 0; + + device->d3d12.device->CreateQueryHeap(&desc, IID_GRAPHICS_PPV_ARGS(&query_set->d3d12.query_heap)); +} + uint32_t kope_d3d12_device_align_texture_row_bytes(kope_g5_device *device, uint32_t row_bytes) { return (uint32_t)align_pow2((int)row_bytes, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT); } diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h index ccb5e731f..413ad1ca5 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h @@ -39,6 +39,8 @@ void kope_d3d12_device_create_raytracing_volume(kope_g5_device *device, kope_g5_ void kope_d3d12_device_create_raytracing_hierarchy(kope_g5_device *device, kope_g5_raytracing_volume **volumes, kinc_matrix4x4_t *volume_transforms, uint32_t volumes_count, kope_g5_raytracing_hierarchy *hierarchy); +void kope_d3d12_device_create_query_set(kope_g5_device *device, const kope_g5_query_set_parameters *parameters, kope_g5_query_set *query_set); + uint32_t kope_d3d12_device_align_texture_row_bytes(kope_g5_device *device, uint32_t row_bytes); #ifdef __cplusplus diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_structs.h b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_structs.h index a6309f23e..e3161c742 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_structs.h +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_structs.h @@ -14,6 +14,7 @@ extern "C" { struct ID3D12CommandAllocator; struct ID3D12DescriptorHeap; +struct ID3D12QueryHeap; #define KOPE_D3D12_FRAME_COUNT 2 @@ -48,6 +49,10 @@ typedef struct kope_d3d12_device { kope_g5_command_list management_list; } kope_d3d12_device; +typedef struct kope_d3d12_query_set { + struct ID3D12QueryHeap *query_heap; +} kope_d3d12_query_set; + typedef struct kope_d3d12_raytracing_volume { kope_g5_buffer *vertex_buffer; uint64_t vertex_count; diff --git a/Sources/kope/graphics5/device.c b/Sources/kope/graphics5/device.c index 811639ff6..bb5de4116 100644 --- a/Sources/kope/graphics5/device.c +++ b/Sources/kope/graphics5/device.c @@ -48,6 +48,10 @@ kope_g5_texture *kope_g5_device_get_framebuffer(kope_g5_device *device) { return KOPE_G5_CALL1(device_get_framebuffer, device); } +void kope_g5_device_create_query_set(kope_g5_device *device, const kope_g5_query_set_parameters *parameters, kope_g5_query_set *query_set) { + KOPE_G5_CALL3(device_create_query_set, device, parameters, query_set); +} + void kope_g5_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) { KOPE_G5_CALL2(device_execute_command_list, device, list); } diff --git a/Sources/kope/graphics5/device.h b/Sources/kope/graphics5/device.h index efeb395fa..e972ad427 100644 --- a/Sources/kope/graphics5/device.h +++ b/Sources/kope/graphics5/device.h @@ -117,7 +117,18 @@ KOPE_FUNC void kope_g5_device_create_sampler(kope_g5_device *device, const kope_ KOPE_FUNC void kope_g5_device_create_command_list(kope_g5_device *device, kope_g5_command_list *list); -KOPE_FUNC void kope_g5_device_create_query_set(void *descriptor); +typedef struct kope_g5_query_set { + KOPE_G5_IMPL(query_set); +} kope_g5_query_set; + +typedef enum kope_g5_query_type { KOPE_G5_QUERY_TYPE_OCCLUSION, KOPE_G5_QUERY_TYPE_TIMESTAMP } kope_g5_query_type; + +typedef struct kope_g5_query_set_parameters { + kope_g5_query_type type; + uint32_t count; +} kope_g5_query_set_parameters; + +KOPE_FUNC void kope_g5_device_create_query_set(kope_g5_device *device, const kope_g5_query_set_parameters *parameters, kope_g5_query_set *query_set); KOPE_FUNC void kope_g5_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list);