Signed-off-by: Philip Rebohle philip.rebohle@tu-dortmund.de --- libs/vkd3d/device.c | 1 + libs/vkd3d/vkd3d_private.h | 1 + libs/vkd3d/vulkan_procs.h | 4 ++++ 3 files changed, 6 insertions(+)
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 5239911..ddec0f7 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -151,6 +151,7 @@ static const struct vkd3d_optional_extension_info optional_device_extensions[] = { /* KHR extensions */ {VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, KHR_dedicated_allocation)}, + {VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, KHR_draw_indirect_count)}, {VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, KHR_get_memory_requirements2)}, {VK_KHR_MAINTENANCE3_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, KHR_maintenance3)}, {VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, KHR_push_descriptor)}, diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 0f0d77f..036b9eb 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -92,6 +92,7 @@ struct vkd3d_vulkan_info
/* KHR device extensions */ bool KHR_dedicated_allocation; + bool KHR_draw_indirect_count; bool KHR_get_memory_requirements2; bool KHR_maintenance3; bool KHR_push_descriptor; diff --git a/libs/vkd3d/vulkan_procs.h b/libs/vkd3d/vulkan_procs.h index 38ead47..a55fb07 100644 --- a/libs/vkd3d/vulkan_procs.h +++ b/libs/vkd3d/vulkan_procs.h @@ -177,6 +177,10 @@ VK_DEVICE_PFN(vkUnmapMemory) VK_DEVICE_PFN(vkUpdateDescriptorSets) VK_DEVICE_PFN(vkWaitForFences)
+/* VK_KHR_draw_indirect_count */ +VK_DEVICE_EXT_PFN(vkCmdDrawIndirectCountKHR); +VK_DEVICE_EXT_PFN(vkCmdDrawIndexedIndirectCountKHR); + /* VK_KHR_get_memory_requirements2 */ VK_DEVICE_EXT_PFN(vkGetBufferMemoryRequirements2KHR) VK_DEVICE_EXT_PFN(vkGetImageMemoryRequirements2KHR)
Used by Resident Evil 2.
Signed-off-by: Philip Rebohle philip.rebohle@tu-dortmund.de --- libs/vkd3d/command.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 9187ad0..d3ec387 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -4873,6 +4873,7 @@ static void STDMETHODCALLTYPE d3d12_command_list_ExecuteIndirect(ID3D12GraphicsC { struct d3d12_command_signature *sig_impl = unsafe_impl_from_ID3D12CommandSignature(command_signature); struct d3d12_resource *arg_impl = unsafe_impl_from_ID3D12Resource(arg_buffer); + struct d3d12_resource *count_impl = unsafe_impl_from_ID3D12Resource(count_buffer); struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList1(iface); const D3D12_COMMAND_SIGNATURE_DESC *signature_desc; const struct vkd3d_vk_device_procs *vk_procs; @@ -4885,9 +4886,9 @@ static void STDMETHODCALLTYPE d3d12_command_list_ExecuteIndirect(ID3D12GraphicsC
vk_procs = &list->device->vk_procs;
- if (count_buffer) + if (count_buffer && !list->device->vk_info.KHR_draw_indirect_count) { - FIXME("Count buffers not implemented.\n"); + FIXME("Count buffers not supported by Vulkan implementation.\n"); return; }
@@ -4905,8 +4906,14 @@ static void STDMETHODCALLTYPE d3d12_command_list_ExecuteIndirect(ID3D12GraphicsC break; }
- VK_CALL(vkCmdDrawIndirect(list->vk_command_buffer, arg_impl->u.vk_buffer, - arg_buffer_offset, max_command_count, signature_desc->ByteStride)); + if (!count_buffer) { + VK_CALL(vkCmdDrawIndirect(list->vk_command_buffer, arg_impl->u.vk_buffer, + arg_buffer_offset, max_command_count, signature_desc->ByteStride)); + } else { + VK_CALL(vkCmdDrawIndirectCountKHR(list->vk_command_buffer, arg_impl->u.vk_buffer, + arg_buffer_offset, count_impl->u.vk_buffer, count_buffer_offset, + max_command_count, signature_desc->ByteStride)); + } break;
case D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED: @@ -4918,14 +4925,25 @@ static void STDMETHODCALLTYPE d3d12_command_list_ExecuteIndirect(ID3D12GraphicsC
d3d12_command_list_check_index_buffer_strip_cut_value(list);
- VK_CALL(vkCmdDrawIndexedIndirect(list->vk_command_buffer, arg_impl->u.vk_buffer, - arg_buffer_offset, max_command_count, signature_desc->ByteStride)); + if (!count_buffer) { + VK_CALL(vkCmdDrawIndexedIndirect(list->vk_command_buffer, arg_impl->u.vk_buffer, + arg_buffer_offset, max_command_count, signature_desc->ByteStride)); + } else { + VK_CALL(vkCmdDrawIndexedIndirectCountKHR(list->vk_command_buffer, arg_impl->u.vk_buffer, + arg_buffer_offset, count_impl->u.vk_buffer, count_buffer_offset, + max_command_count, signature_desc->ByteStride)); + } break;
case D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH: if (max_command_count != 1) FIXME("Ignoring command count %u.\n", max_command_count);
+ if (count_buffer) { + WARN("Count buffers not supported for indirect dispatch.\n"); + break; + } + if (list->state->vk_bind_point != VK_PIPELINE_BIND_POINT_COMPUTE) { WARN("Pipeline state %p has bind point %#x, ignoring dispatch.\n",
Thanks for the patches. I submitted a v2 with some modifications.
On Sat, May 18, 2019 at 4:34 PM Philip Rebohle philip.rebohle@tu-dortmund.de wrote:
VK_CALL(vkCmdDrawIndirect(list->vk_command_buffer, arg_impl->u.vk_buffer,
arg_buffer_offset, max_command_count, signature_desc->ByteStride));
if (!count_buffer) {
VK_CALL(vkCmdDrawIndirect(list->vk_command_buffer, arg_impl->u.vk_buffer,
arg_buffer_offset, max_command_count, signature_desc->ByteStride));
} else {
VK_CALL(vkCmdDrawIndirectCountKHR(list->vk_command_buffer, arg_impl->u.vk_buffer,
arg_buffer_offset, count_impl->u.vk_buffer, count_buffer_offset,
max_command_count, signature_desc->ByteStride));
} break;
Coding style.
if (count_buffer) {
WARN("Count buffers not supported for indirect dispatch.\n");
break;
}
We use FIXME() for missing functionality.
Signed-off-by: Philip Rebohle philip.rebohle@tu-dortmund.de --- tests/d3d12.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/tests/d3d12.c b/tests/d3d12.c index c7dfd8a..4f8e8f5 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -21557,7 +21557,7 @@ static void test_execute_indirect(void) D3D12_ROOT_SIGNATURE_DESC root_signature_desc; ID3D12CommandSignature *command_signature; ID3D12GraphicsCommandList *command_list; - ID3D12Resource *argument_buffer, *uav; + ID3D12Resource *argument_buffer, *count_buffer, *uav; D3D12_INPUT_LAYOUT_DESC input_layout; D3D12_ROOT_PARAMETER root_parameter; ID3D12PipelineState *pipeline_state; @@ -21682,6 +21682,7 @@ static void test_execute_indirect(void) {2, 3, 4}, {{6, 1, 0, 0, 0}, {6, 1, 0, 4, 0}}, }; + static const uint32_t count_data[] = {1, 2}; static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
memset(&desc, 0, sizeof(desc)); @@ -21692,6 +21693,7 @@ static void test_execute_indirect(void) queue = context.queue;
argument_buffer = create_upload_buffer(context.device, sizeof(argument_data), &argument_data); + count_buffer = create_upload_buffer(context.device, sizeof(count_data), count_data);
command_signature = create_command_signature(context.device, D3D12_INDIRECT_ARGUMENT_TYPE_DRAW);
@@ -21711,6 +21713,23 @@ static void test_execute_indirect(void)
reset_command_list(command_list, context.allocator);
+ ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL); + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_ExecuteIndirect(command_list, command_signature, 1, argument_buffer, 0, + count_buffer, 0); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + check_sub_resource_uint(context.render_target, 0, queue, command_list, 0xff00ff00, 0); + + reset_command_list(command_list, context.allocator); + ID3D12CommandSignature_Release(command_signature); command_signature = create_command_signature(context.device, D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH);
@@ -21796,6 +21815,36 @@ static void test_execute_indirect(void) check_readback_data_uint(&rb, &box, 0xff00ff00, 0); release_resource_readback(&rb);
+ reset_command_list(command_list, context.allocator); + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); + + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL); + + ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, context.root_signature); + ID3D12GraphicsCommandList_SetPipelineState(command_list, context.pipeline_state); + ID3D12GraphicsCommandList_IASetPrimitiveTopology(command_list, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D12GraphicsCommandList_IASetIndexBuffer(command_list, &ibv); + ID3D12GraphicsCommandList_IASetVertexBuffers(command_list, 0, 1, &vbv); + ID3D12GraphicsCommandList_RSSetViewports(command_list, 1, &context.viewport); + ID3D12GraphicsCommandList_RSSetScissorRects(command_list, 1, &context.scissor_rect); + ID3D12GraphicsCommandList_OMSetRenderTargets(command_list, 1, &context.rtv, FALSE, NULL); + ID3D12GraphicsCommandList_ExecuteIndirect(command_list, command_signature, + ARRAY_SIZE(argument_data.indexed_draws), argument_buffer, + offsetof(struct argument_data, indexed_draws), count_buffer, + sizeof(uint32_t)); + + transition_resource_state(command_list, context.render_target, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + get_texture_readback_with_command_list(context.render_target, 0, &rb, queue, command_list); + set_box(&box, 0, 0, 0, 32, 8, 1); + check_readback_data_uint(&rb, &box, 0xffffff00, 0); + set_box(&box, 24, 8, 0, 32, 32, 1); + check_readback_data_uint(&rb, &box, 0xffffff00, 0); + set_box(&box, 0, 8, 0, 24, 32, 1); + check_readback_data_uint(&rb, &box, 0xff00ff00, 0); + release_resource_readback(&rb); + ID3D12PipelineState_Release(pipeline_state); ID3D12RootSignature_Release(root_signature); ID3D12Resource_Release(ib); @@ -21803,6 +21852,7 @@ static void test_execute_indirect(void) ID3D12Resource_Release(vb); ID3D12CommandSignature_Release(command_signature); ID3D12Resource_Release(argument_buffer); + ID3D12Resource_Release(count_buffer); destroy_test_context(&context); }
On Sat, May 18, 2019 at 4:34 PM Philip Rebohle philip.rebohle@tu-dortmund.de wrote:
Signed-off-by: Philip Rebohle philip.rebohle@tu-dortmund.de
tests/d3d12.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)
The test isn't very interesting. The test succeeds even with a dummy implementation that ignores count buffers.
diff --git a/tests/d3d12.c b/tests/d3d12.c index c7dfd8a..4f8e8f5 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -21557,7 +21557,7 @@ static void test_execute_indirect(void) D3D12_ROOT_SIGNATURE_DESC root_signature_desc; ID3D12CommandSignature *command_signature; ID3D12GraphicsCommandList *command_list;
- ID3D12Resource *argument_buffer, *uav;
- ID3D12Resource *argument_buffer, *count_buffer, *uav; D3D12_INPUT_LAYOUT_DESC input_layout; D3D12_ROOT_PARAMETER root_parameter; ID3D12PipelineState *pipeline_state;
@@ -21682,6 +21682,7 @@ static void test_execute_indirect(void) {2, 3, 4}, {{6, 1, 0, 0, 0}, {6, 1, 0, 4, 0}}, };
static const uint32_t count_data[] = {1, 2}; static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
memset(&desc, 0, sizeof(desc));
@@ -21692,6 +21693,7 @@ static void test_execute_indirect(void) queue = context.queue;
argument_buffer = create_upload_buffer(context.device, sizeof(argument_data), &argument_data);
count_buffer = create_upload_buffer(context.device, sizeof(count_data), count_data);
command_signature = create_command_signature(context.device, D3D12_INDIRECT_ARGUMENT_TYPE_DRAW);
@@ -21711,6 +21713,23 @@ static void test_execute_indirect(void)
reset_command_list(command_list, context.allocator);
- ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, context.rtv, white, 0, NULL);
The render target should be transitioned from D3D12_RESOURCE_STATE_COPY_SOURCE to D3D12_RESOURCE_STATE_RENDER_TARGET.