Skip to content

Commit

Permalink
Add async and copy queues
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Nov 30, 2024
1 parent 1687403 commit 3f7490e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
53 changes: 46 additions & 7 deletions Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ void kope_d3d12_device_create(kope_g5_device *device, const kope_g5_device_wishl
kinc_microsoft_affirm(device->d3d12.device->CreateCommandQueue(&desc, IID_PPV_ARGS(&device->d3d12.queue)));
}

{
D3D12_COMMAND_QUEUE_DESC desc = {};
desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
desc.Type = D3D12_COMMAND_LIST_TYPE_COMPUTE;

kinc_microsoft_affirm(device->d3d12.device->CreateCommandQueue(&desc, IID_PPV_ARGS(&device->d3d12.async_queue)));
}

{
D3D12_COMMAND_QUEUE_DESC desc = {};
desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
desc.Type = D3D12_COMMAND_LIST_TYPE_COPY;

kinc_microsoft_affirm(device->d3d12.device->CreateCommandQueue(&desc, IID_PPV_ARGS(&device->d3d12.copy_queue)));
}

{
DXGI_SWAP_CHAIN_DESC desc = {0};
desc.BufferCount = 2;
Expand Down Expand Up @@ -578,8 +594,10 @@ static void clean_buffer_accesses(kope_g5_buffer *buffer, uint64_t finished_exec
buffer->d3d12.ranges_count = ranges_count;
}

void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) {
if (list->d3d12.presenting) {
enum command_list_type { COMMAND_LIST_TYPE_DIRECT, COMMAND_LIST_TYPE_ASYNC, COMMAND_LIST_TYPE_COPY };

static void execute_command_list(command_list_type list_type, kope_g5_device *device, kope_g5_command_list *list) {
if (list_type == COMMAND_LIST_TYPE_DIRECT && list->d3d12.presenting) {
kope_g5_texture *framebuffer = kope_d3d12_device_get_framebuffer(device);
if (framebuffer->d3d12.resource_states[0] != D3D12_RESOURCE_STATE_PRESENT) {
D3D12_RESOURCE_BARRIER barrier;
Expand All @@ -596,7 +614,7 @@ void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_comm
}
}

if (list->d3d12.blocking_frame_index > 0) {
if (list_type == COMMAND_LIST_TYPE_DIRECT && list->d3d12.blocking_frame_index > 0) {
wait_for_frame(device, list->d3d12.blocking_frame_index);
list->d3d12.blocking_frame_index = 0;
}
Expand Down Expand Up @@ -627,9 +645,18 @@ void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_comm
list->d3d12.allocator_execution_index[list->d3d12.current_allocator_index] = device->d3d12.execution_index;

ID3D12CommandList *lists[] = {list->d3d12.list};
device->d3d12.queue->ExecuteCommandLists(1, lists);

device->d3d12.queue->Signal(device->d3d12.execution_fence, device->d3d12.execution_index);
if (list_type == COMMAND_LIST_TYPE_DIRECT) {
device->d3d12.queue->ExecuteCommandLists(1, lists);
device->d3d12.queue->Signal(device->d3d12.execution_fence, device->d3d12.execution_index);
}
else if (list_type == COMMAND_LIST_TYPE_ASYNC) {
device->d3d12.async_queue->ExecuteCommandLists(1, lists);
device->d3d12.async_queue->Signal(device->d3d12.execution_fence, device->d3d12.execution_index);
}
else if (list_type == COMMAND_LIST_TYPE_COPY) {
device->d3d12.copy_queue->ExecuteCommandLists(1, lists);
device->d3d12.copy_queue->Signal(device->d3d12.execution_fence, device->d3d12.execution_index);
}

uint8_t allocator_index = command_list_oldest_allocator(list);
list->d3d12.current_allocator_index = allocator_index;
Expand All @@ -644,7 +671,7 @@ void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_comm
ID3D12DescriptorHeap *heaps[] = {list->d3d12.device->descriptor_heap, list->d3d12.device->sampler_heap};
list->d3d12.list->SetDescriptorHeaps(2, heaps);

if (list->d3d12.presenting) {
if (list_type == COMMAND_LIST_TYPE_DIRECT && list->d3d12.presenting) {
kope_g5_texture *framebuffer = kope_d3d12_device_get_framebuffer(device);
framebuffer->d3d12.in_flight_frame_index = device->d3d12.current_frame_index;

Expand All @@ -661,6 +688,18 @@ void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_comm
device->d3d12.execution_index += 1;
}

void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) {
execute_command_list(COMMAND_LIST_TYPE_DIRECT, device, list);
}

void kope_d3d12_device_execute_async_command_list(kope_g5_device *device, kope_g5_command_list *list) {
execute_command_list(COMMAND_LIST_TYPE_ASYNC, device, list);
}

void kope_d3d12_device_execute_copy_command_list(kope_g5_device *device, kope_g5_command_list *list) {
execute_command_list(COMMAND_LIST_TYPE_COPY, device, list);
}

void kope_d3d12_device_wait_until_idle(kope_g5_device *device) {
wait_for_fence(device, device->d3d12.execution_fence, device->d3d12.execution_event, device->d3d12.execution_index - 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ kope_g5_texture *kope_d3d12_device_get_framebuffer(kope_g5_device *device);

void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list);

void kope_d3d12_device_execute_async_command_list(kope_g5_device *device, kope_g5_command_list *list);

void kope_d3d12_device_execute_copy_command_list(kope_g5_device *device, kope_g5_command_list *list);

void kope_d3d12_device_wait_until_idle(kope_g5_device *device);

void kope_d3d12_device_create_raytracing_volume(kope_g5_device *device, kope_g5_buffer *vertex_buffer, uint64_t vertex_count, kope_g5_buffer *index_buffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct ID3D12QueryHeap;
typedef struct kope_d3d12_device {
struct ID3D12Device5 *device;
struct ID3D12CommandQueue *queue;
struct ID3D12CommandQueue *async_queue;
struct ID3D12CommandQueue *copy_queue;
struct IDXGISwapChain *swap_chain;

uint32_t cbv_srv_uav_increment;
Expand Down
8 changes: 8 additions & 0 deletions Sources/kope/graphics5/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ void kope_g5_device_execute_command_list(kope_g5_device *device, kope_g5_command
KOPE_G5_CALL2(device_execute_command_list, device, list);
}

void kope_g5_device_execute_async_command_list(kope_g5_device *device, kope_g5_command_list *list) {
KOPE_G5_CALL2(device_execute_async_command_list, device, list);
}

void kope_g5_device_execute_copy_command_list(kope_g5_device *device, kope_g5_command_list *list) {
KOPE_G5_CALL2(device_execute_copy_command_list, device, list);
}

void kope_g5_device_create_sampler(kope_g5_device *device, const kope_g5_sampler_parameters *parameters, kope_g5_sampler *sampler) {
KOPE_G5_CALL3(device_create_sampler, device, parameters, sampler);
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/kope/graphics5/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ KOPE_FUNC void kope_g5_device_create_query_set(kope_g5_device *device, const kop

KOPE_FUNC void kope_g5_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list);

KOPE_FUNC void kope_g5_device_execute_async_command_list(kope_g5_device *device, kope_g5_command_list *list);

KOPE_FUNC void kope_g5_device_execute_copy_command_list(kope_g5_device *device, kope_g5_command_list *list);

KOPE_FUNC void kope_g5_device_wait_until_idle(kope_g5_device *device);

typedef struct kope_g5_raytracing_volume {
Expand Down

0 comments on commit 3f7490e

Please sign in to comment.