#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;
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);
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,
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)
/* 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];
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)
{
/* 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];
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;
* 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
{
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:
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;
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;
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};
}
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));
* 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++;
/* 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 */
*/
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;
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,
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,
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,
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.
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] =
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;
*/
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;
}
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];
}
/* insert into list */
- vpv->next = stvp->vp_variants;
- stvp->vp_variants = vpv;
+ vpv->next = stp->vp_variants;
+ stp->vp_variants = vpv;
}
}
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];
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 ||
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 {