r5xx: FP refactor, take one.

Yes, I know it's massive. Imagine how I felt, auditing 3000 lines of code.
This commit is contained in:
Corbin Simpson 2008-06-14 07:03:08 -07:00
parent 9704414d13
commit 0a341ef296
5 changed files with 444 additions and 1508 deletions

View File

@ -28,7 +28,6 @@ DRIVER_SOURCES = \
radeon_span.c \ radeon_span.c \
radeon_state.c \ radeon_state.c \
r300_mem.c \ r300_mem.c \
\
r300_context.c \ r300_context.c \
r300_ioctl.c \ r300_ioctl.c \
r300_cmdbuf.c \ r300_cmdbuf.c \
@ -42,6 +41,7 @@ DRIVER_SOURCES = \
r300_fragprog.c \ r300_fragprog.c \
r300_fragprog_emit.c \ r300_fragprog_emit.c \
r500_fragprog.c \ r500_fragprog.c \
r500_fragprog_emit.c \
r300_shader.c \ r300_shader.c \
r300_emit.c \ r300_emit.c \
r300_swtcl.c \ r300_swtcl.c \

View File

@ -748,14 +748,30 @@ struct r300_fragment_program {
struct r500_pfs_compile_state; struct r500_pfs_compile_state;
struct r500_fragment_program { struct r500_fragment_program_external_state {
struct gl_fragment_program mesa_program; struct {
/**
* If the sampler is used as a shadow sampler,
* this field is:
* 0 - GL_LUMINANCE
* 1 - GL_INTENSITY
* 2 - GL_ALPHA
* depending on the depth texture mode.
*/
GLuint depth_texture_mode : 2;
GLcontext *ctx; /**
GLboolean translated; * If the sampler is used as a shadow sampler,
GLboolean error; * this field is (texture_compare_func - GL_NEVER).
struct r500_pfs_compile_state *cs; * [e.g. if compare function is GL_LEQUAL, this field is 3]
*
* Otherwise, this field is 0.
*/
GLuint texture_compare_func : 3;
} unit[16];
};
struct r500_fragment_program_code {
struct { struct {
GLuint inst0; GLuint inst0;
GLuint inst1; GLuint inst1;
@ -772,17 +788,28 @@ struct r500_fragment_program {
int inst_end; int inst_end;
/* Hardware constants. /* Hardware constants.
* Contains a pointer to the value. The destination of the pointer * Contains a pointer to the value. The destination of the pointer
* is supposed to be updated when GL state changes. * is supposed to be updated when GL state changes.
* Typically, this is either a pointer into * Typically, this is either a pointer into
* gl_program_parameter_list::ParameterValues, or a pointer to a * gl_program_parameter_list::ParameterValues, or a pointer to a
* global constant (e.g. for sin/cos-approximation) * global constant (e.g. for sin/cos-approximation)
*/ */
const GLfloat *constant[PFS_NUM_CONST_REGS]; const GLfloat *constant[PFS_NUM_CONST_REGS];
int const_nr; int const_nr;
int max_temp_idx; int max_temp_idx;
};
struct r500_fragment_program {
struct gl_fragment_program mesa_program;
GLcontext *ctx;
GLboolean translated;
GLboolean error;
struct r500_fragment_program_external_state state;
struct r500_fragment_program_code code;
GLboolean writes_depth; GLboolean writes_depth;
GLuint optimization; GLuint optimization;

View File

@ -1351,14 +1351,15 @@ static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
int i; int i;
struct r500_fragment_program *fp = (struct r500_fragment_program *) struct r500_fragment_program *fp = (struct r500_fragment_program *)
(char *)ctx->FragmentProgram._Current; (char *)ctx->FragmentProgram._Current;
struct r500_fragment_program_code *code = &fp->code;
/* find all the texture instructions and relocate the texture units */ /* find all the texture instructions and relocate the texture units */
for (i = 0; i < fp->inst_end + 1; i++) { for (i = 0; i < code->inst_end + 1; i++) {
if ((fp->inst[i].inst0 & 0x3) == R500_INST_TYPE_TEX) { if ((code->inst[i].inst0 & 0x3) == R500_INST_TYPE_TEX) {
uint32_t val; uint32_t val;
int unit, opcode, new_unit; int unit, opcode, new_unit;
val = fp->inst[i].inst1; val = code->inst[i].inst1;
unit = (val >> 16) & 0xf; unit = (val >> 16) & 0xf;
@ -1375,7 +1376,7 @@ static void r500SetupFragmentShaderTextures(GLcontext *ctx, int *tmu_mappings)
} }
} }
val |= R500_TEX_ID(new_unit); val |= R500_TEX_ID(new_unit);
fp->inst[i].inst1 = val; code->inst[i].inst1 = val;
} }
} }
} }
@ -2499,6 +2500,7 @@ static void r500SetupPixelShader(r300ContextPtr rmesa)
struct r500_fragment_program *fp = (struct r500_fragment_program *) struct r500_fragment_program *fp = (struct r500_fragment_program *)
(char *)ctx->FragmentProgram._Current; (char *)ctx->FragmentProgram._Current;
int i; int i;
struct r500_fragment_program_code *code;
if (!fp) /* should only happenen once, just after context is created */ if (!fp) /* should only happenen once, just after context is created */
return; return;
@ -2512,42 +2514,43 @@ static void r500SetupPixelShader(r300ContextPtr rmesa)
__FUNCTION__); __FUNCTION__);
return; return;
} }
code = &fp->code;
r300SetupTextures(ctx); r300SetupTextures(ctx);
R300_STATECHANGE(rmesa, fp); R300_STATECHANGE(rmesa, fp);
rmesa->hw.fp.cmd[R500_FP_PIXSIZE] = fp->max_temp_idx; rmesa->hw.fp.cmd[R500_FP_PIXSIZE] = code->max_temp_idx;
rmesa->hw.fp.cmd[R500_FP_CODE_ADDR] = rmesa->hw.fp.cmd[R500_FP_CODE_ADDR] =
R500_US_CODE_START_ADDR(fp->inst_offset) | R500_US_CODE_START_ADDR(code->inst_offset) |
R500_US_CODE_END_ADDR(fp->inst_end); R500_US_CODE_END_ADDR(code->inst_end);
rmesa->hw.fp.cmd[R500_FP_CODE_RANGE] = rmesa->hw.fp.cmd[R500_FP_CODE_RANGE] =
R500_US_CODE_RANGE_ADDR(fp->inst_offset) | R500_US_CODE_RANGE_ADDR(code->inst_offset) |
R500_US_CODE_RANGE_SIZE(fp->inst_end); R500_US_CODE_RANGE_SIZE(code->inst_end);
rmesa->hw.fp.cmd[R500_FP_CODE_OFFSET] = rmesa->hw.fp.cmd[R500_FP_CODE_OFFSET] =
R500_US_CODE_OFFSET_ADDR(0); /* FIXME when we add flow control */ R500_US_CODE_OFFSET_ADDR(0); /* FIXME when we add flow control */
R300_STATECHANGE(rmesa, r500fp); R300_STATECHANGE(rmesa, r500fp);
/* Emit our shader... */ /* Emit our shader... */
for (i = 0; i < fp->inst_end+1; i++) { for (i = 0; i < code->inst_end+1; i++) {
rmesa->hw.r500fp.cmd[i*6+1] = fp->inst[i].inst0; rmesa->hw.r500fp.cmd[i*6+1] = code->inst[i].inst0;
rmesa->hw.r500fp.cmd[i*6+2] = fp->inst[i].inst1; rmesa->hw.r500fp.cmd[i*6+2] = code->inst[i].inst1;
rmesa->hw.r500fp.cmd[i*6+3] = fp->inst[i].inst2; rmesa->hw.r500fp.cmd[i*6+3] = code->inst[i].inst2;
rmesa->hw.r500fp.cmd[i*6+4] = fp->inst[i].inst3; rmesa->hw.r500fp.cmd[i*6+4] = code->inst[i].inst3;
rmesa->hw.r500fp.cmd[i*6+5] = fp->inst[i].inst4; rmesa->hw.r500fp.cmd[i*6+5] = code->inst[i].inst4;
rmesa->hw.r500fp.cmd[i*6+6] = fp->inst[i].inst5; rmesa->hw.r500fp.cmd[i*6+6] = code->inst[i].inst5;
} }
bump_r500fp_count(rmesa->hw.r500fp.cmd, (fp->inst_end + 1) * 6); bump_r500fp_count(rmesa->hw.r500fp.cmd, (code->inst_end + 1) * 6);
R300_STATECHANGE(rmesa, r500fp_const); R300_STATECHANGE(rmesa, r500fp_const);
for (i = 0; i < fp->const_nr; i++) { for (i = 0; i < code->const_nr; i++) {
rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat32(fp->constant[i][0]); rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat32(code->constant[i][0]);
rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat32(fp->constant[i][1]); rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat32(code->constant[i][1]);
rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat32(fp->constant[i][2]); rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat32(code->constant[i][2]);
rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 3] = r300PackFloat32(fp->constant[i][3]); rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 3] = r300PackFloat32(code->constant[i][3]);
} }
bump_r500fp_const_count(rmesa->hw.r500fp_const.cmd, fp->const_nr * 4); bump_r500fp_const_count(rmesa->hw.r500fp_const.cmd, code->const_nr * 4);
} }

File diff suppressed because it is too large Load Diff

View File

@ -36,10 +36,14 @@
#include "glheader.h" #include "glheader.h"
#include "macros.h" #include "macros.h"
#include "enums.h" #include "enums.h"
#include "shader/prog_parameter.h"
#include "shader/prog_print.h"
#include "shader/program.h" #include "shader/program.h"
#include "shader/prog_instruction.h" #include "shader/prog_instruction.h"
#include "r300_context.h" #include "r300_context.h"
#include "r300_state.h"
#include "radeon_program.h"
/* supported hw opcodes */ /* supported hw opcodes */
#define PFS_OP_MAD 0 #define PFS_OP_MAD 0
@ -76,4 +80,13 @@ struct r500_fragment_program;
extern void r500TranslateFragmentShader(r300ContextPtr r300, extern void r500TranslateFragmentShader(r300ContextPtr r300,
struct r500_fragment_program *fp); struct r500_fragment_program *fp);
struct r500_fragment_program_compiler {
r300ContextPtr r300;
struct r500_fragment_program *fp;
struct r500_fragment_program_code *code;
struct radeon_compiler compiler;
};
extern GLboolean r500FragmentProgramEmit(struct r500_fragment_program_compiler *compiler);
#endif #endif