r300_fragprog: Refactoring and cleanup
Refactor so that r300_pfs_compile_state "owns"/holds a pointer to r300_fragment_program instead of the other way round. This is more natural from an object orientation point of view. Move the compiled hardware state into r300_fragment_program_code, in anticipation of on-the-fly program recompilation based on external OpenGL state.
This commit is contained in:
@@ -657,17 +657,9 @@ struct r300_vertex_program_cont {
|
||||
struct r300_pfs_compile_state;
|
||||
|
||||
/**
|
||||
* Store everything about a fragment program that is needed
|
||||
* to render with that program.
|
||||
* Stores an R300 fragment program in its compiled-to-hardware form.
|
||||
*/
|
||||
struct r300_fragment_program {
|
||||
struct gl_fragment_program mesa_program;
|
||||
|
||||
GLcontext *ctx;
|
||||
GLboolean translated;
|
||||
GLboolean error;
|
||||
struct r300_pfs_compile_state *cs;
|
||||
|
||||
struct r300_fragment_program_code {
|
||||
struct {
|
||||
int length;
|
||||
GLuint inst[PFS_MAX_TEX_INST];
|
||||
@@ -708,6 +700,19 @@ struct r300_fragment_program {
|
||||
int const_nr;
|
||||
|
||||
int max_temp_idx;
|
||||
};
|
||||
|
||||
/**
|
||||
* Store everything about a fragment program that is needed
|
||||
* to render with that program.
|
||||
*/
|
||||
struct r300_fragment_program {
|
||||
struct gl_fragment_program mesa_program;
|
||||
|
||||
GLboolean translated;
|
||||
GLboolean error;
|
||||
|
||||
struct r300_fragment_program_code code;
|
||||
|
||||
GLboolean WritesDepth;
|
||||
GLuint optimization;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,6 @@ static struct gl_program *r300NewProgram(GLcontext * ctx, GLenum target,
|
||||
target, id);
|
||||
} else {
|
||||
r300_fp = CALLOC_STRUCT(r300_fragment_program);
|
||||
r300_fp->ctx = ctx;
|
||||
return _mesa_init_fragment_program(ctx, &r300_fp->mesa_program,
|
||||
target, id);
|
||||
}
|
||||
|
||||
@@ -1308,18 +1308,19 @@ static void r300SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
|
||||
int i;
|
||||
struct r300_fragment_program *fp = (struct r300_fragment_program *)
|
||||
(char *)ctx->FragmentProgram._Current;
|
||||
struct r300_fragment_program_code *code = &fp->code;
|
||||
|
||||
R300_STATECHANGE(r300, fpt);
|
||||
|
||||
for (i = 0; i < fp->tex.length; i++) {
|
||||
for (i = 0; i < code->tex.length; i++) {
|
||||
int unit;
|
||||
int opcode;
|
||||
unsigned long val;
|
||||
|
||||
unit = fp->tex.inst[i] >> R300_TEX_ID_SHIFT;
|
||||
unit = code->tex.inst[i] >> R300_TEX_ID_SHIFT;
|
||||
unit &= 15;
|
||||
|
||||
val = fp->tex.inst[i];
|
||||
val = code->tex.inst[i];
|
||||
val &= ~R300_TEX_ID_MASK;
|
||||
|
||||
opcode =
|
||||
@@ -1341,7 +1342,7 @@ static void r300SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
|
||||
}
|
||||
|
||||
r300->hw.fpt.cmd[R300_FPT_CMD_0] =
|
||||
cmdpacket0(R300_US_TEX_INST_0, fp->tex.length);
|
||||
cmdpacket0(R300_US_TEX_INST_0, code->tex.length);
|
||||
}
|
||||
|
||||
static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
|
||||
@@ -2405,6 +2406,7 @@ static void r300SetupPixelShader(r300ContextPtr rmesa)
|
||||
GLcontext *ctx = rmesa->radeon.glCtx;
|
||||
struct r300_fragment_program *fp = (struct r300_fragment_program *)
|
||||
(char *)ctx->FragmentProgram._Current;
|
||||
struct r300_fragment_program_code *code;
|
||||
int i, k;
|
||||
|
||||
if (!fp) /* should only happenen once, just after context is created */
|
||||
@@ -2416,62 +2418,63 @@ static void r300SetupPixelShader(r300ContextPtr rmesa)
|
||||
__FUNCTION__);
|
||||
return;
|
||||
}
|
||||
code = &fp->code;
|
||||
|
||||
r300SetupTextures(ctx);
|
||||
|
||||
R300_STATECHANGE(rmesa, fpi[0]);
|
||||
rmesa->hw.fpi[0].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_RGB_INST_0, fp->alu_end + 1);
|
||||
for (i = 0; i <= fp->alu_end; i++) {
|
||||
rmesa->hw.fpi[0].cmd[R300_FPI_INSTR_0 + i] = fp->alu.inst[i].inst0;
|
||||
rmesa->hw.fpi[0].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_RGB_INST_0, code->alu_end + 1);
|
||||
for (i = 0; i <= code->alu_end; i++) {
|
||||
rmesa->hw.fpi[0].cmd[R300_FPI_INSTR_0 + i] = code->alu.inst[i].inst0;
|
||||
}
|
||||
|
||||
R300_STATECHANGE(rmesa, fpi[1]);
|
||||
rmesa->hw.fpi[1].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_RGB_ADDR_0, fp->alu_end + 1);
|
||||
for (i = 0; i <= fp->alu_end; i++) {
|
||||
rmesa->hw.fpi[1].cmd[R300_FPI_INSTR_0 + i] = fp->alu.inst[i].inst1;
|
||||
rmesa->hw.fpi[1].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_RGB_ADDR_0, code->alu_end + 1);
|
||||
for (i = 0; i <= code->alu_end; i++) {
|
||||
rmesa->hw.fpi[1].cmd[R300_FPI_INSTR_0 + i] = code->alu.inst[i].inst1;
|
||||
}
|
||||
|
||||
R300_STATECHANGE(rmesa, fpi[2]);
|
||||
rmesa->hw.fpi[2].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_ALPHA_INST_0, fp->alu_end + 1);
|
||||
for (i = 0; i <= fp->alu_end; i++) {
|
||||
rmesa->hw.fpi[2].cmd[R300_FPI_INSTR_0 + i] = fp->alu.inst[i].inst2;
|
||||
rmesa->hw.fpi[2].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_ALPHA_INST_0, code->alu_end + 1);
|
||||
for (i = 0; i <= code->alu_end; i++) {
|
||||
rmesa->hw.fpi[2].cmd[R300_FPI_INSTR_0 + i] = code->alu.inst[i].inst2;
|
||||
}
|
||||
|
||||
R300_STATECHANGE(rmesa, fpi[3]);
|
||||
rmesa->hw.fpi[3].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_ALPHA_ADDR_0, fp->alu_end + 1);
|
||||
for (i = 0; i <= fp->alu_end; i++) {
|
||||
rmesa->hw.fpi[3].cmd[R300_FPI_INSTR_0 + i] = fp->alu.inst[i].inst3;
|
||||
rmesa->hw.fpi[3].cmd[R300_FPI_CMD_0] = cmdpacket0(R300_US_ALU_ALPHA_ADDR_0, code->alu_end + 1);
|
||||
for (i = 0; i <= code->alu_end; i++) {
|
||||
rmesa->hw.fpi[3].cmd[R300_FPI_INSTR_0 + i] = code->alu.inst[i].inst3;
|
||||
}
|
||||
|
||||
R300_STATECHANGE(rmesa, fp);
|
||||
rmesa->hw.fp.cmd[R300_FP_CNTL0] = fp->cur_node | (fp->first_node_has_tex << 3);
|
||||
rmesa->hw.fp.cmd[R300_FP_CNTL1] = fp->max_temp_idx;
|
||||
rmesa->hw.fp.cmd[R300_FP_CNTL0] = code->cur_node | (code->first_node_has_tex << 3);
|
||||
rmesa->hw.fp.cmd[R300_FP_CNTL1] = code->max_temp_idx;
|
||||
rmesa->hw.fp.cmd[R300_FP_CNTL2] =
|
||||
(fp->alu_offset << R300_PFS_CNTL_ALU_OFFSET_SHIFT) |
|
||||
(fp->alu_end << R300_PFS_CNTL_ALU_END_SHIFT) |
|
||||
(fp->tex_offset << R300_PFS_CNTL_TEX_OFFSET_SHIFT) |
|
||||
(fp->tex_end << R300_PFS_CNTL_TEX_END_SHIFT);
|
||||
(code->alu_offset << R300_PFS_CNTL_ALU_OFFSET_SHIFT) |
|
||||
(code->alu_end << R300_PFS_CNTL_ALU_END_SHIFT) |
|
||||
(code->tex_offset << R300_PFS_CNTL_TEX_OFFSET_SHIFT) |
|
||||
(code->tex_end << R300_PFS_CNTL_TEX_END_SHIFT);
|
||||
/* I just want to say, the way these nodes are stored.. weird.. */
|
||||
for (i = 0, k = (4 - (fp->cur_node + 1)); i < 4; i++, k++) {
|
||||
if (i < (fp->cur_node + 1)) {
|
||||
for (i = 0, k = (4 - (code->cur_node + 1)); i < 4; i++, k++) {
|
||||
if (i < (code->cur_node + 1)) {
|
||||
rmesa->hw.fp.cmd[R300_FP_NODE0 + k] =
|
||||
(fp->node[i].alu_offset << R300_ALU_START_SHIFT) |
|
||||
(fp->node[i].alu_end << R300_ALU_SIZE_SHIFT) |
|
||||
(fp->node[i].tex_offset << R300_TEX_START_SHIFT) |
|
||||
(fp->node[i].tex_end << R300_TEX_SIZE_SHIFT) |
|
||||
fp->node[i].flags;
|
||||
(code->node[i].alu_offset << R300_ALU_START_SHIFT) |
|
||||
(code->node[i].alu_end << R300_ALU_SIZE_SHIFT) |
|
||||
(code->node[i].tex_offset << R300_TEX_START_SHIFT) |
|
||||
(code->node[i].tex_end << R300_TEX_SIZE_SHIFT) |
|
||||
code->node[i].flags;
|
||||
} else {
|
||||
rmesa->hw.fp.cmd[R300_FP_NODE0 + (3 - i)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
R300_STATECHANGE(rmesa, fpp);
|
||||
rmesa->hw.fpp.cmd[R300_FPP_CMD_0] = cmdpacket0(R300_PFS_PARAM_0_X, fp->const_nr * 4);
|
||||
for (i = 0; i < fp->const_nr; i++) {
|
||||
rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat24(fp->constant[i][0]);
|
||||
rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat24(fp->constant[i][1]);
|
||||
rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat24(fp->constant[i][2]);
|
||||
rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 3] = r300PackFloat24(fp->constant[i][3]);
|
||||
rmesa->hw.fpp.cmd[R300_FPP_CMD_0] = cmdpacket0(R300_PFS_PARAM_0_X, code->const_nr * 4);
|
||||
for (i = 0; i < code->const_nr; i++) {
|
||||
rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat24(code->constant[i][0]);
|
||||
rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat24(code->constant[i][1]);
|
||||
rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat24(code->constant[i][2]);
|
||||
rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 3] = r300PackFloat24(code->constant[i][3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user