diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist_structs.h b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist_structs.h index 7e4ad909f..659db289d 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist_structs.h +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist_structs.h @@ -38,6 +38,8 @@ typedef struct kope_d3d12_buffer_access { typedef struct kope_d3d12_command_list { struct kope_d3d12_device *device; + int list_type; + struct ID3D12CommandAllocator *allocator[KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT]; uint64_t allocator_execution_index[KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT]; oa_allocation_t dynamic_descriptor_allocations[KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT]; diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp index f5fa89234..b9b5cf730 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device.cpp @@ -318,11 +318,26 @@ static uint8_t command_list_oldest_allocator(kope_g5_command_list *list) { return allocator_index; } -void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_command_list *list) { +static D3D12_COMMAND_LIST_TYPE convert_command_list_type(kope_g5_command_list_type type) { + switch (type) { + case KOPE_G5_COMMAND_LIST_TYPE_GRAPHICS: + return D3D12_COMMAND_LIST_TYPE_DIRECT; + case KOPE_G5_COMMAND_LIST_TYPE_ASYNC: + return D3D12_COMMAND_LIST_TYPE_COMPUTE; + case KOPE_G5_COMMAND_LIST_TYPE_COPY: + return D3D12_COMMAND_LIST_TYPE_COPY; + } +} + +void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_command_list_type type, kope_g5_command_list *list) { list->d3d12.device = &device->d3d12; + D3D12_COMMAND_LIST_TYPE list_type = convert_command_list_type(type); + + list->d3d12.list_type = list_type; + for (int i = 0; i < KOPE_D3D12_COMMAND_LIST_ALLOCATOR_COUNT; ++i) { - kinc_microsoft_affirm(device->d3d12.device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_GRAPHICS_PPV_ARGS(&list->d3d12.allocator[i]))); + kinc_microsoft_affirm(device->d3d12.device->CreateCommandAllocator(list_type, IID_GRAPHICS_PPV_ARGS(&list->d3d12.allocator[i]))); list->d3d12.allocator_execution_index[i] = 0; oa_allocate(&device->d3d12.descriptor_heap_allocator, KOPE_D3D12_COMMAND_LIST_DYNAMIC_DESCRIPTORS_COUNT, @@ -332,8 +347,8 @@ void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_comma list->d3d12.current_allocator_index = 0; - kinc_microsoft_affirm(device->d3d12.device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, list->d3d12.allocator[list->d3d12.current_allocator_index], - NULL, IID_GRAPHICS_PPV_ARGS(&list->d3d12.list))); + kinc_microsoft_affirm(device->d3d12.device->CreateCommandList(0, list_type, list->d3d12.allocator[list->d3d12.current_allocator_index], NULL, + IID_GRAPHICS_PPV_ARGS(&list->d3d12.list))); list->d3d12.compute_pipe = NULL; list->d3d12.ray_pipe = NULL; @@ -594,10 +609,8 @@ static void clean_buffer_accesses(kope_g5_buffer *buffer, uint64_t finished_exec buffer->d3d12.ranges_count = ranges_count; } -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) { +void kope_d3d12_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) { + if (list->d3d12.list_type == D3D12_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; @@ -614,7 +627,7 @@ static void execute_command_list(command_list_type list_type, kope_g5_device *de } } - if (list_type == COMMAND_LIST_TYPE_DIRECT && list->d3d12.blocking_frame_index > 0) { + if (list->d3d12.list_type == D3D12_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; } @@ -645,15 +658,15 @@ static void execute_command_list(command_list_type list_type, kope_g5_device *de list->d3d12.allocator_execution_index[list->d3d12.current_allocator_index] = device->d3d12.execution_index; ID3D12CommandList *lists[] = {list->d3d12.list}; - if (list_type == COMMAND_LIST_TYPE_DIRECT) { + if (list->d3d12.list_type == D3D12_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) { + else if (list->d3d12.list_type == D3D12_COMMAND_LIST_TYPE_COMPUTE) { 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) { + else if (list->d3d12.list_type == D3D12_COMMAND_LIST_TYPE_COPY) { device->d3d12.copy_queue->ExecuteCommandLists(1, lists); device->d3d12.copy_queue->Signal(device->d3d12.execution_fence, device->d3d12.execution_index); } @@ -671,7 +684,7 @@ static void execute_command_list(command_list_type list_type, kope_g5_device *de ID3D12DescriptorHeap *heaps[] = {list->d3d12.device->descriptor_heap, list->d3d12.device->sampler_heap}; list->d3d12.list->SetDescriptorHeaps(2, heaps); - if (list_type == COMMAND_LIST_TYPE_DIRECT && list->d3d12.presenting) { + if (list->d3d12.list_type == D3D12_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; @@ -688,18 +701,6 @@ static void execute_command_list(command_list_type list_type, kope_g5_device *de 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); } diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h index 63a53864c..2594620f0 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/device_functions.h @@ -19,7 +19,7 @@ void kope_d3d12_device_set_name(kope_g5_device *device, const char *name); void kope_d3d12_device_create_buffer(kope_g5_device *device, const kope_g5_buffer_parameters *parameters, kope_g5_buffer *buffer); -void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_command_list *list); +void kope_d3d12_device_create_command_list(kope_g5_device *device, kope_g5_command_list_type type, kope_g5_command_list *list); void kope_d3d12_device_create_texture(kope_g5_device *device, const kope_g5_texture_parameters *parameters, kope_g5_texture *texture); @@ -32,10 +32,6 @@ 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, diff --git a/Sources/kope/graphics5/device.c b/Sources/kope/graphics5/device.c index a99b00df3..980dec9e7 100644 --- a/Sources/kope/graphics5/device.c +++ b/Sources/kope/graphics5/device.c @@ -29,8 +29,8 @@ void kope_g5_device_create_buffer(kope_g5_device *device, const kope_g5_buffer_p KOPE_G5_CALL3(device_create_buffer, device, parameters, buffer); } -void kope_g5_device_create_command_list(kope_g5_device *device, kope_g5_command_list *list) { - KOPE_G5_CALL2(device_create_command_list, device, list); +void kope_g5_device_create_command_list(kope_g5_device *device, kope_g5_command_list_type type, kope_g5_command_list *list) { + KOPE_G5_CALL3(device_create_command_list, device, type, list); } void kope_g5_device_create_texture(kope_g5_device *device, const kope_g5_texture_parameters *parameters, kope_g5_texture *texture) { @@ -56,14 +56,6 @@ 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); } diff --git a/Sources/kope/graphics5/device.h b/Sources/kope/graphics5/device.h index f8eee7e7a..601d415ad 100644 --- a/Sources/kope/graphics5/device.h +++ b/Sources/kope/graphics5/device.h @@ -117,7 +117,13 @@ typedef struct kope_g5_sampler_parameters { KOPE_FUNC void kope_g5_device_create_sampler(kope_g5_device *device, const kope_g5_sampler_parameters *parameters, kope_g5_sampler *sampler); -KOPE_FUNC void kope_g5_device_create_command_list(kope_g5_device *device, kope_g5_command_list *list); +typedef enum kope_g5_command_list_type { + KOPE_G5_COMMAND_LIST_TYPE_GRAPHICS, + KOPE_G5_COMMAND_LIST_TYPE_ASYNC, + KOPE_G5_COMMAND_LIST_TYPE_COPY +} kope_g5_command_list_type; + +KOPE_FUNC void kope_g5_device_create_command_list(kope_g5_device *device, kope_g5_command_list_type type, kope_g5_command_list *list); typedef struct kope_g5_query_set { KOPE_G5_IMPL(query_set); @@ -134,10 +140,6 @@ 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 {