From bebffc7d643ba6923d7dfffeb64e59539030819f Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Sat, 28 Jun 2025 00:08:45 -0700 Subject: [PATCH] nv2a/glsl: Let pgraph_gen_geom_glsl take VshState and GlslOptions --- hw/xbox/nv2a/pgraph/gl/shaders.c | 5 ++--- hw/xbox/nv2a/pgraph/glsl/geom.c | 24 +++++++++++------------- hw/xbox/nv2a/pgraph/glsl/geom.h | 12 ++++++------ hw/xbox/nv2a/pgraph/vk/shaders.c | 3 +-- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/hw/xbox/nv2a/pgraph/gl/shaders.c b/hw/xbox/nv2a/pgraph/gl/shaders.c index 9c162b93b2..20314de42d 100644 --- a/hw/xbox/nv2a/pgraph/gl/shaders.c +++ b/hw/xbox/nv2a/pgraph/gl/shaders.c @@ -150,9 +150,8 @@ static void generate_shaders(ShaderBinding *binding) /* Create an optional geometry shader and find primitive type */ GLenum gl_primitive_mode = get_gl_primitive_mode( state->vsh.polygon_front_mode, state->vsh.primitive_mode); - MString *geometry_shader_code = pgraph_gen_geom_glsl( - state->vsh.polygon_front_mode, state->vsh.polygon_back_mode, - state->vsh.primitive_mode, state->vsh.smooth_shading, false); + MString *geometry_shader_code = + pgraph_gen_geom_glsl(&state->vsh, (GenGeomGlslOptions){ 0 }); if (geometry_shader_code) { const char* geometry_shader_code_str = mstring_get_str(geometry_shader_code); diff --git a/hw/xbox/nv2a/pgraph/glsl/geom.c b/hw/xbox/nv2a/pgraph/glsl/geom.c index 258e1fca8b..81451811a1 100644 --- a/hw/xbox/nv2a/pgraph/glsl/geom.c +++ b/hw/xbox/nv2a/pgraph/glsl/geom.c @@ -23,15 +23,11 @@ #include "common.h" #include "geom.h" -MString *pgraph_gen_geom_glsl(enum ShaderPolygonMode polygon_front_mode, - enum ShaderPolygonMode polygon_back_mode, - enum ShaderPrimitiveMode primitive_mode, - bool smooth_shading, - bool vulkan) +MString *pgraph_gen_geom_glsl(const VshState *state, GenGeomGlslOptions opts) { /* FIXME: Missing support for 2-sided-poly mode */ - assert(polygon_front_mode == polygon_back_mode); - enum ShaderPolygonMode polygon_mode = polygon_front_mode; + assert(state->polygon_front_mode == state->polygon_back_mode); + enum ShaderPolygonMode polygon_mode = state->polygon_front_mode; /* POINT mode shouldn't require any special work */ if (polygon_mode == POLY_MODE_POINT) { @@ -42,7 +38,7 @@ MString *pgraph_gen_geom_glsl(enum ShaderPolygonMode polygon_front_mode, const char *layout_in = NULL; const char *layout_out = NULL; const char *body = NULL; - switch (primitive_mode) { + switch (state->primitive_mode) { case PRIM_TYPE_POINTS: return NULL; case PRIM_TYPE_LINES: return NULL; case PRIM_TYPE_LINE_LOOP: return NULL; @@ -145,7 +141,7 @@ MString *pgraph_gen_geom_glsl(enum ShaderPolygonMode polygon_front_mode, return NULL; } if (polygon_mode == POLY_MODE_FILL) { - if (smooth_shading) { + if (state->smooth_shading) { return NULL; } layout_in = "layout(triangles) in;\n"; @@ -170,14 +166,16 @@ MString *pgraph_gen_geom_glsl(enum ShaderPolygonMode polygon_front_mode, assert(layout_out); assert(body); MString *s = mstring_new(); - mstring_append_fmt(s, "#version %d\n\n", vulkan ? 450 : 400); + mstring_append_fmt(s, "#version %d\n\n", opts.vulkan ? 450 : 400); mstring_append(s, layout_in); mstring_append(s, layout_out); mstring_append(s, "\n"); - pgraph_get_glsl_vtx_header(s, vulkan, smooth_shading, true, true, true); - pgraph_get_glsl_vtx_header(s, vulkan, smooth_shading, false, false, false); + pgraph_get_glsl_vtx_header(s, opts.vulkan, state->smooth_shading, true, + true, true); + pgraph_get_glsl_vtx_header(s, opts.vulkan, state->smooth_shading, false, + false, false); - if (smooth_shading) { + if (state->smooth_shading) { mstring_append(s, "void emit_vertex(int index, int _unused) {\n" " gl_Position = gl_in[index].gl_Position;\n" diff --git a/hw/xbox/nv2a/pgraph/glsl/geom.h b/hw/xbox/nv2a/pgraph/glsl/geom.h index 1be247d546..f8050b2176 100644 --- a/hw/xbox/nv2a/pgraph/glsl/geom.h +++ b/hw/xbox/nv2a/pgraph/glsl/geom.h @@ -23,12 +23,12 @@ #define HW_XBOX_NV2A_PGRAPH_GLSL_GEOM_H #include "qemu/mstring.h" -#include "hw/xbox/nv2a/pgraph/shaders.h" +#include "hw/xbox/nv2a/pgraph/vsh.h" -MString *pgraph_gen_geom_glsl(enum ShaderPolygonMode polygon_front_mode, - enum ShaderPolygonMode polygon_back_mode, - enum ShaderPrimitiveMode primitive_mode, - bool smooth_shading, - bool vulkan); +typedef struct GenGeomGlslOptions { + bool vulkan; +} GenGeomGlslOptions; + +MString *pgraph_gen_geom_glsl(const VshState *state, GenGeomGlslOptions opts); #endif diff --git a/hw/xbox/nv2a/pgraph/vk/shaders.c b/hw/xbox/nv2a/pgraph/vk/shaders.c index 6eff4cdf24..fe6d6e00dd 100644 --- a/hw/xbox/nv2a/pgraph/vk/shaders.c +++ b/hw/xbox/nv2a/pgraph/vk/shaders.c @@ -333,8 +333,7 @@ static ShaderBinding *gen_shaders(PGRAPHState *pg, ShaderState *state) setlocale(LC_NUMERIC, "C"); MString *geometry_shader_code = pgraph_gen_geom_glsl( - state->vsh.polygon_front_mode, state->vsh.polygon_back_mode, - state->vsh.primitive_mode, state->vsh.smooth_shading, true); + &state->vsh, (GenGeomGlslOptions){ .vulkan = true }); if (geometry_shader_code) { NV2A_VK_DPRINTF("geometry shader: \n%s", mstring_get_str(geometry_shader_code));