nouveau: fail translate if we use too many params somehow
authorBen Skeggs <skeggsb@gmail.com>
Tue, 20 Mar 2007 04:52:57 +0000 (15:52 +1100)
committerBen Skeggs <skeggsb@gmail.com>
Tue, 20 Mar 2007 05:08:07 +0000 (16:08 +1100)
src/mesa/drivers/dri/nouveau/nouveau_shader.c
src/mesa/drivers/dri/nouveau/nouveau_shader.h
src/mesa/drivers/dri/nouveau/nouveau_shader_0.c

index 9cb837ff3b701073b9701b215be40c0a57013150..3d5b6843a15db3efb100bdc5a6a1df3e05c45d3f 100644 (file)
@@ -96,7 +96,9 @@ nouveauProgramStringNotify(GLcontext *ctx, GLenum target,
 
    if (nvs->translated)
       FREE(nvs->program);
-   nvs->translated = 0;
+
+   nvs->error      = GL_FALSE;
+   nvs->translated = GL_FALSE;
 
    _tnl_program_string(ctx, target, prog);
 }
index 56ae270764b8c63cb66e0bf0184130f823ee84b5..7125a2ae82194840aa4316558abc6296000b886e 100644 (file)
@@ -51,6 +51,7 @@ typedef struct _nouveauShader {
    nvsFunc *func;
 
    /* State of the final program */
+   GLboolean error;
    GLboolean translated;
    GLboolean on_hardware;
    unsigned int *program;
@@ -424,6 +425,12 @@ nvsSwizzle(nvsRegister reg, nvsSwzComp x, nvsSwzComp y,
    return reg;
 }
 
+#define nvsProgramError(nvs,fmt,args...) do {                           \
+       fprintf(stderr, "nvsProgramError (%s): "fmt, __func__, ##args); \
+       (nvs)->error = GL_TRUE;                                         \
+       (nvs)->translated = GL_FALSE;                                   \
+} while(0)
+
 extern GLboolean nvsUpdateShader(GLcontext *ctx, nouveauShader *nvs);
 extern void nvsDisasmHWShader(nvsPtr);
 extern void nvsDumpFragmentList(nvsFragmentHeader *f, int lvl);
index 0308a6c39764afd9f4a3e1c20c0e2efdbac9d3c0..7c2e2b9443bff7415037be25ea33269f72a6fb65 100644 (file)
@@ -924,7 +924,7 @@ pass0_rebase_mesa_consts(nouveauShader *nvs)
        }
 }
 
-static void
+static GLboolean
 pass0_resolve_mesa_consts(nouveauShader *nvs)
 {
        struct pass0_rec *rec = nvs->pass_rec;
@@ -945,6 +945,11 @@ pass0_resolve_mesa_consts(nouveauShader *nvs)
        for (i=0; i<plist->NumParameters; i++) {
                int hw = rec->mesa_const_base + i;
 
+               if (hw > NVS_MAX_CONSTS) {
+                       nvsProgramError(nvs, "hw = %d > NVS_MAX_CONSTS!\n", hw);
+                       return GL_FALSE;
+               }
+
                switch (plist->Parameters[i].Type) {
                case PROGRAM_NAMED_PARAM:
                case PROGRAM_STATE_VAR:
@@ -958,10 +963,13 @@ pass0_resolve_mesa_consts(nouveauShader *nvs)
                        COPY_4V(nvs->params[hw].val, plist->ParameterValues[i]);
                        break;
                default:
-                       assert(0);
-                       break;
+                       nvsProgramError(nvs, "hit bad type=%d on param %d\n",
+                                       plist->Parameters[i].Type, i);
+                       return GL_FALSE;
                }
        }
+
+       return GL_TRUE;
 }
 
 GLboolean
@@ -976,6 +984,14 @@ nouveau_shader_pass0(GLcontext *ctx, nouveauShader *nvs)
 
        NVSDBG("start: nvs=%p\n", nvs);
 
+       /* Previously detected an error, and haven't recieved new program
+        * string, so fail immediately.
+        */
+       if (nvs->error) {
+               NVSDBG("failed previous compile attempt, not retrying\n");
+               return GL_FALSE;
+       }
+
        rec = CALLOC_STRUCT(pass0_rec);
        if (!rec)
                return GL_FALSE;
@@ -1020,7 +1036,8 @@ nouveau_shader_pass0(GLcontext *ctx, nouveauShader *nvs)
 
        ret = pass0_translate_instructions(nvs, 0, 0, nvs->program_tree);
        if (ret)
-               pass0_resolve_mesa_consts(nvs);
+               ret = pass0_resolve_mesa_consts(nvs);   
+       
        /*XXX: if (!ret) DESTROY TREE!!! */
 
        FREE(rec);