summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2019-11-01 23:04:11 -0400
committerMarek Olšák <[email protected]>2019-11-19 18:02:06 -0500
commit4e70cba638b98ee2e3952d30ac767ce9f325656c (patch)
tree4d7440cbbd405766e40f3a3388ce3f4c5542a5fa /src/mesa
parent16e5f13b64c1acbfbb637c06f1ebd138c08eec0e (diff)
st/mesa: subclass st_vertex_program for VP-specific members
Inheritance: gl_program -> st_program -> st_vertex_program Acked-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/state_tracker/st_atom.h8
-rw-r--r--src/mesa/state_tracker/st_atom_array.c12
-rw-r--r--src/mesa/state_tracker/st_cb_feedback.c5
-rw-r--r--src/mesa/state_tracker/st_cb_program.c8
-rw-r--r--src/mesa/state_tracker/st_cb_rasterpos.c3
-rw-r--r--src/mesa/state_tracker/st_draw_feedback.c4
-rw-r--r--src/mesa/state_tracker/st_program.c95
-rw-r--r--src/mesa/state_tracker/st_program.h6
-rw-r--r--src/mesa/state_tracker/st_shader_cache.c31
9 files changed, 92 insertions, 80 deletions
diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h
index b40f4e24933..ffc64bd83f1 100644
--- a/src/mesa/state_tracker/st_atom.h
+++ b/src/mesa/state_tracker/st_atom.h
@@ -37,7 +37,7 @@
#include "main/glheader.h"
struct st_context;
-struct st_program;
+struct st_vertex_program;
struct st_vp_variant;
struct pipe_vertex_buffer;
struct pipe_vertex_element;
@@ -60,21 +60,21 @@ GLuint st_compare_func_to_pipe(GLenum func);
void
st_setup_arrays(struct st_context *st,
- const struct st_program *vp,
+ const struct st_vertex_program *vp,
const struct st_vp_variant *vp_variant,
struct pipe_vertex_element *velements,
struct pipe_vertex_buffer *vbuffer, unsigned *num_vbuffers);
void
st_setup_current(struct st_context *st,
- const struct st_program *vp,
+ const struct st_vertex_program *vp,
const struct st_vp_variant *vp_variant,
struct pipe_vertex_element *velements,
struct pipe_vertex_buffer *vbuffer, unsigned *num_vbuffers);
void
st_setup_current_user(struct st_context *st,
- const struct st_program *vp,
+ const struct st_vertex_program *vp,
const struct st_vp_variant *vp_variant,
struct pipe_vertex_element *velements,
struct pipe_vertex_buffer *vbuffer, unsigned *num_vbuffers);
diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c
index 4694cbf7e1f..9dafbb01b79 100644
--- a/src/mesa/state_tracker/st_atom_array.c
+++ b/src/mesa/state_tracker/st_atom_array.c
@@ -318,7 +318,7 @@ static void init_velement(struct pipe_vertex_element *velement,
assert(velement->src_format);
}
-static void init_velement_lowered(const struct st_program *vp,
+static void init_velement_lowered(const struct st_vertex_program *vp,
struct pipe_vertex_element *velements,
const struct gl_vertex_format *vformat,
int src_offset, int instance_divisor,
@@ -385,7 +385,7 @@ set_vertex_attribs(struct st_context *st,
void
st_setup_arrays(struct st_context *st,
- const struct st_program *vp,
+ const struct st_vertex_program *vp,
const struct st_vp_variant *vp_variant,
struct pipe_vertex_element *velements,
struct pipe_vertex_buffer *vbuffer, unsigned *num_vbuffers)
@@ -455,7 +455,7 @@ st_setup_arrays(struct st_context *st,
void
st_setup_current(struct st_context *st,
- const struct st_program *vp,
+ const struct st_vertex_program *vp,
const struct st_vp_variant *vp_variant,
struct pipe_vertex_element *velements,
struct pipe_vertex_buffer *vbuffer, unsigned *num_vbuffers)
@@ -466,8 +466,6 @@ st_setup_current(struct st_context *st,
/* Process values that should have better been uniforms in the application */
GLbitfield curmask = inputs_read & _mesa_draw_current_bits(ctx);
if (curmask) {
- /* vertex program validation must be done before this */
- const struct st_program *vp = st->vp;
const ubyte *input_to_index = vp->input_to_index;
/* For each attribute, upload the maximum possible size. */
GLubyte data[VERT_ATTRIB_MAX * sizeof(GLdouble) * 4];
@@ -517,7 +515,7 @@ st_setup_current(struct st_context *st,
void
st_setup_current_user(struct st_context *st,
- const struct st_program *vp,
+ const struct st_vertex_program *vp,
const struct st_vp_variant *vp_variant,
struct pipe_vertex_element *velements,
struct pipe_vertex_buffer *vbuffer, unsigned *num_vbuffers)
@@ -550,7 +548,7 @@ st_update_array(struct st_context *st)
{
/* vertex program validation must be done before this */
/* _NEW_PROGRAM, ST_NEW_VS_STATE */
- const struct st_program *vp = st->vp;
+ const struct st_vertex_program *vp = (struct st_vertex_program *)st->vp;
const struct st_vp_variant *vp_variant = st->vp_variant;
struct pipe_vertex_buffer vbuffer[PIPE_MAX_ATTRIBS];
diff --git a/src/mesa/state_tracker/st_cb_feedback.c b/src/mesa/state_tracker/st_cb_feedback.c
index a282e9b0269..1a02d8c5524 100644
--- a/src/mesa/state_tracker/st_cb_feedback.c
+++ b/src/mesa/state_tracker/st_cb_feedback.c
@@ -84,6 +84,7 @@ feedback_vertex(struct gl_context *ctx, const struct draw_context *draw,
const struct vertex_header *v)
{
const struct st_context *st = st_context(ctx);
+ struct st_vertex_program *stvp = (struct st_vertex_program *)st->vp;
GLfloat win[4];
const GLfloat *color, *texcoord;
GLuint slot;
@@ -101,13 +102,13 @@ feedback_vertex(struct gl_context *ctx, const struct draw_context *draw,
* color and texcoord attribs to use here.
*/
- slot = st->vp->result_to_output[VARYING_SLOT_COL0];
+ slot = stvp->result_to_output[VARYING_SLOT_COL0];
if (slot != ~0U)
color = v->data[slot];
else
color = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
- slot = st->vp->result_to_output[VARYING_SLOT_TEX0];
+ slot = stvp->result_to_output[VARYING_SLOT_TEX0];
if (slot != ~0U)
texcoord = v->data[slot];
else
diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c
index 2eb9c13d929..3a62212cce7 100644
--- a/src/mesa/state_tracker/st_cb_program.c
+++ b/src/mesa/state_tracker/st_cb_program.c
@@ -60,17 +60,15 @@ st_new_program(struct gl_context *ctx, GLenum target, GLuint id,
{
switch (target) {
case GL_VERTEX_PROGRAM_ARB: {
- struct st_program *prog = rzalloc(NULL,
- struct st_program);
- return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
+ struct st_vertex_program *prog = rzalloc(NULL, struct st_vertex_program);
+ return _mesa_init_gl_program(&prog->Base.Base, target, id, is_arb_asm);
}
case GL_TESS_CONTROL_PROGRAM_NV:
case GL_TESS_EVALUATION_PROGRAM_NV:
case GL_GEOMETRY_PROGRAM_NV:
case GL_FRAGMENT_PROGRAM_ARB:
case GL_COMPUTE_PROGRAM_NV: {
- struct st_program *prog = rzalloc(NULL,
- struct st_program);
+ struct st_program *prog = rzalloc(NULL, struct st_program);
return _mesa_init_gl_program(&prog->Base, target, id, is_arb_asm);
}
default:
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index 52ead76baab..108b11ede41 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -140,7 +140,8 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim)
struct gl_context *ctx = rs->ctx;
struct st_context *st = st_context(ctx);
const GLfloat height = (GLfloat) ctx->DrawBuffer->Height;
- const ubyte *outputMapping = st->vp->result_to_output;
+ struct st_vertex_program *stvp = (struct st_vertex_program *)st->vp;
+ const ubyte *outputMapping = stvp->result_to_output;
const GLfloat *pos;
GLuint i;
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index ebd30eaeb97..51c8459a083 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -106,7 +106,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe;
struct draw_context *draw = st_get_draw_context(st);
- const struct st_program *vp;
+ const struct st_vertex_program *vp;
struct st_vp_variant *vp_variant;
struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS];
unsigned num_vbuffers = 0;
@@ -136,7 +136,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
vbo_get_minmax_indices(ctx, prims, ib, &min_index, &max_index, nr_prims);
/* must get these after state validation! */
- vp = st->vp;
+ vp = (struct st_vertex_program *)st->vp;
vp_variant = st->vp_variant;
struct pipe_shader_state state = {0};
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index fd26b990e80..62d4de3d5b5 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -440,8 +440,10 @@ st_translate_prog_to_nir(struct st_context *st, struct gl_program *prog,
}
void
-st_prepare_vertex_program(struct st_program *stvp)
+st_prepare_vertex_program(struct st_program *stp)
{
+ struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
+
stvp->num_inputs = 0;
memset(stvp->input_to_index, ~0, sizeof(stvp->input_to_index));
memset(stvp->result_to_output, ~0, sizeof(stvp->result_to_output));
@@ -450,12 +452,12 @@ st_prepare_vertex_program(struct st_program *stvp)
* and TGSI generic input indexes, plus input attrib semantic info.
*/
for (unsigned attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
- if ((stvp->Base.info.inputs_read & BITFIELD64_BIT(attr)) != 0) {
+ if ((stp->Base.info.inputs_read & BITFIELD64_BIT(attr)) != 0) {
stvp->input_to_index[attr] = stvp->num_inputs;
stvp->index_to_input[stvp->num_inputs] = attr;
stvp->num_inputs++;
- if ((stvp->Base.DualSlotInputs & BITFIELD64_BIT(attr)) != 0) {
+ if ((stp->Base.DualSlotInputs & BITFIELD64_BIT(attr)) != 0) {
/* add placeholder for second part of a double attribute */
stvp->index_to_input[stvp->num_inputs] = ST_DOUBLE_ATTRIB_PLACEHOLDER;
stvp->num_inputs++;
@@ -469,7 +471,7 @@ st_prepare_vertex_program(struct st_program *stvp)
/* Compute mapping of vertex program outputs to slots. */
unsigned num_outputs = 0;
for (unsigned attr = 0; attr < VARYING_SLOT_MAX; attr++) {
- if (stvp->Base.info.outputs_written & BITFIELD64_BIT(attr))
+ if (stp->Base.info.outputs_written & BITFIELD64_BIT(attr))
stvp->result_to_output[attr] = num_outputs++;
}
/* pre-setup potentially unused edgeflag output */
@@ -518,7 +520,7 @@ st_translate_stream_output_info(struct gl_program *prog)
*/
bool
st_translate_vertex_program(struct st_context *st,
- struct st_program *stvp)
+ struct st_program *stp)
{
struct ureg_program *ureg;
enum pipe_error error;
@@ -527,31 +529,31 @@ st_translate_vertex_program(struct st_context *st,
ubyte output_semantic_name[VARYING_SLOT_MAX] = {0};
ubyte output_semantic_index[VARYING_SLOT_MAX] = {0};
- if (stvp->Base.arb.IsPositionInvariant)
- _mesa_insert_mvp_code(st->ctx, &stvp->Base);
+ if (stp->Base.arb.IsPositionInvariant)
+ _mesa_insert_mvp_code(st->ctx, &stp->Base);
- st_prepare_vertex_program(stvp);
+ st_prepare_vertex_program(stp);
/* ARB_vp: */
- if (!stvp->glsl_to_tgsi) {
- _mesa_remove_output_reads(&stvp->Base, PROGRAM_OUTPUT);
+ if (!stp->glsl_to_tgsi) {
+ _mesa_remove_output_reads(&stp->Base, PROGRAM_OUTPUT);
/* This determines which states will be updated when the assembly
* shader is bound.
*/
- stvp->affected_states = ST_NEW_VS_STATE |
+ stp->affected_states = ST_NEW_VS_STATE |
ST_NEW_RASTERIZER |
ST_NEW_VERTEX_ARRAYS;
- if (stvp->Base.Parameters->NumParameters)
- stvp->affected_states |= ST_NEW_VS_CONSTANTS;
+ if (stp->Base.Parameters->NumParameters)
+ stp->affected_states |= ST_NEW_VS_CONSTANTS;
/* No samplers are allowed in ARB_vp. */
}
/* Get semantic names and indices. */
for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
- if (stvp->Base.info.outputs_written & BITFIELD64_BIT(attr)) {
+ if (stp->Base.info.outputs_written & BITFIELD64_BIT(attr)) {
unsigned slot = num_outputs++;
unsigned semantic_name, semantic_index;
tgsi_get_gl_varying_semantic(attr, st->needs_texcoord_semantic,
@@ -568,25 +570,27 @@ st_translate_vertex_program(struct st_context *st,
if (ureg == NULL)
return false;
- if (stvp->Base.info.clip_distance_array_size)
+ if (stp->Base.info.clip_distance_array_size)
ureg_property(ureg, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED,
- stvp->Base.info.clip_distance_array_size);
- if (stvp->Base.info.cull_distance_array_size)
+ stp->Base.info.clip_distance_array_size);
+ if (stp->Base.info.cull_distance_array_size)
ureg_property(ureg, TGSI_PROPERTY_NUM_CULLDIST_ENABLED,
- stvp->Base.info.cull_distance_array_size);
+ stp->Base.info.cull_distance_array_size);
if (ST_DEBUG & DEBUG_MESA) {
- _mesa_print_program(&stvp->Base);
- _mesa_print_program_parameters(st->ctx, &stvp->Base);
+ _mesa_print_program(&stp->Base);
+ _mesa_print_program_parameters(st->ctx, &stp->Base);
debug_printf("\n");
}
- if (stvp->glsl_to_tgsi) {
+ struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
+
+ if (stp->glsl_to_tgsi) {
error = st_translate_program(st->ctx,
PIPE_SHADER_VERTEX,
ureg,
- stvp->glsl_to_tgsi,
- &stvp->Base,
+ stp->glsl_to_tgsi,
+ &stp->Base,
/* inputs */
stvp->num_inputs,
stvp->input_to_index,
@@ -600,14 +604,14 @@ st_translate_vertex_program(struct st_context *st,
output_semantic_name,
output_semantic_index);
- st_translate_stream_output_info(&stvp->Base);
+ st_translate_stream_output_info(&stp->Base);
- free_glsl_to_tgsi_visitor(stvp->glsl_to_tgsi);
+ free_glsl_to_tgsi_visitor(stp->glsl_to_tgsi);
} else
error = st_translate_mesa_program(st->ctx,
PIPE_SHADER_VERTEX,
ureg,
- &stvp->Base,
+ &stp->Base,
/* inputs */
stvp->num_inputs,
stvp->input_to_index,
@@ -622,17 +626,17 @@ st_translate_vertex_program(struct st_context *st,
if (error) {
debug_printf("%s: failed to translate Mesa program:\n", __func__);
- _mesa_print_program(&stvp->Base);
+ _mesa_print_program(&stp->Base);
debug_assert(0);
return false;
}
- stvp->state.tokens = ureg_get_tokens(ureg, NULL);
+ stp->state.tokens = ureg_get_tokens(ureg, NULL);
ureg_destroy(ureg);
- if (stvp->glsl_to_tgsi) {
- stvp->glsl_to_tgsi = NULL;
- st_store_ir_in_disk_cache(st, &stvp->Base, false);
+ if (stp->glsl_to_tgsi) {
+ stp->glsl_to_tgsi = NULL;
+ st_store_ir_in_disk_cache(st, &stp->Base, false);
}
/* Translate to NIR.
@@ -644,20 +648,20 @@ st_translate_vertex_program(struct st_context *st,
if (st->pipe->screen->get_shader_param(st->pipe->screen,
PIPE_SHADER_VERTEX,
PIPE_SHADER_CAP_PREFERRED_IR)) {
- assert(!stvp->glsl_to_tgsi);
+ assert(!stp->glsl_to_tgsi);
nir_shader *nir =
- st_translate_prog_to_nir(st, &stvp->Base, MESA_SHADER_VERTEX);
+ st_translate_prog_to_nir(st, &stp->Base, MESA_SHADER_VERTEX);
- if (stvp->state.ir.nir)
- ralloc_free(stvp->state.ir.nir);
- stvp->state.type = PIPE_SHADER_IR_NIR;
- stvp->state.ir.nir = nir;
- stvp->Base.nir = nir;
+ if (stp->state.ir.nir)
+ ralloc_free(stp->state.ir.nir);
+ stp->state.type = PIPE_SHADER_IR_NIR;
+ stp->state.ir.nir = nir;
+ stp->Base.nir = nir;
return true;
}
- return stvp->state.tokens != NULL;
+ return stp->state.tokens != NULL;
}
static const gl_state_index16 depth_range_state[STATE_LENGTH] =
@@ -678,7 +682,7 @@ st_create_vp_variant(struct st_context *st,
struct gl_program_parameter_list *params = stvp->Base.Parameters;
vpv->key = *key;
- vpv->num_inputs = stvp->num_inputs;
+ vpv->num_inputs = ((struct st_vertex_program*)stvp)->num_inputs;
state.stream_output = stvp->state.stream_output;
@@ -807,13 +811,14 @@ st_create_vp_variant(struct st_context *st,
*/
struct st_vp_variant *
st_get_vp_variant(struct st_context *st,
- struct st_program *stvp,
+ struct st_program *stp,
const struct st_common_variant_key *key)
{
+ struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
struct st_vp_variant *vpv;
/* Search for existing variant */
- for (vpv = stvp->vp_variants; vpv; vpv = vpv->next) {
+ for (vpv = stp->vp_variants; vpv; vpv = vpv->next) {
if (memcmp(&vpv->key, key, sizeof(*key)) == 0) {
break;
}
@@ -821,7 +826,7 @@ st_get_vp_variant(struct st_context *st,
if (!vpv) {
/* create now */
- vpv = st_create_vp_variant(st, stvp, key);
+ vpv = st_create_vp_variant(st, stp, key);
if (vpv) {
for (unsigned index = 0; index < vpv->num_inputs; ++index) {
unsigned attr = stvp->index_to_input[index];
@@ -831,8 +836,8 @@ st_get_vp_variant(struct st_context *st,
}
/* insert into list */
- vpv->next = stvp->vp_variants;
- stvp->vp_variants = vpv;
+ vpv->next = stp->vp_variants;
+ stp->vp_variants = vpv;
}
}
diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h
index 869b7ead55b..9ad23235bcb 100644
--- a/src/mesa/state_tracker/st_program.h
+++ b/src/mesa/state_tracker/st_program.h
@@ -251,6 +251,12 @@ struct st_program
struct st_vp_variant *vp_variants;
struct st_fp_variant *fp_variants;
};
+};
+
+
+struct st_vertex_program
+{
+ struct st_program Base;
/** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
ubyte index_to_input[PIPE_MAX_ATTRIBS];
diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
index b9c4556d634..b777e8dcbba 100644
--- a/src/mesa/state_tracker/st_shader_cache.c
+++ b/src/mesa/state_tracker/st_shader_cache.c
@@ -86,13 +86,15 @@ st_serialise_ir_program(struct gl_context *ctx, struct gl_program *prog,
blob_init(&blob);
if (prog->info.stage == MESA_SHADER_VERTEX) {
- blob_write_uint32(&blob, stp->num_inputs);
- blob_write_bytes(&blob, stp->index_to_input,
- sizeof(stp->index_to_input));
- blob_write_bytes(&blob, stp->input_to_index,
- sizeof(stp->input_to_index));
- blob_write_bytes(&blob, stp->result_to_output,
- sizeof(stp->result_to_output));
+ struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
+
+ blob_write_uint32(&blob, stvp->num_inputs);
+ blob_write_bytes(&blob, stvp->index_to_input,
+ sizeof(stvp->index_to_input));
+ blob_write_bytes(&blob, stvp->input_to_index,
+ sizeof(stvp->input_to_index));
+ blob_write_bytes(&blob, stvp->result_to_output,
+ sizeof(stvp->result_to_output));
}
if (prog->info.stage == MESA_SHADER_VERTEX ||
@@ -174,13 +176,14 @@ st_deserialise_ir_program(struct gl_context *ctx,
if (prog->info.stage == MESA_SHADER_VERTEX) {
st_release_vp_variants(st, stp);
- stp->num_inputs = blob_read_uint32(&blob_reader);
- blob_copy_bytes(&blob_reader, (uint8_t *) stp->index_to_input,
- sizeof(stp->index_to_input));
- blob_copy_bytes(&blob_reader, (uint8_t *) stp->input_to_index,
- sizeof(stp->input_to_index));
- blob_copy_bytes(&blob_reader, (uint8_t *) stp->result_to_output,
- sizeof(stp->result_to_output));
+ struct st_vertex_program *stvp = (struct st_vertex_program *)stp;
+ stvp->num_inputs = blob_read_uint32(&blob_reader);
+ blob_copy_bytes(&blob_reader, (uint8_t *) stvp->index_to_input,
+ sizeof(stvp->index_to_input));
+ blob_copy_bytes(&blob_reader, (uint8_t *) stvp->input_to_index,
+ sizeof(stvp->input_to_index));
+ blob_copy_bytes(&blob_reader, (uint8_t *) stvp->result_to_output,
+ sizeof(stvp->result_to_output));
} else if (prog->info.stage == MESA_SHADER_FRAGMENT) {
st_release_fp_variants(st, stp);
} else {