r300: Remove some dependencies on additional fragment program copies
authorNicolai Hähnle <nhaehnle@gmail.com>
Thu, 16 Jul 2009 20:58:13 +0000 (22:58 +0200)
committerNicolai Hähnle <nhaehnle@gmail.com>
Mon, 27 Jul 2009 18:32:04 +0000 (20:32 +0200)
The copy is still needed because some program transforms add state variables
or constants.

Signed-off-by: Nicolai Hähnle <nhaehnle@gmail.com>
src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_fragprog_common.c
src/mesa/drivers/dri/r300/r300_fragprog_common.h
src/mesa/drivers/dri/r300/r300_shader.c
src/mesa/drivers/dri/r300/r300_state.c
src/mesa/drivers/dri/r300/r300_swtcl.c
src/mesa/drivers/dri/r300/r300_vertprog.c

index b692f8bf809a46df51ef49082c8c67f0e80bad6d..ea30d3e12ff6c12275cd4aff8740ad02cd57a2b4 100644 (file)
@@ -445,14 +445,13 @@ struct r300_vertex_program_cont {
 * to render with that program.
 */
 struct r300_fragment_program {
-       struct gl_program *Base;
-
-       GLboolean translated;
        GLboolean error;
+       struct gl_program *Base;
        struct r300_fragment_program *next;
        struct r300_fragment_program_external_state state;
 
        struct rX00_fragment_program_code code;
+       GLbitfield InputsRead;
 };
 
 struct r300_fragment_program_cont {
index b37f29691269e6aae78002a960c122aeaf58bbd3..1c57ba49e5b4e3786aff1cc00adb9ec6059ddf4e 100644 (file)
@@ -90,24 +90,26 @@ static void build_state(
 }
 
 
-void r300TranslateFragmentShader(GLcontext *ctx, struct r300_fragment_program *fp)
+static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_program_cont *cont, struct r300_fragment_program *fp)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
        struct r300_fragment_program_compiler compiler;
 
        compiler.code = &fp->code;
        compiler.state = fp->state;
-       compiler.program = fp->Base;
+       compiler.program = _mesa_clone_program(ctx, &cont->Base.Base);
        compiler.is_r500 = (r300->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) ? GL_TRUE : GL_FALSE;
        compiler.debug = (RADEON_DEBUG & DEBUG_PIXEL) ? GL_TRUE : GL_FALSE;
 
        if (!r3xx_compile_fragment_program(&compiler))
                fp->error = GL_TRUE;
 
-       fp->translated = GL_TRUE;
+       fp->InputsRead = compiler.program->InputsRead;
+
+       fp->Base = compiler.program;
 }
 
-struct r300_fragment_program *r300SelectFragmentShader(GLcontext *ctx)
+struct r300_fragment_program *r300SelectAndTranslateFragmentShader(GLcontext *ctx)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
        struct r300_fragment_program_cont *fp_list;
@@ -128,11 +130,11 @@ struct r300_fragment_program *r300SelectFragmentShader(GLcontext *ctx)
        fp = _mesa_calloc(sizeof(struct r300_fragment_program));
 
        fp->state = state;
-       fp->translated = GL_FALSE;
-       fp->Base = _mesa_clone_program(ctx, &ctx->FragmentProgram._Current->Base);
 
        fp->next = fp_list->progs;
        fp_list->progs = fp;
 
+       translate_fragment_program(ctx, fp_list, fp);
+
        return r300->selected_fp = fp;
 }
index 5e103ee4086d0edb9a085b8804cbcb65bb867fb4..3d64c08cee97dc3729c96f555af6a9a19b0f1b9a 100644 (file)
@@ -32,8 +32,6 @@
 
 #include "r300_context.h"
 
-extern void r300TranslateFragmentShader(GLcontext *ctx, struct r300_fragment_program *fp);
-
-struct r300_fragment_program *r300SelectFragmentShader(GLcontext *ctx);
+struct r300_fragment_program *r300SelectAndTranslateFragmentShader(GLcontext *ctx);
 
 #endif
index 62228a3786e821913fd089f6d7e7c592a50a8899..06c893881e5c974f2b7f2b199db08ae946155950 100644 (file)
@@ -122,9 +122,7 @@ static GLboolean
 r300IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
 {
        if (target == GL_FRAGMENT_PROGRAM_ARB) {
-               struct r300_fragment_program *fp = r300SelectFragmentShader(ctx);
-               if (!fp->translated)
-                       r300TranslateFragmentShader(ctx, fp);
+               struct r300_fragment_program *fp = r300SelectAndTranslateFragmentShader(ctx);
 
                return !fp->error;
        } else {
index 62a03281ca8786681288637f6ad661383f855dda..66d9a69622a018fa81cfd23ab57c1c16a9e2aed2 100644 (file)
@@ -1462,7 +1462,7 @@ static void r300SetupRSUnit(GLcontext * ctx)
        else
                RENDERINPUTS_COPY(OutputsWritten.index_bitset, r300->render_inputs_bitset);
 
-       InputsRead = r300->selected_fp->Base->InputsRead;
+       InputsRead = r300->selected_fp->InputsRead;
 
        R300_STATECHANGE(r300, ri);
        R300_STATECHANGE(r300, rc);
@@ -1556,7 +1556,7 @@ static void r500SetupRSUnit(GLcontext * ctx)
        else
                RENDERINPUTS_COPY(OutputsWritten.index_bitset, r300->render_inputs_bitset);
 
-       InputsRead = r300->selected_fp->Base->InputsRead;
+       InputsRead = r300->selected_fp->InputsRead;
 
        R300_STATECHANGE(r300, ri);
        R300_STATECHANGE(r300, rc);
@@ -1995,9 +1995,7 @@ void r300UpdateShaders(r300ContextPtr rmesa)
        {
                struct r300_fragment_program *fp;
 
-               fp = r300SelectFragmentShader(ctx);
-               if (!fp->translated)
-                       r300TranslateFragmentShader(ctx, fp);
+               fp = r300SelectAndTranslateFragmentShader(ctx);
 
                r300SwitchFallback(ctx, R300_FALLBACK_FRAGMENT_PROGRAM, fp->error);
        }
@@ -2034,9 +2032,11 @@ void r300UpdateShaders(r300ContextPtr rmesa)
 }
 
 static const GLfloat *get_fragmentprogram_constant(GLcontext *ctx,
-       struct gl_program *program, struct prog_src_register srcreg)
+       struct prog_src_register srcreg)
 {
        static const GLfloat dummy[4] = { 0, 0, 0, 0 };
+       r300ContextPtr rmesa = R300_CONTEXT(ctx);
+       struct gl_program * program = rmesa->selected_fp->Base;
 
        switch(srcreg.File) {
        case PROGRAM_LOCAL_PARAM:
@@ -2103,7 +2103,7 @@ static void r300SetupPixelShader(GLcontext *ctx)
        R300_STATECHANGE(rmesa, fpp);
        rmesa->hw.fpp.cmd[R300_FPP_CMD_0] = cmdpacket0(rmesa->radeon.radeonScreen, R300_PFS_PARAM_0_X, code->const_nr * 4);
        for (i = 0; i < code->const_nr; i++) {
-               const GLfloat *constant = get_fragmentprogram_constant(ctx, fp->Base, code->constant[i]);
+               const GLfloat *constant = get_fragmentprogram_constant(ctx, code->constant[i]);
                rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat24(constant[0]);
                rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat24(constant[1]);
                rmesa->hw.fpp.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat24(constant[2]);
@@ -2164,7 +2164,7 @@ static void r500SetupPixelShader(GLcontext *ctx)
 
        R300_STATECHANGE(rmesa, r500fp_const);
        for (i = 0; i < code->const_nr; i++) {
-               const GLfloat *constant = get_fragmentprogram_constant(ctx, fp->Base, code->constant[i]);
+               const GLfloat *constant = get_fragmentprogram_constant(ctx, code->constant[i]);
                rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 0] = r300PackFloat32(constant[0]);
                rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 1] = r300PackFloat32(constant[1]);
                rmesa->hw.r500fp_const.cmd[R300_FPP_PARAM_0 + 4 * i + 2] = r300PackFloat32(constant[2]);
index a7e8e711499e4ace7c1e3e4354bb84d0425d490d..1e4ea2c577586f184ea89f3846eba80b68f9e1ce 100644 (file)
@@ -76,7 +76,7 @@ void r300ChooseSwtclVertexFormat(GLcontext *ctx, GLuint *_InputsRead,  GLuint *_
        GLuint InputsRead = 0;
        GLuint OutputsWritten = 0;
        int num_attrs = 0;
-       GLuint fp_reads = rmesa->selected_fp->Base->InputsRead;
+       GLuint fp_reads = rmesa->selected_fp->InputsRead;
        struct vertex_attribute *attrs = rmesa->vbuf.attribs;
 
        rmesa->swtcl.coloroffset = rmesa->swtcl.specoffset = 0;
index f98de34e93c018bd2a33eb7e085876c2a5e1e1d7..cf4788411fe476c2ba7937190de2de6d7b1f1bb2 100644 (file)
@@ -1452,7 +1452,7 @@ static void addArtificialOutputs(GLcontext *ctx, struct gl_program *prog)
 
        OutputsAdded = 0;
        count = 0;
-       FpReads = r300->selected_fp->Base->InputsRead;
+       FpReads = r300->selected_fp->InputsRead;
 
        ADD_OUTPUT(FRAG_ATTRIB_COL0, VERT_RESULT_COL0);
        ADD_OUTPUT(FRAG_ATTRIB_COL1, VERT_RESULT_COL1);
@@ -1499,7 +1499,7 @@ static void nqssadceInit(struct nqssadce_state* s)
        r300ContextPtr r300 = (r300ContextPtr)(s->UserData);
        GLuint fp_reads;
 
-       fp_reads = r300->selected_fp->Base->InputsRead;
+       fp_reads = r300->selected_fp->InputsRead;
        {
                if (fp_reads & FRAG_BIT_COL0) {
                                s->Outputs[VERT_RESULT_COL0].Sourced = WRITEMASK_XYZW;
@@ -1639,7 +1639,7 @@ struct r300_vertex_program * r300SelectVertexShader(GLcontext *ctx)
        struct r300_vertex_program *vp;
 
        vpc = (struct r300_vertex_program_cont *)ctx->VertexProgram._Current;
-       wanted_key.FpReads = r300->selected_fp->Base->InputsRead;
+       wanted_key.FpReads = r300->selected_fp->InputsRead;
        wanted_key.FogAttr = r300->selected_fp->code.fog_attr;
        wanted_key.WPosAttr = r300->selected_fp->code.wpos_attr;