nv2a/glsl: Add glsl_ prefix to public functions

This commit is contained in:
Matt Borgerson
2025-06-28 00:18:28 -07:00
committed by mborgerson
parent cbcb7c2181
commit 1489253c68
16 changed files with 67 additions and 62 deletions
+7 -7
View File
@@ -147,7 +147,7 @@ static void generate_shaders(ShaderBinding *binding)
GLenum gl_primitive_mode = get_gl_primitive_mode(
state->geom.polygon_front_mode, state->geom.primitive_mode);
MString *geometry_shader_code =
pgraph_gen_geom_glsl(&state->geom, (GenGeomGlslOptions){ 0 });
pgraph_glsl_gen_geom(&state->geom, (GenGeomGlslOptions){ 0 });
if (geometry_shader_code) {
const char* geometry_shader_code_str =
mstring_get_str(geometry_shader_code);
@@ -159,7 +159,7 @@ static void generate_shaders(ShaderBinding *binding)
}
/* create the vertex shader */
MString *vertex_shader_code = pgraph_gen_vsh_glsl(
MString *vertex_shader_code = pgraph_glsl_gen_vsh(
&state->vsh, (GenVshGlslOptions){
.prefix_outputs = geometry_shader_code != NULL,
});
@@ -171,7 +171,7 @@ static void generate_shaders(ShaderBinding *binding)
/* generate a fragment shader from register combiners */
MString *fragment_shader_code =
pgraph_gen_psh_glsl(&state->psh, (GenPshGlslOptions){ 0 });
pgraph_glsl_gen_psh(&state->psh, (GenPshGlslOptions){ 0 });
const char *fragment_shader_code_str =
mstring_get_str(fragment_shader_code);
GLuint fragment_shader = create_gl_shader(GL_FRAGMENT_SHADER,
@@ -678,13 +678,13 @@ static void update_shader_uniforms(PGRAPHState *pg, ShaderBinding *binding)
PGRAPHGLState *r = pg->gl_renderer_state;
VshUniformValues vsh_values;
pgraph_set_vsh_uniform_values(pg, &binding->state.vsh,
pgraph_glsl_set_vsh_uniform_values(pg, &binding->state.vsh,
binding->uniform_locs.vsh, &vsh_values);
apply_uniform_updates(VshUniformInfo, binding->uniform_locs.vsh,
&vsh_values, VshUniform__COUNT);
PshUniformValues psh_values;
pgraph_set_psh_uniform_values(pg, binding->uniform_locs.psh, &psh_values);
pgraph_glsl_set_psh_uniform_values(pg, binding->uniform_locs.psh, &psh_values);
for (int i = 0; i < 4; i++) {
if (r->texture_binding[i] != NULL) {
@@ -702,13 +702,13 @@ void pgraph_gl_bind_shaders(PGRAPHState *pg)
bool binding_changed = false;
if (r->shader_binding &&
!pgraph_check_shader_state_dirty(pg, &r->shader_binding->state)) {
!pgraph_glsl_check_shader_state_dirty(pg, &r->shader_binding->state)) {
nv2a_profile_inc_counter(NV2A_PROF_SHADER_BIND_NOTDIRTY);
goto update_uniforms;
}
ShaderBinding *old_binding = r->shader_binding;
ShaderState state = pgraph_get_shader_state(pg);
ShaderState state = pgraph_glsl_get_shader_state(pg);
NV2A_GL_DGROUP_BEGIN("%s (%s)", __func__,
state.vsh.is_fixed_function ? "FF" : "PROG");
+3 -2
View File
@@ -25,7 +25,8 @@ const char *uniform_element_type_to_str[] = {
UNIFORM_ELEMENT_TYPE_X(DECL_UNIFORM_ELEMENT_NAME)
};
MString *pgraph_get_glsl_vtx_header(MString *out, bool location, bool smooth, bool in, bool prefix, bool array)
MString *pgraph_glsl_get_vtx_header(MString *out, bool location, bool smooth,
bool in, bool prefix, bool array)
{
const char *smooth_s = "";
const char *flat_s = "flat ";
@@ -61,7 +62,7 @@ MString *pgraph_get_glsl_vtx_header(MString *out, bool location, bool smooth, bo
return out;
}
void pgraph_set_clip_range_uniform_value(PGRAPHState *pg, float clipRange[4])
void pgraph_glsl_set_clip_range_uniform_value(PGRAPHState *pg, float clipRange[4])
{
float zmax;
switch (pg->surface_shape.zeta_format) {
+4 -2
View File
@@ -95,10 +95,12 @@ typedef struct UniformInfo {
#define GLSL_DEFINE(a, b) "#define " stringify(a) " " b "\n"
MString *pgraph_get_glsl_vtx_header(MString *out, bool location, bool smooth, bool in, bool prefix, bool array);
MString *pgraph_glsl_get_vtx_header(MString *out, bool location, bool smooth,
bool in, bool prefix, bool array);
typedef struct PGRAPHState PGRAPHState;
void pgraph_set_clip_range_uniform_value(PGRAPHState *pg, float clipRange[4]);
void pgraph_glsl_set_clip_range_uniform_value(PGRAPHState *pg,
float clipRange[4]);
#endif
+4 -4
View File
@@ -23,7 +23,7 @@
#include "hw/xbox/nv2a/pgraph/pgraph.h"
#include "geom.h"
void pgraph_set_geom_state(PGRAPHState *pg, GeomState *state)
void pgraph_glsl_set_geom_state(PGRAPHState *pg, GeomState *state)
{
state->primitive_mode = (enum ShaderPrimitiveMode)pg->primitive_mode;
@@ -39,7 +39,7 @@ void pgraph_set_geom_state(PGRAPHState *pg, GeomState *state)
NV_PGRAPH_CONTROL_3_SHADEMODE_SMOOTH;
}
MString *pgraph_gen_geom_glsl(const GeomState *state, GenGeomGlslOptions opts)
MString *pgraph_glsl_gen_geom(const GeomState *state, GenGeomGlslOptions opts)
{
/* FIXME: Missing support for 2-sided-poly mode */
assert(state->polygon_front_mode == state->polygon_back_mode);
@@ -186,9 +186,9 @@ MString *pgraph_gen_geom_glsl(const GeomState *state, GenGeomGlslOptions opts)
mstring_append(s, layout_in);
mstring_append(s, layout_out);
mstring_append(s, "\n");
pgraph_get_glsl_vtx_header(s, opts.vulkan, state->smooth_shading, true,
pgraph_glsl_get_vtx_header(s, opts.vulkan, state->smooth_shading, true,
true, true);
pgraph_get_glsl_vtx_header(s, opts.vulkan, state->smooth_shading, false,
pgraph_glsl_get_vtx_header(s, opts.vulkan, state->smooth_shading, false,
false, false);
if (state->smooth_shading) {
+2 -2
View File
@@ -36,8 +36,8 @@ typedef struct GenGeomGlslOptions {
bool vulkan;
} GenGeomGlslOptions;
void pgraph_set_geom_state(PGRAPHState *pg, GeomState *geom);
void pgraph_glsl_set_geom_state(PGRAPHState *pg, GeomState *geom);
MString *pgraph_gen_geom_glsl(const GeomState *state, GenGeomGlslOptions opts);
MString *pgraph_glsl_gen_geom(const GeomState *state, GenGeomGlslOptions opts);
#endif
+7 -6
View File
@@ -58,7 +58,7 @@ static uint32_t get_color_key_mask_for_texture(PGRAPHState *pg, int i)
return get_colorkey_mask(color_format);
}
void pgraph_set_psh_state(PGRAPHState *pg, PshState *state)
void pgraph_glsl_set_psh_state(PGRAPHState *pg, PshState *state)
{
state->window_clip_exclusive = pgraph_reg_r(pg, NV_PGRAPH_SETUPRASTER) &
NV_PGRAPH_SETUPRASTER_WINDOWCLIPTYPE;
@@ -779,7 +779,7 @@ static void define_colorkey_comparator(MString *preflight)
static MString* psh_convert(struct PixelShader *ps)
{
MString *preflight = mstring_new();
pgraph_get_glsl_vtx_header(preflight, ps->opts.vulkan,
pgraph_glsl_get_vtx_header(preflight, ps->opts.vulkan,
ps->state->smooth_shading, true, false, false);
if (ps->opts.vulkan) {
@@ -1400,7 +1400,7 @@ static void parse_combiner_output(uint32_t value, struct OutputInfo *out)
out->cd_alphablue = flags & 0x40;
}
MString *pgraph_gen_psh_glsl(const PshState *state, GenPshGlslOptions opts)
MString *pgraph_glsl_gen_psh(const PshState *state, GenPshGlslOptions opts)
{
int i;
struct PixelShader ps;
@@ -1454,8 +1454,9 @@ MString *pgraph_gen_psh_glsl(const PshState *state, GenPshGlslOptions opts)
return psh_convert(&ps);
}
void pgraph_set_psh_uniform_values(PGRAPHState *pg, const PshUniformLocs locs,
PshUniformValues *values)
void pgraph_glsl_set_psh_uniform_values(PGRAPHState *pg,
const PshUniformLocs locs,
PshUniformValues *values)
{
if (locs[PshUniform_consts] != -1) {
for (int i = 0; i < 9; i++) {
@@ -1539,7 +1540,7 @@ void pgraph_set_psh_uniform_values(PGRAPHState *pg, const PshUniformLocs locs,
}
if (locs[PshUniform_clipRange] != -1) {
pgraph_set_clip_range_uniform_value(pg, values->clipRange[0]);
pgraph_glsl_set_clip_range_uniform_value(pg, values->clipRange[0]);
}
if (locs[PshUniform_depthOffset] != -1) {
+5 -5
View File
@@ -63,7 +63,7 @@ typedef struct PshState {
bool z_perspective;
} PshState;
void pgraph_set_psh_state(PGRAPHState *pg, PshState *state);
void pgraph_glsl_set_psh_state(PGRAPHState *pg, PshState *state);
#define PSH_UNIFORM_DECL_X(S, DECL) \
DECL(S, alphaRef, int, 1) \
@@ -87,10 +87,10 @@ typedef struct GenPshGlslOptions {
int tex_binding;
} GenPshGlslOptions;
MString *pgraph_gen_psh_glsl(const PshState *state, GenPshGlslOptions opts);
MString *pgraph_glsl_gen_psh(const PshState *state, GenPshGlslOptions opts);
void pgraph_set_psh_uniform_values(PGRAPHState *pg,
const PshUniformLocs locs,
PshUniformValues *values);
void pgraph_glsl_set_psh_uniform_values(PGRAPHState *pg,
const PshUniformLocs locs,
PshUniformValues *values);
#endif
+6 -5
View File
@@ -20,7 +20,7 @@
#include "hw/xbox/nv2a/pgraph/pgraph.h"
#include "shaders.h"
ShaderState pgraph_get_shader_state(PGRAPHState *pg)
ShaderState pgraph_glsl_get_shader_state(PGRAPHState *pg)
{
pg->program_data_dirty = false; /* fixme */
@@ -29,14 +29,15 @@ ShaderState pgraph_get_shader_state(PGRAPHState *pg)
// We will hash it, so make sure any padding is zeroed
memset(&state, 0, sizeof(ShaderState));
pgraph_set_vsh_state(pg, &state.vsh);
pgraph_set_geom_state(pg, &state.geom);
pgraph_set_psh_state(pg, &state.psh);
pgraph_glsl_set_vsh_state(pg, &state.vsh);
pgraph_glsl_set_geom_state(pg, &state.geom);
pgraph_glsl_set_psh_state(pg, &state.psh);
return state;
}
bool pgraph_check_shader_state_dirty(PGRAPHState *pg, const ShaderState *state)
bool pgraph_glsl_check_shader_state_dirty(PGRAPHState *pg,
const ShaderState *state)
{
if (pg->program_data_dirty) {
return true;
+3 -2
View File
@@ -32,8 +32,9 @@ typedef struct ShaderState {
typedef struct PGRAPHState PGRAPHState;
ShaderState pgraph_get_shader_state(PGRAPHState *pg);
ShaderState pgraph_glsl_get_shader_state(PGRAPHState *pg);
bool pgraph_check_shader_state_dirty(PGRAPHState *pg, const ShaderState *state);
bool pgraph_glsl_check_shader_state_dirty(PGRAPHState *pg,
const ShaderState *state);
#endif
+1 -1
View File
@@ -64,7 +64,7 @@ static void append_skinning_code(MString *str, bool mix, unsigned int count,
}
}
void pgraph_gen_vsh_ff_glsl(const VshState *state, MString *header,
void pgraph_glsl_gen_vsh_ff(const VshState *state, MString *header,
MString *body)
{
int i, j;
+1 -1
View File
@@ -25,7 +25,7 @@
#include "qemu/mstring.h"
#include "vsh.h"
void pgraph_gen_vsh_ff_glsl(const VshState *state, MString *header,
void pgraph_glsl_gen_vsh_ff(const VshState *state, MString *header,
MString *body);
#endif
+1 -1
View File
@@ -723,7 +723,7 @@ static const char* vsh_header =
" return t;\n"
"}\n";
void pgraph_gen_vsh_prog_glsl(uint16_t version, const uint32_t *tokens,
void pgraph_glsl_gen_vsh_prog(uint16_t version, const uint32_t *tokens,
unsigned int length, MString *header,
MString *body)
{
+1 -1
View File
@@ -24,7 +24,7 @@
#include "qemu/mstring.h"
void pgraph_gen_vsh_prog_glsl(uint16_t version, const uint32_t *tokens,
void pgraph_glsl_gen_vsh_prog(uint16_t version, const uint32_t *tokens,
unsigned int length, MString *header,
MString *body);
+10 -11
View File
@@ -100,7 +100,7 @@ static void set_programmable_vsh_state(PGRAPHState *pg,
}
}
void pgraph_set_vsh_state(PGRAPHState *pg, VshState *vsh)
void pgraph_glsl_set_vsh_state(PGRAPHState *pg, VshState *vsh)
{
bool vertex_program = GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_CSV0_D),
NV_PGRAPH_CSV0_D_MODE) == 2;
@@ -161,8 +161,7 @@ void pgraph_set_vsh_state(PGRAPHState *pg, VshState *vsh)
}
}
MString *pgraph_gen_vsh_glsl(const VshState *state,
GenVshGlslOptions opts)
MString *pgraph_glsl_gen_vsh(const VshState *state, GenVshGlslOptions opts)
{
MString *output =
mstring_from_fmt("#version %d\n\n", opts.vulkan ? 450 : 400);
@@ -237,8 +236,8 @@ MString *pgraph_gen_vsh_glsl(const VshState *state,
" return trunc(pos * 16.0f) / 16.0f;\n"
"}\n");
pgraph_get_glsl_vtx_header(header, opts.vulkan, state->smooth_shading,
false, opts.prefix_outputs, false);
pgraph_glsl_get_vtx_header(header, opts.vulkan, state->smooth_shading,
false, opts.prefix_outputs, false);
if (opts.prefix_outputs) {
mstring_append(header,
@@ -300,9 +299,9 @@ MString *pgraph_gen_vsh_glsl(const VshState *state,
}
if (state->is_fixed_function) {
pgraph_gen_vsh_ff_glsl(state, header, body);
pgraph_glsl_gen_vsh_ff(state, header, body);
} else {
pgraph_gen_vsh_prog_glsl(
pgraph_glsl_gen_vsh_prog(
VSH_VERSION_XVS, (uint32_t *)state->programmable.program_data,
state->programmable.program_length, header, body);
}
@@ -466,9 +465,9 @@ MString *pgraph_gen_vsh_glsl(const VshState *state,
return output;
}
void pgraph_set_vsh_uniform_values(PGRAPHState *pg, const VshState *state,
const VshUniformLocs locs,
VshUniformValues *values)
void pgraph_glsl_set_vsh_uniform_values(PGRAPHState *pg, const VshState *state,
const VshUniformLocs locs,
VshUniformValues *values)
{
if (locs[VshUniform_c] != -1) {
QEMU_BUILD_BUG_MSG(sizeof(values->c) != sizeof(pg->vsh_constants),
@@ -477,7 +476,7 @@ void pgraph_set_vsh_uniform_values(PGRAPHState *pg, const VshState *state,
}
if (locs[VshUniform_clipRange] != -1) {
pgraph_set_clip_range_uniform_value(pg, values->clipRange[0]);
pgraph_glsl_set_clip_range_uniform_value(pg, values->clipRange[0]);
}
if (locs[VshUniform_fogParam] != -1) {
+5 -5
View File
@@ -75,7 +75,7 @@ typedef struct {
ProgrammableVshState programmable;
} VshState;
void pgraph_set_vsh_state(PGRAPHState *pg, VshState *state);
void pgraph_glsl_set_vsh_state(PGRAPHState *pg, VshState *state);
#define VSH_UNIFORM_DECL_X(S, DECL) \
DECL(S, c, vec4, NV2A_VERTEXSHADER_CONSTANTS) \
@@ -103,11 +103,11 @@ typedef struct GenVshGlslOptions {
int ubo_binding;
} GenVshGlslOptions;
MString *pgraph_gen_vsh_glsl(const VshState *state,
MString *pgraph_glsl_gen_vsh(const VshState *state,
GenVshGlslOptions glsl_opts);
void pgraph_set_vsh_uniform_values(PGRAPHState *pg, const VshState *state,
const VshUniformLocs locs,
VshUniformValues *values);
void pgraph_glsl_set_vsh_uniform_values(PGRAPHState *pg, const VshState *state,
const VshUniformLocs locs,
VshUniformValues *values);
#endif
+7 -7
View File
@@ -328,7 +328,7 @@ static ShaderBinding *gen_shaders(PGRAPHState *pg, ShaderState *state)
/* Ensure numeric values are printed with '.' radix, no grouping */
setlocale(LC_NUMERIC, "C");
MString *geometry_shader_code = pgraph_gen_geom_glsl(
MString *geometry_shader_code = pgraph_glsl_gen_geom(
&state->geom, (GenGeomGlslOptions){ .vulkan = true });
if (geometry_shader_code) {
NV2A_VK_DPRINTF("geometry shader: \n%s",
@@ -341,7 +341,7 @@ static ShaderBinding *gen_shaders(PGRAPHState *pg, ShaderState *state)
snode->geometry = NULL;
}
MString *vertex_shader_code = pgraph_gen_vsh_glsl(
MString *vertex_shader_code = pgraph_glsl_gen_vsh(
&state->vsh, (GenVshGlslOptions){
.vulkan = true,
.prefix_outputs = geometry_shader_code != NULL,
@@ -356,7 +356,7 @@ static ShaderBinding *gen_shaders(PGRAPHState *pg, ShaderState *state)
mstring_get_str(vertex_shader_code));
mstring_unref(vertex_shader_code);
MString *fragment_shader_code = pgraph_gen_psh_glsl(
MString *fragment_shader_code = pgraph_glsl_gen_psh(
&state->psh, (GenPshGlslOptions){
.vulkan = true,
.ubo_binding = PSH_UBO_BINDING,
@@ -408,14 +408,14 @@ static void update_shader_uniforms(PGRAPHState *pg)
&binding->fragment->uniforms };
VshUniformValues vsh_values;
pgraph_set_vsh_uniform_values(pg, &binding->state.vsh,
pgraph_glsl_set_vsh_uniform_values(pg, &binding->state.vsh,
binding->uniform_locs.vsh, &vsh_values);
apply_uniform_updates(&binding->vertex->uniforms, VshUniformInfo,
binding->uniform_locs.vsh, &vsh_values,
VshUniform__COUNT);
PshUniformValues psh_values;
pgraph_set_psh_uniform_values(pg, binding->uniform_locs.psh, &psh_values);
pgraph_glsl_set_psh_uniform_values(pg, binding->uniform_locs.psh, &psh_values);
for (int i = 0; i < 4; i++) {
assert(r->texture_bindings[i] != NULL);
float scale = r->texture_bindings[i]->key.scale;
@@ -457,8 +457,8 @@ void pgraph_vk_bind_shaders(PGRAPHState *pg)
r->shader_bindings_changed = false;
if (!r->shader_binding ||
pgraph_check_shader_state_dirty(pg, &r->shader_binding->state)) {
ShaderState new_state = pgraph_get_shader_state(pg);
pgraph_glsl_check_shader_state_dirty(pg, &r->shader_binding->state)) {
ShaderState new_state = pgraph_glsl_get_shader_state(pg);
if (!r->shader_binding || memcmp(&r->shader_binding->state, &new_state,
sizeof(ShaderState))) {
r->shader_binding = gen_shaders(pg, &new_state);