anv: Remove dead prototype from entrypoints
[mesa.git] / src / intel / blorp / blorp.c
index 4dbba0174891bb99836e6bfdaaaeaf287622b28a..0b2395d9f7a5521e8704ea53aef57e80b03b7412 100644 (file)
@@ -26,8 +26,8 @@
 #include "program/prog_instruction.h"
 
 #include "blorp_priv.h"
-#include "brw_compiler.h"
-#include "brw_nir.h"
+#include "compiler/brw_compiler.h"
+#include "compiler/brw_nir.h"
 
 void
 blorp_init(struct blorp_context *blorp, void *driver_ctx,
@@ -45,10 +45,12 @@ blorp_finish(struct blorp_context *blorp)
 
 void
 blorp_batch_init(struct blorp_context *blorp,
-                 struct blorp_batch *batch, void *driver_batch)
+                 struct blorp_batch *batch, void *driver_batch,
+                 enum blorp_batch_flags flags)
 {
    batch->blorp = blorp;
    batch->driver_batch = driver_batch;
+   batch->flags = flags;
 }
 
 void
@@ -64,15 +66,7 @@ brw_blorp_surface_info_init(struct blorp_context *blorp,
                             unsigned int level, unsigned int layer,
                             enum isl_format format, bool is_render_target)
 {
-   /* Layer is a physical layer, so if this is a 2D multisample array texture
-    * using INTEL_MSAA_LAYOUT_UMS or INTEL_MSAA_LAYOUT_CMS, then it had better
-    * be a multiple of num_samples.
-    */
-   unsigned layer_multiplier = 1;
-   if (surf->surf->msaa_layout == ISL_MSAA_LAYOUT_ARRAY) {
-      assert(layer % surf->surf->samples == 0);
-      layer_multiplier = surf->surf->samples;
-   }
+   info->enabled = true;
 
    if (format == ISL_FORMAT_UNSUPPORTED)
       format = surf->surf->format;
@@ -111,14 +105,12 @@ brw_blorp_surface_info_init(struct blorp_context *blorp,
       .format = format,
       .base_level = level,
       .levels = 1,
-      .channel_select = {
-         ISL_CHANNEL_SELECT_RED,
-         ISL_CHANNEL_SELECT_GREEN,
-         ISL_CHANNEL_SELECT_BLUE,
-         ISL_CHANNEL_SELECT_ALPHA,
-      },
+      .swizzle = ISL_SWIZZLE_IDENTITY,
    };
 
+   info->view.array_len = MAX2(info->surf.logical_level0_px.depth,
+                               info->surf.logical_level0_px.array_len);
+
    if (!is_render_target &&
        (info->surf.dim == ISL_SURF_DIM_3D ||
         info->surf.msaa_layout == ISL_MSAA_LAYOUT_ARRAY)) {
@@ -128,14 +120,20 @@ brw_blorp_surface_info_init(struct blorp_context *blorp,
        * guaranteed that we won't be doing any funny surface hacks.
        */
       info->view.base_array_layer = 0;
-      info->view.array_len = MAX2(info->surf.logical_level0_px.depth,
-                                  info->surf.logical_level0_px.array_len);
-      info->z_offset = layer / layer_multiplier;
+      info->z_offset = layer;
    } else {
-      info->view.base_array_layer = layer / layer_multiplier;
-      info->view.array_len = 1;
+      info->view.base_array_layer = layer;
+
+      assert(info->view.array_len >= info->view.base_array_layer);
+      info->view.array_len -= info->view.base_array_layer;
       info->z_offset = 0;
    }
+
+   /* Sandy Bridge has a limit of a maximum of 512 layers for layered
+    * rendering.
+    */
+   if (is_render_target && blorp->isl_dev->info->gen == 6)
+      info->view.array_len = MIN2(info->view.array_len, 512);
 }
 
 
@@ -143,6 +141,7 @@ void
 blorp_params_init(struct blorp_params *params)
 {
    memset(params, 0, sizeof(*params));
+   params->num_samples = 1;
    params->num_draw_buffers = 1;
    params->num_layers = 1;
 }
@@ -156,79 +155,68 @@ brw_blorp_init_wm_prog_key(struct brw_wm_prog_key *wm_key)
       wm_key->tex.swizzles[i] = SWIZZLE_XYZW;
 }
 
-static int
-nir_uniform_type_size(const struct glsl_type *type)
-{
-   /* Only very basic types are allowed */
-   assert(glsl_type_is_vector_or_scalar(type));
-   assert(glsl_get_bit_size(type) == 32);
-
-   return glsl_get_vector_elements(type) * 4;
-}
-
 const unsigned *
-brw_blorp_compile_nir_shader(struct blorp_context *blorp, struct nir_shader *nir,
-                             const struct brw_wm_prog_key *wm_key,
-                             bool use_repclear,
-                             struct brw_blorp_prog_data *prog_data,
-                             unsigned *program_size)
+blorp_compile_fs(struct blorp_context *blorp, void *mem_ctx,
+                 struct nir_shader *nir,
+                 const struct brw_wm_prog_key *wm_key,
+                 bool use_repclear,
+                 struct brw_wm_prog_data *wm_prog_data,
+                 unsigned *program_size)
 {
    const struct brw_compiler *compiler = blorp->compiler;
 
-   void *mem_ctx = ralloc_context(NULL);
-
-   /* Calling brw_preprocess_nir and friends is destructive and, if cloning is
-    * enabled, may end up completely replacing the nir_shader.  Therefore, we
-    * own it and might as well put it in our context for easy cleanup.
-    */
-   ralloc_steal(mem_ctx, nir);
    nir->options =
       compiler->glsl_compiler_options[MESA_SHADER_FRAGMENT].NirOptions;
 
-   struct brw_wm_prog_data wm_prog_data;
-   memset(&wm_prog_data, 0, sizeof(wm_prog_data));
+   memset(wm_prog_data, 0, sizeof(*wm_prog_data));
 
-   wm_prog_data.base.nr_params = 0;
-   wm_prog_data.base.param = NULL;
+   assert(exec_list_is_empty(&nir->uniforms));
+   wm_prog_data->base.nr_params = 0;
+   wm_prog_data->base.param = NULL;
 
    /* BLORP always just uses the first two binding table entries */
-   wm_prog_data.binding_table.render_target_start = BLORP_RENDERBUFFER_BT_INDEX;
-   wm_prog_data.base.binding_table.texture_start = BLORP_TEXTURE_BT_INDEX;
+   wm_prog_data->binding_table.render_target_start = BLORP_RENDERBUFFER_BT_INDEX;
+   wm_prog_data->base.binding_table.texture_start = BLORP_TEXTURE_BT_INDEX;
 
    nir = brw_preprocess_nir(compiler, nir);
    nir_remove_dead_variables(nir, nir_var_shader_in);
    nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
 
-   /* Uniforms are required to be lowered before going into compile_fs.  For
-    * BLORP, we'll assume that whoever builds the shader sets the location
-    * they want so we just need to lower them and figure out how many we have
-    * in total.
-    */
-   nir->num_uniforms = 0;
-   nir_foreach_variable(var, &nir->uniforms) {
-      var->data.driver_location = var->data.location;
-      unsigned end = var->data.location + nir_uniform_type_size(var->type);
-      nir->num_uniforms = MAX2(nir->num_uniforms, end);
-   }
-   nir_lower_io(nir, nir_var_uniform, nir_uniform_type_size);
+   const unsigned *program =
+      brw_compile_fs(compiler, blorp->driver_ctx, mem_ctx, wm_key,
+                     wm_prog_data, nir, NULL, -1, -1, false, use_repclear,
+                     NULL, program_size, NULL);
+
+   return program;
+}
+
+const unsigned *
+blorp_compile_vs(struct blorp_context *blorp, void *mem_ctx,
+                 struct nir_shader *nir,
+                 struct brw_vs_prog_data *vs_prog_data,
+                 unsigned *program_size)
+{
+   const struct brw_compiler *compiler = blorp->compiler;
+
+   nir->options =
+      compiler->glsl_compiler_options[MESA_SHADER_VERTEX].NirOptions;
+
+   nir = brw_preprocess_nir(compiler, nir);
+   nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
+
+   vs_prog_data->inputs_read = nir->info->inputs_read;
+
+   brw_compute_vue_map(compiler->devinfo,
+                       &vs_prog_data->base.vue_map,
+                       nir->info->outputs_written,
+                       nir->info->separate_shader);
+
+   struct brw_vs_prog_key vs_key = { 0, };
 
    const unsigned *program =
-      brw_compile_fs(compiler, blorp->driver_ctx, mem_ctx,
-                     wm_key, &wm_prog_data, nir,
-                     NULL, -1, -1, false, use_repclear, program_size, NULL);
-
-   /* Copy the relavent bits of wm_prog_data over into the blorp prog data */
-   prog_data->dispatch_8 = wm_prog_data.dispatch_8;
-   prog_data->dispatch_16 = wm_prog_data.dispatch_16;
-   prog_data->first_curbe_grf_0 = wm_prog_data.base.dispatch_grf_start_reg;
-   prog_data->first_curbe_grf_2 = wm_prog_data.dispatch_grf_start_reg_2;
-   prog_data->ksp_offset_2 = wm_prog_data.prog_offset_2;
-   prog_data->persample_msaa_dispatch = wm_prog_data.persample_dispatch;
-   prog_data->flat_inputs = wm_prog_data.flat_inputs;
-   prog_data->num_varying_inputs = wm_prog_data.num_varying_inputs;
-   prog_data->inputs_read = nir->info.inputs_read;
-
-   assert(wm_prog_data.base.nr_params == 0);
+      brw_compile_vs(compiler, blorp->driver_ctx, mem_ctx,
+                     &vs_key, vs_prog_data, nir,
+                     NULL, false, -1, program_size, NULL);
 
    return program;
 }
@@ -287,6 +275,7 @@ blorp_gen6_hiz_op(struct blorp_batch *batch,
    params.dst.surf.samples = params.depth.surf.samples;
    params.dst.surf.logical_level0_px = params.depth.surf.logical_level0_px;
    params.depth_format = isl_format_get_depth_format(surf->surf->format, false);
+   params.num_samples = params.depth.surf.samples;
 
    batch->blorp->exec(batch, &params);
 }