vk: Use UBO for basic transform constants

- Instancing still uses SSBOs, but that's ok. 95% of draw calls are uninstanced anyway.
This commit is contained in:
kd-11
2026-04-30 04:27:11 +03:00
committed by kd-11
parent 5144a999b3
commit 91a8c56c37
2 changed files with 7 additions and 5 deletions
+5 -3
View File
@@ -513,7 +513,7 @@ VKGSRender::VKGSRender(utils::serial* ar) noexcept : GSRender(ar)
m_fragment_texture_params_ring_info.create(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_UBO_RING_BUFFER_SIZE_M * 0x100000, vk::heap_pool_low_latency, "fragment texture params buffer", 0x10000, VK_TRUE);
m_vertex_layout_ring_info.create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_UBO_RING_BUFFER_SIZE_M * 0x100000, vk::heap_pool_low_latency, "vertex layout buffer", 0x10000, VK_TRUE);
m_fragment_constants_ring_info.create(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_UBO_RING_BUFFER_SIZE_M * 0x100000, vk::heap_pool_low_latency, "fragment constants buffer", 0x10000, VK_TRUE);
m_transform_constants_ring_info.create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_TRANSFORM_CONSTANTS_BUFFER_SIZE_M * 0x100000, vk::heap_pool_default, "transform constants buffer", 0x10000, VK_TRUE);
m_transform_constants_ring_info.create(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_TRANSFORM_CONSTANTS_BUFFER_SIZE_M * 0x100000, vk::heap_pool_default, "transform constants buffer", 0x10000, VK_TRUE);
m_raster_env_ring_info.create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_UBO_RING_BUFFER_SIZE_M * 0x100000, vk::heap_pool_low_latency, "raster env buffer", 0x10000, VK_TRUE);
// Below here, we do not bind these persistently. Each draw call specifies the range manually so we do not need heap_grow notifications.
m_instancing_buffer_ring_info.create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_TRANSFORM_CONSTANTS_BUFFER_SIZE_M * 0x100000, vk::heap_pool_default, "instancing data buffer");
@@ -2006,8 +2006,7 @@ void VKGSRender::load_program_env()
usz mem_offset = 0;
auto alloc_storage = [&](usz size) -> std::pair<void*, usz>
{
const auto alignment = m_device->gpu().get_limits().minStorageBufferOffsetAlignment;
mem_offset = m_transform_constants_ring_info.alloc<1>(utils::align(size, alignment));
mem_offset = m_transform_constants_ring_info.alloc<256>(size);
return std::make_pair(m_transform_constants_ring_info.map(mem_offset, size), size);
};
@@ -2018,6 +2017,9 @@ void VKGSRender::load_program_env()
{
m_transform_constants_ring_info.unmap();
m_xform_constants_dynamic_offset = mem_offset;
m_vertex_constants_buffer_info = m_transform_constants_ring_info.window<16>(m_xform_constants_dynamic_offset, io_buf.size(), gpu_limits.maxUniformBufferRange);
m_xform_constants_dynamic_offset -= m_vertex_constants_buffer_info.offset;
}
}
+2 -2
View File
@@ -199,14 +199,14 @@ void VKVertexDecompilerThread::insertConstants(std::stringstream & OS, const std
{
if (!(m_prog.ctrl & RSX_SHADER_CONTROL_INSTANCED_CONSTANTS))
{
OS << "layout(std430, set=0, binding=" << vk_prog->binding_table.cbuf_location << ") readonly restrict buffer VertexConstantsBuffer\n";
OS << "layout(std430, set=0, binding=" << vk_prog->binding_table.cbuf_location << ") uniform VertexConstantsBuffer\n";
OS << "{\n";
OS << " vec4 vc[];\n";
OS << "};\n\n";
in.location = vk_prog->binding_table.cbuf_location;
in.name = "VertexConstantsBuffer";
in.type = vk::glsl::input_type_storage_buffer;
in.type = vk::glsl::input_type_uniform_buffer;
inputs.push_back(in);
continue;