nv2a/vk: Clean up layout binding ids

This commit is contained in:
Matt Borgerson 2025-06-25 16:49:24 -07:00
parent adbbcfff1f
commit 4010cba32e
5 changed files with 20 additions and 13 deletions

View File

@ -762,9 +762,11 @@ static MString* psh_convert(struct PixelShader *ps)
ps->state.smooth_shading, true, false, false); ps->state.smooth_shading, true, false, false);
if (ps->opts.vulkan) { if (ps->opts.vulkan) {
mstring_append_fmt(preflight, mstring_append_fmt(
preflight,
"layout(location = 0) out vec4 fragColor;\n" "layout(location = 0) out vec4 fragColor;\n"
"layout(binding = %d, std140) uniform PshUniforms {\n", PSH_UBO_BINDING); "layout(binding = %d, std140) uniform PshUniforms {\n",
ps->opts.ubo_binding);
} else { } else {
mstring_append_fmt(preflight, mstring_append_fmt(preflight,
"layout(location = 0) out vec4 fragColor;\n"); "layout(location = 0) out vec4 fragColor;\n");
@ -1201,7 +1203,7 @@ static MString* psh_convert(struct PixelShader *ps)
if (sampler_type != NULL) { if (sampler_type != NULL) {
if (ps->opts.vulkan) { if (ps->opts.vulkan) {
mstring_append_fmt(preflight, "layout(binding = %d) ", PSH_TEX_BINDING + i); mstring_append_fmt(preflight, "layout(binding = %d) ", ps->opts.tex_binding + i);
} }
mstring_append_fmt(preflight, "uniform %s texSamp%d;\n", sampler_type, i); mstring_append_fmt(preflight, "uniform %s texSamp%d;\n", sampler_type, i);

View File

@ -32,12 +32,10 @@
#include "qemu/mstring.h" #include "qemu/mstring.h"
#include "hw/xbox/nv2a/pgraph/psh.h" #include "hw/xbox/nv2a/pgraph/psh.h"
// FIXME: Move to struct
#define PSH_UBO_BINDING 1
#define PSH_TEX_BINDING 2
typedef struct GenPshGlslOptions { typedef struct GenPshGlslOptions {
bool vulkan; bool vulkan;
int ubo_binding;
int tex_binding;
} GenPshGlslOptions; } GenPshGlslOptions;
MString *pgraph_gen_psh_glsl(const PshState state, GenPshGlslOptions opts); MString *pgraph_gen_psh_glsl(const PshState state, GenPshGlslOptions opts);

View File

@ -310,7 +310,7 @@ MString *pgraph_gen_vsh_glsl(const VshState *state,
"layout(binding = %d, std140) uniform VshUniforms {\n" "layout(binding = %d, std140) uniform VshUniforms {\n"
"%s" "%s"
"};\n\n", "};\n\n",
VSH_UBO_BINDING, mstring_get_str(uniforms)); opts.ubo_binding, mstring_get_str(uniforms));
} else { } else {
mstring_append( mstring_append(
output, mstring_get_str(uniforms)); output, mstring_get_str(uniforms));

View File

@ -25,13 +25,11 @@
#include "qemu/mstring.h" #include "qemu/mstring.h"
#include "hw/xbox/nv2a/pgraph/vsh.h" #include "hw/xbox/nv2a/pgraph/vsh.h"
// FIXME: Move to struct
#define VSH_UBO_BINDING 0
typedef struct GenVshGlslOptions { typedef struct GenVshGlslOptions {
bool vulkan; bool vulkan;
bool prefix_outputs; bool prefix_outputs;
bool use_push_constants_for_uniform_attrs; bool use_push_constants_for_uniform_attrs;
int ubo_binding;
} GenVshGlslOptions; } GenVshGlslOptions;
MString *pgraph_gen_vsh_glsl(const VshState *state, MString *pgraph_gen_vsh_glsl(const VshState *state,

View File

@ -34,6 +34,10 @@
#include "renderer.h" #include "renderer.h"
#include <locale.h> #include <locale.h>
#define VSH_UBO_BINDING 0
#define PSH_UBO_BINDING 1
#define PSH_TEX_BINDING 2
const size_t MAX_UNIFORM_ATTR_VALUES_SIZE = NV2A_VERTEXSHADER_ATTRIBUTES * 4 * sizeof(float); const size_t MAX_UNIFORM_ATTR_VALUES_SIZE = NV2A_VERTEXSHADER_ATTRIBUTES * 4 * sizeof(float);
static void create_descriptor_pool(PGRAPHState *pg) static void create_descriptor_pool(PGRAPHState *pg)
@ -428,6 +432,7 @@ static ShaderBinding *gen_shaders(PGRAPHState *pg, ShaderState *state)
.prefix_outputs = geometry_shader_code != NULL, .prefix_outputs = geometry_shader_code != NULL,
.use_push_constants_for_uniform_attrs = .use_push_constants_for_uniform_attrs =
r->use_push_constants_for_uniform_attrs, r->use_push_constants_for_uniform_attrs,
.ubo_binding = VSH_UBO_BINDING,
}); });
NV2A_VK_DPRINTF("vertex shader: \n%s", NV2A_VK_DPRINTF("vertex shader: \n%s",
mstring_get_str(vertex_shader_code)); mstring_get_str(vertex_shader_code));
@ -437,7 +442,11 @@ static ShaderBinding *gen_shaders(PGRAPHState *pg, ShaderState *state)
mstring_unref(vertex_shader_code); mstring_unref(vertex_shader_code);
MString *fragment_shader_code = pgraph_gen_psh_glsl( MString *fragment_shader_code = pgraph_gen_psh_glsl(
state->psh, (GenPshGlslOptions){ .vulkan = true }); state->psh, (GenPshGlslOptions){
.vulkan = true,
.ubo_binding = PSH_UBO_BINDING,
.tex_binding = PSH_TEX_BINDING,
});
NV2A_VK_DPRINTF("fragment shader: \n%s", NV2A_VK_DPRINTF("fragment shader: \n%s",
mstring_get_str(fragment_shader_code)); mstring_get_str(fragment_shader_code));
snode->fragment = pgraph_vk_create_shader_module_from_glsl( snode->fragment = pgraph_vk_create_shader_module_from_glsl(