From 75589de0a4a880f7792ddafede2a1a43e5371257 Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Mon, 27 Oct 2025 18:42:50 +0900 Subject: [PATCH] [Vulkan] Ensure descriptor sets always initialized for user_clip_planes --- .../gpu/vulkan/vulkan_command_processor.cc | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/xenia/gpu/vulkan/vulkan_command_processor.cc b/src/xenia/gpu/vulkan/vulkan_command_processor.cc index 6be391fa0..fddf8d3bf 100644 --- a/src/xenia/gpu/vulkan/vulkan_command_processor.cc +++ b/src/xenia/gpu/vulkan/vulkan_command_processor.cc @@ -4475,27 +4475,32 @@ bool VulkanCommandProcessor::UpdateBindings(const VulkanShader* vertex_shader, UINT32_C(1) << SpirvShaderTranslator::kConstantBufferSystem; } // Clip plane constants. - auto pa_cl_clip_cntl = regs.Get(); - bool clip_planes_enabled = - !pa_cl_clip_cntl.clip_disable && pa_cl_clip_cntl.ucp_ena; - if (clip_planes_enabled) { - if (!(current_constant_buffers_up_to_date_ & - (UINT32_C(1) - << SpirvShaderTranslator::kConstantBufferClipPlanes))) { - VkDescriptorBufferInfo& buffer_info = current_constant_buffer_infos_ - [SpirvShaderTranslator::kConstantBufferClipPlanes]; - uint8_t* mapping = uniform_buffer_pool_->Request( - frame_current_, sizeof(SpirvShaderTranslator::ClipPlaneConstants), - uniform_buffer_alignment, buffer_info.buffer, buffer_info.offset); - if (!mapping) { - return false; - } - buffer_info.range = sizeof(SpirvShaderTranslator::ClipPlaneConstants); + // Always initialize the buffer info, even if clip planes are disabled, + // because the descriptor set write always includes all constant buffers. + if (!(current_constant_buffers_up_to_date_ & + (UINT32_C(1) << SpirvShaderTranslator::kConstantBufferClipPlanes))) { + VkDescriptorBufferInfo& buffer_info = current_constant_buffer_infos_ + [SpirvShaderTranslator::kConstantBufferClipPlanes]; + uint8_t* mapping = uniform_buffer_pool_->Request( + frame_current_, sizeof(SpirvShaderTranslator::ClipPlaneConstants), + uniform_buffer_alignment, buffer_info.buffer, buffer_info.offset); + if (!mapping) { + return false; + } + buffer_info.range = sizeof(SpirvShaderTranslator::ClipPlaneConstants); + auto pa_cl_clip_cntl = regs.Get(); + bool clip_planes_enabled = + !pa_cl_clip_cntl.clip_disable && pa_cl_clip_cntl.ucp_ena; + if (clip_planes_enabled) { std::memcpy(mapping, &clip_plane_constants_, sizeof(SpirvShaderTranslator::ClipPlaneConstants)); - current_constant_buffers_up_to_date_ |= - UINT32_C(1) << SpirvShaderTranslator::kConstantBufferClipPlanes; + } else { + // Zero out the buffer when clip planes are disabled + std::memset(mapping, 0, + sizeof(SpirvShaderTranslator::ClipPlaneConstants)); } + current_constant_buffers_up_to_date_ |= + UINT32_C(1) << SpirvShaderTranslator::kConstantBufferClipPlanes; } // Vertex shader float constants. if (!(current_constant_buffers_up_to_date_ &