From 0a7e0191354a90db14827ccaa3546831397e6c1c Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Sun, 12 Oct 2025 17:03:26 -0700 Subject: [PATCH] nv2a: Handle cubemap textures passed to 2D projective samplers Tests: https://github.com/abaire/nxdk_pgraph_tests/blob/bb915c94798906b325cc011383e1c2c270515d50/src/tests/texture_3d_as_2d_tests.cpp#L39 HW results: https://abaire.github.io/nxdk_pgraph_tests_golden_results/results/Texture_3D_as_2D/index.html Fixes #2384 --- hw/xbox/nv2a/pgraph/glsl/psh.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/xbox/nv2a/pgraph/glsl/psh.c b/hw/xbox/nv2a/pgraph/glsl/psh.c index e2d1ee66971..d9d43256a5e 100644 --- a/hw/xbox/nv2a/pgraph/glsl/psh.c +++ b/hw/xbox/nv2a/pgraph/glsl/psh.c @@ -632,6 +632,9 @@ static const char *get_sampler_type(struct PixelShader *ps, enum PS_TEXTUREMODES if (state->tex_x8y24[i] && ps->opts.vulkan) { return "usampler2D"; } + if (state->tex_cubemap[i]) { + return samplerCube; + } return sampler2D; } if (dim == 3) return sampler3D; @@ -959,6 +962,11 @@ static MString* psh_convert(struct PixelShader *ps) " }\n" " return uv;\n" "}\n" + "\n" + "vec3 remap2DToCube(vec3 texCoord2DProjective) {\n" + " vec2 st = (texCoord2DProjective.xy / texCoord2DProjective.z);" + " return normalize(vec3(1.0, st.y, -st.x));" + "}\n" ); MString *clip = mstring_new(); @@ -1106,8 +1114,17 @@ static MString* psh_convert(struct PixelShader *ps) apply_convolution_filter(ps, vars, i); } else { if (ps->state->dim_tex[i] == 2) { - mstring_append_fmt(vars, "vec4 t%d = textureProj(texSamp%d, %s(pT%d.xyw));\n", - i, i, tex_remap, i); + if (ps->state->tex_cubemap[i]) { + mstring_append_fmt( + vars, + "vec4 t%d = texture(texSamp%d, remap2DToCube(%s(pT%d.xyw)));\n", + i, i, tex_remap, i); + } else { + mstring_append_fmt( + vars, + "vec4 t%d = textureProj(texSamp%d, %s(pT%d.xyw));\n", + i, i, tex_remap, i); + } } else if (ps->state->dim_tex[i] == 3) { mstring_append_fmt(vars, "vec4 t%d = textureProj(texSamp%d, vec4(pT%d.xy, 0.0, pT%d.w));\n", i, i, i, i);