1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2012 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include <errno.h> 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "program/prog_instruction.h" 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "blorp_priv.h" 29bf215546Sopenharmony_ci#include "compiler/brw_compiler.h" 30bf215546Sopenharmony_ci#include "compiler/brw_nir.h" 31bf215546Sopenharmony_ci#include "dev/intel_debug.h" 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ciconst char * 34bf215546Sopenharmony_ciblorp_shader_type_to_name(enum blorp_shader_type type) 35bf215546Sopenharmony_ci{ 36bf215546Sopenharmony_ci static const char *shader_name[] = { 37bf215546Sopenharmony_ci [BLORP_SHADER_TYPE_COPY] = "BLORP-copy", 38bf215546Sopenharmony_ci [BLORP_SHADER_TYPE_BLIT] = "BLORP-blit", 39bf215546Sopenharmony_ci [BLORP_SHADER_TYPE_CLEAR] = "BLORP-clear", 40bf215546Sopenharmony_ci [BLORP_SHADER_TYPE_MCS_PARTIAL_RESOLVE] = "BLORP-mcs-partial-resolve", 41bf215546Sopenharmony_ci [BLORP_SHADER_TYPE_LAYER_OFFSET_VS] = "BLORP-layer-offset-vs", 42bf215546Sopenharmony_ci [BLORP_SHADER_TYPE_GFX4_SF] = "BLORP-gfx4-sf", 43bf215546Sopenharmony_ci }; 44bf215546Sopenharmony_ci assert(type < ARRAY_SIZE(shader_name)); 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci return shader_name[type]; 47bf215546Sopenharmony_ci} 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ciconst char * 50bf215546Sopenharmony_ciblorp_shader_pipeline_to_name(enum blorp_shader_pipeline pipe) 51bf215546Sopenharmony_ci{ 52bf215546Sopenharmony_ci static const char *pipeline_name[] = { 53bf215546Sopenharmony_ci [BLORP_SHADER_PIPELINE_RENDER] = "render", 54bf215546Sopenharmony_ci [BLORP_SHADER_PIPELINE_COMPUTE] = "compute", 55bf215546Sopenharmony_ci }; 56bf215546Sopenharmony_ci assert(pipe < ARRAY_SIZE(pipeline_name)); 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci return pipeline_name[pipe]; 59bf215546Sopenharmony_ci} 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_civoid 62bf215546Sopenharmony_ciblorp_init(struct blorp_context *blorp, void *driver_ctx, 63bf215546Sopenharmony_ci struct isl_device *isl_dev, const struct blorp_config *config) 64bf215546Sopenharmony_ci{ 65bf215546Sopenharmony_ci memset(blorp, 0, sizeof(*blorp)); 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci blorp->driver_ctx = driver_ctx; 68bf215546Sopenharmony_ci blorp->isl_dev = isl_dev; 69bf215546Sopenharmony_ci if (config) 70bf215546Sopenharmony_ci blorp->config = *config; 71bf215546Sopenharmony_ci} 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_civoid 74bf215546Sopenharmony_ciblorp_finish(struct blorp_context *blorp) 75bf215546Sopenharmony_ci{ 76bf215546Sopenharmony_ci blorp->driver_ctx = NULL; 77bf215546Sopenharmony_ci} 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_civoid 80bf215546Sopenharmony_ciblorp_batch_init(struct blorp_context *blorp, 81bf215546Sopenharmony_ci struct blorp_batch *batch, void *driver_batch, 82bf215546Sopenharmony_ci enum blorp_batch_flags flags) 83bf215546Sopenharmony_ci{ 84bf215546Sopenharmony_ci batch->blorp = blorp; 85bf215546Sopenharmony_ci batch->driver_batch = driver_batch; 86bf215546Sopenharmony_ci batch->flags = flags; 87bf215546Sopenharmony_ci} 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_civoid 90bf215546Sopenharmony_ciblorp_batch_finish(struct blorp_batch *batch) 91bf215546Sopenharmony_ci{ 92bf215546Sopenharmony_ci batch->blorp = NULL; 93bf215546Sopenharmony_ci} 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_civoid 96bf215546Sopenharmony_cibrw_blorp_surface_info_init(struct blorp_batch *batch, 97bf215546Sopenharmony_ci struct brw_blorp_surface_info *info, 98bf215546Sopenharmony_ci const struct blorp_surf *surf, 99bf215546Sopenharmony_ci unsigned int level, float layer, 100bf215546Sopenharmony_ci enum isl_format format, bool is_dest) 101bf215546Sopenharmony_ci{ 102bf215546Sopenharmony_ci struct blorp_context *blorp = batch->blorp; 103bf215546Sopenharmony_ci memset(info, 0, sizeof(*info)); 104bf215546Sopenharmony_ci assert(level < surf->surf->levels); 105bf215546Sopenharmony_ci assert(layer < MAX2(surf->surf->logical_level0_px.depth >> level, 106bf215546Sopenharmony_ci surf->surf->logical_level0_px.array_len)); 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci info->enabled = true; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci if (format == ISL_FORMAT_UNSUPPORTED) 111bf215546Sopenharmony_ci format = surf->surf->format; 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_ci info->surf = *surf->surf; 114bf215546Sopenharmony_ci info->addr = surf->addr; 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci info->aux_usage = surf->aux_usage; 117bf215546Sopenharmony_ci if (info->aux_usage != ISL_AUX_USAGE_NONE) { 118bf215546Sopenharmony_ci info->aux_surf = *surf->aux_surf; 119bf215546Sopenharmony_ci info->aux_addr = surf->aux_addr; 120bf215546Sopenharmony_ci } 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci info->clear_color = surf->clear_color; 123bf215546Sopenharmony_ci info->clear_color_addr = surf->clear_color_addr; 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci isl_surf_usage_flags_t view_usage; 126bf215546Sopenharmony_ci if (is_dest) { 127bf215546Sopenharmony_ci if (batch->flags & BLORP_BATCH_USE_COMPUTE) 128bf215546Sopenharmony_ci view_usage = ISL_SURF_USAGE_STORAGE_BIT; 129bf215546Sopenharmony_ci else 130bf215546Sopenharmony_ci view_usage = ISL_SURF_USAGE_RENDER_TARGET_BIT; 131bf215546Sopenharmony_ci } else { 132bf215546Sopenharmony_ci view_usage = ISL_SURF_USAGE_TEXTURE_BIT; 133bf215546Sopenharmony_ci } 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci info->view = (struct isl_view) { 136bf215546Sopenharmony_ci .usage = view_usage, 137bf215546Sopenharmony_ci .format = format, 138bf215546Sopenharmony_ci .base_level = level, 139bf215546Sopenharmony_ci .levels = 1, 140bf215546Sopenharmony_ci .swizzle = ISL_SWIZZLE_IDENTITY, 141bf215546Sopenharmony_ci }; 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci info->view.array_len = MAX2(info->surf.logical_level0_px.depth, 144bf215546Sopenharmony_ci info->surf.logical_level0_px.array_len); 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci if (!is_dest && 147bf215546Sopenharmony_ci (info->surf.dim == ISL_SURF_DIM_3D || 148bf215546Sopenharmony_ci info->surf.msaa_layout == ISL_MSAA_LAYOUT_ARRAY)) { 149bf215546Sopenharmony_ci /* 3-D textures don't support base_array layer and neither do 2-D 150bf215546Sopenharmony_ci * multisampled textures on IVB so we need to pass it through the 151bf215546Sopenharmony_ci * sampler in those cases. These are also two cases where we are 152bf215546Sopenharmony_ci * guaranteed that we won't be doing any funny surface hacks. 153bf215546Sopenharmony_ci */ 154bf215546Sopenharmony_ci info->view.base_array_layer = 0; 155bf215546Sopenharmony_ci info->z_offset = layer; 156bf215546Sopenharmony_ci } else { 157bf215546Sopenharmony_ci info->view.base_array_layer = layer; 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_ci assert(info->view.array_len >= info->view.base_array_layer); 160bf215546Sopenharmony_ci info->view.array_len -= info->view.base_array_layer; 161bf215546Sopenharmony_ci info->z_offset = 0; 162bf215546Sopenharmony_ci } 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci /* Sandy Bridge and earlier have a limit of a maximum of 512 layers for 165bf215546Sopenharmony_ci * layered rendering. 166bf215546Sopenharmony_ci */ 167bf215546Sopenharmony_ci if (is_dest && blorp->isl_dev->info->ver <= 6) 168bf215546Sopenharmony_ci info->view.array_len = MIN2(info->view.array_len, 512); 169bf215546Sopenharmony_ci 170bf215546Sopenharmony_ci if (surf->tile_x_sa || surf->tile_y_sa) { 171bf215546Sopenharmony_ci /* This is only allowed on simple 2D surfaces without MSAA */ 172bf215546Sopenharmony_ci assert(info->surf.dim == ISL_SURF_DIM_2D); 173bf215546Sopenharmony_ci assert(info->surf.samples == 1); 174bf215546Sopenharmony_ci assert(info->surf.levels == 1); 175bf215546Sopenharmony_ci assert(info->surf.logical_level0_px.array_len == 1); 176bf215546Sopenharmony_ci assert(info->aux_usage == ISL_AUX_USAGE_NONE); 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci info->tile_x_sa = surf->tile_x_sa; 179bf215546Sopenharmony_ci info->tile_y_sa = surf->tile_y_sa; 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_ci /* Instead of using the X/Y Offset fields in RENDER_SURFACE_STATE, we 182bf215546Sopenharmony_ci * place the image at the tile boundary and offset our sampling or 183bf215546Sopenharmony_ci * rendering. For this reason, we need to grow the image by the offset 184bf215546Sopenharmony_ci * to ensure that the hardware doesn't think we've gone past the edge. 185bf215546Sopenharmony_ci */ 186bf215546Sopenharmony_ci info->surf.logical_level0_px.w += surf->tile_x_sa; 187bf215546Sopenharmony_ci info->surf.logical_level0_px.h += surf->tile_y_sa; 188bf215546Sopenharmony_ci info->surf.phys_level0_sa.w += surf->tile_x_sa; 189bf215546Sopenharmony_ci info->surf.phys_level0_sa.h += surf->tile_y_sa; 190bf215546Sopenharmony_ci } 191bf215546Sopenharmony_ci} 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_civoid 195bf215546Sopenharmony_ciblorp_params_init(struct blorp_params *params) 196bf215546Sopenharmony_ci{ 197bf215546Sopenharmony_ci memset(params, 0, sizeof(*params)); 198bf215546Sopenharmony_ci params->num_samples = 1; 199bf215546Sopenharmony_ci params->num_draw_buffers = 1; 200bf215546Sopenharmony_ci params->num_layers = 1; 201bf215546Sopenharmony_ci} 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_cistatic void 204bf215546Sopenharmony_ciblorp_init_base_prog_key(struct brw_base_prog_key *key) 205bf215546Sopenharmony_ci{ 206bf215546Sopenharmony_ci for (int i = 0; i < BRW_MAX_SAMPLERS; i++) 207bf215546Sopenharmony_ci key->tex.swizzles[i] = SWIZZLE_XYZW; 208bf215546Sopenharmony_ci} 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_civoid 211bf215546Sopenharmony_cibrw_blorp_init_wm_prog_key(struct brw_wm_prog_key *wm_key) 212bf215546Sopenharmony_ci{ 213bf215546Sopenharmony_ci memset(wm_key, 0, sizeof(*wm_key)); 214bf215546Sopenharmony_ci wm_key->nr_color_regions = 1; 215bf215546Sopenharmony_ci blorp_init_base_prog_key(&wm_key->base); 216bf215546Sopenharmony_ci} 217bf215546Sopenharmony_ci 218bf215546Sopenharmony_civoid 219bf215546Sopenharmony_cibrw_blorp_init_cs_prog_key(struct brw_cs_prog_key *cs_key) 220bf215546Sopenharmony_ci{ 221bf215546Sopenharmony_ci memset(cs_key, 0, sizeof(*cs_key)); 222bf215546Sopenharmony_ci blorp_init_base_prog_key(&cs_key->base); 223bf215546Sopenharmony_ci} 224bf215546Sopenharmony_ci 225bf215546Sopenharmony_ciconst unsigned * 226bf215546Sopenharmony_ciblorp_compile_fs(struct blorp_context *blorp, void *mem_ctx, 227bf215546Sopenharmony_ci struct nir_shader *nir, 228bf215546Sopenharmony_ci struct brw_wm_prog_key *wm_key, 229bf215546Sopenharmony_ci bool use_repclear, 230bf215546Sopenharmony_ci struct brw_wm_prog_data *wm_prog_data) 231bf215546Sopenharmony_ci{ 232bf215546Sopenharmony_ci const struct brw_compiler *compiler = blorp->compiler; 233bf215546Sopenharmony_ci 234bf215546Sopenharmony_ci nir->options = compiler->nir_options[MESA_SHADER_FRAGMENT]; 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_ci memset(wm_prog_data, 0, sizeof(*wm_prog_data)); 237bf215546Sopenharmony_ci 238bf215546Sopenharmony_ci wm_prog_data->base.nr_params = 0; 239bf215546Sopenharmony_ci wm_prog_data->base.param = NULL; 240bf215546Sopenharmony_ci 241bf215546Sopenharmony_ci brw_preprocess_nir(compiler, nir, NULL); 242bf215546Sopenharmony_ci nir_remove_dead_variables(nir, nir_var_shader_in, NULL); 243bf215546Sopenharmony_ci nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir)); 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_ci if (blorp->compiler->devinfo->ver < 6) { 246bf215546Sopenharmony_ci if (nir->info.fs.uses_discard) 247bf215546Sopenharmony_ci wm_key->iz_lookup |= BRW_WM_IZ_PS_KILL_ALPHATEST_BIT; 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_ci wm_key->input_slots_valid = nir->info.inputs_read | VARYING_BIT_POS; 250bf215546Sopenharmony_ci } 251bf215546Sopenharmony_ci 252bf215546Sopenharmony_ci struct brw_compile_fs_params params = { 253bf215546Sopenharmony_ci .nir = nir, 254bf215546Sopenharmony_ci .key = wm_key, 255bf215546Sopenharmony_ci .prog_data = wm_prog_data, 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci .use_rep_send = use_repclear, 258bf215546Sopenharmony_ci .log_data = blorp->driver_ctx, 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_ci .debug_flag = DEBUG_BLORP, 261bf215546Sopenharmony_ci }; 262bf215546Sopenharmony_ci 263bf215546Sopenharmony_ci return brw_compile_fs(compiler, mem_ctx, ¶ms); 264bf215546Sopenharmony_ci} 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ciconst unsigned * 267bf215546Sopenharmony_ciblorp_compile_vs(struct blorp_context *blorp, void *mem_ctx, 268bf215546Sopenharmony_ci struct nir_shader *nir, 269bf215546Sopenharmony_ci struct brw_vs_prog_data *vs_prog_data) 270bf215546Sopenharmony_ci{ 271bf215546Sopenharmony_ci const struct brw_compiler *compiler = blorp->compiler; 272bf215546Sopenharmony_ci 273bf215546Sopenharmony_ci nir->options = compiler->nir_options[MESA_SHADER_VERTEX]; 274bf215546Sopenharmony_ci 275bf215546Sopenharmony_ci brw_preprocess_nir(compiler, nir, NULL); 276bf215546Sopenharmony_ci nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir)); 277bf215546Sopenharmony_ci 278bf215546Sopenharmony_ci vs_prog_data->inputs_read = nir->info.inputs_read; 279bf215546Sopenharmony_ci 280bf215546Sopenharmony_ci brw_compute_vue_map(compiler->devinfo, 281bf215546Sopenharmony_ci &vs_prog_data->base.vue_map, 282bf215546Sopenharmony_ci nir->info.outputs_written, 283bf215546Sopenharmony_ci nir->info.separate_shader, 284bf215546Sopenharmony_ci 1); 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ci struct brw_vs_prog_key vs_key = { 0, }; 287bf215546Sopenharmony_ci 288bf215546Sopenharmony_ci struct brw_compile_vs_params params = { 289bf215546Sopenharmony_ci .nir = nir, 290bf215546Sopenharmony_ci .key = &vs_key, 291bf215546Sopenharmony_ci .prog_data = vs_prog_data, 292bf215546Sopenharmony_ci .log_data = blorp->driver_ctx, 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci .debug_flag = DEBUG_BLORP, 295bf215546Sopenharmony_ci }; 296bf215546Sopenharmony_ci 297bf215546Sopenharmony_ci return brw_compile_vs(compiler, mem_ctx, ¶ms); 298bf215546Sopenharmony_ci} 299bf215546Sopenharmony_ci 300bf215546Sopenharmony_ciconst unsigned * 301bf215546Sopenharmony_ciblorp_compile_cs(struct blorp_context *blorp, void *mem_ctx, 302bf215546Sopenharmony_ci struct nir_shader *nir, 303bf215546Sopenharmony_ci struct brw_cs_prog_key *cs_key, 304bf215546Sopenharmony_ci struct brw_cs_prog_data *cs_prog_data) 305bf215546Sopenharmony_ci{ 306bf215546Sopenharmony_ci const struct brw_compiler *compiler = blorp->compiler; 307bf215546Sopenharmony_ci 308bf215546Sopenharmony_ci nir->options = compiler->nir_options[MESA_SHADER_COMPUTE]; 309bf215546Sopenharmony_ci 310bf215546Sopenharmony_ci memset(cs_prog_data, 0, sizeof(*cs_prog_data)); 311bf215546Sopenharmony_ci 312bf215546Sopenharmony_ci brw_preprocess_nir(compiler, nir, NULL); 313bf215546Sopenharmony_ci nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir)); 314bf215546Sopenharmony_ci 315bf215546Sopenharmony_ci NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, type_size_scalar_bytes, 316bf215546Sopenharmony_ci (nir_lower_io_options)0); 317bf215546Sopenharmony_ci 318bf215546Sopenharmony_ci STATIC_ASSERT(offsetof(struct brw_blorp_wm_inputs, subgroup_id) + 4 == 319bf215546Sopenharmony_ci sizeof(struct brw_blorp_wm_inputs)); 320bf215546Sopenharmony_ci nir->num_uniforms = offsetof(struct brw_blorp_wm_inputs, subgroup_id); 321bf215546Sopenharmony_ci unsigned nr_params = nir->num_uniforms / 4; 322bf215546Sopenharmony_ci cs_prog_data->base.nr_params = nr_params; 323bf215546Sopenharmony_ci cs_prog_data->base.param = rzalloc_array(NULL, uint32_t, nr_params); 324bf215546Sopenharmony_ci 325bf215546Sopenharmony_ci NIR_PASS_V(nir, brw_nir_lower_cs_intrinsics); 326bf215546Sopenharmony_ci 327bf215546Sopenharmony_ci struct brw_compile_cs_params params = { 328bf215546Sopenharmony_ci .nir = nir, 329bf215546Sopenharmony_ci .key = cs_key, 330bf215546Sopenharmony_ci .prog_data = cs_prog_data, 331bf215546Sopenharmony_ci .log_data = blorp->driver_ctx, 332bf215546Sopenharmony_ci .debug_flag = DEBUG_BLORP, 333bf215546Sopenharmony_ci }; 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ci const unsigned *program = brw_compile_cs(compiler, mem_ctx, ¶ms); 336bf215546Sopenharmony_ci 337bf215546Sopenharmony_ci ralloc_free(cs_prog_data->base.param); 338bf215546Sopenharmony_ci cs_prog_data->base.param = NULL; 339bf215546Sopenharmony_ci 340bf215546Sopenharmony_ci return program; 341bf215546Sopenharmony_ci} 342bf215546Sopenharmony_ci 343bf215546Sopenharmony_cistruct blorp_sf_key { 344bf215546Sopenharmony_ci struct brw_blorp_base_key base; 345bf215546Sopenharmony_ci struct brw_sf_prog_key key; 346bf215546Sopenharmony_ci}; 347bf215546Sopenharmony_ci 348bf215546Sopenharmony_cibool 349bf215546Sopenharmony_ciblorp_ensure_sf_program(struct blorp_batch *batch, 350bf215546Sopenharmony_ci struct blorp_params *params) 351bf215546Sopenharmony_ci{ 352bf215546Sopenharmony_ci struct blorp_context *blorp = batch->blorp; 353bf215546Sopenharmony_ci const struct brw_wm_prog_data *wm_prog_data = params->wm_prog_data; 354bf215546Sopenharmony_ci assert(params->wm_prog_data); 355bf215546Sopenharmony_ci 356bf215546Sopenharmony_ci /* Gfx6+ doesn't need a strips and fans program */ 357bf215546Sopenharmony_ci if (blorp->compiler->devinfo->ver >= 6) 358bf215546Sopenharmony_ci return true; 359bf215546Sopenharmony_ci 360bf215546Sopenharmony_ci struct blorp_sf_key key = { 361bf215546Sopenharmony_ci .base = BRW_BLORP_BASE_KEY_INIT(BLORP_SHADER_TYPE_GFX4_SF), 362bf215546Sopenharmony_ci }; 363bf215546Sopenharmony_ci 364bf215546Sopenharmony_ci /* Everything gets compacted in vertex setup, so we just need a 365bf215546Sopenharmony_ci * pass-through for the correct number of input varyings. 366bf215546Sopenharmony_ci */ 367bf215546Sopenharmony_ci const uint64_t slots_valid = VARYING_BIT_POS | 368bf215546Sopenharmony_ci ((1ull << wm_prog_data->num_varying_inputs) - 1) << VARYING_SLOT_VAR0; 369bf215546Sopenharmony_ci 370bf215546Sopenharmony_ci key.key.attrs = slots_valid; 371bf215546Sopenharmony_ci key.key.primitive = BRW_SF_PRIM_TRIANGLES; 372bf215546Sopenharmony_ci key.key.contains_flat_varying = wm_prog_data->contains_flat_varying; 373bf215546Sopenharmony_ci 374bf215546Sopenharmony_ci STATIC_ASSERT(sizeof(key.key.interp_mode) == 375bf215546Sopenharmony_ci sizeof(wm_prog_data->interp_mode)); 376bf215546Sopenharmony_ci memcpy(key.key.interp_mode, wm_prog_data->interp_mode, 377bf215546Sopenharmony_ci sizeof(key.key.interp_mode)); 378bf215546Sopenharmony_ci 379bf215546Sopenharmony_ci if (blorp->lookup_shader(batch, &key, sizeof(key), 380bf215546Sopenharmony_ci ¶ms->sf_prog_kernel, ¶ms->sf_prog_data)) 381bf215546Sopenharmony_ci return true; 382bf215546Sopenharmony_ci 383bf215546Sopenharmony_ci void *mem_ctx = ralloc_context(NULL); 384bf215546Sopenharmony_ci 385bf215546Sopenharmony_ci const unsigned *program; 386bf215546Sopenharmony_ci unsigned program_size; 387bf215546Sopenharmony_ci 388bf215546Sopenharmony_ci struct brw_vue_map vue_map; 389bf215546Sopenharmony_ci brw_compute_vue_map(blorp->compiler->devinfo, &vue_map, slots_valid, false, 1); 390bf215546Sopenharmony_ci 391bf215546Sopenharmony_ci struct brw_sf_prog_data prog_data_tmp; 392bf215546Sopenharmony_ci program = brw_compile_sf(blorp->compiler, mem_ctx, &key.key, 393bf215546Sopenharmony_ci &prog_data_tmp, &vue_map, &program_size); 394bf215546Sopenharmony_ci 395bf215546Sopenharmony_ci bool result = 396bf215546Sopenharmony_ci blorp->upload_shader(batch, MESA_SHADER_NONE, 397bf215546Sopenharmony_ci &key, sizeof(key), program, program_size, 398bf215546Sopenharmony_ci (void *)&prog_data_tmp, sizeof(prog_data_tmp), 399bf215546Sopenharmony_ci ¶ms->sf_prog_kernel, ¶ms->sf_prog_data); 400bf215546Sopenharmony_ci 401bf215546Sopenharmony_ci ralloc_free(mem_ctx); 402bf215546Sopenharmony_ci 403bf215546Sopenharmony_ci return result; 404bf215546Sopenharmony_ci} 405bf215546Sopenharmony_ci 406bf215546Sopenharmony_civoid 407bf215546Sopenharmony_ciblorp_hiz_op(struct blorp_batch *batch, struct blorp_surf *surf, 408bf215546Sopenharmony_ci uint32_t level, uint32_t start_layer, uint32_t num_layers, 409bf215546Sopenharmony_ci enum isl_aux_op op) 410bf215546Sopenharmony_ci{ 411bf215546Sopenharmony_ci const struct intel_device_info *devinfo = batch->blorp->isl_dev->info; 412bf215546Sopenharmony_ci 413bf215546Sopenharmony_ci struct blorp_params params; 414bf215546Sopenharmony_ci blorp_params_init(¶ms); 415bf215546Sopenharmony_ci 416bf215546Sopenharmony_ci params.hiz_op = op; 417bf215546Sopenharmony_ci params.full_surface_hiz_op = true; 418bf215546Sopenharmony_ci switch (op) { 419bf215546Sopenharmony_ci case ISL_AUX_OP_FULL_RESOLVE: 420bf215546Sopenharmony_ci params.snapshot_type = INTEL_SNAPSHOT_HIZ_RESOLVE; 421bf215546Sopenharmony_ci break; 422bf215546Sopenharmony_ci case ISL_AUX_OP_AMBIGUATE: 423bf215546Sopenharmony_ci params.snapshot_type = INTEL_SNAPSHOT_HIZ_AMBIGUATE; 424bf215546Sopenharmony_ci break; 425bf215546Sopenharmony_ci case ISL_AUX_OP_FAST_CLEAR: 426bf215546Sopenharmony_ci params.snapshot_type = INTEL_SNAPSHOT_HIZ_CLEAR; 427bf215546Sopenharmony_ci break; 428bf215546Sopenharmony_ci case ISL_AUX_OP_PARTIAL_RESOLVE: 429bf215546Sopenharmony_ci case ISL_AUX_OP_NONE: 430bf215546Sopenharmony_ci unreachable("Invalid HiZ op"); 431bf215546Sopenharmony_ci } 432bf215546Sopenharmony_ci 433bf215546Sopenharmony_ci for (uint32_t a = 0; a < num_layers; a++) { 434bf215546Sopenharmony_ci const uint32_t layer = start_layer + a; 435bf215546Sopenharmony_ci 436bf215546Sopenharmony_ci brw_blorp_surface_info_init(batch, ¶ms.depth, surf, level, 437bf215546Sopenharmony_ci layer, surf->surf->format, true); 438bf215546Sopenharmony_ci 439bf215546Sopenharmony_ci /* Align the rectangle primitive to 8x4 pixels. 440bf215546Sopenharmony_ci * 441bf215546Sopenharmony_ci * During fast depth clears, the emitted rectangle primitive must be 442bf215546Sopenharmony_ci * aligned to 8x4 pixels. From the Ivybridge PRM, Vol 2 Part 1 Section 443bf215546Sopenharmony_ci * 11.5.3.1 Depth Buffer Clear (and the matching section in the 444bf215546Sopenharmony_ci * Sandybridge PRM): 445bf215546Sopenharmony_ci * 446bf215546Sopenharmony_ci * If Number of Multisamples is NUMSAMPLES_1, the rectangle must be 447bf215546Sopenharmony_ci * aligned to an 8x4 pixel block relative to the upper left corner 448bf215546Sopenharmony_ci * of the depth buffer [...] 449bf215546Sopenharmony_ci * 450bf215546Sopenharmony_ci * For hiz resolves, the rectangle must also be 8x4 aligned. Item 451bf215546Sopenharmony_ci * WaHizAmbiguate8x4Aligned from the Haswell workarounds page and the 452bf215546Sopenharmony_ci * Ivybridge simulator require the alignment. 453bf215546Sopenharmony_ci * 454bf215546Sopenharmony_ci * To be safe, let's just align the rect for all hiz operations and all 455bf215546Sopenharmony_ci * hardware generations. 456bf215546Sopenharmony_ci * 457bf215546Sopenharmony_ci * However, for some miptree slices of a Z24 texture, emitting an 8x4 458bf215546Sopenharmony_ci * aligned rectangle that covers the slice may clobber adjacent slices 459bf215546Sopenharmony_ci * if we strictly adhered to the texture alignments specified in the 460bf215546Sopenharmony_ci * PRM. The Ivybridge PRM, Section "Alignment Unit Size", states that 461bf215546Sopenharmony_ci * SURFACE_STATE.Surface_Horizontal_Alignment should be 4 for Z24 462bf215546Sopenharmony_ci * surfaces, not 8. But commit 1f112cc increased the alignment from 4 to 463bf215546Sopenharmony_ci * 8, which prevents the clobbering. 464bf215546Sopenharmony_ci */ 465bf215546Sopenharmony_ci params.x1 = u_minify(params.depth.surf.logical_level0_px.width, 466bf215546Sopenharmony_ci params.depth.view.base_level); 467bf215546Sopenharmony_ci params.y1 = u_minify(params.depth.surf.logical_level0_px.height, 468bf215546Sopenharmony_ci params.depth.view.base_level); 469bf215546Sopenharmony_ci params.x1 = ALIGN(params.x1, 8); 470bf215546Sopenharmony_ci params.y1 = ALIGN(params.y1, 4); 471bf215546Sopenharmony_ci 472bf215546Sopenharmony_ci if (params.depth.view.base_level == 0) { 473bf215546Sopenharmony_ci /* TODO: What about MSAA? */ 474bf215546Sopenharmony_ci params.depth.surf.logical_level0_px.width = params.x1; 475bf215546Sopenharmony_ci params.depth.surf.logical_level0_px.height = params.y1; 476bf215546Sopenharmony_ci } else if (devinfo->ver >= 8 && devinfo->ver <= 9 && 477bf215546Sopenharmony_ci op == ISL_AUX_OP_AMBIGUATE) { 478bf215546Sopenharmony_ci /* On some platforms, it's not enough to just adjust the clear 479bf215546Sopenharmony_ci * rectangle when the LOD is greater than 0. 480bf215546Sopenharmony_ci * 481bf215546Sopenharmony_ci * From the BDW and SKL PRMs, Vol 7, "Optimized Hierarchical Depth 482bf215546Sopenharmony_ci * Buffer Resolve": 483bf215546Sopenharmony_ci * 484bf215546Sopenharmony_ci * The following is required when performing a hierarchical depth 485bf215546Sopenharmony_ci * buffer resolve: 486bf215546Sopenharmony_ci * 487bf215546Sopenharmony_ci * - A rectangle primitive covering the full render target must be 488bf215546Sopenharmony_ci * programmed on Xmin, Ymin, Xmax, and Ymax in the 489bf215546Sopenharmony_ci * 3DSTATE_WM_HZ_OP command. 490bf215546Sopenharmony_ci * 491bf215546Sopenharmony_ci * - The rectangle primitive size must be aligned to 8x4 pixels. 492bf215546Sopenharmony_ci * 493bf215546Sopenharmony_ci * And from the Clear Rectangle programming note in 3DSTATE_WM_HZ_OP 494bf215546Sopenharmony_ci * (Vol 2a): 495bf215546Sopenharmony_ci * 496bf215546Sopenharmony_ci * Hence the max values must be less than or equal to: ( Surface 497bf215546Sopenharmony_ci * Width » LOD ) and ( Surface Height » LOD ) for X Max and Y Max 498bf215546Sopenharmony_ci * respectively. 499bf215546Sopenharmony_ci * 500bf215546Sopenharmony_ci * This means that the extent of the LOD must be naturally 501bf215546Sopenharmony_ci * 8x4-aligned after minification of the base LOD. Since the base LOD 502bf215546Sopenharmony_ci * dimensions affect the placement of smaller LODs, it's not trivial 503bf215546Sopenharmony_ci * (nor possible, at times) to satisfy the requirement by adjusting 504bf215546Sopenharmony_ci * the base LOD extent. Just assert that the caller is accessing an 505bf215546Sopenharmony_ci * LOD that satisfies this requirement. 506bf215546Sopenharmony_ci */ 507bf215546Sopenharmony_ci assert(u_minify(params.depth.surf.logical_level0_px.width, 508bf215546Sopenharmony_ci params.depth.view.base_level) == params.x1); 509bf215546Sopenharmony_ci assert(u_minify(params.depth.surf.logical_level0_px.height, 510bf215546Sopenharmony_ci params.depth.view.base_level) == params.y1); 511bf215546Sopenharmony_ci } 512bf215546Sopenharmony_ci 513bf215546Sopenharmony_ci params.dst.surf.samples = params.depth.surf.samples; 514bf215546Sopenharmony_ci params.dst.surf.logical_level0_px = params.depth.surf.logical_level0_px; 515bf215546Sopenharmony_ci params.depth_format = 516bf215546Sopenharmony_ci isl_format_get_depth_format(surf->surf->format, false); 517bf215546Sopenharmony_ci params.num_samples = params.depth.surf.samples; 518bf215546Sopenharmony_ci 519bf215546Sopenharmony_ci batch->blorp->exec(batch, ¶ms); 520bf215546Sopenharmony_ci } 521bf215546Sopenharmony_ci} 522