r300: don't modify original vertex program
authorMaciej Cencora <m.cencora@gmail.com>
Fri, 3 Jul 2009 18:06:23 +0000 (20:06 +0200)
committerMaciej Cencora <m.cencora@gmail.com>
Mon, 13 Jul 2009 17:25:57 +0000 (19:25 +0200)
Keep the original vertex program untouched because it may be needed after some state change for generating new r300 specific vertex program.

src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_shader.c
src/mesa/drivers/dri/r300/r300_vertprog.c

index fc436e1100e1b3bba6052c557458f45913f1c503..30b6e75039848bf8b87ae040100e68ae8a9f8309 100644 (file)
@@ -405,6 +405,7 @@ struct r300_hw_state {
 #undef TAG
 
 struct r300_vertex_program {
+       struct gl_vertex_program *Base;
        struct r300_vertex_program *next;
 
        struct r300_vertex_program_key {
@@ -674,9 +675,6 @@ extern GLboolean r300CreateContext(const __GLcontextModes * glVisual,
 
 extern void r300SelectVertexShader(r300ContextPtr r300);
 extern void r300InitShaderFuncs(struct dd_function_table *functions);
-extern int r300VertexProgUpdateParams(GLcontext * ctx,
-                                     struct r300_vertex_program_cont *vp,
-                                     float *dst);
 
 extern void r300InitShaderFunctions(r300ContextPtr r300);
 
index c9a429943ab28ac7508681daa4eaa10b96f9f2c0..7206379ea0598c246d5192f5cafbc18b4a74b7aa 100644 (file)
@@ -50,6 +50,7 @@ static void freeVertProgCache(GLcontext *ctx, struct r300_vertex_program_cont *c
 
        while (vp) {
                tmp = vp->next;
+               _mesa_reference_vertprog(ctx, &vp->Base, NULL);
                _mesa_free(vp);
                vp = tmp;
        }
index 49fcb6ff2c092e1dac16b81e1042ddb2afb43ac4..25c42814ec72bf494db1e7f289b6f443999aa7f8 100644 (file)
@@ -99,15 +99,13 @@ static GLuint combineSwizzles(GLuint src, GLuint swz_x, GLuint swz_y, GLuint swz
        return ret;
 }
 
-int r300VertexProgUpdateParams(GLcontext * ctx,
-                              struct r300_vertex_program_cont *vp, float *dst)
+static int r300VertexProgUpdateParams(GLcontext * ctx, struct gl_vertex_program *vp, float *dst)
 {
        int pi;
-       struct gl_vertex_program *mesa_vp = &vp->mesa_program;
        float *dst_o = dst;
        struct gl_program_parameter_list *paramList;
 
-       if (mesa_vp->IsNVProgram) {
+       if (vp->IsNVProgram) {
                _mesa_load_tracked_matrices(ctx);
 
                for (pi = 0; pi < MAX_NV_VERTEX_PROGRAM_PARAMS; pi++) {
@@ -119,16 +117,18 @@ int r300VertexProgUpdateParams(GLcontext * ctx,
                return dst - dst_o;
        }
 
-       assert(mesa_vp->Base.Parameters);
-       _mesa_load_state_parameters(ctx, mesa_vp->Base.Parameters);
+       if (!vp->Base.Parameters)
+               return 0;
+
+       _mesa_load_state_parameters(ctx, vp->Base.Parameters);
 
-       if (mesa_vp->Base.Parameters->NumParameters * 4 >
+       if (vp->Base.Parameters->NumParameters * 4 >
            VSF_MAX_FRAGMENT_LENGTH) {
                fprintf(stderr, "%s:Params exhausted\n", __FUNCTION__);
                _mesa_exit(-1);
        }
 
-       paramList = mesa_vp->Base.Parameters;
+       paramList = vp->Base.Parameters;
        for (pi = 0; pi < paramList->NumParameters; pi++) {
                switch (paramList->Parameters[pi].Type) {
                case PROGRAM_STATE_VAR:
@@ -1027,9 +1027,9 @@ static void t_inputs_outputs(struct r300_vertex_program *vp)
        }
 }
 
-static void r300TranslateVertexShader(struct r300_vertex_program *vp,
-                                     struct prog_instruction *vpi)
+static void r300TranslateVertexShader(struct r300_vertex_program *vp)
 {
+       struct prog_instruction *vpi = vp->Base->Base.Instructions;
        int i;
        GLuint *inst;
        unsigned long num_operands;
@@ -1450,27 +1450,31 @@ static void translateInsts(struct gl_program *prog)
 
 static struct r300_vertex_program *build_program(GLcontext *ctx,
                                                 struct r300_vertex_program_key *wanted_key,
-                                                struct gl_vertex_program *mesa_vp,
+                                                const struct gl_vertex_program *mesa_vp,
                                                 GLint wpos_idx)
 {
        struct r300_vertex_program *vp;
+       struct gl_program *prog;
 
        vp = _mesa_calloc(sizeof(*vp));
+       vp->Base = (struct gl_vertex_program *) _mesa_clone_program(ctx, &mesa_vp->Base);
        _mesa_memcpy(&vp->key, wanted_key, sizeof(vp->key));
        vp->wpos_idx = wpos_idx;
 
+       prog = &vp->Base->Base;
+
        if (RADEON_DEBUG & DEBUG_VERTS) {
                fprintf(stderr, "Initial vertex program:\n");
-               _mesa_print_program(&mesa_vp->Base);
+               _mesa_print_program(prog);
                fflush(stdout);
        }
 
        if (mesa_vp->IsPositionInvariant) {
-               _mesa_insert_mvp_code(ctx, mesa_vp);
+               _mesa_insert_mvp_code(ctx, vp->Base);
        }
 
        if (wpos_idx > -1) {
-               pos_as_texcoord(vp, &mesa_vp->Base);
+               pos_as_texcoord(vp, prog);
        }
 
        /* Some outputs may be artificially added, to match the inputs of the fragment program.
@@ -1488,8 +1492,8 @@ static struct r300_vertex_program *build_program(GLcontext *ctx,
                if (count > 0) {
                        struct prog_instruction *inst;
 
-                       _mesa_insert_instructions(&mesa_vp->Base, mesa_vp->Base.NumInstructions - 1, count);
-                       inst = &mesa_vp->Base.Instructions[mesa_vp->Base.NumInstructions - 1 - count];
+                       _mesa_insert_instructions(prog, prog->NumInstructions - 1, count);
+                       inst = &prog->Instructions[prog->NumInstructions - 1 - count];
 
                        for (i = 0; i < VERT_RESULT_MAX; ++i) {
                                if (vp->key.OutputsAdded & (1 << i)) {
@@ -1510,17 +1514,17 @@ static struct r300_vertex_program *build_program(GLcontext *ctx,
                }
        }
 
-       translateInsts(&mesa_vp->Base);
+       translateInsts(prog);
 
        if (RADEON_DEBUG & DEBUG_VERTS) {
                fprintf(stderr, "Vertex program after native rewrite:\n");
-               _mesa_print_program(&mesa_vp->Base);
+               _mesa_print_program(prog);
                fflush(stdout);
        }
 
-       assert(mesa_vp->Base.NumInstructions);
-       vp->num_temporaries = mesa_vp->Base.NumTemporaries;
-       r300TranslateVertexShader(vp, mesa_vp->Base.Instructions);
+       assert(prog->NumInstructions);
+       vp->num_temporaries = prog->NumTemporaries;
+       r300TranslateVertexShader(vp);
 
        return vp;
 }
@@ -1653,10 +1657,7 @@ void r300SetupVertexProgram(r300ContextPtr rmesa)
        ((drm_r300_cmd_header_t *) rmesa->hw.vps.cmd)->vpu.count = 0;
        
        R300_STATECHANGE(rmesa, vpp);
-       param_count = r300VertexProgUpdateParams(ctx,
-                                                               (struct r300_vertex_program_cont *)
-                                                               ctx->VertexProgram._Current,
-                                                               (float *)&rmesa->hw.vpp.cmd[R300_VPP_PARAM_0]);
+       param_count = r300VertexProgUpdateParams(ctx, prog->Base, (float *)&rmesa->hw.vpp.cmd[R300_VPP_PARAM_0]);
        bump_vpu_count(rmesa->hw.vpp.cmd, param_count);
        param_count /= 4;