intel/blorp: Add a shader type to make keys more unique
[mesa.git] / src / intel / blorp / blorp_clear.c
index 831c8ed0a6e578c0b7ae71492047d9a8399cb5fc..2b8af18019dd6784ecbb3339d599a26e23b5dd42 100644 (file)
@@ -23,6 +23,9 @@
 
 #include "util/ralloc.h"
 
+#include "main/macros.h" /* Needed for MAX3 and MAX2 for format_rgb9e5 */
+#include "util/format_rgb9e5.h"
+
 #include "blorp_priv.h"
 #include "brw_defines.h"
 
@@ -32,6 +35,7 @@
 
 struct brw_blorp_const_color_prog_key
 {
+   enum blorp_shader_type shader_type; /* Must be BLORP_SHADER_TYPE_CLEAR */
    bool use_simd16_replicated_data;
    bool pad[3];
 };
@@ -41,9 +45,10 @@ blorp_params_get_clear_kernel(struct blorp_context *blorp,
                               struct blorp_params *params,
                               bool use_replicated_data)
 {
-   struct brw_blorp_const_color_prog_key blorp_key;
-   memset(&blorp_key, 0, sizeof(blorp_key));
-   blorp_key.use_simd16_replicated_data = use_replicated_data;
+   const struct brw_blorp_const_color_prog_key blorp_key = {
+      .shader_type = BLORP_SHADER_TYPE_CLEAR,
+      .use_simd16_replicated_data = use_replicated_data,
+   };
 
    if (blorp->lookup_shader(blorp, &blorp_key, sizeof(blorp_key),
                             &params->wm_prog_kernel, &params->wm_prog_data))
@@ -52,8 +57,8 @@ blorp_params_get_clear_kernel(struct blorp_context *blorp,
    void *mem_ctx = ralloc_context(NULL);
 
    nir_builder b;
-   nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_FRAGMENT, NULL);
-   b.shader->info.name = ralloc_strdup(b.shader, "BLORP-clear");
+   nir_builder_init_simple_shader(&b, mem_ctx, MESA_SHADER_FRAGMENT, NULL);
+   b.shader->info->name = ralloc_strdup(b.shader, "BLORP-clear");
 
    nir_variable *v_color = nir_variable_create(b.shader, nir_var_shader_in,
                                                glsl_vec4_type(), "v_color");
@@ -70,15 +75,15 @@ blorp_params_get_clear_kernel(struct blorp_context *blorp,
    struct brw_wm_prog_key wm_key;
    brw_blorp_init_wm_prog_key(&wm_key);
 
-   struct brw_blorp_prog_data prog_data;
+   struct brw_wm_prog_data prog_data;
    unsigned program_size;
    const unsigned *program =
-      brw_blorp_compile_nir_shader(blorp, b.shader, &wm_key, use_replicated_data,
-                                   &prog_data, &program_size);
+      blorp_compile_fs(blorp, mem_ctx, b.shader, &wm_key, use_replicated_data,
+                       &prog_data, &program_size);
 
    blorp->upload_shader(blorp, &blorp_key, sizeof(blorp_key),
                         program, program_size,
-                        &prog_data, sizeof(prog_data),
+                        &prog_data.base, sizeof(prog_data),
                         &params->wm_prog_kernel, &params->wm_prog_data);
 
    ralloc_free(mem_ctx);
@@ -208,12 +213,13 @@ get_fast_clear_rect(const struct isl_device *dev,
 
 void
 blorp_fast_clear(struct blorp_batch *batch,
-                 const struct blorp_surf *surf,
-                 uint32_t level, uint32_t layer, enum isl_format format,
+                 const struct blorp_surf *surf, enum isl_format format,
+                 uint32_t level, uint32_t start_layer, uint32_t num_layers,
                  uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
 {
    struct blorp_params params;
    blorp_params_init(&params);
+   params.num_layers = num_layers;
 
    params.x0 = x0;
    params.y0 = y0;
@@ -228,8 +234,9 @@ blorp_fast_clear(struct blorp_batch *batch,
 
    blorp_params_get_clear_kernel(batch->blorp, &params, true);
 
-   brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, level, layer,
-                               format, true);
+   brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, level,
+                               start_layer, format, true);
+   params.num_samples = params.dst.surf.samples;
 
    batch->blorp->exec(batch, &params);
 }
@@ -238,10 +245,11 @@ blorp_fast_clear(struct blorp_batch *batch,
 void
 blorp_clear(struct blorp_batch *batch,
             const struct blorp_surf *surf,
-            uint32_t level, uint32_t layer,
+            enum isl_format format, struct isl_swizzle swizzle,
+            uint32_t level, uint32_t start_layer, uint32_t num_layers,
             uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
-            enum isl_format format, union isl_color_value clear_color,
-            bool color_write_disable[4])
+            union isl_color_value clear_color,
+            const bool color_write_disable[4])
 {
    struct blorp_params params;
    blorp_params_init(&params);
@@ -251,6 +259,11 @@ blorp_clear(struct blorp_batch *batch,
    params.x1 = x1;
    params.y1 = y1;
 
+   if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) {
+      clear_color.u32[0] = float3_to_rgb9e5(clear_color.f32);
+      format = ISL_FORMAT_R32_UINT;
+   }
+
    memcpy(&params.wm_inputs, clear_color.f32, sizeof(float) * 4);
 
    bool use_simd16_replicated_data = true;
@@ -267,19 +280,107 @@ blorp_clear(struct blorp_batch *batch,
    /* Constant color writes ignore everyting in blend and color calculator
     * state.  This is not documented.
     */
-   for (unsigned i = 0; i < 4; i++) {
-      params.color_write_disable[i] = color_write_disable[i];
-      if (color_write_disable[i])
-         use_simd16_replicated_data = false;
+   if (color_write_disable) {
+      for (unsigned i = 0; i < 4; i++) {
+         params.color_write_disable[i] = color_write_disable[i];
+         if (color_write_disable[i])
+            use_simd16_replicated_data = false;
+      }
    }
 
    blorp_params_get_clear_kernel(batch->blorp, &params,
                                  use_simd16_replicated_data);
 
-   brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, level, layer,
-                               format, true);
+   while (num_layers > 0) {
+      brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, level,
+                                  start_layer, format, true);
+      params.dst.view.swizzle = swizzle;
 
-   batch->blorp->exec(batch, &params);
+      params.num_samples = params.dst.surf.samples;
+
+      /* We may be restricted on the number of layers we can bind at any one
+       * time.  In particular, Sandy Bridge has a maximum number of layers of
+       * 512 but a maximum 3D texture size is much larger.
+       */
+      params.num_layers = MIN2(params.dst.view.array_len, num_layers);
+      batch->blorp->exec(batch, &params);
+
+      start_layer += params.num_layers;
+      num_layers -= params.num_layers;
+   }
+}
+
+void
+blorp_clear_depth_stencil(struct blorp_batch *batch,
+                          const struct blorp_surf *depth,
+                          const struct blorp_surf *stencil,
+                          uint32_t level, uint32_t start_layer,
+                          uint32_t num_layers,
+                          uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
+                          bool clear_depth, float depth_value,
+                          uint8_t stencil_mask, uint8_t stencil_value)
+{
+   struct blorp_params params;
+   blorp_params_init(&params);
+
+   params.x0 = x0;
+   params.y0 = y0;
+   params.x1 = x1;
+   params.y1 = y1;
+
+   while (num_layers > 0) {
+      params.num_layers = num_layers;
+
+      if (stencil_mask) {
+         brw_blorp_surface_info_init(batch->blorp, &params.stencil, stencil,
+                                     level, start_layer,
+                                     ISL_FORMAT_UNSUPPORTED, true);
+         params.stencil_mask = stencil_mask;
+         params.stencil_ref = stencil_value;
+
+         params.dst.surf.samples = params.stencil.surf.samples;
+         params.dst.surf.logical_level0_px =
+            params.stencil.surf.logical_level0_px;
+         params.dst.view = params.depth.view;
+
+         params.num_samples = params.stencil.surf.samples;
+
+         /* We may be restricted on the number of layers we can bind at any
+          * one time.  In particular, Sandy Bridge has a maximum number of
+          * layers of 512 but a maximum 3D texture size is much larger.
+          */
+         if (params.stencil.view.array_len < params.num_layers)
+            params.num_layers = params.stencil.view.array_len;
+      }
+
+      if (clear_depth) {
+         brw_blorp_surface_info_init(batch->blorp, &params.depth, depth,
+                                     level, start_layer,
+                                     ISL_FORMAT_UNSUPPORTED, true);
+         params.z = depth_value;
+         params.depth_format =
+            isl_format_get_depth_format(depth->surf->format, false);
+
+         params.dst.surf.samples = params.depth.surf.samples;
+         params.dst.surf.logical_level0_px =
+            params.depth.surf.logical_level0_px;
+         params.dst.view = params.depth.view;
+
+         params.num_samples = params.depth.surf.samples;
+
+         /* We may be restricted on the number of layers we can bind at any
+          * one time.  In particular, Sandy Bridge has a maximum number of
+          * layers of 512 but a maximum 3D texture size is much larger.
+          */
+         if (params.depth.view.array_len < params.num_layers)
+            params.num_layers = params.depth.view.array_len;
+      }
+
+      batch->blorp->exec(batch, &params);
+
+      start_layer += params.num_layers;
+      num_layers -= params.num_layers;
+   }
 }
 
 void