Skip to content

Commit

Permalink
Implement occlusion queries
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 30, 2024
1 parent eef34d5 commit 930f218
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void kope_d3d12_command_list_begin_render_pass(kope_g5_command_list *list, const
NULL);
}
}

list->d3d12.occlusion_query_set = parameters->occlusion_query_set;
}

void kope_d3d12_command_list_end_render_pass(kope_g5_command_list *list) {}
Expand Down Expand Up @@ -662,3 +664,19 @@ void kope_d3d12_command_list_insert_debug_marker(kope_g5_command_list *list, con
PIXSetMarker(list->d3d12.list, 0, "%s", name);
#endif
}

void kope_d3d12_command_list_begin_occlusion_query(kope_g5_command_list *list, uint32_t query_index) {
list->d3d12.current_occlusion_query_index = query_index;
list->d3d12.list->BeginQuery(list->d3d12.occlusion_query_set->d3d12.query_heap, D3D12_QUERY_TYPE_OCCLUSION, query_index);
}

void kope_d3d12_command_list_end_occlusion_query(kope_g5_command_list *list) {
list->d3d12.list->EndQuery(list->d3d12.occlusion_query_set->d3d12.query_heap, D3D12_QUERY_TYPE_OCCLUSION, list->d3d12.current_occlusion_query_index);
}

void kope_d3d12_command_list_resolve_query_set(kope_g5_command_list *list, kope_g5_query_set *query_set, uint32_t first_query, uint32_t query_count,
kope_g5_buffer *destination, uint64_t destination_offset) {
list->d3d12.list->ResolveQueryData(query_set->d3d12.query_heap,
query_set->d3d12.query_type == KOPE_G5_QUERY_TYPE_OCCLUSION ? D3D12_QUERY_TYPE_OCCLUSION : D3D12_QUERY_TYPE_TIMESTAMP,
first_query, query_count, destination->d3d12.resource, destination_offset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ void kope_d3d12_command_list_pop_debug_group(kope_g5_command_list *list);

void kope_d3d12_command_list_insert_debug_marker(kope_g5_command_list *list, const char *name);

void kope_d3d12_command_list_begin_occlusion_query(kope_g5_command_list *list, uint32_t query_index);

void kope_d3d12_command_list_end_occlusion_query(kope_g5_command_list *list);

void kope_d3d12_command_list_resolve_query_set(kope_g5_command_list *list, kope_g5_query_set *query_set, uint32_t first_query, uint32_t query_count,
kope_g5_buffer *destination, uint64_t destination_offset);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ extern "C" {
struct kope_d3d12_device;
struct kope_d3d12_texture;
struct kope_d3d12_ray_pipeline;
struct kope_g5_query_set;

struct ID3D12Fence;

// Allocators can not be re-used while a command-list is executing. We carry along a bag of allocators so we only have to wait when we ran out of in-flight
Expand Down Expand Up @@ -38,6 +40,9 @@ typedef struct kope_d3d12_command_list {

struct kope_d3d12_ray_pipeline *ray_pipe;

struct kope_g5_query_set *occlusion_query_set;
uint32_t current_occlusion_query_index;

bool presenting;
} kope_d3d12_command_list;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_comma
list->d3d12.dsv_increment = device->d3d12.device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
}

list->d3d12.occlusion_query_set = NULL;
list->d3d12.current_occlusion_query_index = 0;

list->d3d12.blocking_frame_index = 0;

list->d3d12.presenting = false;
Expand Down Expand Up @@ -739,6 +742,7 @@ void kope_d3d12_device_create_query_set(kope_g5_device *device, const kope_g5_qu
desc.Count = parameters->count;
desc.NodeMask = 0;

query_set->d3d12.query_type = (uint8_t)parameters->type;
device->d3d12.device->CreateQueryHeap(&desc, IID_GRAPHICS_PPV_ARGS(&query_set->d3d12.query_heap));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct kope_d3d12_device {

typedef struct kope_d3d12_query_set {
struct ID3D12QueryHeap *query_heap;
uint8_t query_type;
} kope_d3d12_query_set;

typedef struct kope_d3d12_raytracing_volume {
Expand Down
13 changes: 13 additions & 0 deletions Sources/kope/graphics5/commandlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,16 @@ void kope_g5_command_list_pop_debug_group(kope_g5_command_list *list) {
void kope_g5_command_list_insert_debug_marker(kope_g5_command_list *list, const char *name) {
KOPE_G5_CALL2(command_list_insert_debug_marker, list, name);
}

void kope_g5_command_list_begin_occlusion_query(kope_g5_command_list *list, uint32_t query_index) {
KOPE_G5_CALL2(command_list_begin_occlusion_query, list, query_index);
}

void kope_g5_command_list_end_occlusion_query(kope_g5_command_list *list) {
KOPE_G5_CALL1(command_list_end_occlusion_query, list);
}

void kope_g5_command_list_resolve_query_set(kope_g5_command_list *list, kope_g5_query_set *query_set, uint32_t first_query, uint32_t query_count,
kope_g5_buffer *destination, uint64_t destination_offset) {
KOPE_G5_CALL6(command_list_resolve_query_set, list, query_set, first_query, query_count, destination, destination_offset);
}
8 changes: 5 additions & 3 deletions Sources/kope/graphics5/commandlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
extern "C" {
#endif

struct kope_g5_query_set;

typedef struct kope_g5_command_list {
KOPE_G5_IMPL(command_list);
} kope_g5_command_list;
Expand Down Expand Up @@ -75,7 +77,7 @@ typedef struct kope_g5_render_pass_parameters {
kope_g5_render_pass_color_attachment color_attachments[8];
size_t color_attachments_count;
kope_g5_render_pass_depth_stencil_attachment depth_stencil_attachment;
// GPUQuerySet occlusionQuerySet;
struct kope_g5_query_set *occlusion_query_set;
// GPURenderPassTimestampWrites timestampWrites;
} kope_g5_render_pass_parameters;

Expand Down Expand Up @@ -114,8 +116,8 @@ KOPE_FUNC void kope_g5_command_list_copy_texture_to_texture(kope_g5_command_list

KOPE_FUNC void kope_g5_command_list_clear_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, size_t offset, uint64_t size);

// KOPE_FUNC void kope_g5_command_list_resolve_query_set(kope_g5_command_list *list, GPUQuerySet query_set, uint32_t first_query, uint32_t query_count,
// kope_g5_buffer *destination, uint64_t destination_offset);
KOPE_FUNC void kope_g5_command_list_resolve_query_set(kope_g5_command_list *list, struct kope_g5_query_set *query_set, uint32_t first_query,
uint32_t query_count, kope_g5_buffer *destination, uint64_t destination_offset);

typedef enum kope_g5_index_format { KOPE_G5_INDEX_FORMAT_UINT16, KOPE_G5_INDEX_FORMAT_UINT32 } kope_g5_index_format;

Expand Down

0 comments on commit 930f218

Please sign in to comment.