shader: Patch shader just after creating it.

The plan is to remove the patch step and generate the correct glsl
from the beginning. As the first step, just move the patch step to
where we create glsl.

Signed-off-by: Lepton Wu <lepton@chromium.org>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Lepton Wu 4 years ago
parent c488abed8d
commit 0f5cb454e1
  1. 51
      src/vrend_renderer.c
  2. 35
      src/vrend_shader.c
  3. 11
      src/vrend_shader.h

@ -379,7 +379,7 @@ struct vrend_shader {
struct vrend_strarray glsl_strings; struct vrend_strarray glsl_strings;
GLuint id; GLuint id;
GLuint compiled_fs_id; uint32_t uid;
struct vrend_shader_key key; struct vrend_shader_key key;
struct list_head programs; struct list_head programs;
}; };
@ -1481,47 +1481,9 @@ static struct vrend_linked_shader_program *add_shader_program(struct vrend_conte
GLint lret; GLint lret;
int id; int id;
int last_shader; int last_shader;
bool do_patch = false;
if (!sprog) if (!sprog)
return NULL; return NULL;
/* need to rewrite VS code to add interpolation params */
if (gs && gs->compiled_fs_id != fs->id)
do_patch = true;
if (!gs && tes && tes->compiled_fs_id != fs->id)
do_patch = true;
if (!gs && !tes && vs->compiled_fs_id != fs->id)
do_patch = true;
if (do_patch) {
bool ret;
if (gs)
vrend_patch_vertex_shader_interpolants(ctx, &ctx->shader_cfg, &gs->glsl_strings,
&gs->sel->sinfo,
&fs->sel->sinfo, "gso", fs->key.flatshade);
else if (tes)
vrend_patch_vertex_shader_interpolants(ctx, &ctx->shader_cfg, &tes->glsl_strings,
&tes->sel->sinfo,
&fs->sel->sinfo, "teo", fs->key.flatshade);
else
vrend_patch_vertex_shader_interpolants(ctx, &ctx->shader_cfg, &vs->glsl_strings,
&vs->sel->sinfo,
&fs->sel->sinfo, "vso", fs->key.flatshade);
ret = vrend_compile_shader(ctx, gs ? gs : (tes ? tes : vs));
if (ret == false) {
glDeleteShader(gs ? gs->id : (tes ? tes->id : vs->id));
free(sprog);
return NULL;
}
if (gs)
gs->compiled_fs_id = fs->id;
else if (tes)
tes->compiled_fs_id = fs->id;
else
vs->compiled_fs_id = fs->id;
}
prog_id = glCreateProgram(); prog_id = glCreateProgram();
glAttachShader(prog_id, vs->id); glAttachShader(prog_id, vs->id);
if (tcs && tcs->id > 0) if (tcs && tcs->id > 0)
@ -3267,6 +3229,14 @@ static inline void vrend_fill_shader_key(struct vrend_context *ctx,
key->num_indirect_patch_outputs = ctx->sub->shaders[next_type]->sinfo.num_indirect_patch_inputs; key->num_indirect_patch_outputs = ctx->sub->shaders[next_type]->sinfo.num_indirect_patch_inputs;
key->generic_outputs_expected_mask = ctx->sub->shaders[next_type]->sinfo.generic_inputs_emitted_mask; key->generic_outputs_expected_mask = ctx->sub->shaders[next_type]->sinfo.generic_inputs_emitted_mask;
} }
if (type != PIPE_SHADER_FRAGMENT &&
ctx->sub->shaders[PIPE_SHADER_FRAGMENT]) {
struct vrend_shader *fs =
ctx->sub->shaders[PIPE_SHADER_FRAGMENT]->current;
key->compiled_fs_uid = fs->uid;
key->fs_info = &fs->sel->sinfo;
}
} }
static inline int conv_shader_type(int type) static inline int conv_shader_type(int type)
@ -3287,9 +3257,10 @@ static int vrend_shader_create(struct vrend_context *ctx,
struct vrend_shader *shader, struct vrend_shader *shader,
struct vrend_shader_key *key) struct vrend_shader_key *key)
{ {
static uint32_t uid;
shader->id = glCreateShader(conv_shader_type(shader->sel->type)); shader->id = glCreateShader(conv_shader_type(shader->sel->type));
shader->compiled_fs_id = 0; shader->uid = ++uid;
if (shader->sel->tokens) { if (shader->sel->tokens) {
bool ret = vrend_convert_shader(ctx, &ctx->shader_cfg, shader->sel->tokens, bool ret = vrend_convert_shader(ctx, &ctx->shader_cfg, shader->sel->tokens,

@ -6726,6 +6726,14 @@ static void set_strbuffers(MAYBE_UNUSED const struct vrend_context *rctx, struct
VREND_DEBUG(dbg_shader_glsl, rctx, "\n"); VREND_DEBUG(dbg_shader_glsl, rctx, "\n");
} }
static bool vrend_patch_vertex_shader_interpolants(MAYBE_UNUSED const struct vrend_context *rctx,
const struct vrend_shader_cfg *cfg,
struct vrend_strarray *prog_strings,
const struct vrend_shader_info *vs_info,
const struct vrend_shader_info *fs_info,
const char *oprefix,
bool flatshade);
bool vrend_convert_shader(const struct vrend_context *rctx, bool vrend_convert_shader(const struct vrend_context *rctx,
const struct vrend_shader_cfg *cfg, const struct vrend_shader_cfg *cfg,
const struct tgsi_token *tokens, const struct tgsi_token *tokens,
@ -6818,6 +6826,31 @@ bool vrend_convert_shader(const struct vrend_context *rctx,
fill_sinfo(&ctx, sinfo); fill_sinfo(&ctx, sinfo);
set_strbuffers(rctx, &ctx, shader); set_strbuffers(rctx, &ctx, shader);
if (ctx.prog_type == TGSI_PROCESSOR_GEOMETRY) {
vrend_patch_vertex_shader_interpolants(rctx,
cfg,
shader,
sinfo,
key->fs_info, "gso",
key->flatshade);
} else if (!key->gs_present &&
ctx.prog_type == TGSI_PROCESSOR_TESS_EVAL) {
vrend_patch_vertex_shader_interpolants(rctx,
cfg,
shader,
sinfo,
key->fs_info, "teo",
key->flatshade);
} else if (!key->gs_present && !key->tes_present &&
ctx.prog_type == TGSI_PROCESSOR_VERTEX) {
vrend_patch_vertex_shader_interpolants(rctx,
cfg,
shader,
sinfo,
key->fs_info, "vso",
key->flatshade);
}
return true; return true;
fail: fail:
strbuf_free(&ctx.glsl_main); strbuf_free(&ctx.glsl_main);
@ -6866,7 +6899,7 @@ static void require_gpu_shader5_and_msinterp(struct vrend_strarray *program)
strbuf_append(&program->strings[SHADER_STRING_VER_EXT], gpu_shader5_and_msinterp_string); strbuf_append(&program->strings[SHADER_STRING_VER_EXT], gpu_shader5_and_msinterp_string);
} }
bool vrend_patch_vertex_shader_interpolants(MAYBE_UNUSED const struct vrend_context *rctx, static bool vrend_patch_vertex_shader_interpolants(MAYBE_UNUSED const struct vrend_context *rctx,
const struct vrend_shader_cfg *cfg, const struct vrend_shader_cfg *cfg,
struct vrend_strarray *prog_strings, struct vrend_strarray *prog_strings,
const struct vrend_shader_info *vs_info, const struct vrend_shader_info *vs_info,

@ -125,6 +125,9 @@ struct vrend_shader_key {
uint32_t generic_outputs_expected_mask; uint32_t generic_outputs_expected_mask;
uint8_t fs_swizzle_output_rgb_to_bgr; uint8_t fs_swizzle_output_rgb_to_bgr;
uint64_t force_invariant_inputs; uint64_t force_invariant_inputs;
uint32_t compiled_fs_uid;
struct vrend_shader_info *fs_info;
}; };
struct vrend_shader_cfg { struct vrend_shader_cfg {
@ -145,14 +148,6 @@ struct vrend_context;
#define SHADER_STRING_VER_EXT 0 #define SHADER_STRING_VER_EXT 0
#define SHADER_STRING_HDR 1 #define SHADER_STRING_HDR 1
bool vrend_patch_vertex_shader_interpolants(const struct vrend_context *rctx,
const struct vrend_shader_cfg *cfg,
struct vrend_strarray *shader,
const struct vrend_shader_info *vs_info,
const struct vrend_shader_info *fs_info,
const char *oprefix, bool flatshade);
bool vrend_convert_shader(const struct vrend_context *rctx, bool vrend_convert_shader(const struct vrend_context *rctx,
const struct vrend_shader_cfg *cfg, const struct vrend_shader_cfg *cfg,
const struct tgsi_token *tokens, const struct tgsi_token *tokens,

Loading…
Cancel
Save