vc4: Add support for point size setting.
authorEric Anholt <eric@anholt.net>
Wed, 24 Sep 2014 21:23:25 +0000 (14:23 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 24 Sep 2014 22:56:39 +0000 (15:56 -0700)
This is the support for both the global and per-vertex modes.

src/gallium/drivers/vc4/vc4_draw.c
src/gallium/drivers/vc4/vc4_emit.c
src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qir.h
src/gallium/drivers/vc4/vc4_screen.c
src/gallium/drivers/vc4/vc4_state.c

index c88e43c..0c06bfd 100644 (file)
@@ -153,7 +153,11 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                            1);
 
         cl_start_shader_reloc(&vc4->shader_rec, 3 + vtx->num_elements);
-        cl_u16(&vc4->shader_rec, VC4_SHADER_FLAG_ENABLE_CLIPPING);
+        cl_u16(&vc4->shader_rec,
+               VC4_SHADER_FLAG_ENABLE_CLIPPING |
+               ((info->mode == PIPE_PRIM_POINTS &&
+                 vc4->rasterizer->base.point_size_per_vertex) ?
+                VC4_SHADER_FLAG_VS_POINT_SIZE : 0));
         cl_u8(&vc4->shader_rec, 0); /* fs num uniforms (unused) */
         cl_u8(&vc4->shader_rec, vc4->prog.fs->num_inputs);
         cl_reloc(vc4, &vc4->shader_rec, vc4->prog.fs->bo, 0);
index 0f533f0..8df7073 100644 (file)
@@ -54,6 +54,9 @@ vc4_emit_state(struct pipe_context *pctx)
                 cl_u16(&vc4->bcl, vc4->rasterizer->offset_factor);
                 cl_u16(&vc4->bcl, vc4->rasterizer->offset_units);
 
+                cl_u8(&vc4->bcl, VC4_PACKET_POINT_SIZE);
+                cl_f(&vc4->bcl, vc4->rasterizer->point_size);
+
                 cl_u8(&vc4->bcl, VC4_PACKET_LINE_WIDTH);
                 cl_f(&vc4->bcl, vc4->rasterizer->base.line_width);
         }
index 315a857..a520922 100644 (file)
@@ -67,6 +67,7 @@ struct vc4_fs_key {
 struct vc4_vs_key {
         struct vc4_key base;
         enum pipe_format attr_formats[8];
+        bool per_vertex_point_size;
 };
 
 static void
@@ -934,6 +935,9 @@ emit_tgsi_declaration(struct vc4_compile *c,
                 case TGSI_SEMANTIC_COLOR:
                         c->output_color_index = decl->Range.First * 4;
                         break;
+                case TGSI_SEMANTIC_PSIZE:
+                        c->output_point_size_index = decl->Range.First * 4;
+                        break;
                 }
 
                 break;
@@ -1432,6 +1436,24 @@ emit_rcp_wc_write(struct vc4_compile *c, struct qreg rcp_w)
 }
 
 static void
+emit_point_size_write(struct vc4_compile *c)
+{
+        struct qreg point_size;
+
+        if (c->output_point_size_index)
+                point_size = c->outputs[c->output_point_size_index + 3];
+        else
+                point_size = qir_uniform_f(c, 1.0);
+
+        /* Workaround: HW-2726 PTB does not handle zero-size points (BCM2835,
+         * BCM21553).
+         */
+        point_size = qir_FMAX(c, point_size, qir_uniform_f(c, .125));
+
+        qir_VPM_WRITE(c, point_size);
+}
+
+static void
 emit_vert_end(struct vc4_compile *c)
 {
         struct qreg rcp_w = qir_RCP(c, c->outputs[3]);
@@ -1439,6 +1461,8 @@ emit_vert_end(struct vc4_compile *c)
         emit_scaled_viewport_write(c, rcp_w);
         emit_zs_write(c, rcp_w);
         emit_rcp_wc_write(c, rcp_w);
+        if (c->vs_key->per_vertex_point_size)
+                emit_point_size_write(c);
 
         for (int i = 4; i < c->num_outputs; i++) {
                 qir_VPM_WRITE(c, c->outputs[i]);
@@ -1456,6 +1480,8 @@ emit_coord_end(struct vc4_compile *c)
         emit_scaled_viewport_write(c, rcp_w);
         emit_zs_write(c, rcp_w);
         emit_rcp_wc_write(c, rcp_w);
+        if (c->vs_key->per_vertex_point_size)
+                emit_point_size_write(c);
 }
 
 static struct vc4_compile *
@@ -1700,7 +1726,7 @@ vc4_update_compiled_fs(struct vc4_context *vc4, uint8_t prim_mode)
 }
 
 static void
-vc4_update_compiled_vs(struct vc4_context *vc4)
+vc4_update_compiled_vs(struct vc4_context *vc4, uint8_t prim_mode)
 {
         struct vc4_vs_key local_key;
         struct vc4_vs_key *key = &local_key;
@@ -1712,6 +1738,10 @@ vc4_update_compiled_vs(struct vc4_context *vc4)
         for (int i = 0; i < ARRAY_SIZE(key->attr_formats); i++)
                 key->attr_formats[i] = vc4->vtx->pipe[i].src_format;
 
+        key->per_vertex_point_size =
+                (prim_mode == PIPE_PRIM_POINTS &&
+                 vc4->rasterizer->base.point_size_per_vertex);
+
         vc4->prog.vs = util_hash_table_get(vc4->vs_cache, key);
         if (vc4->prog.vs)
                 return;
@@ -1730,7 +1760,7 @@ void
 vc4_update_compiled_shaders(struct vc4_context *vc4, uint8_t prim_mode)
 {
         vc4_update_compiled_fs(vc4, prim_mode);
-        vc4_update_compiled_vs(vc4);
+        vc4_update_compiled_vs(vc4, prim_mode);
 }
 
 static unsigned
index 0a2c685..6a2e3c4 100644 (file)
@@ -238,6 +238,7 @@ struct vc4_compile {
         uint32_t num_texture_samples;
         uint32_t output_position_index;
         uint32_t output_color_index;
+        uint32_t output_point_size_index;
 
         struct qreg undef;
         enum qstage stage;
index 4472efd..a327c7f 100644 (file)
@@ -243,7 +243,8 @@ vc4_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
 
         case PIPE_CAPF_MAX_POINT_WIDTH:
         case PIPE_CAPF_MAX_POINT_WIDTH_AA:
-                return 8192.0f;
+                return 512.0f;
+
         case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
                 return 0.0f;
         case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
index 81dac21..5f5eee8 100644 (file)
@@ -102,8 +102,10 @@ vc4_create_rasterizer_state(struct pipe_context *pctx,
         if (!(cso->cull_face & PIPE_FACE_BACK))
                 so->config_bits[0] |= VC4_CONFIG_BITS_ENABLE_PRIM_BACK;
 
-        /* XXX: per_vertex */
-        so->point_size = cso->point_size;
+        /* Workaround: HW-2726 PTB does not handle zero-size points (BCM2835,
+         * BCM21553).
+         */
+        so->point_size = MAX2(cso->point_size, .125);
 
         if (cso->front_ccw)
                 so->config_bits[0] |= VC4_CONFIG_BITS_CW_PRIMITIVES;