Checkpoint: rework shader input/output register mapping.
This is a step toward removing TGSI_ATTRIB_ tokens. Basically, when translating Mesa programs to TGSI programs, pass in input and output register re-maps, plus interpolation info. There's some known breakage (cubemap.c) so more to be done...
This commit is contained in:
@@ -67,6 +67,10 @@ fetch_attrib4(const void *ptr, unsigned format, float attrib[4])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch vertex attributes for 'count' vertices.
|
||||||
|
*/
|
||||||
void draw_vertex_fetch( struct draw_context *draw,
|
void draw_vertex_fetch( struct draw_context *draw,
|
||||||
struct tgsi_exec_machine *machine,
|
struct tgsi_exec_machine *machine,
|
||||||
const unsigned *elts,
|
const unsigned *elts,
|
||||||
@@ -74,12 +78,12 @@ void draw_vertex_fetch( struct draw_context *draw,
|
|||||||
{
|
{
|
||||||
unsigned j;
|
unsigned j;
|
||||||
|
|
||||||
|
/* loop over vertices */
|
||||||
/* load machine inputs */
|
|
||||||
for (j = 0; j < count; j++) {
|
for (j = 0; j < count; j++) {
|
||||||
unsigned attr;
|
uint attr;
|
||||||
for (attr = 0; attr < 16; attr++) {
|
/* loop over vertex attributes (vertex shader inputs) */
|
||||||
if (draw->vertex_shader.inputs_read & (1 << attr)) {
|
for (attr = 0; attr < draw->vertex_shader.num_inputs; attr++) {
|
||||||
|
|
||||||
unsigned buf = draw->vertex_element[attr].vertex_buffer_index;
|
unsigned buf = draw->vertex_element[attr].vertex_buffer_index;
|
||||||
const void *src
|
const void *src
|
||||||
= (const void *) ((const ubyte *) draw->mapped_vbuffer[buf]
|
= (const void *) ((const ubyte *) draw->mapped_vbuffer[buf]
|
||||||
@@ -96,6 +100,5 @@ void draw_vertex_fetch( struct draw_context *draw,
|
|||||||
machine->Inputs[attr].xyzw[3].f[j] = p[3]; /*W*/
|
machine->Inputs[attr].xyzw[3].f[j] = p[3]; /*W*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -114,7 +114,6 @@ run_vertex_program(struct draw_context *draw,
|
|||||||
|
|
||||||
draw_vertex_fetch( draw, &machine, elts, count );
|
draw_vertex_fetch( draw, &machine, elts, count );
|
||||||
|
|
||||||
|
|
||||||
/* run shader */
|
/* run shader */
|
||||||
if( draw->vertex_shader.executable != NULL ) {
|
if( draw->vertex_shader.executable != NULL ) {
|
||||||
#if defined(USE_X86_ASM) || defined(SLANG_X86)
|
#if defined(USE_X86_ASM) || defined(SLANG_X86)
|
||||||
@@ -159,14 +158,23 @@ run_vertex_program(struct draw_context *draw,
|
|||||||
vOut[j]->data[0][2] = z * scale[2] + trans[2];
|
vOut[j]->data[0][2] = z * scale[2] + trans[2];
|
||||||
vOut[j]->data[0][3] = w;
|
vOut[j]->data[0][3] = w;
|
||||||
|
|
||||||
/* remaining attributes are packed into sequential post-transform
|
/* Remaining attributes are packed into sequential post-transform
|
||||||
* vertex attrib slots.
|
* vertex attrib slots.
|
||||||
|
* Skip 0 since we just did it above.
|
||||||
|
* Subtract two because of the VERTEX_HEADER, CLIP_POS attribs.
|
||||||
*/
|
*/
|
||||||
for (slot = 1; slot < draw->vertex_info.num_attribs; slot++) {
|
for (slot = 1; slot < draw->vertex_info.num_attribs - 2; slot++) {
|
||||||
vOut[j]->data[slot][0] = machine.Outputs[slot].xyzw[0].f[j];
|
vOut[j]->data[slot][0] = machine.Outputs[slot].xyzw[0].f[j];
|
||||||
vOut[j]->data[slot][1] = machine.Outputs[slot].xyzw[1].f[j];
|
vOut[j]->data[slot][1] = machine.Outputs[slot].xyzw[1].f[j];
|
||||||
vOut[j]->data[slot][2] = machine.Outputs[slot].xyzw[2].f[j];
|
vOut[j]->data[slot][2] = machine.Outputs[slot].xyzw[2].f[j];
|
||||||
vOut[j]->data[slot][3] = machine.Outputs[slot].xyzw[3].f[j];
|
vOut[j]->data[slot][3] = machine.Outputs[slot].xyzw[3].f[j];
|
||||||
|
/*
|
||||||
|
printf("output %d: %f %f %f %f\n", slot,
|
||||||
|
vOut[j]->data[slot][0],
|
||||||
|
vOut[j]->data[slot][1],
|
||||||
|
vOut[j]->data[slot][2],
|
||||||
|
vOut[j]->data[slot][3]);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
} /* loop over vertices */
|
} /* loop over vertices */
|
||||||
}
|
}
|
||||||
|
@@ -144,6 +144,9 @@ struct pipe_shader_state {
|
|||||||
unsigned outputs_written; /**< TGSI_ATTRIB_ bits */
|
unsigned outputs_written; /**< TGSI_ATTRIB_ bits */
|
||||||
const struct tgsi_token *tokens;
|
const struct tgsi_token *tokens;
|
||||||
void *executable;
|
void *executable;
|
||||||
|
|
||||||
|
uint num_inputs;
|
||||||
|
uint num_outputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pipe_depth_stencil_state
|
struct pipe_depth_stencil_state
|
||||||
|
@@ -448,6 +448,14 @@ static void tri_persp_coeff( struct setup_stage *setup,
|
|||||||
float a = setup->ebot.dy * majda - botda * setup->emaj.dy;
|
float a = setup->ebot.dy * majda - botda * setup->emaj.dy;
|
||||||
float b = setup->emaj.dx * botda - majda * setup->ebot.dx;
|
float b = setup->emaj.dx * botda - majda * setup->ebot.dx;
|
||||||
|
|
||||||
|
/*
|
||||||
|
printf("tri persp %d,%d: %f %f %f\n", slot, i,
|
||||||
|
setup->vmin->data[slot][i],
|
||||||
|
setup->vmid->data[slot][i],
|
||||||
|
setup->vmax->data[slot][i]
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
assert(slot < TGSI_ATTRIB_MAX);
|
assert(slot < TGSI_ATTRIB_MAX);
|
||||||
assert(i <= 3);
|
assert(i <= 3);
|
||||||
|
|
||||||
|
@@ -211,6 +211,7 @@ tgsi_mesa_translate_fragment_output(GLuint attrib)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 01
|
||||||
uint
|
uint
|
||||||
tgsi_mesa_translate_vertex_input_mask(GLbitfield mask)
|
tgsi_mesa_translate_vertex_input_mask(GLbitfield mask)
|
||||||
{
|
{
|
||||||
@@ -224,7 +225,7 @@ tgsi_mesa_translate_vertex_input_mask(GLbitfield mask)
|
|||||||
}
|
}
|
||||||
return tgsiMask;
|
return tgsiMask;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
uint
|
uint
|
||||||
tgsi_mesa_translate_vertex_output_mask(GLbitfield mask)
|
tgsi_mesa_translate_vertex_output_mask(GLbitfield mask)
|
||||||
@@ -318,7 +319,9 @@ map_register_file_index(
|
|||||||
GLuint processor,
|
GLuint processor,
|
||||||
GLuint file,
|
GLuint file,
|
||||||
GLuint index,
|
GLuint index,
|
||||||
GLbitfield usage_bitmask )
|
GLbitfield usage_bitmask,
|
||||||
|
const GLuint inputMapping[],
|
||||||
|
const GLuint outputMapping[])
|
||||||
{
|
{
|
||||||
GLuint mapped_index;
|
GLuint mapped_index;
|
||||||
GLuint i;
|
GLuint i;
|
||||||
@@ -337,6 +340,12 @@ map_register_file_index(
|
|||||||
* etc.
|
* etc.
|
||||||
*/
|
*/
|
||||||
assert( index < 32 );
|
assert( index < 32 );
|
||||||
|
if (inputMapping) {
|
||||||
|
printf("New map %d input %d to %d\n", processor, index,
|
||||||
|
inputMapping[index]);
|
||||||
|
return inputMapping[index];
|
||||||
|
}
|
||||||
|
|
||||||
assert( usage_bitmask & (1 << index) );
|
assert( usage_bitmask & (1 << index) );
|
||||||
mapped_index = 0;
|
mapped_index = 0;
|
||||||
for( i = 0; i < index; i++ ) {
|
for( i = 0; i < index; i++ ) {
|
||||||
@@ -344,7 +353,7 @@ map_register_file_index(
|
|||||||
mapped_index++;
|
mapped_index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Map input %d to %d\n", index, mapped_index);
|
printf("Map %d input %d to %d\n", processor, index, mapped_index);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TGSI_FILE_OUTPUT:
|
case TGSI_FILE_OUTPUT:
|
||||||
@@ -372,6 +381,8 @@ map_register_file_index(
|
|||||||
mapped_index++;
|
mapped_index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("Map VP output from %d to %d\n", index, mapped_index);
|
||||||
|
assert(outputMapping[index] == mapped_index);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -443,6 +454,8 @@ compile_instruction(
|
|||||||
struct tgsi_full_instruction *fullinst,
|
struct tgsi_full_instruction *fullinst,
|
||||||
GLuint inputs_read,
|
GLuint inputs_read,
|
||||||
GLuint outputs_written,
|
GLuint outputs_written,
|
||||||
|
const GLuint inputMapping[],
|
||||||
|
const GLuint outputMapping[],
|
||||||
GLuint preamble_size,
|
GLuint preamble_size,
|
||||||
GLuint processor )
|
GLuint processor )
|
||||||
{
|
{
|
||||||
@@ -462,7 +475,9 @@ compile_instruction(
|
|||||||
processor,
|
processor,
|
||||||
fulldst->DstRegister.File,
|
fulldst->DstRegister.File,
|
||||||
inst->DstReg.Index,
|
inst->DstReg.Index,
|
||||||
outputs_written
|
outputs_written,
|
||||||
|
NULL,
|
||||||
|
outputMapping
|
||||||
);
|
);
|
||||||
fulldst->DstRegister.WriteMask = convert_writemask( inst->DstReg.WriteMask );
|
fulldst->DstRegister.WriteMask = convert_writemask( inst->DstReg.WriteMask );
|
||||||
|
|
||||||
@@ -475,7 +490,9 @@ compile_instruction(
|
|||||||
processor,
|
processor,
|
||||||
fullsrc->SrcRegister.File,
|
fullsrc->SrcRegister.File,
|
||||||
inst->SrcReg[i].Index,
|
inst->SrcReg[i].Index,
|
||||||
inputs_read );
|
inputs_read,
|
||||||
|
inputMapping,
|
||||||
|
outputMapping );
|
||||||
|
|
||||||
for( j = 0; j < 4; j++ ) {
|
for( j = 0; j < 4; j++ ) {
|
||||||
GLuint swz;
|
GLuint swz;
|
||||||
@@ -789,9 +806,20 @@ make_frag_output_decl(
|
|||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert Mesa fragment program to TGSI format.
|
||||||
|
* \param inputMapping array to map original Mesa fragment program inputs
|
||||||
|
* registers to TGSI generic input indexes
|
||||||
|
* \param interpMode array[FRAG_ATTRIB_x] of TGSI_INTERPOLATE_LINEAR/PERSP.
|
||||||
|
*
|
||||||
|
*/
|
||||||
GLboolean
|
GLboolean
|
||||||
tgsi_mesa_compile_fp_program(
|
tgsi_mesa_compile_fp_program(
|
||||||
const struct gl_fragment_program *program,
|
const struct gl_fragment_program *program,
|
||||||
|
const GLuint inputMapping[],
|
||||||
|
const GLuint interpMode[],
|
||||||
|
const GLuint outputMapping[],
|
||||||
struct tgsi_token *tokens,
|
struct tgsi_token *tokens,
|
||||||
GLuint maxTokens )
|
GLuint maxTokens )
|
||||||
{
|
{
|
||||||
@@ -800,8 +828,10 @@ tgsi_mesa_compile_fp_program(
|
|||||||
struct tgsi_processor *processor;
|
struct tgsi_processor *processor;
|
||||||
struct tgsi_full_declaration fulldecl;
|
struct tgsi_full_declaration fulldecl;
|
||||||
struct tgsi_full_instruction fullinst;
|
struct tgsi_full_instruction fullinst;
|
||||||
|
/*
|
||||||
struct tgsi_full_dst_register *fulldst;
|
struct tgsi_full_dst_register *fulldst;
|
||||||
struct tgsi_full_src_register *fullsrc;
|
struct tgsi_full_src_register *fullsrc;
|
||||||
|
*/
|
||||||
GLuint inputs_read;
|
GLuint inputs_read;
|
||||||
GLboolean reads_wpos;
|
GLboolean reads_wpos;
|
||||||
GLuint preamble_size = 0;
|
GLuint preamble_size = 0;
|
||||||
@@ -822,7 +852,7 @@ tgsi_mesa_compile_fp_program(
|
|||||||
/*
|
/*
|
||||||
* Declare input attributes. Note that we do not interpolate fragment position.
|
* Declare input attributes. Note that we do not interpolate fragment position.
|
||||||
*/
|
*/
|
||||||
|
reads_wpos = 1;
|
||||||
/* Fragment position. */
|
/* Fragment position. */
|
||||||
if( reads_wpos ) {
|
if( reads_wpos ) {
|
||||||
fulldecl = make_frag_input_decl(
|
fulldecl = make_frag_input_decl(
|
||||||
@@ -853,20 +883,16 @@ tgsi_mesa_compile_fp_program(
|
|||||||
for( i = 1; i < 32; i++ ) {
|
for( i = 1; i < 32; i++ ) {
|
||||||
if( inputs_read & (1 << i) ) {
|
if( inputs_read & (1 << i) ) {
|
||||||
count++;
|
count++;
|
||||||
}
|
fulldecl = make_frag_input_decl(count,
|
||||||
}
|
count,
|
||||||
if( count > 0 ) {
|
interpMode[i],
|
||||||
fulldecl = make_frag_input_decl(
|
|
||||||
1,
|
|
||||||
1 + count - 1,
|
|
||||||
TGSI_INTERPOLATE_PERSPECTIVE,
|
|
||||||
TGSI_WRITEMASK_XYZW );
|
TGSI_WRITEMASK_XYZW );
|
||||||
ti += tgsi_build_full_declaration(
|
ti += tgsi_build_full_declaration(&fulldecl,
|
||||||
&fulldecl,
|
|
||||||
&tokens[ti],
|
&tokens[ti],
|
||||||
header,
|
header,
|
||||||
maxTokens - ti );
|
maxTokens - ti );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Declare output attributes.
|
* Declare output attributes.
|
||||||
@@ -932,6 +958,8 @@ tgsi_mesa_compile_fp_program(
|
|||||||
&fullinst,
|
&fullinst,
|
||||||
inputs_read,
|
inputs_read,
|
||||||
~0, /*outputs_written*/
|
~0, /*outputs_written*/
|
||||||
|
inputMapping,
|
||||||
|
outputMapping,
|
||||||
preamble_size,
|
preamble_size,
|
||||||
TGSI_PROCESSOR_FRAGMENT ) ) {
|
TGSI_PROCESSOR_FRAGMENT ) ) {
|
||||||
assert( i == program->Base.NumInstructions - 1 );
|
assert( i == program->Base.NumInstructions - 1 );
|
||||||
@@ -955,8 +983,10 @@ tgsi_mesa_compile_fp_program(
|
|||||||
GLboolean
|
GLboolean
|
||||||
tgsi_mesa_compile_vp_program(
|
tgsi_mesa_compile_vp_program(
|
||||||
const struct gl_vertex_program *program,
|
const struct gl_vertex_program *program,
|
||||||
|
const GLuint inputMapping[],
|
||||||
|
const GLuint outputMapping[],
|
||||||
struct tgsi_token *tokens,
|
struct tgsi_token *tokens,
|
||||||
GLuint maxTokens )
|
GLuint maxTokens)
|
||||||
{
|
{
|
||||||
GLuint i, ti;
|
GLuint i, ti;
|
||||||
struct tgsi_header *header;
|
struct tgsi_header *header;
|
||||||
@@ -983,6 +1013,8 @@ tgsi_mesa_compile_vp_program(
|
|||||||
&fullinst,
|
&fullinst,
|
||||||
inputs_read,
|
inputs_read,
|
||||||
outputs_written,
|
outputs_written,
|
||||||
|
inputMapping,
|
||||||
|
outputMapping,
|
||||||
0,
|
0,
|
||||||
TGSI_PROCESSOR_VERTEX ) ) {
|
TGSI_PROCESSOR_VERTEX ) ) {
|
||||||
assert( i == program->Base.NumInstructions - 1 );
|
assert( i == program->Base.NumInstructions - 1 );
|
||||||
|
@@ -10,12 +10,17 @@ struct tgsi_token;
|
|||||||
GLboolean
|
GLboolean
|
||||||
tgsi_mesa_compile_fp_program(
|
tgsi_mesa_compile_fp_program(
|
||||||
const struct gl_fragment_program *program,
|
const struct gl_fragment_program *program,
|
||||||
|
const GLuint inputMapping[],
|
||||||
|
const GLuint interpMode[],
|
||||||
|
const GLuint outputMapping[],
|
||||||
struct tgsi_token *tokens,
|
struct tgsi_token *tokens,
|
||||||
GLuint maxTokens );
|
GLuint maxTokens );
|
||||||
|
|
||||||
GLboolean
|
GLboolean
|
||||||
tgsi_mesa_compile_vp_program(
|
tgsi_mesa_compile_vp_program(
|
||||||
const struct gl_vertex_program *program,
|
const struct gl_vertex_program *program,
|
||||||
|
const GLuint inputMapping[],
|
||||||
|
const GLuint outputMapping[],
|
||||||
struct tgsi_token *tokens,
|
struct tgsi_token *tokens,
|
||||||
GLuint maxTokens );
|
GLuint maxTokens );
|
||||||
|
|
||||||
|
@@ -42,17 +42,34 @@
|
|||||||
#include "st_atom.h"
|
#include "st_atom.h"
|
||||||
#include "st_program.h"
|
#include "st_program.h"
|
||||||
|
|
||||||
#define TGSI_DEBUG 0
|
#define TGSI_DEBUG 1
|
||||||
|
|
||||||
static void compile_fs( struct st_context *st )
|
static void compile_fs( struct st_context *st )
|
||||||
{
|
{
|
||||||
|
/* Map FRAG_RESULT_COLR to output 1, map FRAG_RESULT_DEPR to output 0 */
|
||||||
|
static const GLuint outputMapping[2] = {1, 0};
|
||||||
struct st_fragment_program *fp = st->fp;
|
struct st_fragment_program *fp = st->fp;
|
||||||
struct pipe_shader_state fs;
|
struct pipe_shader_state fs;
|
||||||
struct pipe_shader_state *cached;
|
struct pipe_shader_state *cached;
|
||||||
|
GLuint interpMode[16]; /* XXX size? */
|
||||||
|
GLuint i;
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
if (fp->Base.Base.InputsRead & (1 << i)) {
|
||||||
|
if (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1) {
|
||||||
|
interpMode[i] = TGSI_INTERPOLATE_LINEAR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
interpMode[i] = TGSI_INTERPOLATE_PERSPECTIVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* XXX: fix static allocation of tokens:
|
/* XXX: fix static allocation of tokens:
|
||||||
*/
|
*/
|
||||||
tgsi_mesa_compile_fp_program( &fp->Base, fp->tokens, ST_FP_MAX_TOKENS );
|
tgsi_mesa_compile_fp_program( &fp->Base, NULL, interpMode,
|
||||||
|
outputMapping,
|
||||||
|
fp->tokens, ST_FP_MAX_TOKENS );
|
||||||
|
|
||||||
memset(&fs, 0, sizeof(fs));
|
memset(&fs, 0, sizeof(fs));
|
||||||
fs.inputs_read
|
fs.inputs_read
|
||||||
@@ -64,7 +81,7 @@ static void compile_fs( struct st_context *st )
|
|||||||
fp->fsx = cached;
|
fp->fsx = cached;
|
||||||
|
|
||||||
if (TGSI_DEBUG)
|
if (TGSI_DEBUG)
|
||||||
tgsi_dump( fp->tokens, TGSI_DUMP_VERBOSE );
|
tgsi_dump( fp->tokens, 0/*TGSI_DUMP_VERBOSE*/ );
|
||||||
|
|
||||||
fp->dirty = 0;
|
fp->dirty = 0;
|
||||||
}
|
}
|
||||||
|
@@ -51,25 +51,61 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* translate shader to TGSI format
|
/**
|
||||||
*/
|
* Translate Mesa shader to TGSI format
|
||||||
|
*/
|
||||||
static void compile_vs( struct st_context *st )
|
static void compile_vs( struct st_context *st )
|
||||||
{
|
{
|
||||||
struct st_vertex_program *vp = st->vp;
|
struct st_vertex_program *vp = st->vp;
|
||||||
struct pipe_shader_state vs;
|
struct pipe_shader_state vs;
|
||||||
struct pipe_shader_state *cached;
|
struct pipe_shader_state *cached;
|
||||||
/* XXX: fix static allocation of tokens:
|
GLuint i;
|
||||||
*/
|
|
||||||
tgsi_mesa_compile_vp_program( &vp->Base, vp->tokens, ST_FP_MAX_TOKENS );
|
|
||||||
|
|
||||||
memset(&vs, 0, sizeof(vs));
|
memset(&vs, 0, sizeof(vs));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine how many inputs there are.
|
||||||
|
* Also, compute two look-up tables that map between Mesa VERT_ATTRIB_x
|
||||||
|
* values and TGSI generic input indexes.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < MAX_VERTEX_PROGRAM_ATTRIBS; i++) {
|
||||||
|
if (vp->Base.Base.InputsRead & (1 << i)) {
|
||||||
|
vp->input_to_index[i] = vs.num_inputs;
|
||||||
|
vp->index_to_input[vs.num_inputs] = i;
|
||||||
|
vs.num_inputs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine output register mapping.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < VERT_RESULT_MAX; i++) {
|
||||||
|
if (vp->Base.Base.OutputsWritten & (1 << i)) {
|
||||||
|
vp->output_to_index[i] = vs.num_outputs;
|
||||||
|
vp->index_to_output[vs.num_outputs] = i;
|
||||||
|
vs.num_outputs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* XXX: fix static allocation of tokens:
|
||||||
|
*/
|
||||||
|
tgsi_mesa_compile_vp_program( &vp->Base,
|
||||||
|
vp->input_to_index,
|
||||||
|
vp->output_to_index,
|
||||||
|
vp->tokens, ST_FP_MAX_TOKENS );
|
||||||
|
|
||||||
|
#if 01
|
||||||
vs.inputs_read
|
vs.inputs_read
|
||||||
= tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead);
|
= tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead);
|
||||||
|
#endif
|
||||||
vs.outputs_written
|
vs.outputs_written
|
||||||
= tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten);
|
= tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten);
|
||||||
|
|
||||||
vs.tokens = &vp->tokens[0];
|
vs.tokens = &vp->tokens[0];
|
||||||
|
|
||||||
cached = st_cached_shader_state(st, &vs);
|
cached = st_cached_shader_state(st, &vs);
|
||||||
|
|
||||||
vp->vs = cached;
|
vp->vs = cached;
|
||||||
|
|
||||||
if (TGSI_DEBUG)
|
if (TGSI_DEBUG)
|
||||||
@@ -121,7 +157,7 @@ static void update_vs( struct st_context *st )
|
|||||||
const struct st_tracked_state st_update_vs = {
|
const struct st_tracked_state st_update_vs = {
|
||||||
.name = "st_update_vs",
|
.name = "st_update_vs",
|
||||||
.dirty = {
|
.dirty = {
|
||||||
.mesa = 0,
|
.mesa = _NEW_PROGRAM,
|
||||||
.st = ST_NEW_VERTEX_PROGRAM,
|
.st = ST_NEW_VERTEX_PROGRAM,
|
||||||
},
|
},
|
||||||
.update = update_vs
|
.update = update_vs
|
||||||
|
@@ -119,12 +119,19 @@ is_depth_stencil_format(GLuint pipeFormat)
|
|||||||
* Create a simple fragment shader that just passes through the fragment color.
|
* Create a simple fragment shader that just passes through the fragment color.
|
||||||
*/
|
*/
|
||||||
static struct st_fragment_program *
|
static struct st_fragment_program *
|
||||||
make_color_shader(struct st_context *st)
|
make_frag_shader(struct st_context *st)
|
||||||
{
|
{
|
||||||
|
static const GLuint outputMapping[] = { 1, 0 };
|
||||||
GLcontext *ctx = st->ctx;
|
GLcontext *ctx = st->ctx;
|
||||||
struct st_fragment_program *stfp;
|
struct st_fragment_program *stfp;
|
||||||
struct gl_program *p;
|
struct gl_program *p;
|
||||||
GLboolean b;
|
GLboolean b;
|
||||||
|
GLuint interpMode[16];
|
||||||
|
GLuint i;
|
||||||
|
|
||||||
|
/* XXX temporary */
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
interpMode[i] = TGSI_INTERPOLATE_LINEAR;
|
||||||
|
|
||||||
p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
|
p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
|
||||||
if (!p)
|
if (!p)
|
||||||
@@ -151,7 +158,8 @@ make_color_shader(struct st_context *st)
|
|||||||
|
|
||||||
stfp = (struct st_fragment_program *) p;
|
stfp = (struct st_fragment_program *) p;
|
||||||
/* compile into tgsi format */
|
/* compile into tgsi format */
|
||||||
b = tgsi_mesa_compile_fp_program(&stfp->Base,
|
b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode,
|
||||||
|
outputMapping,
|
||||||
stfp->tokens, ST_FP_MAX_TOKENS);
|
stfp->tokens, ST_FP_MAX_TOKENS);
|
||||||
assert(b);
|
assert(b);
|
||||||
|
|
||||||
@@ -166,6 +174,11 @@ make_color_shader(struct st_context *st)
|
|||||||
static struct st_vertex_program *
|
static struct st_vertex_program *
|
||||||
make_vertex_shader(struct st_context *st)
|
make_vertex_shader(struct st_context *st)
|
||||||
{
|
{
|
||||||
|
/* Map VERT_ATTRIB_POS to 0, VERT_ATTRIB_COLOR0 to 1 */
|
||||||
|
static const GLuint inputMapping[4] = { 0, 0, 0, 1 };
|
||||||
|
/* Map VERT_RESULT_HPOS to 0, VERT_RESULT_COL0 to 1 */
|
||||||
|
static const GLuint outputMapping[2] = { 0, 1 };
|
||||||
|
|
||||||
GLcontext *ctx = st->ctx;
|
GLcontext *ctx = st->ctx;
|
||||||
struct st_vertex_program *stvp;
|
struct st_vertex_program *stvp;
|
||||||
struct gl_program *p;
|
struct gl_program *p;
|
||||||
@@ -204,6 +217,8 @@ make_vertex_shader(struct st_context *st)
|
|||||||
stvp = (struct st_vertex_program *) p;
|
stvp = (struct st_vertex_program *) p;
|
||||||
/* compile into tgsi format */
|
/* compile into tgsi format */
|
||||||
b = tgsi_mesa_compile_vp_program(&stvp->Base,
|
b = tgsi_mesa_compile_vp_program(&stvp->Base,
|
||||||
|
inputMapping,
|
||||||
|
outputMapping,
|
||||||
stvp->tokens, ST_FP_MAX_TOKENS);
|
stvp->tokens, ST_FP_MAX_TOKENS);
|
||||||
assert(b);
|
assert(b);
|
||||||
|
|
||||||
@@ -349,7 +364,7 @@ clear_with_quad(GLcontext *ctx,
|
|||||||
struct pipe_shader_state fs;
|
struct pipe_shader_state fs;
|
||||||
const struct pipe_shader_state *cached;
|
const struct pipe_shader_state *cached;
|
||||||
if (!stfp) {
|
if (!stfp) {
|
||||||
stfp = make_color_shader(st);
|
stfp = make_frag_shader(st);
|
||||||
}
|
}
|
||||||
memset(&fs, 0, sizeof(fs));
|
memset(&fs, 0, sizeof(fs));
|
||||||
fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead);
|
fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead);
|
||||||
|
@@ -56,10 +56,17 @@
|
|||||||
static struct st_fragment_program *
|
static struct st_fragment_program *
|
||||||
make_fragment_shader(struct st_context *st)
|
make_fragment_shader(struct st_context *st)
|
||||||
{
|
{
|
||||||
|
static const GLuint outputMapping[2] = { 1, 0 };
|
||||||
GLcontext *ctx = st->ctx;
|
GLcontext *ctx = st->ctx;
|
||||||
struct st_fragment_program *stfp;
|
struct st_fragment_program *stfp;
|
||||||
struct gl_program *p;
|
struct gl_program *p;
|
||||||
GLboolean b;
|
GLboolean b;
|
||||||
|
GLuint interpMode[16];
|
||||||
|
GLuint i;
|
||||||
|
|
||||||
|
/* XXX temporary */
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
interpMode[i] = TGSI_INTERPOLATE_LINEAR;
|
||||||
|
|
||||||
p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
|
p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0);
|
||||||
if (!p)
|
if (!p)
|
||||||
@@ -88,7 +95,8 @@ make_fragment_shader(struct st_context *st)
|
|||||||
|
|
||||||
stfp = (struct st_fragment_program *) p;
|
stfp = (struct st_fragment_program *) p;
|
||||||
/* compile into tgsi format */
|
/* compile into tgsi format */
|
||||||
b = tgsi_mesa_compile_fp_program(&stfp->Base,
|
b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode,
|
||||||
|
outputMapping,
|
||||||
stfp->tokens, ST_FP_MAX_TOKENS);
|
stfp->tokens, ST_FP_MAX_TOKENS);
|
||||||
assert(b);
|
assert(b);
|
||||||
|
|
||||||
@@ -103,6 +111,8 @@ make_fragment_shader(struct st_context *st)
|
|||||||
static struct st_vertex_program *
|
static struct st_vertex_program *
|
||||||
make_vertex_shader(struct st_context *st)
|
make_vertex_shader(struct st_context *st)
|
||||||
{
|
{
|
||||||
|
/* Map VERT_RESULT_HPOS to 0, VERT_RESULT_TEX0 to 1 */
|
||||||
|
static const GLuint outputMapping[] = { 0, 0, 0, 0, 1 };
|
||||||
GLcontext *ctx = st->ctx;
|
GLcontext *ctx = st->ctx;
|
||||||
struct st_vertex_program *stvp;
|
struct st_vertex_program *stvp;
|
||||||
struct gl_program *p;
|
struct gl_program *p;
|
||||||
@@ -140,7 +150,8 @@ make_vertex_shader(struct st_context *st)
|
|||||||
|
|
||||||
stvp = (struct st_vertex_program *) p;
|
stvp = (struct st_vertex_program *) p;
|
||||||
/* compile into tgsi format */
|
/* compile into tgsi format */
|
||||||
b = tgsi_mesa_compile_vp_program(&stvp->Base,
|
b = tgsi_mesa_compile_vp_program(&stvp->Base, NULL,
|
||||||
|
outputMapping,
|
||||||
stvp->tokens, ST_FP_MAX_TOKENS);
|
stvp->tokens, ST_FP_MAX_TOKENS);
|
||||||
assert(b);
|
assert(b);
|
||||||
|
|
||||||
|
@@ -37,10 +37,12 @@
|
|||||||
|
|
||||||
#include "tnl/t_vp_build.h"
|
#include "tnl/t_vp_build.h"
|
||||||
|
|
||||||
#include "st_context.h"
|
|
||||||
#include "st_atom.h"
|
#include "st_atom.h"
|
||||||
#include "st_draw.h"
|
#include "st_context.h"
|
||||||
#include "st_cb_bufferobjects.h"
|
#include "st_cb_bufferobjects.h"
|
||||||
|
#include "st_draw.h"
|
||||||
|
#include "st_program.h"
|
||||||
|
|
||||||
#include "pipe/p_context.h"
|
#include "pipe/p_context.h"
|
||||||
#include "pipe/p_defines.h"
|
#include "pipe/p_defines.h"
|
||||||
#include "pipe/p_winsys.h"
|
#include "pipe/p_winsys.h"
|
||||||
@@ -185,18 +187,22 @@ st_draw_vbo(GLcontext *ctx,
|
|||||||
GLuint max_index)
|
GLuint max_index)
|
||||||
{
|
{
|
||||||
struct pipe_context *pipe = ctx->st->pipe;
|
struct pipe_context *pipe = ctx->st->pipe;
|
||||||
GLuint attr, i;
|
const struct st_vertex_program *vp = ctx->st->vp;
|
||||||
GLbitfield attrsNeeded;
|
const struct pipe_shader_state *vs;
|
||||||
const unsigned attr0_offset = (unsigned) arrays[0]->Ptr;
|
const unsigned attr0_offset = (unsigned) arrays[0]->Ptr;
|
||||||
|
GLboolean needDefaultAttribs = GL_FALSE;
|
||||||
|
GLuint attr;
|
||||||
|
|
||||||
st_validate_state(ctx->st);
|
st_validate_state(ctx->st);
|
||||||
update_default_attribs_buffer(ctx);
|
|
||||||
|
|
||||||
/* this must be after state validation */
|
/* must do this after state validation! */
|
||||||
attrsNeeded = ctx->st->state.vs->inputs_read;
|
vs = ctx->st->state.vs;
|
||||||
|
|
||||||
|
/* loop over TGSI shader inputs */
|
||||||
|
for (attr = 0; attr < vs->num_inputs; attr++) {
|
||||||
|
const GLuint mesaAttr = vp->index_to_input[attr];
|
||||||
|
struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
|
||||||
|
|
||||||
/* tell pipe about the vertex array element/attributes */
|
|
||||||
for (attr = 0; attr < 16; attr++) {
|
|
||||||
struct pipe_vertex_buffer vbuffer;
|
struct pipe_vertex_buffer vbuffer;
|
||||||
struct pipe_vertex_element velement;
|
struct pipe_vertex_element velement;
|
||||||
|
|
||||||
@@ -206,10 +212,6 @@ st_draw_vbo(GLcontext *ctx,
|
|||||||
velement.vertex_buffer_index = 0;
|
velement.vertex_buffer_index = 0;
|
||||||
velement.src_format = 0;
|
velement.src_format = 0;
|
||||||
|
|
||||||
if (attrsNeeded & (1 << attr)) {
|
|
||||||
const GLuint mesaAttr = tgsi_attrib_to_mesa_attrib(attr);
|
|
||||||
struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
|
|
||||||
|
|
||||||
if (bufobj && bufobj->Name) {
|
if (bufobj && bufobj->Name) {
|
||||||
struct st_buffer_object *stobj = st_buffer_object(bufobj);
|
struct st_buffer_object *stobj = st_buffer_object(bufobj);
|
||||||
/* Recall that for VBOs, the gl_client_array->Ptr field is
|
/* Recall that for VBOs, the gl_client_array->Ptr field is
|
||||||
@@ -233,17 +235,18 @@ st_draw_vbo(GLcontext *ctx,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* use the default attribute buffer */
|
/* use the default attribute buffer */
|
||||||
|
needDefaultAttribs = GL_TRUE;
|
||||||
|
|
||||||
vbuffer.buffer = ctx->st->default_attrib_buffer;
|
vbuffer.buffer = ctx->st->default_attrib_buffer;
|
||||||
vbuffer.buffer_offset = 0;
|
vbuffer.buffer_offset = 0;
|
||||||
vbuffer.pitch = 0; /* must be zero! */
|
vbuffer.pitch = 0; /* must be zero! */
|
||||||
vbuffer.max_index = 1;
|
vbuffer.max_index = 1;
|
||||||
|
|
||||||
velement.src_offset = attr * 4 * sizeof(GLfloat);
|
velement.src_offset = mesaAttr * 4 * sizeof(GLfloat);
|
||||||
velement.vertex_buffer_index = attr;
|
velement.vertex_buffer_index = attr;
|
||||||
velement.dst_offset = 0;
|
velement.dst_offset = 0;
|
||||||
velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
|
velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (attr == 0)
|
if (attr == 0)
|
||||||
assert(vbuffer.buffer);
|
assert(vbuffer.buffer);
|
||||||
@@ -252,12 +255,17 @@ st_draw_vbo(GLcontext *ctx,
|
|||||||
pipe->set_vertex_element(pipe, attr, &velement);
|
pipe->set_vertex_element(pipe, attr, &velement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needDefaultAttribs) {
|
||||||
|
update_default_attribs_buffer(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* do actual drawing */
|
/* do actual drawing */
|
||||||
if (ib) {
|
if (ib) {
|
||||||
/* indexed primitive */
|
/* indexed primitive */
|
||||||
struct gl_buffer_object *bufobj = ib->obj;
|
struct gl_buffer_object *bufobj = ib->obj;
|
||||||
struct pipe_buffer_handle *bh = NULL;
|
struct pipe_buffer_handle *bh = NULL;
|
||||||
unsigned indexSize;
|
unsigned indexSize, i;
|
||||||
|
|
||||||
if (bufobj && bufobj->Name) {
|
if (bufobj && bufobj->Name) {
|
||||||
/* elements/indexes are in a real VBO */
|
/* elements/indexes are in a real VBO */
|
||||||
@@ -285,6 +293,7 @@ st_draw_vbo(GLcontext *ctx,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* non-indexed */
|
/* non-indexed */
|
||||||
|
GLuint i;
|
||||||
for (i = 0; i < nr_prims; i++) {
|
for (i = 0; i < nr_prims; i++) {
|
||||||
pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count);
|
pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count);
|
||||||
}
|
}
|
||||||
|
@@ -61,13 +61,20 @@ struct st_fragment_program
|
|||||||
|
|
||||||
struct st_vertex_program
|
struct st_vertex_program
|
||||||
{
|
{
|
||||||
struct gl_vertex_program Base;
|
struct gl_vertex_program Base; /**< The Mesa vertex program */
|
||||||
GLboolean error; /* If program is malformed for any reason. */
|
GLboolean error; /**< Set if program is malformed for any reason. */
|
||||||
|
|
||||||
GLuint id; /* String id, for tracking
|
GLuint id; /**< String id, for tracking ProgramStringNotify changes. */
|
||||||
* ProgramStringNotify changes.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
|
||||||
|
GLuint input_to_index[MAX_VERTEX_PROGRAM_ATTRIBS];
|
||||||
|
/** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
|
||||||
|
GLuint index_to_input[MAX_VERTEX_PROGRAM_ATTRIBS];
|
||||||
|
|
||||||
|
GLuint output_to_index[MAX_VERTEX_PROGRAM_ATTRIBS];
|
||||||
|
GLuint index_to_output[MAX_VERTEX_PROGRAM_ATTRIBS];
|
||||||
|
|
||||||
|
/** The program in TGSI format */
|
||||||
struct tgsi_token tokens[ST_FP_MAX_TOKENS];
|
struct tgsi_token tokens[ST_FP_MAX_TOKENS];
|
||||||
GLboolean dirty;
|
GLboolean dirty;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user