r300: fix vertex programs with big number of params (>255) under KMS
authorMaciej Cencora <m.cencora@gmail.com>
Sun, 21 Mar 2010 11:10:06 +0000 (12:10 +0100)
committerMaciej Cencora <m.cencora@gmail.com>
Wed, 24 Mar 2010 19:08:00 +0000 (20:08 +0100)
UMS will probably require some kernel work

src/mesa/drivers/dri/r300/r300_cmdbuf.c
src/mesa/drivers/dri/r300/r300_vertprog.c

index 6cfa5686f4a5a759a0d1b54b08b35d34be2e757e..8eb596d1c5abe97ab1357b2ba15fc0514dc8d715 100644 (file)
@@ -83,6 +83,23 @@ static int check_vpu(GLcontext *ctx, struct radeon_state_atom *atom)
        return cnt ? (cnt * 4) + extra : 0;
 }
 
+static int check_vpp(GLcontext *ctx, struct radeon_state_atom *atom)
+{
+    r300ContextPtr r300 = R300_CONTEXT(ctx);
+    int cnt;
+    int extra = 1;
+
+    if (r300->radeon.radeonScreen->kernel_mm) {
+        cnt = r300->selected_vp->code.constants.Count * 4;
+        extra = 5;
+    } else {
+        cnt = vpu_count(atom->cmd);
+        extra = 1;
+    }
+
+    return cnt ? (cnt * 4) + extra : 0;
+}
+
 void r300_emit_vpu(struct r300_context *r300,
                    uint32_t *data,
                    unsigned len,
@@ -101,15 +118,26 @@ static void emit_vpu_state(GLcontext *ctx, struct radeon_state_atom * atom)
 {
     r300ContextPtr r300 = R300_CONTEXT(ctx);
     drm_r300_cmd_header_t cmd;
-    uint32_t addr, ndw;
+    uint32_t addr;
 
     cmd.u = atom->cmd[0];
     addr = (cmd.vpu.adrhi << 8) | cmd.vpu.adrlo;
-    ndw = atom->check(ctx, atom);
 
     r300_emit_vpu(r300, &atom->cmd[1], vpu_count(atom->cmd) * 4, addr);
 }
 
+static void emit_vpp_state(GLcontext *ctx, struct radeon_state_atom * atom)
+{
+    r300ContextPtr r300 = R300_CONTEXT(ctx);
+    drm_r300_cmd_header_t cmd;
+    uint32_t addr;
+
+    cmd.u = atom->cmd[0];
+    addr = (cmd.vpu.adrhi << 8) | cmd.vpu.adrlo;
+
+    r300_emit_vpu(r300, &atom->cmd[1], r300->selected_vp->code.constants.Count * 4, addr);
+}
+
 void r500_emit_fp(struct r300_context *r300,
                   uint32_t *data,
                   unsigned len,
@@ -784,11 +812,11 @@ void r300InitCmdBuf(r300ContextPtr r300)
                        r300->hw.vpi.emit = emit_vpu_state;
 
                if (is_r500) {
-                       ALLOC_STATE(vpp, vpu, R300_VPP_CMDSIZE, 0);
+                       ALLOC_STATE(vpp, vpp, R300_VPP_CMDSIZE, 0);
                        r300->hw.vpp.cmd[0] =
                                cmdvpu(r300->radeon.radeonScreen, R500_PVS_CONST_START, 0);
                        if (r300->radeon.radeonScreen->kernel_mm)
-                               r300->hw.vpp.emit = emit_vpu_state;
+                               r300->hw.vpp.emit = emit_vpp_state;
 
                        ALLOC_STATE(vps, vpu, R300_VPS_CMDSIZE, 0);
                        r300->hw.vps.cmd[0] =
@@ -805,11 +833,11 @@ void r300InitCmdBuf(r300ContextPtr r300)
                                        r300->hw.vpucp[i].emit = emit_vpu_state;
                        }
                } else {
-                       ALLOC_STATE(vpp, vpu, R300_VPP_CMDSIZE, 0);
+                       ALLOC_STATE(vpp, vpp, R300_VPP_CMDSIZE, 0);
                        r300->hw.vpp.cmd[0] =
                                cmdvpu(r300->radeon.radeonScreen, R300_PVS_CONST_START, 0);
                        if (r300->radeon.radeonScreen->kernel_mm)
-                               r300->hw.vpp.emit = emit_vpu_state;
+                               r300->hw.vpp.emit = emit_vpp_state;
 
                        ALLOC_STATE(vps, vpu, R300_VPS_CMDSIZE, 0);
                        r300->hw.vps.cmd[0] =
index e77cd611f7afbb3ea0f43bb3b22fcc63b0358816..53fe948ab98ccea84d08f47b5218fa89f85ad6d6 100644 (file)
@@ -392,7 +392,11 @@ void r300SetupVertexProgram(r300ContextPtr rmesa)
        R300_STATECHANGE(rmesa, vap_cntl);
        R300_STATECHANGE(rmesa, vpp);
        param_count = r300VertexProgUpdateParams(ctx, prog, (float *)&rmesa->hw.vpp.cmd[R300_VPP_PARAM_0]);
-       bump_vpu_count(rmesa->hw.vpp.cmd, param_count);
+       if (!rmesa->radeon.radeonScreen->kernel_mm && param_count > 255 * 4) {
+               WARN_ONCE("Too many VP params, expect rendering errors\n");
+       }
+       /* Prevent the overflow (vpu.count is u8) */
+       bump_vpu_count(rmesa->hw.vpp.cmd, MIN2(255 * 4, param_count));
        param_count /= 4;
 
        r300EmitVertexProgram(rmesa, R300_PVS_CODE_START, &(prog->code));