summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2025-08-01 21:44:41 +0200
committerGitHub <noreply@github.com>2025-08-01 21:44:41 +0200
commit03b709019d15d144bd7c4acf90f739fecedbc41f (patch)
treeb2dd7cd209d88c0db31e09afa5cc31160a2e0a79 /Source/Core/VideoCommon
parent06e05e0f908595d8d4d43e98ffdad92bc5740d5c (diff)
parent6ab83bdd05d6785d084a3d2e58a9aa182c8d4aa7 (diff)
Merge pull request #13749 from iwubcode/vertex_shadergen_expand_fix
VideoCommon: fix regression in vertexshadergen for line/point expansion
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/VertexShaderGen.cpp61
1 files changed, 47 insertions, 14 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp
index bf313daa5c..4dec9a3b21 100644
--- a/Source/Core/VideoCommon/VertexShaderGen.cpp
+++ b/Source/Core/VideoCommon/VertexShaderGen.cpp
@@ -74,6 +74,28 @@ VertexShaderUid GetVertexShaderUid()
return out;
}
+static void WritePrimitiveExpand(APIType api_type, const ShaderHostConfig& host_config,
+ const vertex_shader_uid_data* uid_data, ShaderCode& out)
+{
+ if (uid_data->vs_expand == VSExpand::None)
+ return;
+
+ out.Write("InputData dolphin_primitive_expand_data(int index_offset)\n");
+ out.Write("{{\n");
+ if (api_type == APIType::D3D)
+ {
+ // D3D doesn't include the base vertex in SV_VertexID
+ // See comment in UberShaderVertex for details
+ out.Write("\tuint vertex_id = (gl_VertexID >> 2) + base_vertex;\n");
+ }
+ else
+ {
+ out.Write("\tuint vertex_id = uint(gl_VertexID) >> 2u;\n");
+ }
+ out.Write("\treturn input_buffer[vertex_id + index_offset];\n");
+ out.Write("}}\n\n");
+}
+
static void WriteTransformMatrices(APIType api_type, const ShaderHostConfig& host_config,
const vertex_shader_uid_data* uid_data, ShaderCode& out)
{
@@ -82,6 +104,11 @@ static void WriteTransformMatrices(APIType api_type, const ShaderHostConfig& hos
out.Write("\tmat3x4 result;\n");
if ((uid_data->components & VB_HAS_POSMTXIDX) != 0)
{
+ if (uid_data->vs_expand != VSExpand::None)
+ {
+ out.Write("\tInputData i = dolphin_primitive_expand_data(0);\n");
+ out.Write("\tuvec4 posmtx = unpack_ubyte4(i.posmtx);\n");
+ }
// Vertex format has a per-vertex matrix
out.Write("\tint posidx = int(posmtx.r);\n"
"\tresult[0] = " I_TRANSFORMMATRICES "[posidx];\n"
@@ -108,6 +135,11 @@ static void WriteTransformMatrices(APIType api_type, const ShaderHostConfig& hos
out.Write("\tmat3 result;\n");
if ((uid_data->components & VB_HAS_POSMTXIDX) != 0)
{
+ if (uid_data->vs_expand != VSExpand::None)
+ {
+ out.Write("\tInputData i = dolphin_primitive_expand_data(0);\n");
+ out.Write("\tuvec4 posmtx = unpack_ubyte4(i.posmtx);\n");
+ }
// Vertex format has a per-vertex matrix
out.Write("\tint posidx = int(posmtx.r);\n");
out.Write("\tint normidx = posidx & 31;\n"
@@ -401,7 +433,8 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
if (uid_data->components & VB_HAS_POSMTXIDX)
{
out.Write(" uint posmtx;\n");
- input_extract.Write("uint4 posmtx = unpack_ubyte4(i.posmtx);\n");
+ // Note: posmtx is handled in the matrix transform functions and
+ // doesn't need to be added to 'input_extract'
}
if (uid_data->position_has_3_elems)
{
@@ -507,6 +540,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
}
// Note: this is done after to ensure above global variables are accessible
+ WritePrimitiveExpand(api_type, host_config, uid_data, out);
WriteTransformMatrices(api_type, host_config, uid_data, out);
WriteTexCoordTransforms(api_type, host_config, uid_data, out);
WriteVertexDefines(api_type, host_config, uid_data, out);
@@ -532,15 +566,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
if (uid_data->vs_expand != VSExpand::None)
{
- out.Write("bool is_bottom = (gl_VertexID & 2) != 0;\n"
- "bool is_right = (gl_VertexID & 1) != 0;\n");
- // D3D doesn't include the base vertex in SV_VertexID
- // See comment in UberShaderVertex for details
- if (api_type == APIType::D3D)
- out.Write("uint vertex_id = (gl_VertexID >> 2) + base_vertex;\n");
- else
- out.Write("uint vertex_id = uint(gl_VertexID) >> 2u;\n");
- out.Write("InputData i = input_buffer[vertex_id];\n"
+ out.Write("InputData i = dolphin_primitive_expand_data(0);\n"
"{}",
input_extract.GetBuffer());
}
@@ -691,14 +717,15 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
if (uid_data->vs_expand == VSExpand::Line)
{
+ out.Write("bool is_bottom = (gl_VertexID & 2) != 0;\n");
out.Write("// Line expansion\n"
- "uint other_id = vertex_id;\n"
+ "int id_offset = 0;\n"
"if (is_bottom) {{\n"
- " other_id -= 1u;\n"
+ " id_offset -= 1;\n"
"}} else {{\n"
- " other_id += 1u;\n"
+ " id_offset += 1;\n"
"}}\n"
- "InputData other = input_buffer[other_id];\n");
+ "InputData other = dolphin_primitive_expand_data(id_offset);\n");
if (uid_data->position_has_3_elems)
out.Write("float4 other_pos = float4(other.pos0, other.pos1, other.pos2, 1.0f);\n");
else
@@ -716,10 +743,16 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho
{
out.Write("other_pos = vec4(other_pos * dolphin_position_matrix(), 1.0);\n");
}
+
+ // Variable needed by GenerateVSLineExpansion
+ out.Write("bool is_right = (gl_VertexID & 1) != 0;\n");
GenerateVSLineExpansion(out, "", uid_data->numTexGens);
}
else if (uid_data->vs_expand == VSExpand::Point)
{
+ // Variables needed by GenerateVSPointExpansion
+ out.Write("bool is_bottom = (gl_VertexID & 2) != 0;\n");
+ out.Write("bool is_right = (gl_VertexID & 1) != 0;\n");
out.Write("// Point expansion\n");
GenerateVSPointExpansion(out, "", uid_data->numTexGens);
}