r600g: emit streamout from dma copy shader
[mesa.git] / src / gallium / drivers / svga / svga_state_constants.c
index 1c0ed6cac942027383a9ba7568aa6c1e3ac5940c..d4682981279d35b596466985a7f7447fe4318651 100644 (file)
 /**
  * Convert from PIPE_SHADER_* to SVGA3D_SHADERTYPE_*
  */
-static int
+static unsigned
 svga_shader_type(unsigned shader)
 {
-   assert(PIPE_SHADER_VERTEX + 1 == SVGA3D_SHADERTYPE_VS);
-   assert(PIPE_SHADER_FRAGMENT + 1 == SVGA3D_SHADERTYPE_PS);
-   assert(shader <= PIPE_SHADER_FRAGMENT);
-   return shader + 1;
+   switch (shader) {
+   case PIPE_SHADER_VERTEX:
+      return SVGA3D_SHADERTYPE_VS;
+   case PIPE_SHADER_FRAGMENT:
+      return SVGA3D_SHADERTYPE_PS;
+   default:
+      assert(!"Unexpected shader type");
+      return SVGA3D_SHADERTYPE_VS;
+   }
 }
 
 
@@ -261,8 +266,7 @@ done:
 static enum pipe_error
 emit_fs_consts(struct svga_context *svga, unsigned dirty)
 {
-   const struct svga_shader_result *result = svga->state.hw_draw.fs;
-   const struct svga_fs_compile_key *key = &result->key.fkey;
+   const struct svga_shader_variant *variant = svga->state.hw_draw.fs;
    enum pipe_error ret = PIPE_OK;
 
    ret = emit_consts( svga, PIPE_SHADER_FRAGMENT );
@@ -270,44 +274,47 @@ emit_fs_consts(struct svga_context *svga, unsigned dirty)
       return ret;
 
    /* The internally generated fragment shader for xor blending
-    * doesn't have a 'result' struct.  It should be fixed to avoid
+    * doesn't have a 'variant' struct.  It should be fixed to avoid
     * this special case, but work around it with a NULL check:
     */
-   if (result != NULL && key->num_unnormalized_coords) {
-      unsigned offset = result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
-      int i;
-
-      for (i = 0; i < key->num_textures; i++) {
-         if (key->tex[i].unnormalized) {
-            struct pipe_resource *tex = svga->curr.sampler_views[i]->texture;
-            float data[4];
-
-            data[0] = 1.0 / (float)tex->width0;
-            data[1] = 1.0 / (float)tex->height0;
-            data[2] = 1.0;
-            data[3] = 1.0;
-
-            ret = emit_const( svga,
-                              PIPE_SHADER_FRAGMENT,
-                              key->tex[i].width_height_idx + offset,
-                              data );
-            if (ret != PIPE_OK)
-               return ret;
+   if (variant) {
+      const struct svga_fs_compile_key *key = &variant->key.fkey;
+      if (key->num_unnormalized_coords) {
+         const unsigned offset =
+            variant->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
+         unsigned i;
+
+         for (i = 0; i < key->num_textures; i++) {
+            if (key->tex[i].unnormalized) {
+               struct pipe_resource *tex = svga->curr.sampler_views[i]->texture;
+               float data[4];
+
+               data[0] = 1.0f / (float) tex->width0;
+               data[1] = 1.0f / (float) tex->height0;
+               data[2] = 1.0f;
+               data[3] = 1.0f;
+
+               ret = emit_const(svga,
+                                PIPE_SHADER_FRAGMENT,
+                                key->tex[i].width_height_idx + offset,
+                                data);
+               if (ret != PIPE_OK) {
+                  return ret;
+               }
+            }
          }
       }
-
-      offset += key->num_unnormalized_coords;
    }
 
    return PIPE_OK;
 }
 
 
-struct svga_tracked_state svga_hw_fs_parameters =
+struct svga_tracked_state svga_hw_fs_constants =
 {
    "hw fs params",
    (SVGA_NEW_FS_CONST_BUFFER |
-    SVGA_NEW_FS_RESULT |
+    SVGA_NEW_FS_VARIANT |
     SVGA_NEW_TEXTURE_BINDING),
    emit_fs_consts
 };
@@ -317,16 +324,18 @@ struct svga_tracked_state svga_hw_fs_parameters =
 static enum pipe_error
 emit_vs_consts(struct svga_context *svga, unsigned dirty)
 {
-   const struct svga_shader_result *result = svga->state.hw_draw.vs;
-   const struct svga_vs_compile_key *key = &result->key.vkey;
+   const struct svga_shader_variant *variant = svga->state.hw_draw.vs;
+   const struct svga_vs_compile_key *key;
    enum pipe_error ret = PIPE_OK;
    unsigned offset;
 
-   /* SVGA_NEW_VS_RESULT
+   /* SVGA_NEW_VS_VARIANT
     */
-   if (result == NULL)
+   if (variant == NULL)
       return PIPE_OK;
 
+   key = &variant->key.vkey;
+
    /* SVGA_NEW_VS_CONST_BUFFER
     */
    ret = emit_consts( svga, PIPE_SHADER_VERTEX );
@@ -334,9 +343,9 @@ emit_vs_consts(struct svga_context *svga, unsigned dirty)
       return ret;
 
    /* offset = number of constants in the VS const buffer */
-   offset = result->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
+   offset = variant->shader->info.file_max[TGSI_FILE_CONSTANT] + 1;
 
-   /* SVGA_NEW_VS_RESULT
+   /* SVGA_NEW_VS_PRESCALE
     * Put the viewport pre-scale/translate values into the const buffer.
     */
    if (key->need_prescale) {
@@ -351,33 +360,15 @@ emit_vs_consts(struct svga_context *svga, unsigned dirty)
          return ret;
    }
 
-   /* SVGA_NEW_ZERO_STRIDE
-    * Put the zero-stride vertex array attributes into the const buffer.
-    */
-   if (key->zero_stride_vertex_elements) {
-      unsigned i, curr_zero_stride = 0;
-      for (i = 0; i < PIPE_MAX_ATTRIBS; ++i) {
-         if (key->zero_stride_vertex_elements & (1 << i)) {
-            ret = emit_const( svga, PIPE_SHADER_VERTEX, offset++,
-                              svga->curr.zero_stride_constants +
-                              4 * curr_zero_stride );
-            if (ret != PIPE_OK)
-               return ret;
-            ++curr_zero_stride;
-         }
-      }
-   }
-
    return PIPE_OK;
 }
 
 
-struct svga_tracked_state svga_hw_vs_parameters =
+struct svga_tracked_state svga_hw_vs_constants =
 {
    "hw vs params",
    (SVGA_NEW_PRESCALE |
     SVGA_NEW_VS_CONST_BUFFER |
-    SVGA_NEW_ZERO_STRIDE |
-    SVGA_NEW_VS_RESULT),
+    SVGA_NEW_VS_VARIANT),
    emit_vs_consts
 };