diff --git a/hw/xbox/nv2a/pgraph/glsl/common.c b/hw/xbox/nv2a/pgraph/glsl/common.c index 0bcfe7ce76..f2745bb7aa 100644 --- a/hw/xbox/nv2a/pgraph/glsl/common.c +++ b/hw/xbox/nv2a/pgraph/glsl/common.c @@ -17,39 +17,39 @@ * License along with this library; if not, see . */ - #include "common.h" - MString *pgraph_get_glsl_vtx_header(MString *out, bool location, bool smooth, bool in, bool prefix, bool array) { - const char *flat_s = "flat "; const char *smooth_s = ""; + const char *flat_s = "flat "; const char *qualifier_s = smooth ? smooth_s : flat_s; - const char *qualifiers[9] = { qualifier_s, qualifier_s, qualifier_s, - qualifier_s, smooth_s, smooth_s, - smooth_s, smooth_s, smooth_s }; - const char *in_out_s = in ? "in" : "out"; - const char *float_s = "float"; const char *vec4_s = "vec4"; - const char *types[9] = { vec4_s, vec4_s, vec4_s, vec4_s, float_s, - vec4_s, vec4_s, vec4_s, vec4_s }; - const char *prefix_s = prefix ? "v_" : ""; - const char *names[9] = { - "vtxD0", "vtxD1", "vtxB0", "vtxB1", "vtxFog", - "vtxT0", "vtxT1", "vtxT2", "vtxT3", - }; const char *suffix_s = array ? "[]" : ""; + const struct { + const char *qualifier, *type, *name; + } attr[] = { + { qualifier_s, vec4_s, "vtxD0" }, + { qualifier_s, vec4_s, "vtxD1" }, + { qualifier_s, vec4_s, "vtxB0" }, + { qualifier_s, vec4_s, "vtxB1" }, + { smooth_s, float_s, "vtxFog" }, + { smooth_s, vec4_s, "vtxT0" }, + { smooth_s, vec4_s, "vtxT1" }, + { smooth_s, vec4_s, "vtxT2" }, + { smooth_s, vec4_s, "vtxT3" }, + }; - for (int i = 0; i < 9; i++) { + for (int i = 0; i < ARRAY_SIZE(attr); i++) { if (location) { mstring_append_fmt(out, "layout(location = %d) ", i); } - mstring_append_fmt(out, "%s%s %s %s%s%s;\n", - qualifiers[i], in_out_s, types[i], prefix_s, names[i], suffix_s); + mstring_append_fmt(out, "%s%s %s %s%s%s;\n", attr[i].qualifier, + in_out_s, attr[i].type, prefix_s, attr[i].name, + suffix_s); } return out; diff --git a/hw/xbox/nv2a/pgraph/glsl/psh.c b/hw/xbox/nv2a/pgraph/glsl/psh.c index 08fec32ec7..a664281f09 100644 --- a/hw/xbox/nv2a/pgraph/glsl/psh.c +++ b/hw/xbox/nv2a/pgraph/glsl/psh.c @@ -576,11 +576,15 @@ static const char *get_sampler_type(enum PS_TEXTUREMODES mode, const PshState *s return NULL; case PS_TEXTUREMODES_PROJECT2D: - assert(state->dim_tex[i] == 2); - if (state->tex_x8y24[i] && state->vulkan) { - return "usampler2D"; + if (state->dim_tex[i] == 2) { + if (state->tex_x8y24[i] && state->vulkan) { + return "usampler2D"; + } + return sampler2D; } - return sampler2D; + if (state->dim_tex[i] == 3) return sampler3D; + assert(!"Unhandled texture dimensions"); + return NULL; case PS_TEXTUREMODES_BUMPENVMAP: case PS_TEXTUREMODES_BUMPENVMAP_LUM: @@ -712,6 +716,7 @@ static void apply_border_adjustment(const struct PixelShader *ps, MString *vars, static void apply_convolution_filter(const struct PixelShader *ps, MString *vars, int tex) { + assert(ps->state.dim_tex[tex] == 2); // FIXME: Quincunx g_autofree gchar *normalize_tex_coords = g_strdup_printf("norm%d", tex); @@ -956,8 +961,15 @@ static MString* psh_convert(struct PixelShader *ps) (ps->state.conv_tex[i] == CONVOLUTION_FILTER_QUINCUNX))) { apply_convolution_filter(ps, vars, i); } else { - mstring_append_fmt(vars, "vec4 t%d = textureProj(texSamp%d, %s(pT%d.xyw));\n", - i, i, tex_remap, i); + 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); + } 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); + } else { + assert(!"Unhandled texture dimensions"); + } } } break; diff --git a/hw/xbox/nv2a/pgraph/vk/vertex.c b/hw/xbox/nv2a/pgraph/vk/vertex.c index af13bd67b4..b7bf97b38a 100644 --- a/hw/xbox/nv2a/pgraph/vk/vertex.c +++ b/hw/xbox/nv2a/pgraph/vk/vertex.c @@ -193,13 +193,6 @@ void pgraph_vk_bind_vertex_attributes(NV2AState *d, unsigned int min_element, hwaddr attrib_data_addr; size_t stride; - if (needs_conversion) { - pg->compressed_attrs |= (1 << i); - } - if (d3d_swizzle) { - pg->swizzle_attrs |= (1 << i); - } - hwaddr start = 0; if (inline_data) { attrib_data_addr = attr->inline_array_offset; @@ -264,6 +257,13 @@ void pgraph_vk_bind_vertex_attributes(NV2AState *d, unsigned int min_element, r->vertex_attribute_offsets[i] = attrib_data_addr; + if (needs_conversion) { + pg->compressed_attrs |= (1 << i); + } + if (d3d_swizzle) { + pg->swizzle_attrs |= (1 << i); + } + NV2A_VK_DGROUP_END(); }