mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-20 22:05:12 +00:00
rsx/gl/vulkan: Refactoring and partial vulkan rewrite
- Updates vulkan to use GPU vertex processing - Rewrites vulkan to buffer entire frames and present when first available to avoid stalls - Move more state into dynamic descriptors to reduce progam cache misses; Fix render pass conflicts before texture access - Discards incomplete cb at destruction to avoid refs to destroyed objects - Move set_viewport to the uninterruptible block before drawing in case cb is switched before we're ready - Manage frame contexts separately for easier async frame management - Avoid wasteful create-destroy cycles when sampling rtts
This commit is contained in:
parent
6a707f515e
commit
00b0311c86
11 changed files with 592 additions and 802 deletions
|
|
@ -30,17 +30,20 @@ void VKVertexDecompilerThread::insertHeader(std::stringstream &OS)
|
|||
{
|
||||
OS << "#version 450\n\n";
|
||||
OS << "#extension GL_ARB_separate_shader_objects : enable\n";
|
||||
OS << "layout(std140, set = 0, binding = 0) uniform ScaleOffsetBuffer\n";
|
||||
OS << "layout(std140, set = 0, binding = 0) uniform VertexContextBuffer\n";
|
||||
OS << "{\n";
|
||||
OS << " mat4 scaleOffsetMat;\n";
|
||||
OS << " ivec4 userClipEnabled[2];\n";
|
||||
OS << " vec4 userClipFactor[2];\n";
|
||||
OS << " mat4 scale_offset_mat;\n";
|
||||
OS << " ivec4 user_clip_enabled[2];\n";
|
||||
OS << " vec4 user_clip_factor[2];\n";
|
||||
OS << " uint transform_branch_bits;\n";
|
||||
OS << " uint vertex_base_index;\n";
|
||||
OS << " ivec4 input_attributes[16];\n";
|
||||
OS << "};\n";
|
||||
|
||||
vk::glsl::program_input in;
|
||||
in.location = SCALE_OFFSET_BIND_SLOT;
|
||||
in.domain = glsl::glsl_vertex_program;
|
||||
in.name = "ScaleOffsetBuffer";
|
||||
in.name = "VertexContextBuffer";
|
||||
in.type = vk::glsl::input_type_uniform_buffer;
|
||||
|
||||
inputs.push_back(in);
|
||||
|
|
@ -48,54 +51,21 @@ void VKVertexDecompilerThread::insertHeader(std::stringstream &OS)
|
|||
|
||||
void VKVertexDecompilerThread::insertInputs(std::stringstream & OS, const std::vector<ParamType>& inputs)
|
||||
{
|
||||
std::vector<std::tuple<size_t, std::string>> input_data;
|
||||
for (const ParamType &PT : inputs)
|
||||
{
|
||||
for (const ParamItem &PI : PT.items)
|
||||
{
|
||||
input_data.push_back(std::make_tuple(PI.location, PI.name));
|
||||
}
|
||||
}
|
||||
OS << "layout(set=0, binding=3) uniform usamplerBuffer persistent_input_stream;\n"; //Data stream with persistent vertex data (cacheable)
|
||||
OS << "layout(set=0, binding=4) uniform usamplerBuffer volatile_input_stream;\n"; //Data stream with per-draw data (registers and immediate draw data)
|
||||
|
||||
/**
|
||||
* Its is important that the locations are in the order that vertex attributes are expected.
|
||||
* If order is not adhered to, channels may be swapped leading to corruption
|
||||
*/
|
||||
vk::glsl::program_input in;
|
||||
in.location = VERTEX_BUFFERS_FIRST_BIND_SLOT;
|
||||
in.domain = glsl::glsl_vertex_program;
|
||||
in.name = "persistent_input_stream";
|
||||
in.type = vk::glsl::input_type_texel_buffer;
|
||||
this->inputs.push_back(in);
|
||||
|
||||
std::sort(input_data.begin(), input_data.end());
|
||||
|
||||
for (const std::tuple<size_t, std::string> item : input_data)
|
||||
{
|
||||
for (const ParamType &PT : inputs)
|
||||
{
|
||||
for (const ParamItem &PI : PT.items)
|
||||
{
|
||||
if (PI.name == std::get<1>(item))
|
||||
{
|
||||
vk::glsl::program_input in;
|
||||
in.location = (int)std::get<0>(item) + VERTEX_BUFFERS_FIRST_BIND_SLOT;
|
||||
in.domain = glsl::glsl_vertex_program;
|
||||
in.name = PI.name + "_buffer";
|
||||
in.type = vk::glsl::input_type_texel_buffer;
|
||||
|
||||
this->inputs.push_back(in);
|
||||
|
||||
bool is_int = false;
|
||||
for (auto &attrib : rsx_vertex_program.rsx_vertex_inputs)
|
||||
{
|
||||
if (attrib.location == std::get<0>(item))
|
||||
{
|
||||
if (attrib.int_type) is_int = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string samplerType = is_int ? "isamplerBuffer" : "samplerBuffer";
|
||||
OS << "layout(set = 0, binding=" << in.location << ")" << " uniform " << samplerType << " " << PI.name << "_buffer;\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
in.location = VERTEX_BUFFERS_FIRST_BIND_SLOT + 1;
|
||||
in.domain = glsl::glsl_vertex_program;
|
||||
in.name = "volatile_input_stream";
|
||||
in.type = vk::glsl::input_type_texel_buffer;
|
||||
this->inputs.push_back(in);
|
||||
}
|
||||
|
||||
void VKVertexDecompilerThread::insertConstants(std::stringstream & OS, const std::vector<ParamType> & constants)
|
||||
|
|
@ -103,7 +73,6 @@ void VKVertexDecompilerThread::insertConstants(std::stringstream & OS, const std
|
|||
OS << "layout(std140, set=0, binding = 1) uniform VertexConstantsBuffer\n";
|
||||
OS << "{\n";
|
||||
OS << " vec4 vc[468];\n";
|
||||
OS << " uint transform_branch_bits;\n";
|
||||
OS << "};\n\n";
|
||||
|
||||
vk::glsl::program_input in;
|
||||
|
|
@ -150,13 +119,13 @@ static const vertex_reg_info reg_table[] =
|
|||
{ "front_spec_color", true, "dst_reg4", "", false },
|
||||
{ "fog_c", true, "dst_reg5", ".xxxx", true, "", "", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_FOG },
|
||||
//Warning: With spir-v if you declare clip distance var, you must assign a value even when its disabled! Runtime does not assign a default value
|
||||
{ "gl_ClipDistance[0]", false, "dst_reg5", ".y * userClipFactor[0].x", false, "userClipEnabled[0].x > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC0 },
|
||||
{ "gl_ClipDistance[1]", false, "dst_reg5", ".z * userClipFactor[0].y", false, "userClipEnabled[0].y > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC1 },
|
||||
{ "gl_ClipDistance[2]", false, "dst_reg5", ".w * userClipFactor[0].z", false, "userClipEnabled[0].z > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC2 },
|
||||
{ "gl_ClipDistance[0]", false, "dst_reg5", ".y * user_clip_factor[0].x", false, "user_clip_enabled[0].x > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC0 },
|
||||
{ "gl_ClipDistance[1]", false, "dst_reg5", ".z * user_clip_factor[0].y", false, "user_clip_enabled[0].y > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC1 },
|
||||
{ "gl_ClipDistance[2]", false, "dst_reg5", ".w * user_clip_factor[0].z", false, "user_clip_enabled[0].z > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC2 },
|
||||
{ "gl_PointSize", false, "dst_reg6", ".x", false },
|
||||
{ "gl_ClipDistance[3]", false, "dst_reg6", ".y * userClipFactor[0].w", false, "userClipEnabled[0].w > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC3 },
|
||||
{ "gl_ClipDistance[4]", false, "dst_reg6", ".z * userClipFactor[1].x", false, "userClipEnabled[1].x > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC4 },
|
||||
{ "gl_ClipDistance[5]", false, "dst_reg6", ".w * userClipFactor[1].y", false, "userClipEnabled[1].y > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC5 },
|
||||
{ "gl_ClipDistance[3]", false, "dst_reg6", ".y * user_clip_factor[0].w", false, "user_clip_enabled[0].w > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC3 },
|
||||
{ "gl_ClipDistance[4]", false, "dst_reg6", ".z * user_clip_factor[1].x", false, "user_clip_enabled[1].x > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC4 },
|
||||
{ "gl_ClipDistance[5]", false, "dst_reg6", ".w * user_clip_factor[1].y", false, "user_clip_enabled[1].y > 0", "0.5", "", true, CELL_GCM_ATTRIB_OUTPUT_MASK_UC5 },
|
||||
{ "tc0", true, "dst_reg7", "", false, "", "", "", false, CELL_GCM_ATTRIB_OUTPUT_MASK_TEX0 },
|
||||
{ "tc1", true, "dst_reg8", "", false, "", "", "", false, CELL_GCM_ATTRIB_OUTPUT_MASK_TEX1 },
|
||||
{ "tc2", true, "dst_reg9", "", false, "", "", "", false, CELL_GCM_ATTRIB_OUTPUT_MASK_TEX2 },
|
||||
|
|
@ -212,44 +181,10 @@ void VKVertexDecompilerThread::insertOutputs(std::stringstream & OS, const std::
|
|||
OS << "layout(location=" << vk::get_varying_register("front_spec_color").reg_location << ") out vec4 front_spec_color;\n";
|
||||
}
|
||||
|
||||
namespace vk
|
||||
{
|
||||
void add_input(std::stringstream & OS, const ParamItem &PI, const std::vector<rsx_vertex_input> &inputs)
|
||||
{
|
||||
for (const auto &real_input : inputs)
|
||||
{
|
||||
if (real_input.location != PI.location)
|
||||
continue;
|
||||
|
||||
if (!real_input.is_array)
|
||||
{
|
||||
OS << " vec4 " << PI.name << " = vec4(texelFetch(" << PI.name << "_buffer, 0));\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (real_input.frequency > 1)
|
||||
{
|
||||
if (real_input.is_modulo)
|
||||
{
|
||||
OS << " vec4 " << PI.name << "= vec4(texelFetch(" << PI.name << "_buffer, gl_VertexIndex %" << real_input.frequency << "));\n";
|
||||
return;
|
||||
}
|
||||
|
||||
OS << " vec4 " << PI.name << "= vec4(texelFetch(" << PI.name << "_buffer, gl_VertexIndex /" << real_input.frequency << "));\n";
|
||||
return;
|
||||
}
|
||||
|
||||
OS << " vec4 " << PI.name << "= vec4(texelFetch(" << PI.name << "_buffer, gl_VertexIndex).rgba);\n";
|
||||
return;
|
||||
}
|
||||
|
||||
OS << " vec4 " << PI.name << "= vec4(texelFetch(" << PI.name << "_buffer, gl_VertexIndex).rgba);\n";
|
||||
}
|
||||
}
|
||||
|
||||
void VKVertexDecompilerThread::insertMainStart(std::stringstream & OS)
|
||||
{
|
||||
glsl::insert_glsl_legacy_function(OS, glsl::glsl_vertex_program);
|
||||
glsl::insert_vertex_input_fetch(OS, glsl::glsl_rules_rpirv);
|
||||
|
||||
std::string parameters = "";
|
||||
for (int i = 0; i < 16; ++i)
|
||||
|
|
@ -286,7 +221,9 @@ void VKVertexDecompilerThread::insertMainStart(std::stringstream & OS)
|
|||
for (const ParamType &PT : m_parr.params[PF_PARAM_IN])
|
||||
{
|
||||
for (const ParamItem &PI : PT.items)
|
||||
vk::add_input(OS, PI, rsx_vertex_program.rsx_vertex_inputs);
|
||||
{
|
||||
OS << " vec4 " << PI.name << "= read_location(" << std::to_string(PI.location) << ");\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -373,7 +310,7 @@ void VKVertexDecompilerThread::insertMainEnd(std::stringstream & OS)
|
|||
if (m_parr.HasParam(PF_PARAM_NONE, "vec4", "dst_reg2"))
|
||||
OS << " front_spec_color = dst_reg2;\n";
|
||||
|
||||
OS << " gl_Position = gl_Position * scaleOffsetMat;\n";
|
||||
OS << " gl_Position = gl_Position * scale_offset_mat;\n";
|
||||
OS << "}\n";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue