nv50,nvc0: add new texture and render target formats
[mesa.git] / src / gallium / drivers / nv50 / nv50_shader_state.c
index f7d78a3b11b99e7305892eb48862c606c72dcb3e..82c346cb5eab340e86ad9d3bc70354fd2e8e1086 100644 (file)
@@ -138,6 +138,7 @@ nv50_program_validate(struct nv50_context *nv50, struct nv50_program *prog)
       return FALSE;
 
    if (prog->type == PIPE_SHADER_FRAGMENT) heap = nv50->screen->fp_code_heap;
+   else
    if (prog->type == PIPE_SHADER_GEOMETRY) heap = nv50->screen->gp_code_heap;
    else
       heap = nv50->screen->vp_code_heap;
@@ -145,14 +146,16 @@ nv50_program_validate(struct nv50_context *nv50, struct nv50_program *prog)
    size = align(prog->code_size, 0x100);
 
    ret = nouveau_resource_alloc(heap, size, prog, &prog->res);
-   if (ret)
+   if (ret) {
+      NOUVEAU_ERR("out of code space for shader type %i\n", prog->type);
       return FALSE;
+   }
    prog->code_base = prog->res->start;
 
    nv50_relocate_program(prog, prog->code_base, 0);
 
    nv50_sifc_linear_u8(&nv50->base, nv50->screen->code,
-                       (prog->type << 16) + prog->code_base,
+                       (prog->type << NV50_CODE_BO_SIZE_LOG2) + prog->code_base,
                        NOUVEAU_BO_VRAM, prog->code_size, prog->code);
 
    BEGIN_RING(nv50->screen->base.channel, RING_3D(CODE_CB_FLUSH), 1);
@@ -223,7 +226,7 @@ nv50_gmtyprog_validate(struct nv50_context *nv50)
    OUT_RING  (chan, gp->code_base);
 }
 
-void
+static void
 nv50_sprite_coords_validate(struct nv50_context *nv50)
 {
    struct nouveau_channel *chan = nv50->screen->base.channel;
@@ -279,6 +282,39 @@ nv50_sprite_coords_validate(struct nv50_context *nv50)
    OUT_RINGp (chan, pntc, 8);
 }
 
+/* Validate state derived from shaders and the rasterizer cso. */
+void
+nv50_validate_derived_rs(struct nv50_context *nv50)
+{
+   struct nouveau_channel *chan = nv50->screen->base.channel;
+   uint32_t color, psize;
+
+   nv50_sprite_coords_validate(nv50);
+
+   if (nv50->dirty & NV50_NEW_FRAGPROG)
+      return;
+   psize = nv50->state.semantic_psize & ~NV50_3D_MAP_SEMANTIC_3_PTSZ_EN__MASK;
+   color = nv50->state.semantic_color & ~NV50_3D_MAP_SEMANTIC_0_CLMP_EN;
+
+   if (nv50->rast->pipe.clamp_vertex_color)
+      color |= NV50_3D_MAP_SEMANTIC_0_CLMP_EN;
+
+   if (color != nv50->state.semantic_color) {
+      nv50->state.semantic_color = color;
+      BEGIN_RING(chan, RING_3D(MAP_SEMANTIC_0), 1);
+      OUT_RING  (chan, color);
+   }
+
+   if (nv50->rast->pipe.point_size_per_vertex)
+      psize |= NV50_3D_MAP_SEMANTIC_3_PTSZ_EN__MASK;
+
+   if (psize != nv50->state.semantic_psize) {
+      nv50->state.semantic_psize = psize;
+      BEGIN_RING(chan, RING_3D(MAP_SEMANTIC_3), 1);
+      OUT_RING  (chan, psize);
+   }
+}
+
 static int
 nv50_vec4_map(uint8_t *map, int mid, uint32_t lin[4],
               struct nv50_varying *in, struct nv50_varying *out)
@@ -369,6 +405,9 @@ nv50_fp_linkage_validate(struct nv50_context *nv50)
       map[m++] = vp->vp.psiz;
    }
 
+   if (nv50->rast->pipe.clamp_vertex_color)
+      colors |= NV50_3D_MAP_SEMANTIC_0_CLMP_EN;
+
    n = (m + 3) / 4;
    assert(m <= 64);
 
@@ -401,6 +440,9 @@ nv50_fp_linkage_validate(struct nv50_context *nv50)
 
    nv50->state.interpolant_ctrl = interp;
 
+   nv50->state.semantic_color = colors;
+   nv50->state.semantic_psize = psiz;
+
    BEGIN_RING(chan, RING_3D(NOPERSPECTIVE_BITMAP(0)), 4);
    OUT_RINGp (chan, lin, 4);