Signed-off-by: Conor McCarthy cmccarthy@codeweavers.com --- libs/vkd3d/command.c | 19 ++++----- libs/vkd3d/state.c | 80 ++++++++++++++++++-------------------- libs/vkd3d/vkd3d_private.h | 17 +++++--- 3 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 116a8a62..614d19e7 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -1862,13 +1862,13 @@ static void d3d12_command_list_invalidate_current_render_pass(struct d3d12_comma static void d3d12_command_list_invalidate_bindings(struct d3d12_command_list *list, struct d3d12_pipeline_state *state) { - if (state && state->uav_counter_count) + if (state && state->uav_counters.binding_count) { enum vkd3d_pipeline_bind_point bind_point = (enum vkd3d_pipeline_bind_point)state->vk_bind_point; struct vkd3d_pipeline_bindings *bindings = &list->pipeline_bindings[bind_point];
vkd3d_array_reserve((void **)&bindings->vk_uav_counter_views, &bindings->vk_uav_counter_views_size, - state->uav_counter_count, sizeof(*bindings->vk_uav_counter_views)); + state->uav_counters.binding_count, sizeof(*bindings->vk_uav_counter_views)); bindings->uav_counters_dirty = true; } } @@ -2694,10 +2694,10 @@ static void d3d12_command_list_update_descriptor_table(struct d3d12_command_list /* Track UAV counters. */ if (range->descriptor_magic == VKD3D_DESCRIPTOR_MAGIC_UAV) { - for (k = 0; k < state->uav_counter_count; ++k) + for (k = 0; k < state->uav_counters.binding_count; ++k) { - if (state->uav_counters[k].register_space == range->register_space - && state->uav_counters[k].register_index == register_idx) + if (state->uav_counters.bindings[k].register_space == range->register_space + && state->uav_counters.bindings[k].register_index == register_idx) { VkBufferView vk_counter_view = descriptor->magic == VKD3D_DESCRIPTOR_MAGIC_UAV ? descriptor->u.view->vk_counter_view : VK_NULL_HANDLE; @@ -2850,15 +2850,16 @@ static void d3d12_command_list_update_uav_counter_descriptors(struct d3d12_comma if (!state || !bindings->uav_counters_dirty) return;
- uav_counter_count = state->uav_counter_count; + uav_counter_count = state->uav_counters.binding_count; if (!(vk_descriptor_writes = vkd3d_calloc(uav_counter_count, sizeof(*vk_descriptor_writes)))) return; - if (!(vk_descriptor_set = d3d12_command_allocator_allocate_descriptor_set(list->allocator, state->vk_set_layout))) + if (!(vk_descriptor_set = d3d12_command_allocator_allocate_descriptor_set(list->allocator, + state->uav_counters.vk_set_layout))) goto done;
for (i = 0; i < uav_counter_count; ++i) { - const struct vkd3d_shader_uav_counter_binding *uav_counter = &state->uav_counters[i]; + const struct vkd3d_shader_uav_counter_binding *uav_counter = &state->uav_counters.bindings[i]; const VkBufferView *vk_uav_counter_views = bindings->vk_uav_counter_views;
assert(vk_uav_counter_views[i]); @@ -2878,7 +2879,7 @@ static void d3d12_command_list_update_uav_counter_descriptors(struct d3d12_comma VK_CALL(vkUpdateDescriptorSets(vk_device, uav_counter_count, vk_descriptor_writes, 0, NULL));
VK_CALL(vkCmdBindDescriptorSets(list->vk_command_buffer, bindings->vk_bind_point, - state->vk_pipeline_layout, state->set_index, 1, &vk_descriptor_set, 0, NULL)); + state->uav_counters.vk_pipeline_layout, state->uav_counters.set_index, 1, &vk_descriptor_set, 0, NULL));
bindings->uav_counters_dirty = false;
diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 4537e319..29121e5f 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1190,6 +1190,19 @@ static void d3d12_pipeline_state_destroy_graphics(struct d3d12_pipeline_state *s } }
+static void d3d12_pipeline_uav_counter_state_cleanup(struct d3d12_pipeline_uav_counter_state *uav_counters, + struct d3d12_device *device) +{ + const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; + + if (uav_counters->vk_set_layout) + VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, uav_counters->vk_set_layout, NULL)); + if (uav_counters->vk_pipeline_layout) + VK_CALL(vkDestroyPipelineLayout(device->vk_device, uav_counters->vk_pipeline_layout, NULL)); + + vkd3d_free(uav_counters->bindings); +} + static ULONG STDMETHODCALLTYPE d3d12_pipeline_state_Release(ID3D12PipelineState *iface) { struct d3d12_pipeline_state *state = impl_from_ID3D12PipelineState(iface); @@ -1209,12 +1222,7 @@ static ULONG STDMETHODCALLTYPE d3d12_pipeline_state_Release(ID3D12PipelineState else if (d3d12_pipeline_state_is_compute(state)) VK_CALL(vkDestroyPipeline(device->vk_device, state->u.compute.vk_pipeline, NULL));
- if (state->vk_set_layout) - VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, state->vk_set_layout, NULL)); - if (state->vk_pipeline_layout) - VK_CALL(vkDestroyPipelineLayout(device->vk_device, state->vk_pipeline_layout, NULL)); - - vkd3d_free(state->uav_counters); + d3d12_pipeline_uav_counter_state_cleanup(&state->uav_counters, device);
vkd3d_free(state);
@@ -1452,12 +1460,12 @@ static HRESULT d3d12_pipeline_state_init_uav_counters(struct d3d12_pipeline_stat
if (!(binding_desc = vkd3d_calloc(uav_counter_count, sizeof(*binding_desc)))) return E_OUTOFMEMORY; - if (!(state->uav_counters = vkd3d_calloc(uav_counter_count, sizeof(*state->uav_counters)))) + if (!(state->uav_counters.bindings = vkd3d_calloc(uav_counter_count, sizeof(*state->uav_counters.bindings)))) { vkd3d_free(binding_desc); return E_OUTOFMEMORY; } - state->uav_counter_count = uav_counter_count; + state->uav_counters.binding_count = uav_counter_count;
descriptor_binding = 0; for (set_index = 0; set_index < root_signature->vk_set_count; ++set_index) @@ -1471,13 +1479,13 @@ static HRESULT d3d12_pipeline_state_init_uav_counters(struct d3d12_pipeline_stat || !(d->flags & VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_COUNTER)) continue;
- state->uav_counters[j].register_space = d->register_space; - state->uav_counters[j].register_index = d->register_index; - state->uav_counters[j].shader_visibility = (stage_flags == VK_SHADER_STAGE_COMPUTE_BIT) + state->uav_counters.bindings[j].register_space = d->register_space; + state->uav_counters.bindings[j].register_index = d->register_index; + state->uav_counters.bindings[j].shader_visibility = (stage_flags == VK_SHADER_STAGE_COMPUTE_BIT) ? VKD3D_SHADER_VISIBILITY_COMPUTE : VKD3D_SHADER_VISIBILITY_PIXEL; - state->uav_counters[j].binding.set = set_index; - state->uav_counters[j].binding.binding = descriptor_binding; - state->uav_counters[j].binding.count = 1; + state->uav_counters.bindings[j].binding.set = set_index; + state->uav_counters.bindings[j].binding.binding = descriptor_binding; + state->uav_counters.bindings[j].binding.count = 1;
binding_desc[j].binding = descriptor_binding; binding_desc[j].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; @@ -1491,25 +1499,25 @@ static HRESULT d3d12_pipeline_state_init_uav_counters(struct d3d12_pipeline_stat
/* Create a descriptor set layout for UAV counters. */ hr = vkd3d_create_descriptor_set_layout(device, - 0, descriptor_binding, binding_desc, &state->vk_set_layout); + 0, descriptor_binding, binding_desc, &state->uav_counters.vk_set_layout); vkd3d_free(binding_desc); if (FAILED(hr)) { - vkd3d_free(state->uav_counters); + vkd3d_free(state->uav_counters.bindings); return hr; }
/* Create a pipeline layout which is compatible for all other descriptor * sets with the root signature's pipeline layout. */ - state->set_index = set_index; - set_layouts[set_index++] = state->vk_set_layout; + state->uav_counters.set_index = set_index; + set_layouts[set_index++] = state->uav_counters.vk_set_layout; if (FAILED(hr = vkd3d_create_pipeline_layout(device, set_index, set_layouts, root_signature->push_constant_range_count, root_signature->push_constant_ranges, - &state->vk_pipeline_layout))) + &state->uav_counters.vk_pipeline_layout))) { - VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, state->vk_set_layout, NULL)); - vkd3d_free(state->uav_counters); + VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, state->uav_counters.vk_set_layout, NULL)); + vkd3d_free(state->uav_counters.bindings); return hr; }
@@ -1530,10 +1538,7 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st state->ID3D12PipelineState_iface.lpVtbl = &d3d12_pipeline_state_vtbl; state->refcount = 1;
- state->vk_pipeline_layout = VK_NULL_HANDLE; - state->vk_set_layout = VK_NULL_HANDLE; - state->uav_counters = NULL; - state->uav_counter_count = 0; + memset(&state->uav_counters, 0, sizeof(state->uav_counters));
if (!(root_signature = unsafe_impl_from_ID3D12RootSignature(desc->pRootSignature))) { @@ -1565,31 +1570,23 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st shader_interface.push_constant_buffer_count = root_signature->root_constant_count; shader_interface.combined_samplers = NULL; shader_interface.combined_sampler_count = 0; - shader_interface.uav_counters = state->uav_counters; - shader_interface.uav_counter_count = state->uav_counter_count; + shader_interface.uav_counters = state->uav_counters.bindings; + shader_interface.uav_counter_count = state->uav_counters.binding_count;
- vk_pipeline_layout = state->vk_pipeline_layout - ? state->vk_pipeline_layout : root_signature->vk_pipeline_layout; + vk_pipeline_layout = state->uav_counters.vk_pipeline_layout + ? state->uav_counters.vk_pipeline_layout : root_signature->vk_pipeline_layout; if (FAILED(hr = vkd3d_create_compute_pipeline(device, &desc->CS, &shader_interface, vk_pipeline_layout, &state->u.compute.vk_pipeline))) { WARN("Failed to create Vulkan compute pipeline, hr %#x.\n", hr); - if (state->vk_set_layout) - VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, state->vk_set_layout, NULL)); - if (state->vk_pipeline_layout) - VK_CALL(vkDestroyPipelineLayout(device->vk_device, state->vk_pipeline_layout, NULL)); - vkd3d_free(state->uav_counters); + d3d12_pipeline_uav_counter_state_cleanup(&state->uav_counters, device); return hr; }
if (FAILED(hr = vkd3d_private_store_init(&state->private_store))) { VK_CALL(vkDestroyPipeline(device->vk_device, state->u.compute.vk_pipeline, NULL)); - if (state->vk_set_layout) - VK_CALL(vkDestroyDescriptorSetLayout(device->vk_device, state->vk_set_layout, NULL)); - if (state->vk_pipeline_layout) - VK_CALL(vkDestroyPipelineLayout(device->vk_device, state->vk_pipeline_layout, NULL)); - vkd3d_free(state->uav_counters); + d3d12_pipeline_uav_counter_state_cleanup(&state->uav_counters, device); return hr; }
@@ -2075,10 +2072,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s state->ID3D12PipelineState_iface.lpVtbl = &d3d12_pipeline_state_vtbl; state->refcount = 1;
- state->vk_pipeline_layout = VK_NULL_HANDLE; - state->vk_set_layout = VK_NULL_HANDLE; - state->uav_counters = NULL; - state->uav_counter_count = 0; + memset(&state->uav_counters, 0, sizeof(state->uav_counters)); graphics->stage_count = 0;
memset(&input_signature, 0, sizeof(input_signature)); diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index b30e38e9..76a07c38 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -783,6 +783,16 @@ struct d3d12_compute_pipeline_state VkPipeline vk_pipeline; };
+struct d3d12_pipeline_uav_counter_state +{ + VkPipelineLayout vk_pipeline_layout; + VkDescriptorSetLayout vk_set_layout; + uint32_t set_index; + + struct vkd3d_shader_uav_counter_binding *bindings; + unsigned int binding_count; +}; + /* ID3D12PipelineState */ struct d3d12_pipeline_state { @@ -796,12 +806,7 @@ struct d3d12_pipeline_state } u; VkPipelineBindPoint vk_bind_point;
- VkPipelineLayout vk_pipeline_layout; - VkDescriptorSetLayout vk_set_layout; - uint32_t set_index; - - struct vkd3d_shader_uav_counter_binding *uav_counters; - unsigned int uav_counter_count; + struct d3d12_pipeline_uav_counter_state uav_counters;
struct d3d12_device *device;