From 72f723522e25ab75639aafc57d4beed10b4704a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Fri, 28 Jul 2017 10:19:37 +0200 Subject: [PATCH] libs/vkd3d: Implement d3d12_command_list_SetComputeRoot32BitConstant(). --- libs/vkd3d/command.c | 33 ++++++++++++++++++++++++++++++++- libs/vkd3d/state.c | 17 ++++++++++++++++- libs/vkd3d/vkd3d_private.h | 10 ++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 065877c6..8784f52e 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -2337,11 +2337,42 @@ static void STDMETHODCALLTYPE d3d12_command_list_SetGraphicsRootDescriptorTable( root_parameter_index, base_descriptor); } +static void d3d12_command_list_set_root_constants(struct d3d12_command_list *list, + struct d3d12_root_signature *root_signature, unsigned int root_parameter_index, + unsigned int offset, unsigned int count, const void *data) +{ + const struct vkd3d_vk_device_procs *vk_procs = &list->device->vk_procs; + struct d3d12_root_constant *constant = NULL; + unsigned int i; + + for (i = 0; i < root_signature->constant_count; ++i) + { + if (root_signature->constants[i].root_parameter_index == root_parameter_index) + { + constant = &root_signature->constants[i]; + break; + } + } + if (!constant) + { + WARN("Invalid root parameter index %u.\n", root_parameter_index); + return; + } + + VK_CALL(vkCmdPushConstants(list->vk_command_buffer, root_signature->vk_pipeline_layout, + constant->stage_flags, constant->offset + offset * sizeof(uint32_t), count * sizeof(uint32_t), data)); +} + static void STDMETHODCALLTYPE d3d12_command_list_SetComputeRoot32BitConstant(ID3D12GraphicsCommandList *iface, UINT root_parameter_index, UINT data, UINT dst_offset) { - FIXME("iface %p, root_parameter_index %u, data 0x%08x, dst_offset %u stub!\n", + struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList(iface); + + TRACE("iface %p, root_parameter_index %u, data 0x%08x, dst_offset %u.\n", iface, root_parameter_index, data, dst_offset); + + d3d12_command_list_set_root_constants(list, list->compute_root_signature, + root_parameter_index, dst_offset, 1, &data); } static void STDMETHODCALLTYPE d3d12_command_list_SetGraphicsRoot32BitConstant(ID3D12GraphicsCommandList *iface, diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index edfa5104..4adf8599 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -74,6 +74,8 @@ static void d3d12_root_signature_cleanup(struct d3d12_root_signature *root_signa if (root_signature->descriptor_mapping) vkd3d_free(root_signature->descriptor_mapping); + if (root_signature->constants) + vkd3d_free(root_signature->constants); for (i = 0; i < root_signature->static_sampler_count; ++i) { @@ -335,6 +337,7 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa root_signature->pool_sizes = NULL; root_signature->vk_set_layout = VK_NULL_HANDLE; root_signature->descriptor_mapping = NULL; + root_signature->constants = NULL; root_signature->static_sampler_count = 0; root_signature->static_samplers = NULL; @@ -396,6 +399,13 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa hr = E_OUTOFMEMORY; goto fail; } + root_signature->constant_count = push_count; + if (!(root_signature->constants = vkd3d_calloc(root_signature->constant_count, + sizeof(*root_signature->constants)))) + { + hr = E_OUTOFMEMORY; + goto fail; + } /* Map root constants to push constants. */ for (i = 0, j = 0; i < desc->NumParameters; ++i) @@ -414,7 +424,12 @@ static HRESULT d3d12_root_signature_init(struct d3d12_root_signature *root_signa push_constants[j].stageFlags = stage_flags_from_visibility(p->ShaderVisibility); push_constants[j].offset = 0; - push_constants[j].size = 4 * p->u.Constants.Num32BitValues; + push_constants[j].size = p->u.Constants.Num32BitValues * sizeof(uint32_t); + + root_signature->constants[j].root_parameter_index = i; + root_signature->constants[j].stage_flags = push_constants[j].stageFlags; + root_signature->constants[j].offset = push_constants[j].offset; + ++j; } diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 981c7c2a..fc6ae335 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -262,6 +262,13 @@ struct d3d12_query_heap HRESULT d3d12_query_heap_create(struct d3d12_device *device, struct d3d12_query_heap **heap) DECLSPEC_HIDDEN; +struct d3d12_root_constant +{ + unsigned int root_parameter_index; + VkShaderStageFlags stage_flags; + uint32_t offset; +}; + /* ID3D12RootSignature */ struct d3d12_root_signature { @@ -277,6 +284,9 @@ struct d3d12_root_signature unsigned int descriptor_count; struct vkd3d_shader_resource_binding *descriptor_mapping; + unsigned int constant_count; + struct d3d12_root_constant *constants; + unsigned int static_sampler_count; VkSampler *static_samplers;