mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
Vulkan: Support binding texel buffers in UtilityShaderDraw
This commit is contained in:
@ -364,6 +364,15 @@ void UtilityShaderDraw::SetPSSampler(size_t index, VkImageView view, VkSampler s
|
||||
m_ps_samplers[index].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
}
|
||||
|
||||
void UtilityShaderDraw::SetPSTexelBuffer(VkBufferView view)
|
||||
{
|
||||
// Should only be used with the texture conversion pipeline layout.
|
||||
_assert_(m_pipeline_info.pipeline_layout ==
|
||||
g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_TEXTURE_CONVERSION));
|
||||
|
||||
m_ps_texel_buffer = view;
|
||||
}
|
||||
|
||||
void UtilityShaderDraw::SetRasterizationState(const RasterizationState& state)
|
||||
{
|
||||
m_pipeline_info.rasterization_state.bits = state.bits;
|
||||
@ -600,29 +609,59 @@ void UtilityShaderDraw::BindDescriptors()
|
||||
vkUpdateDescriptorSets(g_vulkan_context->GetDevice(), num_set_writes, set_writes.data(), 0,
|
||||
nullptr);
|
||||
|
||||
// Bind only the sets we updated
|
||||
if (bind_descriptor_sets[0] != VK_NULL_HANDLE && bind_descriptor_sets[1] == VK_NULL_HANDLE)
|
||||
if (m_ps_texel_buffer != VK_NULL_HANDLE)
|
||||
{
|
||||
// UBO only
|
||||
// TODO: Handle case where this fails.
|
||||
// This'll only be when we do over say, 1024 allocations per frame, which shouldn't happen.
|
||||
// TODO: Execute the command buffer, reset render passes and then try again.
|
||||
VkDescriptorSet set = g_command_buffer_mgr->AllocateDescriptorSet(
|
||||
g_object_cache->GetDescriptorSetLayout(DESCRIPTOR_SET_LAYOUT_TEXEL_BUFFERS));
|
||||
if (set == VK_NULL_HANDLE)
|
||||
{
|
||||
PanicAlert("Failed to allocate texel buffer descriptor set for utility draw");
|
||||
return;
|
||||
}
|
||||
|
||||
VkWriteDescriptorSet set_write = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
nullptr,
|
||||
set,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&m_ps_texel_buffer};
|
||||
vkUpdateDescriptorSets(g_vulkan_context->GetDevice(), 1, &set_write, 0, nullptr);
|
||||
bind_descriptor_sets[DESCRIPTOR_SET_BIND_POINT_STORAGE_OR_TEXEL_BUFFER] = set;
|
||||
}
|
||||
|
||||
// Fast path when there are no gaps in the set bindings
|
||||
u32 bind_point_index;
|
||||
for (bind_point_index = 0; bind_point_index < NUM_DESCRIPTOR_SET_BIND_POINTS; bind_point_index++)
|
||||
{
|
||||
if (bind_descriptor_sets[bind_point_index] == VK_NULL_HANDLE)
|
||||
break;
|
||||
}
|
||||
if (bind_point_index > 0)
|
||||
{
|
||||
// Bind the contiguous sets, any others after any gaps will be handled below
|
||||
vkCmdBindDescriptorSets(m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
m_pipeline_info.pipeline_layout,
|
||||
DESCRIPTOR_SET_BIND_POINT_UNIFORM_BUFFERS, 1, &bind_descriptor_sets[0],
|
||||
NUM_UBO_DESCRIPTOR_SET_BINDINGS, m_ubo_offsets.data());
|
||||
m_pipeline_info.pipeline_layout, 0, bind_point_index,
|
||||
&bind_descriptor_sets[0], NUM_UBO_DESCRIPTOR_SET_BINDINGS,
|
||||
m_ubo_offsets.data());
|
||||
}
|
||||
else if (bind_descriptor_sets[0] == VK_NULL_HANDLE && bind_descriptor_sets[1] != VK_NULL_HANDLE)
|
||||
|
||||
// Handle any remaining sets
|
||||
for (u32 i = bind_point_index; i < NUM_DESCRIPTOR_SET_BIND_POINTS; i++)
|
||||
{
|
||||
// Samplers only
|
||||
vkCmdBindDescriptorSets(
|
||||
m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline_info.pipeline_layout,
|
||||
DESCRIPTOR_SET_BIND_POINT_PIXEL_SHADER_SAMPLERS, 1, &bind_descriptor_sets[1], 0, nullptr);
|
||||
}
|
||||
else if (bind_descriptor_sets[0] != VK_NULL_HANDLE && bind_descriptor_sets[1] != VK_NULL_HANDLE)
|
||||
{
|
||||
// Both
|
||||
vkCmdBindDescriptorSets(
|
||||
m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline_info.pipeline_layout,
|
||||
DESCRIPTOR_SET_BIND_POINT_UNIFORM_BUFFERS, 2, bind_descriptor_sets.data(),
|
||||
NUM_UBO_DESCRIPTOR_SET_BINDINGS, m_ubo_offsets.data());
|
||||
if (bind_descriptor_sets[i] == VK_NULL_HANDLE)
|
||||
continue;
|
||||
|
||||
// No need to worry about dynamic offsets here, since #0 will always be bound above.
|
||||
vkCmdBindDescriptorSets(m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
m_pipeline_info.pipeline_layout, i, 1, &bind_descriptor_sets[i], 0,
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user