2015-05-08 22:32:37 -07:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright © 2015 Intel Corporation
|
|
|
|
|
|
*
|
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
*
|
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
|
* Software.
|
|
|
|
|
|
*
|
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
2016-02-10 09:43:03 -08:00
|
|
|
|
#include "util/mesa-sha1.h"
|
2019-03-19 15:23:37 +00:00
|
|
|
|
#include "util/os_time.h"
|
2021-03-03 13:20:06 -08:00
|
|
|
|
#include "common/intel_l3_config.h"
|
|
|
|
|
|
#include "common/intel_disasm.h"
|
|
|
|
|
|
#include "common/intel_sample_positions.h"
|
2015-07-17 15:04:27 -07:00
|
|
|
|
#include "anv_private.h"
|
2017-02-28 09:10:43 -08:00
|
|
|
|
#include "compiler/brw_nir.h"
|
2021-01-21 15:28:28 -06:00
|
|
|
|
#include "compiler/brw_nir_rt.h"
|
2015-10-19 22:06:59 -07:00
|
|
|
|
#include "anv_nir.h"
|
2018-09-10 16:17:37 -05:00
|
|
|
|
#include "nir/nir_xfb_info.h"
|
2016-04-14 10:28:45 -07:00
|
|
|
|
#include "spirv/nir_spirv.h"
|
2018-07-02 12:57:44 -07:00
|
|
|
|
#include "vk_util.h"
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
|
|
/* Needed for SWIZZLE macros */
|
|
|
|
|
|
#include "program/prog_instruction.h"
|
2015-05-08 22:32:37 -07:00
|
|
|
|
|
|
|
|
|
|
// Shader functions
|
2015-10-19 22:06:59 -07:00
|
|
|
|
#define SPIR_V_MAGIC_NUMBER 0x07230203
|
|
|
|
|
|
|
2019-05-02 17:43:03 +01:00
|
|
|
|
struct anv_spirv_debug_data {
|
|
|
|
|
|
struct anv_device *device;
|
2021-03-10 17:50:15 -05:00
|
|
|
|
const struct vk_shader_module *module;
|
2019-05-02 17:43:03 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void anv_spirv_nir_debug(void *private_data,
|
|
|
|
|
|
enum nir_spirv_debug_level level,
|
|
|
|
|
|
size_t spirv_offset,
|
|
|
|
|
|
const char *message)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct anv_spirv_debug_data *debug_data = private_data;
|
2020-01-17 23:05:13 -06:00
|
|
|
|
|
2021-05-13 21:39:09 +03:00
|
|
|
|
switch (level) {
|
|
|
|
|
|
case NIR_SPIRV_DEBUG_LEVEL_INFO:
|
|
|
|
|
|
vk_logi(VK_LOG_OBJS(&debug_data->module->base),
|
|
|
|
|
|
"SPIR-V offset %lu: %s",
|
|
|
|
|
|
(unsigned long) spirv_offset, message);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case NIR_SPIRV_DEBUG_LEVEL_WARNING:
|
|
|
|
|
|
vk_logw(VK_LOG_OBJS(&debug_data->module->base),
|
|
|
|
|
|
"SPIR-V offset %lu: %s",
|
|
|
|
|
|
(unsigned long) spirv_offset, message);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case NIR_SPIRV_DEBUG_LEVEL_ERROR:
|
|
|
|
|
|
vk_loge(VK_LOG_OBJS(&debug_data->module->base),
|
|
|
|
|
|
"SPIR-V offset %lu: %s",
|
|
|
|
|
|
(unsigned long) spirv_offset, message);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-05-02 17:43:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
/* Eventually, this will become part of anv_CreateShader. Unfortunately,
|
|
|
|
|
|
* we can't do that yet because we don't have the ability to copy nir.
|
|
|
|
|
|
*/
|
|
|
|
|
|
static nir_shader *
|
2018-08-29 16:40:05 -05:00
|
|
|
|
anv_shader_compile_to_nir(struct anv_device *device,
|
2017-09-28 21:51:48 -07:00
|
|
|
|
void *mem_ctx,
|
2021-03-10 17:50:15 -05:00
|
|
|
|
const struct vk_shader_module *module,
|
2015-12-02 16:08:13 -08:00
|
|
|
|
const char *entrypoint_name,
|
2016-01-12 16:30:43 -08:00
|
|
|
|
gl_shader_stage stage,
|
|
|
|
|
|
const VkSpecializationInfo *spec_info)
|
2015-10-19 22:06:59 -07:00
|
|
|
|
{
|
2020-01-17 22:23:30 -06:00
|
|
|
|
const struct anv_physical_device *pdevice = device->physical;
|
2019-01-19 17:50:23 -06:00
|
|
|
|
const struct brw_compiler *compiler = pdevice->compiler;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
const nir_shader_compiler_options *nir_options =
|
|
|
|
|
|
compiler->glsl_compiler_options[stage].NirOptions;
|
|
|
|
|
|
|
2016-10-07 21:50:31 -07:00
|
|
|
|
uint32_t *spirv = (uint32_t *) module->data;
|
|
|
|
|
|
assert(spirv[0] == SPIR_V_MAGIC_NUMBER);
|
|
|
|
|
|
assert(module->size % 4 == 0);
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t num_spec_entries = 0;
|
2021-07-21 10:36:38 +02:00
|
|
|
|
struct nir_spirv_specialization *spec_entries =
|
|
|
|
|
|
vk_spec_info_to_nir_spirv(spec_info, &num_spec_entries);
|
2016-01-12 16:30:43 -08:00
|
|
|
|
|
2019-05-02 17:43:03 +01:00
|
|
|
|
struct anv_spirv_debug_data spirv_debug_data = {
|
|
|
|
|
|
.device = device,
|
|
|
|
|
|
.module = module,
|
|
|
|
|
|
};
|
2017-10-18 17:28:19 -07:00
|
|
|
|
struct spirv_to_nir_options spirv_options = {
|
2019-07-18 09:59:44 -05:00
|
|
|
|
.frag_coord_is_sysval = true,
|
2017-10-18 17:28:19 -07:00
|
|
|
|
.caps = {
|
2019-06-07 17:37:38 -07:00
|
|
|
|
.demote_to_helper_invocation = true,
|
2019-03-28 10:36:43 -07:00
|
|
|
|
.derivative_group = true,
|
2019-02-27 16:08:20 -06:00
|
|
|
|
.descriptor_array_dynamic_indexing = true,
|
2019-04-29 17:10:24 +02:00
|
|
|
|
.descriptor_array_non_uniform_indexing = true,
|
|
|
|
|
|
.descriptor_indexing = true,
|
2017-09-21 13:54:55 -07:00
|
|
|
|
.device_group = true,
|
2017-10-18 17:28:19 -07:00
|
|
|
|
.draw_parameters = true,
|
2021-03-29 14:41:58 -07:00
|
|
|
|
.float16 = pdevice->info.ver >= 8,
|
2021-08-25 13:00:51 -07:00
|
|
|
|
.float32_atomic_add = pdevice->info.has_lsc,
|
2021-05-07 11:41:13 -07:00
|
|
|
|
.float32_atomic_min_max = pdevice->info.ver >= 9,
|
2021-03-29 14:41:58 -07:00
|
|
|
|
.float64 = pdevice->info.ver >= 8,
|
2021-08-26 10:19:59 -07:00
|
|
|
|
.float64_atomic_min_max = pdevice->info.has_lsc,
|
2021-03-29 14:41:58 -07:00
|
|
|
|
.fragment_shader_sample_interlock = pdevice->info.ver >= 9,
|
|
|
|
|
|
.fragment_shader_pixel_interlock = pdevice->info.ver >= 9,
|
2018-09-10 16:17:37 -05:00
|
|
|
|
.geometry_streams = true,
|
2017-10-18 17:28:19 -07:00
|
|
|
|
.image_write_without_format = true,
|
2021-03-29 14:41:58 -07:00
|
|
|
|
.int8 = pdevice->info.ver >= 8,
|
|
|
|
|
|
.int16 = pdevice->info.ver >= 8,
|
|
|
|
|
|
.int64 = pdevice->info.ver >= 8,
|
|
|
|
|
|
.int64_atomics = pdevice->info.ver >= 9 && pdevice->use_softpin,
|
|
|
|
|
|
.integer_functions2 = pdevice->info.ver >= 8,
|
2018-10-02 22:04:09 -05:00
|
|
|
|
.min_lod = true,
|
2017-10-18 17:28:19 -07:00
|
|
|
|
.multiview = true,
|
2019-02-07 12:01:18 -06:00
|
|
|
|
.physical_storage_buffer_address = pdevice->has_a64_buffer_access,
|
2021-03-29 14:41:58 -07:00
|
|
|
|
.post_depth_coverage = pdevice->info.ver >= 9,
|
2019-02-27 16:08:20 -06:00
|
|
|
|
.runtime_descriptor_array = true,
|
2021-03-29 14:41:58 -07:00
|
|
|
|
.float_controls = pdevice->info.ver >= 8,
|
2021-01-21 15:28:28 -06:00
|
|
|
|
.ray_tracing = pdevice->info.has_ray_tracing,
|
2019-04-19 12:18:02 -07:00
|
|
|
|
.shader_clock = true,
|
2018-04-26 12:11:20 -07:00
|
|
|
|
.shader_viewport_index_layer = true,
|
2021-03-29 14:41:58 -07:00
|
|
|
|
.stencil_export = pdevice->info.ver >= 9,
|
|
|
|
|
|
.storage_8bit = pdevice->info.ver >= 8,
|
|
|
|
|
|
.storage_16bit = pdevice->info.ver >= 8,
|
2017-04-28 01:22:39 -07:00
|
|
|
|
.subgroup_arithmetic = true,
|
|
|
|
|
|
.subgroup_basic = true,
|
|
|
|
|
|
.subgroup_ballot = true,
|
2021-09-24 17:26:23 +03:00
|
|
|
|
.subgroup_dispatch = true,
|
2017-04-28 01:22:39 -07:00
|
|
|
|
.subgroup_quad = true,
|
2021-06-23 15:58:40 -07:00
|
|
|
|
.subgroup_uniform_control_flow = true,
|
2017-04-28 01:22:39 -07:00
|
|
|
|
.subgroup_shuffle = true,
|
|
|
|
|
|
.subgroup_vote = true,
|
2019-01-07 10:28:23 -06:00
|
|
|
|
.tessellation = true,
|
2021-03-29 14:41:58 -07:00
|
|
|
|
.transform_feedback = pdevice->info.ver >= 8,
|
2019-01-07 10:28:23 -06:00
|
|
|
|
.variable_pointers = true,
|
2019-09-05 11:10:02 -07:00
|
|
|
|
.vk_memory_model = true,
|
|
|
|
|
|
.vk_memory_model_device_scope = true,
|
2020-06-05 10:23:35 -07:00
|
|
|
|
.workgroup_memory_explicit_layout = true,
|
2020-10-19 10:12:43 +03:00
|
|
|
|
.fragment_shading_rate = pdevice->info.ver >= 11,
|
2017-10-18 17:28:19 -07:00
|
|
|
|
},
|
2021-01-15 16:44:44 -06:00
|
|
|
|
.ubo_addr_format =
|
|
|
|
|
|
anv_nir_ubo_addr_format(pdevice, device->robust_buffer_access),
|
2019-05-01 14:15:32 -07:00
|
|
|
|
.ssbo_addr_format =
|
|
|
|
|
|
anv_nir_ssbo_addr_format(pdevice, device->robust_buffer_access),
|
|
|
|
|
|
.phys_ssbo_addr_format = nir_address_format_64bit_global,
|
|
|
|
|
|
.push_const_addr_format = nir_address_format_logical,
|
|
|
|
|
|
|
|
|
|
|
|
/* TODO: Consider changing this to an address format that has the NULL
|
|
|
|
|
|
* pointer equals to 0. That might be a better format to play nice
|
|
|
|
|
|
* with certain code / code generators.
|
|
|
|
|
|
*/
|
|
|
|
|
|
.shared_addr_format = nir_address_format_32bit_offset,
|
2019-05-02 17:43:03 +01:00
|
|
|
|
.debug = {
|
|
|
|
|
|
.func = anv_spirv_nir_debug,
|
|
|
|
|
|
.private_data = &spirv_debug_data,
|
|
|
|
|
|
},
|
2017-01-04 13:11:35 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2019-01-09 16:04:22 -06:00
|
|
|
|
|
2019-05-19 00:22:17 -07:00
|
|
|
|
nir_shader *nir =
|
2016-10-07 21:50:31 -07:00
|
|
|
|
spirv_to_nir(spirv, module->size / 4,
|
|
|
|
|
|
spec_entries, num_spec_entries,
|
2017-10-18 17:28:19 -07:00
|
|
|
|
stage, entrypoint_name, &spirv_options, nir_options);
|
2021-05-13 22:48:15 +03:00
|
|
|
|
if (!nir) {
|
|
|
|
|
|
free(spec_entries);
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-14 19:52:38 -07:00
|
|
|
|
assert(nir->info.stage == stage);
|
2018-10-18 15:18:30 -05:00
|
|
|
|
nir_validate_shader(nir, "after spirv_to_nir");
|
2020-06-01 15:43:53 -05:00
|
|
|
|
nir_validate_ssa_dominance(nir, "after spirv_to_nir");
|
2017-09-28 21:51:48 -07:00
|
|
|
|
ralloc_steal(mem_ctx, nir);
|
2016-01-12 16:30:43 -08:00
|
|
|
|
|
2016-10-07 21:50:31 -07:00
|
|
|
|
free(spec_entries);
|
2016-05-17 01:52:16 -07:00
|
|
|
|
|
2020-09-14 18:53:13 +02:00
|
|
|
|
if (INTEL_DEBUG & intel_debug_flag_for_shader_stage(stage)) {
|
2017-07-12 12:34:00 -07:00
|
|
|
|
fprintf(stderr, "NIR (from SPIR-V) for %s shader:\n",
|
|
|
|
|
|
gl_shader_stage_name(stage));
|
|
|
|
|
|
nir_print_shader(nir, stderr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-15 16:55:14 -07:00
|
|
|
|
/* We have to lower away local constant initializers right before we
|
|
|
|
|
|
* inline functions. That way they get properly initialized at the top
|
|
|
|
|
|
* of the function and not at the top of its caller.
|
|
|
|
|
|
*/
|
2020-02-07 14:18:49 -06:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
|
2017-01-06 17:22:56 -08:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_returns);
|
|
|
|
|
|
NIR_PASS_V(nir, nir_inline_functions);
|
2020-06-11 13:29:02 -05:00
|
|
|
|
NIR_PASS_V(nir, nir_copy_prop);
|
2018-12-13 11:08:13 -06:00
|
|
|
|
NIR_PASS_V(nir, nir_opt_deref);
|
2016-01-11 10:54:26 -08:00
|
|
|
|
|
2016-10-07 21:50:31 -07:00
|
|
|
|
/* Pick off the single entrypoint that we want */
|
|
|
|
|
|
foreach_list_typed_safe(nir_function, func, node, &nir->functions) {
|
2019-05-18 00:29:21 -07:00
|
|
|
|
if (!func->is_entrypoint)
|
2016-10-07 21:50:31 -07:00
|
|
|
|
exec_node_remove(&func->node);
|
|
|
|
|
|
}
|
|
|
|
|
|
assert(exec_list_length(&nir->functions) == 1);
|
2016-01-11 10:55:57 -08:00
|
|
|
|
|
2018-03-22 18:37:42 -07:00
|
|
|
|
/* Now that we've deleted all but the main function, we can go ahead and
|
|
|
|
|
|
* lower the rest of the constant initializers. We do this here so that
|
|
|
|
|
|
* nir_remove_dead_variables and split_per_member_structs below see the
|
|
|
|
|
|
* corresponding stores.
|
2018-01-16 09:37:11 +01:00
|
|
|
|
*/
|
2020-02-07 14:18:49 -06:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_variable_initializers, ~0);
|
2018-01-16 09:37:11 +01:00
|
|
|
|
|
2018-03-21 17:30:22 -07:00
|
|
|
|
/* Split member structs. We do this before lower_io_to_temporaries so that
|
|
|
|
|
|
* it doesn't lower system values to temporaries by accident.
|
|
|
|
|
|
*/
|
|
|
|
|
|
NIR_PASS_V(nir, nir_split_var_copies);
|
|
|
|
|
|
NIR_PASS_V(nir, nir_split_per_member_structs);
|
|
|
|
|
|
|
2017-01-06 17:22:56 -08:00
|
|
|
|
NIR_PASS_V(nir, nir_remove_dead_variables,
|
2021-01-21 15:28:28 -06:00
|
|
|
|
nir_var_shader_in | nir_var_shader_out | nir_var_system_value |
|
|
|
|
|
|
nir_var_shader_call_data | nir_var_ray_hit_attrib,
|
2020-05-28 10:59:28 +10:00
|
|
|
|
NULL);
|
2016-06-16 10:57:39 -07:00
|
|
|
|
|
2021-01-13 15:50:52 +00:00
|
|
|
|
NIR_PASS_V(nir, nir_propagate_invariant, false);
|
2017-01-06 17:22:56 -08:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_io_to_temporaries,
|
2019-05-18 00:29:21 -07:00
|
|
|
|
nir_shader_get_entrypoint(nir), true, false);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2019-03-22 09:24:57 +01:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_frexp);
|
|
|
|
|
|
|
2015-10-23 10:53:00 -07:00
|
|
|
|
/* Vulkan uses the separate-shader linking model */
|
2017-05-08 09:20:21 -07:00
|
|
|
|
nir->info.separate_shader = true;
|
2015-10-23 10:53:00 -07:00
|
|
|
|
|
2019-06-04 18:19:06 -05:00
|
|
|
|
brw_preprocess_nir(compiler, nir, NULL);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
|
|
return nir;
|
|
|
|
|
|
}
|
2015-07-14 10:16:22 -07:00
|
|
|
|
|
2020-06-13 13:57:32 -05:00
|
|
|
|
VkResult
|
|
|
|
|
|
anv_pipeline_init(struct anv_pipeline *pipeline,
|
|
|
|
|
|
struct anv_device *device,
|
|
|
|
|
|
enum anv_pipeline_type type,
|
|
|
|
|
|
VkPipelineCreateFlags flags,
|
|
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
|
|
{
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
memset(pipeline, 0, sizeof(*pipeline));
|
|
|
|
|
|
|
|
|
|
|
|
vk_object_base_init(&device->vk, &pipeline->base,
|
|
|
|
|
|
VK_OBJECT_TYPE_PIPELINE);
|
|
|
|
|
|
pipeline->device = device;
|
|
|
|
|
|
|
|
|
|
|
|
/* It's the job of the child class to provide actual backing storage for
|
|
|
|
|
|
* the batch by setting batch.start, batch.next, and batch.end.
|
|
|
|
|
|
*/
|
|
|
|
|
|
pipeline->batch.alloc = pAllocator ? pAllocator : &device->vk.alloc;
|
|
|
|
|
|
pipeline->batch.relocs = &pipeline->batch_relocs;
|
|
|
|
|
|
pipeline->batch.status = VK_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
result = anv_reloc_list_init(&pipeline->batch_relocs,
|
|
|
|
|
|
pipeline->batch.alloc);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
|
|
pipeline->mem_ctx = ralloc_context(NULL);
|
|
|
|
|
|
|
|
|
|
|
|
pipeline->type = type;
|
|
|
|
|
|
pipeline->flags = flags;
|
|
|
|
|
|
|
|
|
|
|
|
util_dynarray_init(&pipeline->executables, pipeline->mem_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
anv_pipeline_finish(struct anv_pipeline *pipeline,
|
|
|
|
|
|
struct anv_device *device,
|
|
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
|
|
{
|
|
|
|
|
|
anv_reloc_list_finish(&pipeline->batch_relocs,
|
|
|
|
|
|
pAllocator ? pAllocator : &device->vk.alloc);
|
|
|
|
|
|
ralloc_free(pipeline->mem_ctx);
|
|
|
|
|
|
vk_object_base_finish(&pipeline->base);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-05 20:50:51 -07:00
|
|
|
|
void anv_DestroyPipeline(
|
2015-07-14 10:26:17 -07:00
|
|
|
|
VkDevice _device,
|
2015-12-02 03:28:27 -08:00
|
|
|
|
VkPipeline _pipeline,
|
|
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
2015-07-14 10:26:17 -07:00
|
|
|
|
{
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline, pipeline, _pipeline);
|
|
|
|
|
|
|
2016-11-10 21:32:32 -08:00
|
|
|
|
if (!pipeline)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-03-03 13:43:39 -08:00
|
|
|
|
switch (pipeline->type) {
|
2020-03-03 15:31:50 -08:00
|
|
|
|
case ANV_PIPELINE_GRAPHICS: {
|
|
|
|
|
|
struct anv_graphics_pipeline *gfx_pipeline =
|
|
|
|
|
|
anv_pipeline_to_graphics(pipeline);
|
|
|
|
|
|
|
|
|
|
|
|
if (gfx_pipeline->blend_state.map)
|
|
|
|
|
|
anv_state_pool_free(&device->dynamic_state_pool, gfx_pipeline->blend_state);
|
2020-10-19 10:12:43 +03:00
|
|
|
|
if (gfx_pipeline->cps_state.map)
|
|
|
|
|
|
anv_state_pool_free(&device->dynamic_state_pool, gfx_pipeline->cps_state);
|
2020-03-03 15:31:50 -08:00
|
|
|
|
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(gfx_pipeline->shaders); s++) {
|
2020-03-03 15:31:50 -08:00
|
|
|
|
if (gfx_pipeline->shaders[s])
|
|
|
|
|
|
anv_shader_bin_unref(device, gfx_pipeline->shaders[s]);
|
2020-03-03 13:43:39 -08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
2020-03-03 15:31:50 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case ANV_PIPELINE_COMPUTE: {
|
|
|
|
|
|
struct anv_compute_pipeline *compute_pipeline =
|
|
|
|
|
|
anv_pipeline_to_compute(pipeline);
|
|
|
|
|
|
|
|
|
|
|
|
if (compute_pipeline->cs)
|
|
|
|
|
|
anv_shader_bin_unref(device, compute_pipeline->cs);
|
2020-03-03 13:43:39 -08:00
|
|
|
|
|
|
|
|
|
|
break;
|
2020-03-03 15:31:50 -08:00
|
|
|
|
}
|
2020-03-03 13:43:39 -08:00
|
|
|
|
|
2020-08-06 18:56:54 -05:00
|
|
|
|
case ANV_PIPELINE_RAY_TRACING: {
|
|
|
|
|
|
struct anv_ray_tracing_pipeline *rt_pipeline =
|
|
|
|
|
|
anv_pipeline_to_ray_tracing(pipeline);
|
|
|
|
|
|
|
|
|
|
|
|
util_dynarray_foreach(&rt_pipeline->shaders,
|
|
|
|
|
|
struct anv_shader_bin *, shader) {
|
|
|
|
|
|
anv_shader_bin_unref(device, *shader);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 13:43:39 -08:00
|
|
|
|
default:
|
|
|
|
|
|
unreachable("invalid pipeline type");
|
2016-08-25 01:49:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-13 13:57:32 -05:00
|
|
|
|
anv_pipeline_finish(pipeline, device, pAllocator);
|
2020-04-21 12:42:59 -05:00
|
|
|
|
vk_free2(&device->vk.alloc, pAllocator, pipeline);
|
2015-07-14 10:26:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-19 15:50:14 -07:00
|
|
|
|
static const uint32_t vk_to_intel_primitive_type[] = {
|
2015-11-30 11:12:44 -08:00
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_POINT_LIST] = _3DPRIM_POINTLIST,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_LINE_LIST] = _3DPRIM_LINELIST,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_LINE_STRIP] = _3DPRIM_LINESTRIP,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST] = _3DPRIM_TRILIST,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP] = _3DPRIM_TRISTRIP,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN] = _3DPRIM_TRIFAN,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY] = _3DPRIM_LINELIST_ADJ,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY] = _3DPRIM_LINESTRIP_ADJ,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY] = _3DPRIM_TRILIST_ADJ,
|
|
|
|
|
|
[VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY] = _3DPRIM_TRISTRIP_ADJ,
|
2015-08-20 22:53:54 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
static void
|
2021-04-05 13:19:39 -07:00
|
|
|
|
populate_sampler_prog_key(const struct intel_device_info *devinfo,
|
2015-10-19 22:06:59 -07:00
|
|
|
|
struct brw_sampler_prog_key_data *key)
|
|
|
|
|
|
{
|
2017-02-17 14:14:48 -08:00
|
|
|
|
/* Almost all multisampled textures are compressed. The only time when we
|
|
|
|
|
|
* don't compress a multisampled texture is for 16x MSAA with a surface
|
|
|
|
|
|
* width greater than 8k which is a bit of an edge case. Since the sampler
|
|
|
|
|
|
* just ignores the MCS parameter to ld2ms when MCS is disabled, it's safe
|
|
|
|
|
|
* to tell the compiler to always assume compression.
|
|
|
|
|
|
*/
|
|
|
|
|
|
key->compressed_multisample_layout_mask = ~0;
|
|
|
|
|
|
|
|
|
|
|
|
/* SkyLake added support for 16x MSAA. With this came a new message for
|
|
|
|
|
|
* reading from a 16x MSAA surface with compression. The new message was
|
|
|
|
|
|
* needed because now the MCS data is 64 bits instead of 32 or lower as is
|
|
|
|
|
|
* the case for 8x, 4x, and 2x. The key->msaa_16 bit-field controls which
|
|
|
|
|
|
* message we use. Fortunately, the 16x message works for 8x, 4x, and 2x
|
|
|
|
|
|
* so we can just use it unconditionally. This may not be quite as
|
|
|
|
|
|
* efficient but it saves us from recompiling.
|
|
|
|
|
|
*/
|
2021-03-29 14:41:58 -07:00
|
|
|
|
if (devinfo->ver >= 9)
|
2017-02-17 14:14:48 -08:00
|
|
|
|
key->msaa_16 = ~0;
|
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
/* XXX: Handle texture swizzle on HSW- */
|
|
|
|
|
|
for (int i = 0; i < MAX_SAMPLERS; i++) {
|
|
|
|
|
|
/* Assume color sampler, no swizzling. (Works for BDW+) */
|
|
|
|
|
|
key->swizzles[i] = SWIZZLE_XYZW;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-21 17:20:39 -06:00
|
|
|
|
static void
|
2021-04-05 13:19:39 -07:00
|
|
|
|
populate_base_prog_key(const struct intel_device_info *devinfo,
|
2021-09-16 17:57:41 -07:00
|
|
|
|
enum brw_subgroup_size_type subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
bool robust_buffer_acccess,
|
2019-02-21 17:20:39 -06:00
|
|
|
|
struct brw_base_prog_key *key)
|
|
|
|
|
|
{
|
2021-09-16 17:57:41 -07:00
|
|
|
|
key->subgroup_size_type = subgroup_size_type;
|
2021-04-09 14:42:53 -07:00
|
|
|
|
key->robust_buffer_access = robust_buffer_acccess;
|
|
|
|
|
|
|
2019-02-21 17:20:39 -06:00
|
|
|
|
populate_sampler_prog_key(devinfo, &key->tex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
static void
|
2021-04-05 13:19:39 -07:00
|
|
|
|
populate_vs_prog_key(const struct intel_device_info *devinfo,
|
2021-09-16 17:57:41 -07:00
|
|
|
|
enum brw_subgroup_size_type subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
bool robust_buffer_acccess,
|
2015-10-19 22:06:59 -07:00
|
|
|
|
struct brw_vs_prog_key *key)
|
|
|
|
|
|
{
|
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_base_prog_key(devinfo, subgroup_size_type,
|
|
|
|
|
|
robust_buffer_acccess, &key->base);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
|
|
/* XXX: Handle vertex input work-arounds */
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX: Handle sampler_prog_key */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-26 18:11:25 -07:00
|
|
|
|
static void
|
2021-04-05 13:19:39 -07:00
|
|
|
|
populate_tcs_prog_key(const struct intel_device_info *devinfo,
|
2021-09-16 17:57:41 -07:00
|
|
|
|
enum brw_subgroup_size_type subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
bool robust_buffer_acccess,
|
2017-10-26 18:11:25 -07:00
|
|
|
|
unsigned input_vertices,
|
|
|
|
|
|
struct brw_tcs_prog_key *key)
|
|
|
|
|
|
{
|
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_base_prog_key(devinfo, subgroup_size_type,
|
|
|
|
|
|
robust_buffer_acccess, &key->base);
|
2017-10-26 18:11:25 -07:00
|
|
|
|
|
|
|
|
|
|
key->input_vertices = input_vertices;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-04-05 13:19:39 -07:00
|
|
|
|
populate_tes_prog_key(const struct intel_device_info *devinfo,
|
2021-09-16 17:57:41 -07:00
|
|
|
|
enum brw_subgroup_size_type subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
bool robust_buffer_acccess,
|
2017-10-26 18:11:25 -07:00
|
|
|
|
struct brw_tes_prog_key *key)
|
|
|
|
|
|
{
|
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_base_prog_key(devinfo, subgroup_size_type,
|
|
|
|
|
|
robust_buffer_acccess, &key->base);
|
2017-10-26 18:11:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-21 18:45:48 -07:00
|
|
|
|
static void
|
2021-04-05 13:19:39 -07:00
|
|
|
|
populate_gs_prog_key(const struct intel_device_info *devinfo,
|
2021-09-16 17:57:41 -07:00
|
|
|
|
enum brw_subgroup_size_type subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
bool robust_buffer_acccess,
|
2015-10-21 18:45:48 -07:00
|
|
|
|
struct brw_gs_prog_key *key)
|
|
|
|
|
|
{
|
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_base_prog_key(devinfo, subgroup_size_type,
|
|
|
|
|
|
robust_buffer_acccess, &key->base);
|
2015-10-21 18:45:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-19 10:12:43 +03:00
|
|
|
|
static bool
|
|
|
|
|
|
pipeline_has_coarse_pixel(const struct anv_graphics_pipeline *pipeline,
|
|
|
|
|
|
const VkPipelineFragmentShadingRateStateCreateInfoKHR *fsr_info)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pipeline->sample_shading_enable)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
/* Not dynamic & not specified for the pipeline. */
|
|
|
|
|
|
if ((pipeline->dynamic_states & ANV_CMD_DIRTY_DYNAMIC_SHADING_RATE) == 0 && !fsr_info)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
/* Not dynamic & pipeline has a 1x1 fragment shading rate with no
|
|
|
|
|
|
* possibility for element of the pipeline to change the value.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if ((pipeline->dynamic_states & ANV_CMD_DIRTY_DYNAMIC_SHADING_RATE) == 0 &&
|
|
|
|
|
|
fsr_info->fragmentSize.width <= 1 &&
|
|
|
|
|
|
fsr_info->fragmentSize.height <= 1 &&
|
|
|
|
|
|
fsr_info->combinerOps[0] == VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR &&
|
|
|
|
|
|
fsr_info->combinerOps[1] == VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
static void
|
2020-10-19 10:12:43 +03:00
|
|
|
|
populate_wm_prog_key(const struct anv_graphics_pipeline *pipeline,
|
2019-02-22 15:21:13 -06:00
|
|
|
|
VkPipelineShaderStageCreateFlags flags,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
bool robust_buffer_acccess,
|
2017-10-26 17:56:07 -07:00
|
|
|
|
const struct anv_subpass *subpass,
|
|
|
|
|
|
const VkPipelineMultisampleStateCreateInfo *ms_info,
|
2020-10-19 10:12:43 +03:00
|
|
|
|
const VkPipelineFragmentShadingRateStateCreateInfoKHR *fsr_info,
|
2015-10-19 22:06:59 -07:00
|
|
|
|
struct brw_wm_prog_key *key)
|
|
|
|
|
|
{
|
2020-10-19 10:12:43 +03:00
|
|
|
|
const struct anv_device *device = pipeline->base.device;
|
|
|
|
|
|
const struct intel_device_info *devinfo = &device->info;
|
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
2021-04-09 14:42:53 -07:00
|
|
|
|
populate_base_prog_key(devinfo, flags, robust_buffer_acccess, &key->base);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2017-10-26 17:56:07 -07:00
|
|
|
|
/* We set this to 0 here and set to the actual value before we call
|
|
|
|
|
|
* brw_compile_fs.
|
|
|
|
|
|
*/
|
|
|
|
|
|
key->input_slots_valid = 0;
|
2015-10-23 21:30:38 -07:00
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
/* Vulkan doesn't specify a default */
|
|
|
|
|
|
key->high_quality_derivatives = false;
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX Vulkan doesn't appear to specify */
|
|
|
|
|
|
key->clamp_fragment_color = false;
|
|
|
|
|
|
|
2020-05-07 19:34:56 -05:00
|
|
|
|
key->ignore_sample_mask_out = false;
|
|
|
|
|
|
|
2017-10-26 17:56:07 -07:00
|
|
|
|
assert(subpass->color_count <= MAX_RTS);
|
|
|
|
|
|
for (uint32_t i = 0; i < subpass->color_count; i++) {
|
|
|
|
|
|
if (subpass->color_attachments[i].attachment != VK_ATTACHMENT_UNUSED)
|
2018-07-10 23:31:47 -07:00
|
|
|
|
key->color_outputs_valid |= (1 << i);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-30 14:07:47 -05:00
|
|
|
|
key->nr_color_regions = subpass->color_count;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
i965,iris,anv: Make alpha to coverage work with sample mask
From "Alpha Coverage" section of SKL PRM Volume 7:
"If Pixel Shader outputs oMask, AlphaToCoverage is disabled in
hardware, regardless of the state setting for this feature."
From OpenGL spec 4.6, "15.2 Shader Execution":
"The built-in integer array gl_SampleMask can be used to change
the sample coverage for a fragment from within the shader."
From OpenGL spec 4.6, "17.3.1 Alpha To Coverage":
"If SAMPLE_ALPHA_TO_COVERAGE is enabled, a temporary coverage value
is generated where each bit is determined by the alpha value at the
corresponding sample location. The temporary coverage value is then
ANDed with the fragment coverage value to generate a new fragment
coverage value."
Similar wording could be found in Vulkan spec 1.1.100
"25.6. Multisample Coverage"
Thus we need to compute alpha to coverage dithering manually in shader
and replace sample mask store with the bitwise-AND of sample mask and
alpha to coverage dithering.
The following formula is used to compute final sample mask:
m = int(16.0 * clamp(src0_alpha, 0.0, 1.0))
dither_mask = 0x1111 * ((0xfea80 >> (m & ~3)) & 0xf) |
0x0808 * (m & 2) | 0x0100 * (m & 1)
sample_mask = sample_mask & dither_mask
Credits to Francisco Jerez <currojerez@riseup.net> for creating it.
It gives a number of ones proportional to the alpha for 2, 4, 8 or 16
least significant bits of the result.
GEN6 hardware does not have issue with simultaneous usage of sample mask
and alpha to coverage however due to the wrong sending order of oMask
and src0_alpha it is still affected by it.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109743
Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
2019-02-20 19:39:18 +02:00
|
|
|
|
/* To reduce possible shader recompilations we would need to know if
|
|
|
|
|
|
* there is a SampleMask output variable to compute if we should emit
|
|
|
|
|
|
* code to workaround the issue that hardware disables alpha to coverage
|
|
|
|
|
|
* when there is SampleMask output.
|
|
|
|
|
|
*/
|
|
|
|
|
|
key->alpha_to_coverage = ms_info && ms_info->alphaToCoverageEnable;
|
|
|
|
|
|
|
|
|
|
|
|
/* Vulkan doesn't support fixed-function alpha test */
|
|
|
|
|
|
key->alpha_test_replicate_alpha = false;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2017-10-26 17:56:07 -07:00
|
|
|
|
if (ms_info) {
|
2015-10-19 22:06:59 -07:00
|
|
|
|
/* We should probably pull this out of the shader, but it's fairly
|
|
|
|
|
|
* harmless to compute it and then let dead-code take care of it.
|
|
|
|
|
|
*/
|
2017-10-26 17:56:07 -07:00
|
|
|
|
if (ms_info->rasterizationSamples > 1) {
|
2019-05-17 13:04:24 -05:00
|
|
|
|
key->persample_interp = ms_info->sampleShadingEnable &&
|
2017-10-26 17:56:07 -07:00
|
|
|
|
(ms_info->minSampleShading * ms_info->rasterizationSamples) > 1;
|
2017-03-23 11:56:06 +01:00
|
|
|
|
key->multisample_fbo = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-17 13:04:24 -05:00
|
|
|
|
key->frag_coord_adds_sample_pos = key->persample_interp;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
}
|
2020-10-19 10:12:43 +03:00
|
|
|
|
|
|
|
|
|
|
key->coarse_pixel =
|
|
|
|
|
|
device->vk.enabled_extensions.KHR_fragment_shading_rate &&
|
|
|
|
|
|
pipeline_has_coarse_pixel(pipeline, fsr_info);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-04-05 13:19:39 -07:00
|
|
|
|
populate_cs_prog_key(const struct intel_device_info *devinfo,
|
2021-09-16 17:57:41 -07:00
|
|
|
|
enum brw_subgroup_size_type subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
bool robust_buffer_acccess,
|
2015-10-19 22:06:59 -07:00
|
|
|
|
struct brw_cs_prog_key *key)
|
|
|
|
|
|
{
|
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_base_prog_key(devinfo, subgroup_size_type,
|
|
|
|
|
|
robust_buffer_acccess, &key->base);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-21 15:28:28 -06:00
|
|
|
|
static void
|
|
|
|
|
|
populate_bs_prog_key(const struct intel_device_info *devinfo,
|
|
|
|
|
|
VkPipelineShaderStageCreateFlags flags,
|
|
|
|
|
|
bool robust_buffer_access,
|
|
|
|
|
|
struct brw_bs_prog_key *key)
|
|
|
|
|
|
{
|
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
|
|
|
|
|
populate_base_prog_key(devinfo, flags, robust_buffer_access, &key->base);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-26 18:42:35 -07:00
|
|
|
|
struct anv_pipeline_stage {
|
|
|
|
|
|
gl_shader_stage stage;
|
|
|
|
|
|
|
2021-03-10 17:50:15 -05:00
|
|
|
|
const struct vk_shader_module *module;
|
2017-10-26 18:42:35 -07:00
|
|
|
|
const char *entrypoint;
|
|
|
|
|
|
const VkSpecializationInfo *spec_info;
|
2017-10-26 18:59:33 -07:00
|
|
|
|
|
2018-10-12 17:01:24 -05:00
|
|
|
|
unsigned char shader_sha1[20];
|
|
|
|
|
|
|
2017-10-26 18:59:33 -07:00
|
|
|
|
union brw_any_prog_key key;
|
2017-10-26 19:24:28 -07:00
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
|
gl_shader_stage stage;
|
|
|
|
|
|
unsigned char sha1[20];
|
|
|
|
|
|
} cache_key;
|
2017-10-27 15:47:11 -07:00
|
|
|
|
|
|
|
|
|
|
nir_shader *nir;
|
|
|
|
|
|
|
|
|
|
|
|
struct anv_pipeline_binding surface_to_descriptor[256];
|
|
|
|
|
|
struct anv_pipeline_binding sampler_to_descriptor[256];
|
|
|
|
|
|
struct anv_pipeline_bind_map bind_map;
|
|
|
|
|
|
|
|
|
|
|
|
union brw_any_prog_data prog_data;
|
2019-03-19 15:23:37 +00:00
|
|
|
|
|
2019-04-24 02:00:25 -05:00
|
|
|
|
uint32_t num_stats;
|
|
|
|
|
|
struct brw_compile_stats stats[3];
|
2019-04-24 03:02:35 -05:00
|
|
|
|
char *disasm[3];
|
2019-04-24 02:00:25 -05:00
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
VkPipelineCreationFeedbackEXT feedback;
|
2019-04-24 03:19:25 -05:00
|
|
|
|
|
|
|
|
|
|
const unsigned *code;
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
|
|
|
|
|
struct anv_shader_bin *bin;
|
2017-10-26 18:42:35 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-04-27 06:25:06 -07:00
|
|
|
|
static void
|
2021-03-10 17:50:15 -05:00
|
|
|
|
anv_pipeline_hash_shader(const struct vk_shader_module *module,
|
2018-10-12 17:01:24 -05:00
|
|
|
|
const char *entrypoint,
|
|
|
|
|
|
gl_shader_stage stage,
|
|
|
|
|
|
const VkSpecializationInfo *spec_info,
|
|
|
|
|
|
unsigned char *sha1_out)
|
2017-04-27 06:25:06 -07:00
|
|
|
|
{
|
2018-10-12 17:01:24 -05:00
|
|
|
|
struct mesa_sha1 ctx;
|
|
|
|
|
|
_mesa_sha1_init(&ctx);
|
|
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &stage, sizeof(stage));
|
|
|
|
|
|
if (spec_info) {
|
|
|
|
|
|
_mesa_sha1_update(&ctx, spec_info->pMapEntries,
|
|
|
|
|
|
spec_info->mapEntryCount *
|
|
|
|
|
|
sizeof(*spec_info->pMapEntries));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, spec_info->pData,
|
|
|
|
|
|
spec_info->dataSize);
|
2017-04-27 06:25:06 -07:00
|
|
|
|
}
|
2018-10-12 17:01:24 -05:00
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_final(&ctx, sha1_out);
|
2017-10-26 19:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_hash_graphics(struct anv_graphics_pipeline *pipeline,
|
2017-10-26 19:24:28 -07:00
|
|
|
|
struct anv_pipeline_layout *layout,
|
|
|
|
|
|
struct anv_pipeline_stage *stages,
|
|
|
|
|
|
unsigned char *sha1_out)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct mesa_sha1 ctx;
|
|
|
|
|
|
_mesa_sha1_init(&ctx);
|
|
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &pipeline->subpass->view_mask,
|
|
|
|
|
|
sizeof(pipeline->subpass->view_mask));
|
|
|
|
|
|
|
|
|
|
|
|
if (layout)
|
|
|
|
|
|
_mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
const bool rba = pipeline->base.device->robust_buffer_access;
|
2018-11-21 17:15:37 -06:00
|
|
|
|
_mesa_sha1_update(&ctx, &rba, sizeof(rba));
|
|
|
|
|
|
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
|
2018-10-12 17:01:24 -05:00
|
|
|
|
if (stages[s].entrypoint) {
|
|
|
|
|
|
_mesa_sha1_update(&ctx, stages[s].shader_sha1,
|
|
|
|
|
|
sizeof(stages[s].shader_sha1));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &stages[s].key, brw_prog_key_size(s));
|
|
|
|
|
|
}
|
2017-10-26 19:24:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_final(&ctx, sha1_out);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_hash_compute(struct anv_compute_pipeline *pipeline,
|
2017-10-26 19:24:28 -07:00
|
|
|
|
struct anv_pipeline_layout *layout,
|
|
|
|
|
|
struct anv_pipeline_stage *stage,
|
|
|
|
|
|
unsigned char *sha1_out)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct mesa_sha1 ctx;
|
|
|
|
|
|
_mesa_sha1_init(&ctx);
|
|
|
|
|
|
|
|
|
|
|
|
if (layout)
|
|
|
|
|
|
_mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
const bool rba = pipeline->base.device->robust_buffer_access;
|
2018-11-21 17:15:37 -06:00
|
|
|
|
_mesa_sha1_update(&ctx, &rba, sizeof(rba));
|
|
|
|
|
|
|
2018-10-12 17:01:24 -05:00
|
|
|
|
_mesa_sha1_update(&ctx, stage->shader_sha1,
|
|
|
|
|
|
sizeof(stage->shader_sha1));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &stage->key.cs, sizeof(stage->key.cs));
|
2017-10-26 19:24:28 -07:00
|
|
|
|
|
2017-04-27 06:25:06 -07:00
|
|
|
|
_mesa_sha1_final(&ctx, sha1_out);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_hash_ray_tracing_shader(struct anv_ray_tracing_pipeline *pipeline,
|
|
|
|
|
|
struct anv_pipeline_layout *layout,
|
|
|
|
|
|
struct anv_pipeline_stage *stage,
|
|
|
|
|
|
unsigned char *sha1_out)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct mesa_sha1 ctx;
|
|
|
|
|
|
_mesa_sha1_init(&ctx);
|
|
|
|
|
|
|
|
|
|
|
|
if (layout != NULL)
|
|
|
|
|
|
_mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
|
|
|
|
|
|
|
|
|
|
|
|
const bool rba = pipeline->base.device->robust_buffer_access;
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &rba, sizeof(rba));
|
|
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_update(&ctx, stage->shader_sha1, sizeof(stage->shader_sha1));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &stage->key, sizeof(stage->key.bs));
|
|
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_final(&ctx, sha1_out);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_hash_ray_tracing_combined_shader(struct anv_ray_tracing_pipeline *pipeline,
|
|
|
|
|
|
struct anv_pipeline_layout *layout,
|
|
|
|
|
|
struct anv_pipeline_stage *intersection,
|
|
|
|
|
|
struct anv_pipeline_stage *any_hit,
|
|
|
|
|
|
unsigned char *sha1_out)
|
|
|
|
|
|
{
|
|
|
|
|
|
struct mesa_sha1 ctx;
|
|
|
|
|
|
_mesa_sha1_init(&ctx);
|
|
|
|
|
|
|
|
|
|
|
|
if (layout != NULL)
|
|
|
|
|
|
_mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
|
|
|
|
|
|
|
|
|
|
|
|
const bool rba = pipeline->base.device->robust_buffer_access;
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &rba, sizeof(rba));
|
|
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_update(&ctx, intersection->shader_sha1, sizeof(intersection->shader_sha1));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &intersection->key, sizeof(intersection->key.bs));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, any_hit->shader_sha1, sizeof(any_hit->shader_sha1));
|
|
|
|
|
|
_mesa_sha1_update(&ctx, &any_hit->key, sizeof(any_hit->key.bs));
|
|
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_final(&ctx, sha1_out);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-12 17:54:41 -05:00
|
|
|
|
static nir_shader *
|
|
|
|
|
|
anv_pipeline_stage_get_nir(struct anv_pipeline *pipeline,
|
|
|
|
|
|
struct anv_pipeline_cache *cache,
|
|
|
|
|
|
void *mem_ctx,
|
|
|
|
|
|
struct anv_pipeline_stage *stage)
|
|
|
|
|
|
{
|
|
|
|
|
|
const struct brw_compiler *compiler =
|
2020-01-17 22:23:30 -06:00
|
|
|
|
pipeline->device->physical->compiler;
|
2018-10-12 17:54:41 -05:00
|
|
|
|
const nir_shader_compiler_options *nir_options =
|
|
|
|
|
|
compiler->glsl_compiler_options[stage->stage].NirOptions;
|
|
|
|
|
|
nir_shader *nir;
|
|
|
|
|
|
|
|
|
|
|
|
nir = anv_device_search_for_nir(pipeline->device, cache,
|
|
|
|
|
|
nir_options,
|
|
|
|
|
|
stage->shader_sha1,
|
|
|
|
|
|
mem_ctx);
|
|
|
|
|
|
if (nir) {
|
|
|
|
|
|
assert(nir->info.stage == stage->stage);
|
|
|
|
|
|
return nir;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nir = anv_shader_compile_to_nir(pipeline->device,
|
|
|
|
|
|
mem_ctx,
|
|
|
|
|
|
stage->module,
|
|
|
|
|
|
stage->entrypoint,
|
|
|
|
|
|
stage->stage,
|
|
|
|
|
|
stage->spec_info);
|
|
|
|
|
|
if (nir) {
|
|
|
|
|
|
anv_device_upload_nir(pipeline->device, cache, nir, stage->shader_sha1);
|
|
|
|
|
|
return nir;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-07 14:17:12 -07:00
|
|
|
|
static void
|
|
|
|
|
|
shared_type_info(const struct glsl_type *type, unsigned *size, unsigned *align)
|
|
|
|
|
|
{
|
|
|
|
|
|
assert(glsl_type_is_vector_or_scalar(type));
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t comp_size = glsl_type_is_boolean(type)
|
|
|
|
|
|
? 4 : glsl_get_bit_size(type) / 8;
|
|
|
|
|
|
unsigned length = glsl_get_vector_elements(type);
|
|
|
|
|
|
*size = comp_size * length,
|
|
|
|
|
|
*align = comp_size * (length == 3 ? 4 : length);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-07 15:47:54 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
|
|
|
|
|
|
void *mem_ctx,
|
|
|
|
|
|
struct anv_pipeline_stage *stage,
|
|
|
|
|
|
struct anv_pipeline_layout *layout)
|
2015-10-19 22:06:59 -07:00
|
|
|
|
{
|
2020-01-17 22:23:30 -06:00
|
|
|
|
const struct anv_physical_device *pdevice = pipeline->device->physical;
|
2019-01-09 16:04:22 -06:00
|
|
|
|
const struct brw_compiler *compiler = pdevice->compiler;
|
2017-12-01 16:10:48 -08:00
|
|
|
|
|
2018-08-07 15:47:54 -07:00
|
|
|
|
struct brw_stage_prog_data *prog_data = &stage->prog_data.base;
|
|
|
|
|
|
nir_shader *nir = stage->nir;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2018-08-29 16:40:05 -05:00
|
|
|
|
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
2021-02-14 17:49:35 +02:00
|
|
|
|
/* Check if sample shading is enabled in the shader and toggle
|
|
|
|
|
|
* it on for the pipeline independent if sampleShadingEnable is set.
|
|
|
|
|
|
*/
|
|
|
|
|
|
nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
|
|
|
|
|
|
if (nir->info.fs.uses_sample_shading)
|
|
|
|
|
|
anv_pipeline_to_graphics(pipeline)->sample_shading_enable = true;
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_wpos_center,
|
|
|
|
|
|
anv_pipeline_to_graphics(pipeline)->sample_shading_enable);
|
2020-07-01 16:55:46 +02:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_input_attachments,
|
|
|
|
|
|
&(nir_input_attachment_options) {
|
|
|
|
|
|
.use_fragcoord_sysval = true,
|
2020-07-01 17:16:01 +02:00
|
|
|
|
.use_layer_id_sysval = true,
|
2020-07-01 16:55:46 +02:00
|
|
|
|
});
|
2018-08-29 16:40:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
|
NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);
|
2017-06-19 16:56:47 +01:00
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
if (pipeline->type == ANV_PIPELINE_GRAPHICS) {
|
|
|
|
|
|
NIR_PASS_V(nir, anv_nir_lower_multiview,
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
anv_pipeline_to_graphics(pipeline));
|
2020-03-03 15:31:50 -08:00
|
|
|
|
}
|
2017-03-22 15:37:17 -07:00
|
|
|
|
|
2017-03-22 15:24:06 -07:00
|
|
|
|
nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
|
|
|
|
|
|
|
2021-08-10 17:30:13 -07:00
|
|
|
|
NIR_PASS_V(nir, brw_nir_lower_storage_image, compiler->devinfo);
|
2018-08-16 16:23:10 -05:00
|
|
|
|
|
2019-05-30 16:55:19 -07:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_mem_global,
|
|
|
|
|
|
nir_address_format_64bit_global);
|
2020-05-27 17:09:33 -05:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_mem_push_const,
|
|
|
|
|
|
nir_address_format_32bit_offset);
|
2019-05-30 16:55:19 -07:00
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
/* Apply the actual pipeline layout to UBOs, SSBOs, and textures */
|
2019-11-06 11:19:00 -06:00
|
|
|
|
anv_nir_apply_pipeline_layout(pdevice,
|
|
|
|
|
|
pipeline->device->robust_buffer_access,
|
2019-12-06 13:00:58 +02:00
|
|
|
|
layout, nir, &stage->bind_map);
|
2019-11-06 11:19:00 -06:00
|
|
|
|
|
|
|
|
|
|
NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_mem_ubo,
|
2021-01-15 16:44:44 -06:00
|
|
|
|
anv_nir_ubo_addr_format(pdevice,
|
|
|
|
|
|
pipeline->device->robust_buffer_access));
|
2019-11-06 11:19:00 -06:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_explicit_io, nir_var_mem_ssbo,
|
|
|
|
|
|
anv_nir_ssbo_addr_format(pdevice,
|
|
|
|
|
|
pipeline->device->robust_buffer_access));
|
|
|
|
|
|
|
2021-01-15 16:44:44 -06:00
|
|
|
|
/* First run copy-prop to get rid of all of the vec() that address
|
|
|
|
|
|
* calculations often create and then constant-fold so that, when we
|
|
|
|
|
|
* get to anv_nir_lower_ubo_loads, we can detect constant offsets.
|
|
|
|
|
|
*/
|
|
|
|
|
|
NIR_PASS_V(nir, nir_copy_prop);
|
2019-11-06 11:19:00 -06:00
|
|
|
|
NIR_PASS_V(nir, nir_opt_constant_folding);
|
|
|
|
|
|
|
2021-01-15 16:44:44 -06:00
|
|
|
|
NIR_PASS_V(nir, anv_nir_lower_ubo_loads);
|
|
|
|
|
|
|
2019-11-06 11:19:00 -06:00
|
|
|
|
/* We don't support non-uniform UBOs and non-uniform SSBO access is
|
|
|
|
|
|
* handled naturally by falling back to A64 messages.
|
|
|
|
|
|
*/
|
|
|
|
|
|
NIR_PASS_V(nir, nir_lower_non_uniform_access,
|
2021-03-22 11:23:29 +00:00
|
|
|
|
&(nir_lower_non_uniform_access_options) {
|
|
|
|
|
|
.types = nir_lower_non_uniform_texture_access |
|
|
|
|
|
|
nir_lower_non_uniform_image_access,
|
|
|
|
|
|
.callback = NULL,
|
|
|
|
|
|
});
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2020-02-07 07:13:12 -06:00
|
|
|
|
anv_nir_compute_push_layout(pdevice, pipeline->device->robust_buffer_access,
|
|
|
|
|
|
nir, prog_data, &stage->bind_map, mem_ctx);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2021-06-07 14:17:12 -07:00
|
|
|
|
if (gl_shader_stage_uses_workgroup(nir->info.stage)) {
|
|
|
|
|
|
if (!nir->info.shared_memory_explicit_layout) {
|
|
|
|
|
|
NIR_PASS_V(nir, nir_lower_vars_to_explicit_types,
|
|
|
|
|
|
nir_var_mem_shared, shared_type_info);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NIR_PASS_V(nir, nir_lower_explicit_io,
|
|
|
|
|
|
nir_var_mem_shared, nir_address_format_32bit_offset);
|
|
|
|
|
|
|
|
|
|
|
|
if (nir->info.zero_initialize_shared_memory &&
|
|
|
|
|
|
nir->info.shared_size > 0) {
|
|
|
|
|
|
/* The effective Shared Local Memory size is at least 1024 bytes and
|
|
|
|
|
|
* is always rounded to a power of two, so it is OK to align the size
|
|
|
|
|
|
* used by the shader to chunk_size -- which does simplify the logic.
|
|
|
|
|
|
*/
|
|
|
|
|
|
const unsigned chunk_size = 16;
|
|
|
|
|
|
const unsigned shared_size = ALIGN(nir->info.shared_size, chunk_size);
|
|
|
|
|
|
assert(shared_size <=
|
|
|
|
|
|
intel_calculate_slm_size(compiler->devinfo->ver, nir->info.shared_size));
|
|
|
|
|
|
|
|
|
|
|
|
NIR_PASS_V(nir, nir_zero_initialize_shared_memory,
|
|
|
|
|
|
shared_size, chunk_size);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-07 15:47:54 -07:00
|
|
|
|
stage->nir = nir;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 16:03:58 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_link_vs(const struct brw_compiler *compiler,
|
|
|
|
|
|
struct anv_pipeline_stage *vs_stage,
|
|
|
|
|
|
struct anv_pipeline_stage *next_stage)
|
|
|
|
|
|
{
|
2017-10-27 17:07:52 -07:00
|
|
|
|
if (next_stage)
|
2019-06-04 18:23:17 -05:00
|
|
|
|
brw_nir_link_shaders(compiler, vs_stage->nir, next_stage->nir);
|
2017-10-27 16:03:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:19:25 -05:00
|
|
|
|
static void
|
2017-10-27 16:54:32 -07:00
|
|
|
|
anv_pipeline_compile_vs(const struct brw_compiler *compiler,
|
|
|
|
|
|
void *mem_ctx,
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
struct anv_graphics_pipeline *pipeline,
|
2017-10-27 16:54:32 -07:00
|
|
|
|
struct anv_pipeline_stage *vs_stage)
|
2015-10-19 22:06:59 -07:00
|
|
|
|
{
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
/* When using Primitive Replication for multiview, each view gets its own
|
|
|
|
|
|
* position slot.
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint32_t pos_slots = pipeline->use_primitive_replication ?
|
|
|
|
|
|
anv_subpass_view_count(pipeline->subpass) : 1;
|
|
|
|
|
|
|
2017-10-27 16:54:32 -07:00
|
|
|
|
brw_compute_vue_map(compiler->devinfo,
|
|
|
|
|
|
&vs_stage->prog_data.vs.base.vue_map,
|
|
|
|
|
|
vs_stage->nir->info.outputs_written,
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
vs_stage->nir->info.separate_shader,
|
|
|
|
|
|
pos_slots);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2019-04-24 02:00:25 -05:00
|
|
|
|
vs_stage->num_stats = 1;
|
2021-03-22 23:07:18 -07:00
|
|
|
|
|
|
|
|
|
|
struct brw_compile_vs_params params = {
|
|
|
|
|
|
.nir = vs_stage->nir,
|
|
|
|
|
|
.key = &vs_stage->key.vs,
|
|
|
|
|
|
.prog_data = &vs_stage->prog_data.vs,
|
|
|
|
|
|
.stats = vs_stage->stats,
|
|
|
|
|
|
.log_data = pipeline->base.device,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
vs_stage->code = brw_compile_vs(compiler, mem_ctx, ¶ms);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-25 17:43:06 -07:00
|
|
|
|
static void
|
|
|
|
|
|
merge_tess_info(struct shader_info *tes_info,
|
|
|
|
|
|
const struct shader_info *tcs_info)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* The Vulkan 1.0.38 spec, section 21.1 Tessellator says:
|
|
|
|
|
|
*
|
|
|
|
|
|
* "PointMode. Controls generation of points rather than triangles
|
|
|
|
|
|
* or lines. This functionality defaults to disabled, and is
|
|
|
|
|
|
* enabled if either shader stage includes the execution mode.
|
|
|
|
|
|
*
|
|
|
|
|
|
* and about Triangles, Quads, IsoLines, VertexOrderCw, VertexOrderCcw,
|
|
|
|
|
|
* PointMode, SpacingEqual, SpacingFractionalEven, SpacingFractionalOdd,
|
|
|
|
|
|
* and OutputVertices, it says:
|
|
|
|
|
|
*
|
|
|
|
|
|
* "One mode must be set in at least one of the tessellation
|
|
|
|
|
|
* shader stages."
|
|
|
|
|
|
*
|
|
|
|
|
|
* So, the fields can be set in either the TCS or TES, but they must
|
|
|
|
|
|
* agree if set in both. Our backend looks at TES, so bitwise-or in
|
|
|
|
|
|
* the values from the TCS.
|
|
|
|
|
|
*/
|
|
|
|
|
|
assert(tcs_info->tess.tcs_vertices_out == 0 ||
|
|
|
|
|
|
tes_info->tess.tcs_vertices_out == 0 ||
|
|
|
|
|
|
tcs_info->tess.tcs_vertices_out == tes_info->tess.tcs_vertices_out);
|
|
|
|
|
|
tes_info->tess.tcs_vertices_out |= tcs_info->tess.tcs_vertices_out;
|
|
|
|
|
|
|
|
|
|
|
|
assert(tcs_info->tess.spacing == TESS_SPACING_UNSPECIFIED ||
|
|
|
|
|
|
tes_info->tess.spacing == TESS_SPACING_UNSPECIFIED ||
|
|
|
|
|
|
tcs_info->tess.spacing == tes_info->tess.spacing);
|
|
|
|
|
|
tes_info->tess.spacing |= tcs_info->tess.spacing;
|
|
|
|
|
|
|
2017-06-28 09:39:55 +02:00
|
|
|
|
assert(tcs_info->tess.primitive_mode == 0 ||
|
|
|
|
|
|
tes_info->tess.primitive_mode == 0 ||
|
|
|
|
|
|
tcs_info->tess.primitive_mode == tes_info->tess.primitive_mode);
|
|
|
|
|
|
tes_info->tess.primitive_mode |= tcs_info->tess.primitive_mode;
|
2016-09-25 17:43:06 -07:00
|
|
|
|
tes_info->tess.ccw |= tcs_info->tess.ccw;
|
|
|
|
|
|
tes_info->tess.point_mode |= tcs_info->tess.point_mode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 16:03:58 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_link_tcs(const struct brw_compiler *compiler,
|
|
|
|
|
|
struct anv_pipeline_stage *tcs_stage,
|
|
|
|
|
|
struct anv_pipeline_stage *tes_stage)
|
|
|
|
|
|
{
|
|
|
|
|
|
assert(tes_stage && tes_stage->stage == MESA_SHADER_TESS_EVAL);
|
|
|
|
|
|
|
2019-06-04 18:23:17 -05:00
|
|
|
|
brw_nir_link_shaders(compiler, tcs_stage->nir, tes_stage->nir);
|
2017-10-27 17:07:52 -07:00
|
|
|
|
|
2017-10-27 16:03:58 -07:00
|
|
|
|
nir_lower_patch_vertices(tes_stage->nir,
|
|
|
|
|
|
tcs_stage->nir->info.tess.tcs_vertices_out,
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy TCS info into the TES info */
|
|
|
|
|
|
merge_tess_info(&tes_stage->nir->info, &tcs_stage->nir->info);
|
|
|
|
|
|
|
|
|
|
|
|
/* Whacking the key after cache lookup is a bit sketchy, but all of
|
|
|
|
|
|
* this comes from the SPIR-V, which is part of the hash used for the
|
|
|
|
|
|
* pipeline cache. So it should be safe.
|
|
|
|
|
|
*/
|
|
|
|
|
|
tcs_stage->key.tcs.tes_primitive_mode =
|
|
|
|
|
|
tes_stage->nir->info.tess.primitive_mode;
|
|
|
|
|
|
tcs_stage->key.tcs.quads_workaround =
|
2021-03-29 14:41:58 -07:00
|
|
|
|
compiler->devinfo->ver < 9 &&
|
2017-10-27 16:03:58 -07:00
|
|
|
|
tes_stage->nir->info.tess.primitive_mode == 7 /* GL_QUADS */ &&
|
|
|
|
|
|
tes_stage->nir->info.tess.spacing == TESS_SPACING_EQUAL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:19:25 -05:00
|
|
|
|
static void
|
2017-10-27 16:54:32 -07:00
|
|
|
|
anv_pipeline_compile_tcs(const struct brw_compiler *compiler,
|
|
|
|
|
|
void *mem_ctx,
|
2019-02-18 15:40:49 +11:00
|
|
|
|
struct anv_device *device,
|
2017-10-27 16:54:32 -07:00
|
|
|
|
struct anv_pipeline_stage *tcs_stage,
|
|
|
|
|
|
struct anv_pipeline_stage *prev_stage)
|
|
|
|
|
|
{
|
2018-08-07 16:21:13 -07:00
|
|
|
|
tcs_stage->key.tcs.outputs_written =
|
|
|
|
|
|
tcs_stage->nir->info.outputs_written;
|
|
|
|
|
|
tcs_stage->key.tcs.patch_outputs_written =
|
|
|
|
|
|
tcs_stage->nir->info.patch_outputs_written;
|
|
|
|
|
|
|
2019-04-24 02:00:25 -05:00
|
|
|
|
tcs_stage->num_stats = 1;
|
2019-04-24 03:19:25 -05:00
|
|
|
|
tcs_stage->code = brw_compile_tcs(compiler, device, mem_ctx,
|
|
|
|
|
|
&tcs_stage->key.tcs,
|
|
|
|
|
|
&tcs_stage->prog_data.tcs,
|
2019-04-24 02:00:25 -05:00
|
|
|
|
tcs_stage->nir, -1,
|
|
|
|
|
|
tcs_stage->stats, NULL);
|
2017-10-27 16:54:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 16:03:58 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_link_tes(const struct brw_compiler *compiler,
|
|
|
|
|
|
struct anv_pipeline_stage *tes_stage,
|
|
|
|
|
|
struct anv_pipeline_stage *next_stage)
|
|
|
|
|
|
{
|
2017-10-27 17:07:52 -07:00
|
|
|
|
if (next_stage)
|
2019-06-04 18:23:17 -05:00
|
|
|
|
brw_nir_link_shaders(compiler, tes_stage->nir, next_stage->nir);
|
2017-10-27 16:03:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:19:25 -05:00
|
|
|
|
static void
|
2017-10-27 16:54:32 -07:00
|
|
|
|
anv_pipeline_compile_tes(const struct brw_compiler *compiler,
|
|
|
|
|
|
void *mem_ctx,
|
2019-02-18 15:40:49 +11:00
|
|
|
|
struct anv_device *device,
|
2017-10-27 16:54:32 -07:00
|
|
|
|
struct anv_pipeline_stage *tes_stage,
|
|
|
|
|
|
struct anv_pipeline_stage *tcs_stage)
|
2016-09-25 17:43:06 -07:00
|
|
|
|
{
|
2018-08-07 16:21:13 -07:00
|
|
|
|
tes_stage->key.tes.inputs_read =
|
|
|
|
|
|
tcs_stage->nir->info.outputs_written;
|
|
|
|
|
|
tes_stage->key.tes.patch_inputs_read =
|
|
|
|
|
|
tcs_stage->nir->info.patch_outputs_written;
|
|
|
|
|
|
|
2019-04-24 02:00:25 -05:00
|
|
|
|
tes_stage->num_stats = 1;
|
2019-04-24 03:19:25 -05:00
|
|
|
|
tes_stage->code = brw_compile_tes(compiler, device, mem_ctx,
|
|
|
|
|
|
&tes_stage->key.tes,
|
|
|
|
|
|
&tcs_stage->prog_data.tcs.base.vue_map,
|
|
|
|
|
|
&tes_stage->prog_data.tes,
|
2019-08-23 15:33:24 -05:00
|
|
|
|
tes_stage->nir, -1,
|
2019-04-24 02:00:25 -05:00
|
|
|
|
tes_stage->stats, NULL);
|
2016-09-25 17:43:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 16:03:58 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_link_gs(const struct brw_compiler *compiler,
|
|
|
|
|
|
struct anv_pipeline_stage *gs_stage,
|
|
|
|
|
|
struct anv_pipeline_stage *next_stage)
|
|
|
|
|
|
{
|
2017-10-27 17:07:52 -07:00
|
|
|
|
if (next_stage)
|
2019-06-04 18:23:17 -05:00
|
|
|
|
brw_nir_link_shaders(compiler, gs_stage->nir, next_stage->nir);
|
2017-10-27 16:03:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:19:25 -05:00
|
|
|
|
static void
|
2017-10-27 16:54:32 -07:00
|
|
|
|
anv_pipeline_compile_gs(const struct brw_compiler *compiler,
|
|
|
|
|
|
void *mem_ctx,
|
2019-02-18 15:40:49 +11:00
|
|
|
|
struct anv_device *device,
|
2017-10-27 16:54:32 -07:00
|
|
|
|
struct anv_pipeline_stage *gs_stage,
|
|
|
|
|
|
struct anv_pipeline_stage *prev_stage)
|
2015-10-21 18:45:48 -07:00
|
|
|
|
{
|
2017-10-27 16:54:32 -07:00
|
|
|
|
brw_compute_vue_map(compiler->devinfo,
|
|
|
|
|
|
&gs_stage->prog_data.gs.base.vue_map,
|
|
|
|
|
|
gs_stage->nir->info.outputs_written,
|
2018-09-21 16:07:38 -07:00
|
|
|
|
gs_stage->nir->info.separate_shader, 1);
|
2017-10-27 16:54:32 -07:00
|
|
|
|
|
2019-04-24 02:00:25 -05:00
|
|
|
|
gs_stage->num_stats = 1;
|
2019-04-24 03:19:25 -05:00
|
|
|
|
gs_stage->code = brw_compile_gs(compiler, device, mem_ctx,
|
|
|
|
|
|
&gs_stage->key.gs,
|
|
|
|
|
|
&gs_stage->prog_data.gs,
|
2021-05-24 10:11:25 +10:00
|
|
|
|
gs_stage->nir, -1,
|
2019-04-24 02:00:25 -05:00
|
|
|
|
gs_stage->stats, NULL);
|
2015-10-21 18:45:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 16:03:58 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_link_fs(const struct brw_compiler *compiler,
|
|
|
|
|
|
struct anv_pipeline_stage *stage)
|
|
|
|
|
|
{
|
2019-10-30 14:07:47 -05:00
|
|
|
|
unsigned num_rt_bindings;
|
|
|
|
|
|
struct anv_pipeline_binding rt_bindings[MAX_RTS];
|
|
|
|
|
|
if (stage->key.wm.nr_color_regions > 0) {
|
|
|
|
|
|
assert(stage->key.wm.nr_color_regions <= MAX_RTS);
|
|
|
|
|
|
for (unsigned rt = 0; rt < stage->key.wm.nr_color_regions; rt++) {
|
|
|
|
|
|
if (stage->key.wm.color_outputs_valid & BITFIELD_BIT(rt)) {
|
|
|
|
|
|
rt_bindings[rt] = (struct anv_pipeline_binding) {
|
|
|
|
|
|
.set = ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS,
|
|
|
|
|
|
.index = rt,
|
|
|
|
|
|
};
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Setup a null render target */
|
|
|
|
|
|
rt_bindings[rt] = (struct anv_pipeline_binding) {
|
|
|
|
|
|
.set = ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS,
|
|
|
|
|
|
.index = UINT32_MAX,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2019-04-30 08:38:16 +02:00
|
|
|
|
}
|
2019-10-30 14:07:47 -05:00
|
|
|
|
num_rt_bindings = stage->key.wm.nr_color_regions;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* Setup a null render target */
|
|
|
|
|
|
rt_bindings[0] = (struct anv_pipeline_binding) {
|
|
|
|
|
|
.set = ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS,
|
|
|
|
|
|
.index = UINT32_MAX,
|
|
|
|
|
|
};
|
|
|
|
|
|
num_rt_bindings = 1;
|
2017-10-27 16:03:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-30 14:07:47 -05:00
|
|
|
|
assert(num_rt_bindings <= MAX_RTS);
|
|
|
|
|
|
assert(stage->bind_map.surface_count == 0);
|
|
|
|
|
|
typed_memcpy(stage->bind_map.surface_to_descriptor,
|
|
|
|
|
|
rt_bindings, num_rt_bindings);
|
|
|
|
|
|
stage->bind_map.surface_count += num_rt_bindings;
|
2017-10-27 16:03:58 -07:00
|
|
|
|
|
2019-10-30 14:07:47 -05:00
|
|
|
|
/* Now that we've set up the color attachments, we can go through and
|
|
|
|
|
|
* eliminate any shader outputs that map to VK_ATTACHMENT_UNUSED in the
|
|
|
|
|
|
* hopes that dead code can clean them up in this and any earlier shader
|
|
|
|
|
|
* stages.
|
|
|
|
|
|
*/
|
|
|
|
|
|
nir_function_impl *impl = nir_shader_get_entrypoint(stage->nir);
|
2017-10-27 16:03:58 -07:00
|
|
|
|
bool deleted_output = false;
|
2020-07-18 18:24:25 -05:00
|
|
|
|
nir_foreach_shader_out_variable_safe(var, stage->nir) {
|
2019-10-30 14:07:47 -05:00
|
|
|
|
/* TODO: We don't delete depth/stencil writes. We probably could if the
|
|
|
|
|
|
* subpass doesn't have a depth/stencil attachment.
|
|
|
|
|
|
*/
|
2017-10-27 16:03:58 -07:00
|
|
|
|
if (var->data.location < FRAG_RESULT_DATA0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
const unsigned rt = var->data.location - FRAG_RESULT_DATA0;
|
2019-04-30 08:38:16 +02:00
|
|
|
|
|
2019-10-30 14:07:47 -05:00
|
|
|
|
/* If this is the RT at location 0 and we have alpha to coverage
|
|
|
|
|
|
* enabled we still need that write because it will affect the coverage
|
|
|
|
|
|
* mask even if it's never written to a color target.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (rt == 0 && stage->key.wm.alpha_to_coverage)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
const unsigned array_len =
|
|
|
|
|
|
glsl_type_is_array(var->type) ? glsl_get_length(var->type) : 1;
|
|
|
|
|
|
assert(rt + array_len <= MAX_RTS);
|
|
|
|
|
|
|
|
|
|
|
|
if (rt >= MAX_RTS || !(stage->key.wm.color_outputs_valid &
|
|
|
|
|
|
BITFIELD_RANGE(rt, array_len))) {
|
2017-10-27 16:03:58 -07:00
|
|
|
|
deleted_output = true;
|
2019-01-16 00:05:04 +01:00
|
|
|
|
var->data.mode = nir_var_function_temp;
|
2017-10-27 16:03:58 -07:00
|
|
|
|
exec_node_remove(&var->node);
|
|
|
|
|
|
exec_list_push_tail(&impl->locals, &var->node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (deleted_output)
|
|
|
|
|
|
nir_fixup_deref_modes(stage->nir);
|
|
|
|
|
|
|
2019-10-30 14:07:47 -05:00
|
|
|
|
/* We stored the number of subpass color attachments in nr_color_regions
|
|
|
|
|
|
* when calculating the key for caching. Now that we've computed the bind
|
|
|
|
|
|
* map, we can reduce this to the actual max before we go into the back-end
|
|
|
|
|
|
* compiler.
|
2019-10-30 15:53:11 -05:00
|
|
|
|
*/
|
2019-10-30 14:07:47 -05:00
|
|
|
|
stage->key.wm.nr_color_regions =
|
|
|
|
|
|
util_last_bit(stage->key.wm.color_outputs_valid);
|
2017-10-27 16:03:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:19:25 -05:00
|
|
|
|
static void
|
2017-10-27 16:54:32 -07:00
|
|
|
|
anv_pipeline_compile_fs(const struct brw_compiler *compiler,
|
|
|
|
|
|
void *mem_ctx,
|
2019-02-18 15:40:49 +11:00
|
|
|
|
struct anv_device *device,
|
2017-10-27 16:54:32 -07:00
|
|
|
|
struct anv_pipeline_stage *fs_stage,
|
|
|
|
|
|
struct anv_pipeline_stage *prev_stage)
|
2015-10-19 22:06:59 -07:00
|
|
|
|
{
|
2017-10-26 17:56:07 -07:00
|
|
|
|
/* TODO: we could set this to 0 based on the information in nir_shader, but
|
|
|
|
|
|
* we need this before we call spirv_to_nir.
|
|
|
|
|
|
*/
|
2017-10-27 16:54:32 -07:00
|
|
|
|
assert(prev_stage);
|
|
|
|
|
|
fs_stage->key.wm.input_slots_valid =
|
|
|
|
|
|
prev_stage->prog_data.vue.vue_map.slots_valid;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2021-03-22 22:13:09 -07:00
|
|
|
|
struct brw_compile_fs_params params = {
|
|
|
|
|
|
.nir = fs_stage->nir,
|
|
|
|
|
|
.key = &fs_stage->key.wm,
|
|
|
|
|
|
.prog_data = &fs_stage->prog_data.wm,
|
|
|
|
|
|
|
|
|
|
|
|
.allow_spilling = true,
|
|
|
|
|
|
.stats = fs_stage->stats,
|
|
|
|
|
|
.log_data = device,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
fs_stage->code = brw_compile_fs(compiler, mem_ctx, ¶ms);
|
2019-04-24 02:00:25 -05:00
|
|
|
|
|
|
|
|
|
|
fs_stage->num_stats = (uint32_t)fs_stage->prog_data.wm.dispatch_8 +
|
|
|
|
|
|
(uint32_t)fs_stage->prog_data.wm.dispatch_16 +
|
|
|
|
|
|
(uint32_t)fs_stage->prog_data.wm.dispatch_32;
|
2018-07-11 00:03:27 -07:00
|
|
|
|
|
2019-10-30 15:50:51 -05:00
|
|
|
|
if (fs_stage->key.wm.color_outputs_valid == 0 &&
|
2018-07-11 00:03:27 -07:00
|
|
|
|
!fs_stage->prog_data.wm.has_side_effects &&
|
2019-10-30 15:50:51 -05:00
|
|
|
|
!fs_stage->prog_data.wm.uses_omask &&
|
|
|
|
|
|
!fs_stage->key.wm.alpha_to_coverage &&
|
2018-07-11 00:03:27 -07:00
|
|
|
|
!fs_stage->prog_data.wm.uses_kill &&
|
|
|
|
|
|
fs_stage->prog_data.wm.computed_depth_mode == BRW_PSCDEPTH_OFF &&
|
|
|
|
|
|
!fs_stage->prog_data.wm.computed_stencil) {
|
|
|
|
|
|
/* This fragment shader has no outputs and no side effects. Go ahead
|
|
|
|
|
|
* and return the code pointer so we don't accidentally think the
|
|
|
|
|
|
* compile failed but zero out prog_data which will set program_size to
|
|
|
|
|
|
* zero and disable the stage.
|
|
|
|
|
|
*/
|
|
|
|
|
|
memset(&fs_stage->prog_data, 0, sizeof(fs_stage->prog_data));
|
|
|
|
|
|
}
|
2015-10-19 22:06:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:02:35 -05:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_add_executable(struct anv_pipeline *pipeline,
|
|
|
|
|
|
struct anv_pipeline_stage *stage,
|
|
|
|
|
|
struct brw_compile_stats *stats,
|
|
|
|
|
|
uint32_t code_offset)
|
|
|
|
|
|
{
|
2019-10-09 13:21:21 -05:00
|
|
|
|
char *nir = NULL;
|
|
|
|
|
|
if (stage->nir &&
|
|
|
|
|
|
(pipeline->flags &
|
|
|
|
|
|
VK_PIPELINE_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR)) {
|
2021-02-05 13:25:03 +02:00
|
|
|
|
nir = nir_shader_as_str(stage->nir, pipeline->mem_ctx);
|
2019-10-09 13:21:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:02:35 -05:00
|
|
|
|
char *disasm = NULL;
|
|
|
|
|
|
if (stage->code &&
|
|
|
|
|
|
(pipeline->flags &
|
|
|
|
|
|
VK_PIPELINE_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR)) {
|
|
|
|
|
|
char *stream_data = NULL;
|
|
|
|
|
|
size_t stream_size = 0;
|
|
|
|
|
|
FILE *stream = open_memstream(&stream_data, &stream_size);
|
|
|
|
|
|
|
2020-03-12 18:05:31 -05:00
|
|
|
|
uint32_t push_size = 0;
|
|
|
|
|
|
for (unsigned i = 0; i < 4; i++)
|
|
|
|
|
|
push_size += stage->bind_map.push_ranges[i].length;
|
|
|
|
|
|
if (push_size > 0) {
|
|
|
|
|
|
fprintf(stream, "Push constant ranges:\n");
|
|
|
|
|
|
for (unsigned i = 0; i < 4; i++) {
|
|
|
|
|
|
if (stage->bind_map.push_ranges[i].length == 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stream, " RANGE%d (%dB): ", i,
|
|
|
|
|
|
stage->bind_map.push_ranges[i].length * 32);
|
|
|
|
|
|
|
|
|
|
|
|
switch (stage->bind_map.push_ranges[i].set) {
|
|
|
|
|
|
case ANV_DESCRIPTOR_SET_NULL:
|
|
|
|
|
|
fprintf(stream, "NULL");
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ANV_DESCRIPTOR_SET_PUSH_CONSTANTS:
|
|
|
|
|
|
fprintf(stream, "Vulkan push constants and API params");
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ANV_DESCRIPTOR_SET_DESCRIPTORS:
|
|
|
|
|
|
fprintf(stream, "Descriptor buffer for set %d (start=%dB)",
|
|
|
|
|
|
stage->bind_map.push_ranges[i].index,
|
|
|
|
|
|
stage->bind_map.push_ranges[i].start * 32);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ANV_DESCRIPTOR_SET_NUM_WORK_GROUPS:
|
|
|
|
|
|
unreachable("gl_NumWorkgroups is never pushed");
|
|
|
|
|
|
|
|
|
|
|
|
case ANV_DESCRIPTOR_SET_SHADER_CONSTANTS:
|
|
|
|
|
|
fprintf(stream, "Inline shader constant data (start=%dB)",
|
|
|
|
|
|
stage->bind_map.push_ranges[i].start * 32);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS:
|
|
|
|
|
|
unreachable("Color attachments can't be pushed");
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
fprintf(stream, "UBO (set=%d binding=%d start=%dB)",
|
|
|
|
|
|
stage->bind_map.push_ranges[i].set,
|
|
|
|
|
|
stage->bind_map.push_ranges[i].index,
|
|
|
|
|
|
stage->bind_map.push_ranges[i].start * 32);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
fprintf(stream, "\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
fprintf(stream, "\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:02:35 -05:00
|
|
|
|
/* Creating this is far cheaper than it looks. It's perfectly fine to
|
|
|
|
|
|
* do it for every binary.
|
|
|
|
|
|
*/
|
2021-03-03 13:49:18 -08:00
|
|
|
|
intel_disassemble(&pipeline->device->info,
|
2021-03-09 09:44:02 -08:00
|
|
|
|
stage->code, code_offset, stream);
|
2019-04-24 03:02:35 -05:00
|
|
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy it to a ralloc'd thing */
|
|
|
|
|
|
disasm = ralloc_size(pipeline->mem_ctx, stream_size + 1);
|
|
|
|
|
|
memcpy(disasm, stream_data, stream_size);
|
|
|
|
|
|
disasm[stream_size] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
free(stream_data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 10:19:15 -08:00
|
|
|
|
const struct anv_pipeline_executable exe = {
|
|
|
|
|
|
.stage = stage->stage,
|
|
|
|
|
|
.stats = *stats,
|
|
|
|
|
|
.nir = nir,
|
|
|
|
|
|
.disasm = disasm,
|
|
|
|
|
|
};
|
|
|
|
|
|
util_dynarray_append(&pipeline->executables,
|
|
|
|
|
|
struct anv_pipeline_executable, exe);
|
2019-04-24 03:02:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_add_executables(struct anv_pipeline *pipeline,
|
|
|
|
|
|
struct anv_pipeline_stage *stage,
|
|
|
|
|
|
struct anv_shader_bin *bin)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (stage->stage == MESA_SHADER_FRAGMENT) {
|
|
|
|
|
|
/* We pull the prog data and stats out of the anv_shader_bin because
|
|
|
|
|
|
* the anv_pipeline_stage may not be fully populated if we successfully
|
|
|
|
|
|
* looked up the shader in a cache.
|
|
|
|
|
|
*/
|
|
|
|
|
|
const struct brw_wm_prog_data *wm_prog_data =
|
|
|
|
|
|
(const struct brw_wm_prog_data *)bin->prog_data;
|
|
|
|
|
|
struct brw_compile_stats *stats = bin->stats;
|
|
|
|
|
|
|
|
|
|
|
|
if (wm_prog_data->dispatch_8) {
|
|
|
|
|
|
anv_pipeline_add_executable(pipeline, stage, stats++, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (wm_prog_data->dispatch_16) {
|
|
|
|
|
|
anv_pipeline_add_executable(pipeline, stage, stats++,
|
|
|
|
|
|
wm_prog_data->prog_offset_16);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (wm_prog_data->dispatch_32) {
|
|
|
|
|
|
anv_pipeline_add_executable(pipeline, stage, stats++,
|
|
|
|
|
|
wm_prog_data->prog_offset_32);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
anv_pipeline_add_executable(pipeline, stage, bin->stats, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-16 17:57:41 -07:00
|
|
|
|
static enum brw_subgroup_size_type
|
|
|
|
|
|
anv_subgroup_size_type(gl_shader_stage stage,
|
|
|
|
|
|
VkPipelineShaderStageCreateFlags flags,
|
|
|
|
|
|
const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT *rss_info)
|
|
|
|
|
|
{
|
|
|
|
|
|
enum brw_subgroup_size_type subgroup_size_type;
|
|
|
|
|
|
|
|
|
|
|
|
if (rss_info) {
|
|
|
|
|
|
assert(stage == MESA_SHADER_COMPUTE);
|
|
|
|
|
|
/* These enum values are expressly chosen to be equal to the subgroup
|
|
|
|
|
|
* size that they require.
|
|
|
|
|
|
*/
|
|
|
|
|
|
assert(rss_info->requiredSubgroupSize == 8 ||
|
|
|
|
|
|
rss_info->requiredSubgroupSize == 16 ||
|
|
|
|
|
|
rss_info->requiredSubgroupSize == 32);
|
|
|
|
|
|
subgroup_size_type = rss_info->requiredSubgroupSize;
|
|
|
|
|
|
} else if (flags & VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT) {
|
|
|
|
|
|
subgroup_size_type = BRW_SUBGROUP_SIZE_VARYING;
|
|
|
|
|
|
} else if (flags & VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT) {
|
|
|
|
|
|
assert(stage == MESA_SHADER_COMPUTE);
|
|
|
|
|
|
/* If the client expressly requests full subgroups and they don't
|
|
|
|
|
|
* specify a subgroup size neither allow varying subgroups, we need to
|
|
|
|
|
|
* pick one. So we specify the API value of 32. Performance will
|
|
|
|
|
|
* likely be terrible in this case but there's nothing we can do about
|
|
|
|
|
|
* that. The client should have chosen a size.
|
|
|
|
|
|
*/
|
|
|
|
|
|
subgroup_size_type = BRW_SUBGROUP_SIZE_REQUIRE_32;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
subgroup_size_type = BRW_SUBGROUP_SIZE_API_CONSTANT;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return subgroup_size_type;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_init_from_cached_graphics(struct anv_graphics_pipeline *pipeline)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* TODO: Cache this pipeline-wide information. */
|
|
|
|
|
|
|
|
|
|
|
|
/* Primitive replication depends on information from all the shaders.
|
|
|
|
|
|
* Recover this bit from the fact that we have more than one position slot
|
|
|
|
|
|
* in the vertex shader when using it.
|
|
|
|
|
|
*/
|
|
|
|
|
|
assert(pipeline->active_stages & VK_SHADER_STAGE_VERTEX_BIT);
|
|
|
|
|
|
int pos_slots = 0;
|
|
|
|
|
|
const struct brw_vue_prog_data *vue_prog_data =
|
|
|
|
|
|
(const void *) pipeline->shaders[MESA_SHADER_VERTEX]->prog_data;
|
|
|
|
|
|
const struct brw_vue_map *vue_map = &vue_prog_data->vue_map;
|
|
|
|
|
|
for (int i = 0; i < vue_map->num_slots; i++) {
|
|
|
|
|
|
if (vue_map->slot_to_varying[i] == VARYING_SLOT_POS)
|
|
|
|
|
|
pos_slots++;
|
|
|
|
|
|
}
|
|
|
|
|
|
pipeline->use_primitive_replication = pos_slots > 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 10:18:31 -07:00
|
|
|
|
static VkResult
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_compile_graphics(struct anv_graphics_pipeline *pipeline,
|
2017-10-27 10:18:31 -07:00
|
|
|
|
struct anv_pipeline_cache *cache,
|
|
|
|
|
|
const VkGraphicsPipelineCreateInfo *info)
|
|
|
|
|
|
{
|
2019-03-19 15:23:37 +00:00
|
|
|
|
VkPipelineCreationFeedbackEXT pipeline_feedback = {
|
|
|
|
|
|
.flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT,
|
|
|
|
|
|
};
|
|
|
|
|
|
int64_t pipeline_start = os_time_get_nano();
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
const struct brw_compiler *compiler = pipeline->base.device->physical->compiler;
|
2017-10-27 10:18:31 -07:00
|
|
|
|
struct anv_pipeline_stage stages[MESA_SHADER_STAGES] = {};
|
|
|
|
|
|
|
2017-10-27 14:47:38 -07:00
|
|
|
|
pipeline->active_stages = 0;
|
|
|
|
|
|
|
2021-05-03 11:09:27 +03:00
|
|
|
|
/* Information on which states are considered dynamic. */
|
|
|
|
|
|
const VkPipelineDynamicStateCreateInfo *dyn_info =
|
|
|
|
|
|
info->pDynamicState;
|
|
|
|
|
|
uint32_t dynamic_states = 0;
|
|
|
|
|
|
if (dyn_info) {
|
|
|
|
|
|
for (unsigned i = 0; i < dyn_info->dynamicStateCount; i++)
|
|
|
|
|
|
dynamic_states |=
|
|
|
|
|
|
anv_cmd_dirty_bit_for_vk_dynamic_state(dyn_info->pDynamicStates[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 10:18:31 -07:00
|
|
|
|
VkResult result;
|
|
|
|
|
|
for (uint32_t i = 0; i < info->stageCount; i++) {
|
|
|
|
|
|
const VkPipelineShaderStageCreateInfo *sinfo = &info->pStages[i];
|
|
|
|
|
|
gl_shader_stage stage = vk_to_mesa_shader_stage(sinfo->stage);
|
|
|
|
|
|
|
|
|
|
|
|
pipeline->active_stages |= sinfo->stage;
|
|
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
2017-10-27 10:18:31 -07:00
|
|
|
|
stages[stage].stage = stage;
|
2021-03-10 17:50:15 -05:00
|
|
|
|
stages[stage].module = vk_shader_module_from_handle(sinfo->module);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
stages[stage].entrypoint = sinfo->pName;
|
|
|
|
|
|
stages[stage].spec_info = sinfo->pSpecializationInfo;
|
2018-10-12 17:01:24 -05:00
|
|
|
|
anv_pipeline_hash_shader(stages[stage].module,
|
|
|
|
|
|
stages[stage].entrypoint,
|
|
|
|
|
|
stage,
|
|
|
|
|
|
stages[stage].spec_info,
|
|
|
|
|
|
stages[stage].shader_sha1);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
|
2021-09-16 17:57:41 -07:00
|
|
|
|
enum brw_subgroup_size_type subgroup_size_type =
|
|
|
|
|
|
anv_subgroup_size_type(stage, sinfo->flags, NULL);
|
|
|
|
|
|
|
2021-04-05 13:19:39 -07:00
|
|
|
|
const struct intel_device_info *devinfo = &pipeline->base.device->info;
|
2017-10-27 10:18:31 -07:00
|
|
|
|
switch (stage) {
|
|
|
|
|
|
case MESA_SHADER_VERTEX:
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_vs_prog_key(devinfo, subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
pipeline->base.device->robust_buffer_access,
|
|
|
|
|
|
&stages[stage].key.vs);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_TESS_CTRL:
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_tcs_prog_key(devinfo, subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
pipeline->base.device->robust_buffer_access,
|
2017-10-27 10:18:31 -07:00
|
|
|
|
info->pTessellationState->patchControlPoints,
|
|
|
|
|
|
&stages[stage].key.tcs);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_TESS_EVAL:
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_tes_prog_key(devinfo, subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
pipeline->base.device->robust_buffer_access,
|
|
|
|
|
|
&stages[stage].key.tes);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_GEOMETRY:
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_gs_prog_key(devinfo, subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
pipeline->base.device->robust_buffer_access,
|
|
|
|
|
|
&stages[stage].key.gs);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
break;
|
2020-01-03 13:23:32 -08:00
|
|
|
|
case MESA_SHADER_FRAGMENT: {
|
|
|
|
|
|
const bool raster_enabled =
|
2021-05-03 11:09:27 +03:00
|
|
|
|
!info->pRasterizationState->rasterizerDiscardEnable ||
|
|
|
|
|
|
dynamic_states & ANV_CMD_DIRTY_DYNAMIC_RASTERIZER_DISCARD_ENABLE;
|
2021-09-16 17:57:41 -07:00
|
|
|
|
populate_wm_prog_key(pipeline, subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
pipeline->base.device->robust_buffer_access,
|
2019-02-22 15:21:13 -06:00
|
|
|
|
pipeline->subpass,
|
2020-01-03 13:23:32 -08:00
|
|
|
|
raster_enabled ? info->pMultisampleState : NULL,
|
2020-10-19 10:12:43 +03:00
|
|
|
|
vk_find_struct_const(info->pNext,
|
|
|
|
|
|
PIPELINE_FRAGMENT_SHADING_RATE_STATE_CREATE_INFO_KHR),
|
2017-10-27 10:18:31 -07:00
|
|
|
|
&stages[stage].key.wm);
|
|
|
|
|
|
break;
|
2020-01-03 13:23:32 -08:00
|
|
|
|
}
|
2017-10-27 10:18:31 -07:00
|
|
|
|
default:
|
|
|
|
|
|
unreachable("Invalid graphics shader stage");
|
|
|
|
|
|
}
|
2019-03-19 15:23:37 +00:00
|
|
|
|
|
|
|
|
|
|
stages[stage].feedback.duration += os_time_get_nano() - stage_start;
|
|
|
|
|
|
stages[stage].feedback.flags |= VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT;
|
2017-10-27 10:18:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pipeline->active_stages & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)
|
|
|
|
|
|
pipeline->active_stages |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
|
|
|
|
|
|
|
|
|
|
|
|
assert(pipeline->active_stages & VK_SHADER_STAGE_VERTEX_BIT);
|
|
|
|
|
|
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char sha1[20];
|
|
|
|
|
|
anv_pipeline_hash_graphics(pipeline, layout, stages, sha1);
|
|
|
|
|
|
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
|
2019-04-24 19:54:14 -05:00
|
|
|
|
if (!stages[s].entrypoint)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
stages[s].cache_key.stage = s;
|
|
|
|
|
|
memcpy(stages[s].cache_key.sha1, sha1, sizeof(sha1));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 19:56:39 -05:00
|
|
|
|
const bool skip_cache_lookup =
|
2020-03-03 15:31:50 -08:00
|
|
|
|
(pipeline->base.flags & VK_PIPELINE_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
|
2019-04-24 19:56:39 -05:00
|
|
|
|
if (!skip_cache_lookup) {
|
|
|
|
|
|
unsigned found = 0;
|
|
|
|
|
|
unsigned cache_hits = 0;
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
|
2019-04-24 19:56:39 -05:00
|
|
|
|
if (!stages[s].entrypoint)
|
|
|
|
|
|
continue;
|
2019-03-19 15:23:37 +00:00
|
|
|
|
|
2019-04-24 19:56:39 -05:00
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
2019-03-19 15:23:37 +00:00
|
|
|
|
|
2019-04-24 19:56:39 -05:00
|
|
|
|
bool cache_hit;
|
|
|
|
|
|
struct anv_shader_bin *bin =
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_device_search_for_kernel(pipeline->base.device, cache,
|
2019-04-24 19:56:39 -05:00
|
|
|
|
&stages[s].cache_key,
|
|
|
|
|
|
sizeof(stages[s].cache_key), &cache_hit);
|
|
|
|
|
|
if (bin) {
|
|
|
|
|
|
found++;
|
|
|
|
|
|
pipeline->shaders[s] = bin;
|
|
|
|
|
|
}
|
2017-10-27 15:05:02 -07:00
|
|
|
|
|
2019-04-24 19:56:39 -05:00
|
|
|
|
if (cache_hit) {
|
|
|
|
|
|
cache_hits++;
|
|
|
|
|
|
stages[s].feedback.flags |=
|
|
|
|
|
|
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
|
|
|
|
|
|
}
|
|
|
|
|
|
stages[s].feedback.duration += os_time_get_nano() - stage_start;
|
2019-03-19 15:23:37 +00:00
|
|
|
|
}
|
2019-04-24 19:56:39 -05:00
|
|
|
|
|
|
|
|
|
|
if (found == __builtin_popcount(pipeline->active_stages)) {
|
|
|
|
|
|
if (cache_hits == found) {
|
|
|
|
|
|
pipeline_feedback.flags |=
|
|
|
|
|
|
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* We found all our shaders in the cache. We're done. */
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
|
2019-04-24 03:02:35 -05:00
|
|
|
|
if (!stages[s].entrypoint)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_add_executables(&pipeline->base, &stages[s],
|
2019-04-24 03:02:35 -05:00
|
|
|
|
pipeline->shaders[s]);
|
|
|
|
|
|
}
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
anv_pipeline_init_from_cached_graphics(pipeline);
|
2019-04-24 19:56:39 -05:00
|
|
|
|
goto done;
|
|
|
|
|
|
} else if (found > 0) {
|
|
|
|
|
|
/* We found some but not all of our shaders. This shouldn't happen
|
|
|
|
|
|
* most of the time but it can if we have a partially populated
|
|
|
|
|
|
* pipeline cache.
|
|
|
|
|
|
*/
|
|
|
|
|
|
assert(found < __builtin_popcount(pipeline->active_stages));
|
|
|
|
|
|
|
2021-05-13 21:39:09 +03:00
|
|
|
|
vk_perf(VK_LOG_OBJS(&cache->base),
|
|
|
|
|
|
"Found a partial pipeline in the cache. This is "
|
|
|
|
|
|
"most likely caused by an incomplete pipeline cache "
|
|
|
|
|
|
"import or export");
|
2019-04-24 19:56:39 -05:00
|
|
|
|
|
|
|
|
|
|
/* We're going to have to recompile anyway, so just throw away our
|
|
|
|
|
|
* references to the shaders in the cache. We'll get them out of the
|
|
|
|
|
|
* cache again as part of the compilation process.
|
|
|
|
|
|
*/
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
|
2019-04-24 19:56:39 -05:00
|
|
|
|
stages[s].feedback.flags = 0;
|
|
|
|
|
|
if (pipeline->shaders[s]) {
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_shader_bin_unref(pipeline->base.device, pipeline->shaders[s]);
|
2019-04-24 19:56:39 -05:00
|
|
|
|
pipeline->shaders[s] = NULL;
|
|
|
|
|
|
}
|
2017-10-27 15:05:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-27 10:18:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-20 12:38:46 -07:00
|
|
|
|
if (info->flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT)
|
|
|
|
|
|
return VK_PIPELINE_COMPILE_REQUIRED_EXT;
|
|
|
|
|
|
|
2017-10-27 15:47:11 -07:00
|
|
|
|
void *pipeline_ctx = ralloc_context(NULL);
|
|
|
|
|
|
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
|
2017-10-27 10:18:31 -07:00
|
|
|
|
if (!stages[s].entrypoint)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
2017-10-27 10:18:31 -07:00
|
|
|
|
assert(stages[s].stage == s);
|
2017-10-27 15:05:02 -07:00
|
|
|
|
assert(pipeline->shaders[s] == NULL);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
|
2017-10-27 15:47:11 -07:00
|
|
|
|
stages[s].bind_map = (struct anv_pipeline_bind_map) {
|
|
|
|
|
|
.surface_to_descriptor = stages[s].surface_to_descriptor,
|
|
|
|
|
|
.sampler_to_descriptor = stages[s].sampler_to_descriptor
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
stages[s].nir = anv_pipeline_stage_get_nir(&pipeline->base, cache,
|
2018-10-12 17:54:41 -05:00
|
|
|
|
pipeline_ctx,
|
|
|
|
|
|
&stages[s]);
|
2018-08-08 15:42:49 +01:00
|
|
|
|
if (stages[s].nir == NULL) {
|
2021-05-13 22:48:15 +03:00
|
|
|
|
result = vk_error(VK_ERROR_UNKNOWN);
|
2017-10-27 15:47:11 -07:00
|
|
|
|
goto fail;
|
2018-08-08 15:42:49 +01:00
|
|
|
|
}
|
2019-03-19 15:23:37 +00:00
|
|
|
|
|
2020-10-19 10:12:43 +03:00
|
|
|
|
/* This is rather ugly.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Any variable annotated as interpolated by sample essentially disables
|
|
|
|
|
|
* coarse pixel shading. Unfortunately the CTS tests exercising this set
|
|
|
|
|
|
* the varying value in the previous stage using a constant. Our NIR
|
|
|
|
|
|
* infrastructure is clever enough to lookup variables across stages and
|
|
|
|
|
|
* constant fold, removing the variable. So in order to comply with CTS
|
|
|
|
|
|
* we have check variables here.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (s == MESA_SHADER_FRAGMENT) {
|
|
|
|
|
|
nir_foreach_variable_in_list(var, &stages[s].nir->variables) {
|
|
|
|
|
|
if (var->data.sample) {
|
|
|
|
|
|
stages[s].key.wm.coarse_pixel = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
stages[s].feedback.duration += os_time_get_nano() - stage_start;
|
2017-10-27 15:47:11 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 16:03:58 -07:00
|
|
|
|
/* Walk backwards to link */
|
|
|
|
|
|
struct anv_pipeline_stage *next_stage = NULL;
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (int s = ARRAY_SIZE(pipeline->shaders) - 1; s >= 0; s--) {
|
2017-10-27 16:03:58 -07:00
|
|
|
|
if (!stages[s].entrypoint)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
switch (s) {
|
|
|
|
|
|
case MESA_SHADER_VERTEX:
|
|
|
|
|
|
anv_pipeline_link_vs(compiler, &stages[s], next_stage);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_TESS_CTRL:
|
|
|
|
|
|
anv_pipeline_link_tcs(compiler, &stages[s], next_stage);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_TESS_EVAL:
|
|
|
|
|
|
anv_pipeline_link_tes(compiler, &stages[s], next_stage);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_GEOMETRY:
|
|
|
|
|
|
anv_pipeline_link_gs(compiler, &stages[s], next_stage);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_FRAGMENT:
|
|
|
|
|
|
anv_pipeline_link_fs(compiler, &stages[s]);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
unreachable("Invalid graphics shader stage");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
next_stage = &stages[s];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-29 14:41:58 -07:00
|
|
|
|
if (pipeline->base.device->info.ver >= 12 &&
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
pipeline->subpass->view_mask != 0) {
|
|
|
|
|
|
/* For some pipelines HW Primitive Replication can be used instead of
|
|
|
|
|
|
* instancing to implement Multiview. This depend on how viewIndex is
|
|
|
|
|
|
* used in all the active shaders, so this check can't be done per
|
|
|
|
|
|
* individual shaders.
|
|
|
|
|
|
*/
|
|
|
|
|
|
nir_shader *shaders[MESA_SHADER_STAGES] = {};
|
|
|
|
|
|
for (unsigned s = 0; s < MESA_SHADER_STAGES; s++)
|
|
|
|
|
|
shaders[s] = stages[s].nir;
|
|
|
|
|
|
|
|
|
|
|
|
pipeline->use_primitive_replication =
|
|
|
|
|
|
anv_check_for_primitive_replication(shaders, pipeline);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
pipeline->use_primitive_replication = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 16:54:32 -07:00
|
|
|
|
struct anv_pipeline_stage *prev_stage = NULL;
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
|
2017-10-27 15:47:11 -07:00
|
|
|
|
if (!stages[s].entrypoint)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
2017-10-27 16:54:32 -07:00
|
|
|
|
void *stage_ctx = ralloc_context(NULL);
|
|
|
|
|
|
|
2020-07-27 18:00:41 +03:00
|
|
|
|
anv_pipeline_lower_nir(&pipeline->base, stage_ctx, &stages[s], layout);
|
|
|
|
|
|
|
|
|
|
|
|
if (prev_stage && compiler->glsl_compiler_options[s].NirOptions->unify_interfaces) {
|
|
|
|
|
|
prev_stage->nir->info.outputs_written |= stages[s].nir->info.inputs_read &
|
|
|
|
|
|
~(VARYING_BIT_TESS_LEVEL_INNER | VARYING_BIT_TESS_LEVEL_OUTER);
|
|
|
|
|
|
stages[s].nir->info.inputs_read |= prev_stage->nir->info.outputs_written &
|
|
|
|
|
|
~(VARYING_BIT_TESS_LEVEL_INNER | VARYING_BIT_TESS_LEVEL_OUTER);
|
|
|
|
|
|
prev_stage->nir->info.patch_outputs_written |= stages[s].nir->info.patch_inputs_read;
|
|
|
|
|
|
stages[s].nir->info.patch_inputs_read |= prev_stage->nir->info.patch_outputs_written;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ralloc_free(stage_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
stages[s].feedback.duration += os_time_get_nano() - stage_start;
|
|
|
|
|
|
|
|
|
|
|
|
prev_stage = &stages[s];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prev_stage = NULL;
|
|
|
|
|
|
for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
|
|
|
|
|
|
if (!stages[s].entrypoint)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
|
|
|
|
|
void *stage_ctx = ralloc_context(NULL);
|
|
|
|
|
|
|
2018-09-10 16:17:37 -05:00
|
|
|
|
nir_xfb_info *xfb_info = NULL;
|
|
|
|
|
|
if (s == MESA_SHADER_VERTEX ||
|
|
|
|
|
|
s == MESA_SHADER_TESS_EVAL ||
|
|
|
|
|
|
s == MESA_SHADER_GEOMETRY)
|
|
|
|
|
|
xfb_info = nir_gather_xfb_info(stages[s].nir, stage_ctx);
|
|
|
|
|
|
|
2017-10-27 10:18:31 -07:00
|
|
|
|
switch (s) {
|
|
|
|
|
|
case MESA_SHADER_VERTEX:
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
anv_pipeline_compile_vs(compiler, stage_ctx, pipeline,
|
2019-04-24 03:19:25 -05:00
|
|
|
|
&stages[s]);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_TESS_CTRL:
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_compile_tcs(compiler, stage_ctx, pipeline->base.device,
|
2019-04-24 03:19:25 -05:00
|
|
|
|
&stages[s], prev_stage);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_TESS_EVAL:
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_compile_tes(compiler, stage_ctx, pipeline->base.device,
|
2019-04-24 03:19:25 -05:00
|
|
|
|
&stages[s], prev_stage);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_GEOMETRY:
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_compile_gs(compiler, stage_ctx, pipeline->base.device,
|
2019-04-24 03:19:25 -05:00
|
|
|
|
&stages[s], prev_stage);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
break;
|
|
|
|
|
|
case MESA_SHADER_FRAGMENT:
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_compile_fs(compiler, stage_ctx, pipeline->base.device,
|
2019-04-24 03:19:25 -05:00
|
|
|
|
&stages[s], prev_stage);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
unreachable("Invalid graphics shader stage");
|
|
|
|
|
|
}
|
2019-04-24 03:19:25 -05:00
|
|
|
|
if (stages[s].code == NULL) {
|
2017-10-27 16:54:32 -07:00
|
|
|
|
ralloc_free(stage_ctx);
|
|
|
|
|
|
result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
goto fail;
|
2017-10-27 16:54:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-07 17:16:14 -06:00
|
|
|
|
anv_nir_validate_push_layout(&stages[s].prog_data.base,
|
|
|
|
|
|
&stages[s].bind_map);
|
2019-11-08 09:42:30 -06:00
|
|
|
|
|
2017-10-27 16:54:32 -07:00
|
|
|
|
struct anv_shader_bin *bin =
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_device_upload_kernel(pipeline->base.device, cache, s,
|
2017-10-27 16:54:32 -07:00
|
|
|
|
&stages[s].cache_key,
|
|
|
|
|
|
sizeof(stages[s].cache_key),
|
2019-04-24 03:19:25 -05:00
|
|
|
|
stages[s].code,
|
|
|
|
|
|
stages[s].prog_data.base.program_size,
|
2017-10-27 16:54:32 -07:00
|
|
|
|
&stages[s].prog_data.base,
|
|
|
|
|
|
brw_prog_data_size(s),
|
2019-04-24 02:00:25 -05:00
|
|
|
|
stages[s].stats, stages[s].num_stats,
|
2018-09-10 16:17:37 -05:00
|
|
|
|
xfb_info, &stages[s].bind_map);
|
2017-10-27 16:54:32 -07:00
|
|
|
|
if (!bin) {
|
|
|
|
|
|
ralloc_free(stage_ctx);
|
|
|
|
|
|
result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
goto fail;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_add_executables(&pipeline->base, &stages[s], bin);
|
2019-04-24 03:02:35 -05:00
|
|
|
|
|
2017-10-27 16:54:32 -07:00
|
|
|
|
pipeline->shaders[s] = bin;
|
|
|
|
|
|
ralloc_free(stage_ctx);
|
|
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
stages[s].feedback.duration += os_time_get_nano() - stage_start;
|
|
|
|
|
|
|
2017-10-27 16:54:32 -07:00
|
|
|
|
prev_stage = &stages[s];
|
2017-10-27 10:18:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 15:47:11 -07:00
|
|
|
|
ralloc_free(pipeline_ctx);
|
|
|
|
|
|
|
2018-07-11 00:03:27 -07:00
|
|
|
|
done:
|
|
|
|
|
|
|
|
|
|
|
|
if (pipeline->shaders[MESA_SHADER_FRAGMENT] &&
|
|
|
|
|
|
pipeline->shaders[MESA_SHADER_FRAGMENT]->prog_data->program_size == 0) {
|
|
|
|
|
|
/* This can happen if we decided to implicitly disable the fragment
|
|
|
|
|
|
* shader. See anv_pipeline_compile_fs().
|
|
|
|
|
|
*/
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_shader_bin_unref(pipeline->base.device,
|
2018-07-11 00:03:27 -07:00
|
|
|
|
pipeline->shaders[MESA_SHADER_FRAGMENT]);
|
|
|
|
|
|
pipeline->shaders[MESA_SHADER_FRAGMENT] = NULL;
|
|
|
|
|
|
pipeline->active_stages &= ~VK_SHADER_STAGE_FRAGMENT_BIT;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
pipeline_feedback.duration = os_time_get_nano() - pipeline_start;
|
|
|
|
|
|
|
|
|
|
|
|
const VkPipelineCreationFeedbackCreateInfoEXT *create_feedback =
|
|
|
|
|
|
vk_find_struct_const(info->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO_EXT);
|
|
|
|
|
|
if (create_feedback) {
|
|
|
|
|
|
*create_feedback->pPipelineCreationFeedback = pipeline_feedback;
|
|
|
|
|
|
|
|
|
|
|
|
assert(info->stageCount == create_feedback->pipelineStageCreationFeedbackCount);
|
|
|
|
|
|
for (uint32_t i = 0; i < info->stageCount; i++) {
|
|
|
|
|
|
gl_shader_stage s = vk_to_mesa_shader_stage(info->pStages[i].stage);
|
|
|
|
|
|
create_feedback->pPipelineStageCreationFeedbacks[i] = stages[s].feedback;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-27 10:18:31 -07:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
fail:
|
2017-10-27 15:47:11 -07:00
|
|
|
|
ralloc_free(pipeline_ctx);
|
|
|
|
|
|
|
2021-01-21 16:58:50 -06:00
|
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(pipeline->shaders); s++) {
|
2017-10-27 10:18:31 -07:00
|
|
|
|
if (pipeline->shaders[s])
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_shader_bin_unref(pipeline->base.device, pipeline->shaders[s]);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
|
VkResult
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_compile_cs(struct anv_compute_pipeline *pipeline,
|
2016-01-05 12:00:54 -08:00
|
|
|
|
struct anv_pipeline_cache *cache,
|
2015-10-19 22:06:59 -07:00
|
|
|
|
const VkComputePipelineCreateInfo *info,
|
2021-03-10 17:50:15 -05:00
|
|
|
|
const struct vk_shader_module *module,
|
2016-01-12 16:30:43 -08:00
|
|
|
|
const char *entrypoint,
|
|
|
|
|
|
const VkSpecializationInfo *spec_info)
|
2015-10-19 22:06:59 -07:00
|
|
|
|
{
|
2019-03-19 15:23:37 +00:00
|
|
|
|
VkPipelineCreationFeedbackEXT pipeline_feedback = {
|
|
|
|
|
|
.flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT,
|
|
|
|
|
|
};
|
|
|
|
|
|
int64_t pipeline_start = os_time_get_nano();
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
const struct brw_compiler *compiler = pipeline->base.device->physical->compiler;
|
2017-10-26 18:42:35 -07:00
|
|
|
|
|
|
|
|
|
|
struct anv_pipeline_stage stage = {
|
|
|
|
|
|
.stage = MESA_SHADER_COMPUTE,
|
|
|
|
|
|
.module = module,
|
|
|
|
|
|
.entrypoint = entrypoint,
|
|
|
|
|
|
.spec_info = spec_info,
|
2018-08-07 19:53:38 -07:00
|
|
|
|
.cache_key = {
|
|
|
|
|
|
.stage = MESA_SHADER_COMPUTE,
|
2019-03-19 15:23:37 +00:00
|
|
|
|
},
|
|
|
|
|
|
.feedback = {
|
|
|
|
|
|
.flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT,
|
|
|
|
|
|
},
|
2017-10-26 18:42:35 -07:00
|
|
|
|
};
|
2018-10-12 17:01:24 -05:00
|
|
|
|
anv_pipeline_hash_shader(stage.module,
|
|
|
|
|
|
stage.entrypoint,
|
|
|
|
|
|
MESA_SHADER_COMPUTE,
|
|
|
|
|
|
stage.spec_info,
|
|
|
|
|
|
stage.shader_sha1);
|
2017-10-26 18:42:35 -07:00
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
|
struct anv_shader_bin *bin = NULL;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2019-02-21 14:50:10 -06:00
|
|
|
|
const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT *rss_info =
|
|
|
|
|
|
vk_find_struct_const(info->stage.pNext,
|
|
|
|
|
|
PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO_EXT);
|
|
|
|
|
|
|
2021-09-16 17:57:41 -07:00
|
|
|
|
const enum brw_subgroup_size_type subgroup_size_type =
|
|
|
|
|
|
anv_subgroup_size_type(MESA_SHADER_COMPUTE, info->stage.flags, rss_info);
|
|
|
|
|
|
|
|
|
|
|
|
populate_cs_prog_key(&pipeline->base.device->info, subgroup_size_type,
|
2021-04-09 14:42:53 -07:00
|
|
|
|
pipeline->base.device->robust_buffer_access,
|
2021-09-16 17:57:41 -07:00
|
|
|
|
&stage.key.cs);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
|
|
|
|
|
|
|
2019-04-24 19:56:39 -05:00
|
|
|
|
const bool skip_cache_lookup =
|
2020-03-03 15:31:50 -08:00
|
|
|
|
(pipeline->base.flags & VK_PIPELINE_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR);
|
2019-04-24 19:56:39 -05:00
|
|
|
|
|
2018-08-07 19:53:38 -07:00
|
|
|
|
anv_pipeline_hash_compute(pipeline, layout, &stage, stage.cache_key.sha1);
|
2019-04-24 19:56:39 -05:00
|
|
|
|
|
|
|
|
|
|
bool cache_hit = false;
|
|
|
|
|
|
if (!skip_cache_lookup) {
|
2020-03-03 15:31:50 -08:00
|
|
|
|
bin = anv_device_search_for_kernel(pipeline->base.device, cache,
|
2019-04-24 19:56:39 -05:00
|
|
|
|
&stage.cache_key,
|
|
|
|
|
|
sizeof(stage.cache_key),
|
|
|
|
|
|
&cache_hit);
|
|
|
|
|
|
}
|
2016-02-10 09:43:03 -08:00
|
|
|
|
|
2020-05-20 12:38:46 -07:00
|
|
|
|
if (bin == NULL &&
|
|
|
|
|
|
(info->flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT))
|
|
|
|
|
|
return VK_PIPELINE_COMPILE_REQUIRED_EXT;
|
|
|
|
|
|
|
2019-04-24 03:02:35 -05:00
|
|
|
|
void *mem_ctx = ralloc_context(NULL);
|
2016-08-25 01:49:49 -07:00
|
|
|
|
if (bin == NULL) {
|
2019-03-19 15:23:37 +00:00
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
2017-10-27 15:47:11 -07:00
|
|
|
|
stage.bind_map = (struct anv_pipeline_bind_map) {
|
|
|
|
|
|
.surface_to_descriptor = stage.surface_to_descriptor,
|
|
|
|
|
|
.sampler_to_descriptor = stage.sampler_to_descriptor
|
2016-03-04 12:56:14 -08:00
|
|
|
|
};
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2019-02-23 13:34:11 -06:00
|
|
|
|
/* Set up a binding for the gl_NumWorkGroups */
|
|
|
|
|
|
stage.bind_map.surface_count = 1;
|
|
|
|
|
|
stage.bind_map.surface_to_descriptor[0] = (struct anv_pipeline_binding) {
|
|
|
|
|
|
.set = ANV_DESCRIPTOR_SET_NUM_WORK_GROUPS,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
stage.nir = anv_pipeline_stage_get_nir(&pipeline->base, cache, mem_ctx, &stage);
|
2018-08-07 19:53:38 -07:00
|
|
|
|
if (stage.nir == NULL) {
|
2017-09-28 21:51:48 -07:00
|
|
|
|
ralloc_free(mem_ctx);
|
2021-05-13 22:48:15 +03:00
|
|
|
|
return vk_error(VK_ERROR_UNKNOWN);
|
2017-09-28 21:51:48 -07:00
|
|
|
|
}
|
2015-12-18 01:42:46 -08:00
|
|
|
|
|
2019-11-07 17:16:14 -06:00
|
|
|
|
NIR_PASS_V(stage.nir, anv_nir_add_base_work_group_id);
|
2018-08-07 15:47:54 -07:00
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_lower_nir(&pipeline->base, mem_ctx, &stage, layout);
|
2017-10-03 15:23:07 -07:00
|
|
|
|
|
2020-04-28 13:28:02 -07:00
|
|
|
|
NIR_PASS_V(stage.nir, brw_nir_lower_cs_intrinsics);
|
2019-06-05 14:14:23 +01:00
|
|
|
|
|
2019-04-24 02:00:25 -05:00
|
|
|
|
stage.num_stats = 1;
|
2021-03-23 21:01:21 -07:00
|
|
|
|
|
|
|
|
|
|
struct brw_compile_cs_params params = {
|
|
|
|
|
|
.nir = stage.nir,
|
|
|
|
|
|
.key = &stage.key.cs,
|
|
|
|
|
|
.prog_data = &stage.prog_data.cs,
|
|
|
|
|
|
.stats = stage.stats,
|
|
|
|
|
|
.log_data = pipeline->base.device,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
stage.code = brw_compile_cs(compiler, mem_ctx, ¶ms);
|
2019-04-24 03:19:25 -05:00
|
|
|
|
if (stage.code == NULL) {
|
2016-02-10 09:43:03 -08:00
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
}
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2019-11-07 17:16:14 -06:00
|
|
|
|
anv_nir_validate_push_layout(&stage.prog_data.base, &stage.bind_map);
|
|
|
|
|
|
|
2019-11-07 11:28:47 -06:00
|
|
|
|
if (!stage.prog_data.cs.uses_num_work_groups) {
|
|
|
|
|
|
assert(stage.bind_map.surface_to_descriptor[0].set ==
|
|
|
|
|
|
ANV_DESCRIPTOR_SET_NUM_WORK_GROUPS);
|
|
|
|
|
|
stage.bind_map.surface_to_descriptor[0].set = ANV_DESCRIPTOR_SET_NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-07 19:53:38 -07:00
|
|
|
|
const unsigned code_size = stage.prog_data.base.program_size;
|
2020-03-03 15:31:50 -08:00
|
|
|
|
bin = anv_device_upload_kernel(pipeline->base.device, cache,
|
2020-03-03 12:10:00 -08:00
|
|
|
|
MESA_SHADER_COMPUTE,
|
2018-08-07 19:53:38 -07:00
|
|
|
|
&stage.cache_key, sizeof(stage.cache_key),
|
2019-04-24 03:19:25 -05:00
|
|
|
|
stage.code, code_size,
|
2018-08-07 19:53:38 -07:00
|
|
|
|
&stage.prog_data.base,
|
|
|
|
|
|
sizeof(stage.prog_data.cs),
|
2019-04-24 02:00:25 -05:00
|
|
|
|
stage.stats, stage.num_stats,
|
2018-09-12 16:40:52 -05:00
|
|
|
|
NULL, &stage.bind_map);
|
2016-08-25 01:49:49 -07:00
|
|
|
|
if (!bin) {
|
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
}
|
2016-03-04 12:56:14 -08:00
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
stage.feedback.duration = os_time_get_nano() - stage_start;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_add_executables(&pipeline->base, &stage, bin);
|
2019-04-24 03:02:35 -05:00
|
|
|
|
|
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
|
|
2019-03-19 15:23:37 +00:00
|
|
|
|
if (cache_hit) {
|
|
|
|
|
|
stage.feedback.flags |=
|
|
|
|
|
|
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
|
|
|
|
|
|
pipeline_feedback.flags |=
|
|
|
|
|
|
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
|
|
|
|
|
|
}
|
|
|
|
|
|
pipeline_feedback.duration = os_time_get_nano() - pipeline_start;
|
|
|
|
|
|
|
|
|
|
|
|
const VkPipelineCreationFeedbackCreateInfoEXT *create_feedback =
|
|
|
|
|
|
vk_find_struct_const(info->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO_EXT);
|
|
|
|
|
|
if (create_feedback) {
|
|
|
|
|
|
*create_feedback->pPipelineCreationFeedback = pipeline_feedback;
|
|
|
|
|
|
|
|
|
|
|
|
assert(create_feedback->pipelineStageCreationFeedbackCount == 1);
|
|
|
|
|
|
create_feedback->pPipelineStageCreationFeedbacks[0] = stage.feedback;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 13:43:39 -08:00
|
|
|
|
pipeline->cs = bin;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-09 12:12:29 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Copy pipeline state not marked as dynamic.
|
|
|
|
|
|
* Dynamic state is pipeline state which hasn't been provided at pipeline
|
|
|
|
|
|
* creation time, but is dynamically provided afterwards using various
|
|
|
|
|
|
* vkCmdSet* functions.
|
|
|
|
|
|
*
|
|
|
|
|
|
* The set of state considered "non_dynamic" is determined by the pieces of
|
|
|
|
|
|
* state that have their corresponding VkDynamicState enums omitted from
|
|
|
|
|
|
* VkPipelineDynamicStateCreateInfo::pDynamicStates.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param[out] pipeline Destination non_dynamic state.
|
|
|
|
|
|
* @param[in] pCreateInfo Source of non_dynamic state to be copied.
|
|
|
|
|
|
*/
|
2015-10-07 09:28:21 -07:00
|
|
|
|
static void
|
2020-03-03 15:31:50 -08:00
|
|
|
|
copy_non_dynamic_state(struct anv_graphics_pipeline *pipeline,
|
2016-06-09 12:12:29 -07:00
|
|
|
|
const VkGraphicsPipelineCreateInfo *pCreateInfo)
|
2015-10-07 09:28:21 -07:00
|
|
|
|
{
|
2015-10-16 20:03:46 -07:00
|
|
|
|
anv_cmd_dirty_mask_t states = ANV_CMD_DIRTY_DYNAMIC_ALL;
|
2017-03-22 15:36:46 -07:00
|
|
|
|
struct anv_subpass *subpass = pipeline->subpass;
|
2015-10-19 11:39:30 -07:00
|
|
|
|
|
|
|
|
|
|
pipeline->dynamic_state = default_dynamic_state;
|
2015-10-07 09:28:21 -07:00
|
|
|
|
|
2020-10-19 10:12:43 +03:00
|
|
|
|
states &= ~pipeline->dynamic_states;
|
2015-10-07 09:28:21 -07:00
|
|
|
|
|
|
|
|
|
|
struct anv_dynamic_state *dynamic = &pipeline->dynamic_state;
|
|
|
|
|
|
|
2021-05-03 11:09:27 +03:00
|
|
|
|
bool raster_discard =
|
|
|
|
|
|
pCreateInfo->pRasterizationState->rasterizerDiscardEnable &&
|
|
|
|
|
|
!(pipeline->dynamic_states & ANV_CMD_DIRTY_DYNAMIC_RASTERIZER_DISCARD_ENABLE);
|
|
|
|
|
|
|
2016-06-09 14:48:00 -07:00
|
|
|
|
/* Section 9.2 of the Vulkan 1.0.15 spec says:
|
|
|
|
|
|
*
|
|
|
|
|
|
* pViewportState is [...] NULL if the pipeline
|
|
|
|
|
|
* has rasterization disabled.
|
|
|
|
|
|
*/
|
2021-05-03 11:09:27 +03:00
|
|
|
|
if (!raster_discard) {
|
2016-06-09 14:48:00 -07:00
|
|
|
|
assert(pCreateInfo->pViewportState);
|
|
|
|
|
|
|
|
|
|
|
|
dynamic->viewport.count = pCreateInfo->pViewportState->viewportCount;
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_VIEWPORT) {
|
2016-06-09 14:48:00 -07:00
|
|
|
|
typed_memcpy(dynamic->viewport.viewports,
|
|
|
|
|
|
pCreateInfo->pViewportState->pViewports,
|
|
|
|
|
|
pCreateInfo->pViewportState->viewportCount);
|
|
|
|
|
|
}
|
2015-10-16 12:04:13 -07:00
|
|
|
|
|
2016-06-09 14:48:00 -07:00
|
|
|
|
dynamic->scissor.count = pCreateInfo->pViewportState->scissorCount;
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_SCISSOR) {
|
2016-06-09 14:48:00 -07:00
|
|
|
|
typed_memcpy(dynamic->scissor.scissors,
|
|
|
|
|
|
pCreateInfo->pViewportState->pScissors,
|
|
|
|
|
|
pCreateInfo->pViewportState->scissorCount);
|
|
|
|
|
|
}
|
2015-10-16 12:04:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH) {
|
2015-11-30 18:05:00 -08:00
|
|
|
|
assert(pCreateInfo->pRasterizationState);
|
|
|
|
|
|
dynamic->line_width = pCreateInfo->pRasterizationState->lineWidth;
|
2015-10-16 12:04:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS) {
|
2015-11-30 18:05:00 -08:00
|
|
|
|
assert(pCreateInfo->pRasterizationState);
|
2015-11-30 14:19:41 -08:00
|
|
|
|
dynamic->depth_bias.bias =
|
2015-11-30 18:05:00 -08:00
|
|
|
|
pCreateInfo->pRasterizationState->depthBiasConstantFactor;
|
|
|
|
|
|
dynamic->depth_bias.clamp =
|
|
|
|
|
|
pCreateInfo->pRasterizationState->depthBiasClamp;
|
2015-11-30 14:19:41 -08:00
|
|
|
|
dynamic->depth_bias.slope =
|
2015-11-30 18:05:00 -08:00
|
|
|
|
pCreateInfo->pRasterizationState->depthBiasSlopeFactor;
|
2015-10-16 12:04:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-29 10:20:18 +03:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_CULL_MODE) {
|
|
|
|
|
|
assert(pCreateInfo->pRasterizationState);
|
|
|
|
|
|
dynamic->cull_mode =
|
|
|
|
|
|
pCreateInfo->pRasterizationState->cullMode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_FRONT_FACE) {
|
|
|
|
|
|
assert(pCreateInfo->pRasterizationState);
|
|
|
|
|
|
dynamic->front_face =
|
|
|
|
|
|
pCreateInfo->pRasterizationState->frontFace;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-16 08:37:26 +03:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_PRIMITIVE_TOPOLOGY) {
|
|
|
|
|
|
assert(pCreateInfo->pInputAssemblyState);
|
2021-06-11 17:47:53 -04:00
|
|
|
|
dynamic->primitive_topology = pCreateInfo->pInputAssemblyState->topology;
|
2020-06-16 08:37:26 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-03 11:09:27 +03:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_RASTERIZER_DISCARD_ENABLE) {
|
|
|
|
|
|
assert(pCreateInfo->pRasterizationState);
|
|
|
|
|
|
dynamic->raster_discard =
|
|
|
|
|
|
pCreateInfo->pRasterizationState->rasterizerDiscardEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-22 14:51:41 +03:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS_ENABLE) {
|
|
|
|
|
|
assert(pCreateInfo->pRasterizationState);
|
|
|
|
|
|
dynamic->depth_bias_enable =
|
|
|
|
|
|
pCreateInfo->pRasterizationState->depthBiasEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-15 11:13:49 +03:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_PRIMITIVE_RESTART_ENABLE) {
|
|
|
|
|
|
assert(pCreateInfo->pInputAssemblyState);
|
|
|
|
|
|
dynamic->primitive_restart_enable =
|
|
|
|
|
|
pCreateInfo->pInputAssemblyState->primitiveRestartEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-09 14:48:00 -07:00
|
|
|
|
/* Section 9.2 of the Vulkan 1.0.15 spec says:
|
|
|
|
|
|
*
|
|
|
|
|
|
* pColorBlendState is [...] NULL if the pipeline has rasterization
|
|
|
|
|
|
* disabled or if the subpass of the render pass the pipeline is
|
|
|
|
|
|
* created against does not use any color attachments.
|
|
|
|
|
|
*/
|
|
|
|
|
|
bool uses_color_att = false;
|
|
|
|
|
|
for (unsigned i = 0; i < subpass->color_count; ++i) {
|
2017-01-31 16:12:50 -08:00
|
|
|
|
if (subpass->color_attachments[i].attachment != VK_ATTACHMENT_UNUSED) {
|
2016-06-09 14:48:00 -07:00
|
|
|
|
uses_color_att = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-03 11:09:27 +03:00
|
|
|
|
if (uses_color_att && !raster_discard) {
|
2015-10-16 12:04:13 -07:00
|
|
|
|
assert(pCreateInfo->pColorBlendState);
|
2016-06-09 14:48:00 -07:00
|
|
|
|
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS)
|
2016-06-09 14:48:00 -07:00
|
|
|
|
typed_memcpy(dynamic->blend_constants,
|
|
|
|
|
|
pCreateInfo->pColorBlendState->blendConstants, 4);
|
2015-10-07 09:28:21 -07:00
|
|
|
|
}
|
2015-10-16 12:04:13 -07:00
|
|
|
|
|
2015-10-19 11:39:30 -07:00
|
|
|
|
/* If there is no depthstencil attachment, then don't read
|
|
|
|
|
|
* pDepthStencilState. The Vulkan spec states that pDepthStencilState may
|
|
|
|
|
|
* be NULL in this case. Even if pDepthStencilState is non-NULL, there is
|
|
|
|
|
|
* no need to override the depthstencil defaults in
|
|
|
|
|
|
* anv_pipeline::dynamic_state when there is no depthstencil attachment.
|
|
|
|
|
|
*
|
2016-06-09 14:48:00 -07:00
|
|
|
|
* Section 9.2 of the Vulkan 1.0.15 spec says:
|
2015-10-19 11:39:30 -07:00
|
|
|
|
*
|
2016-06-09 14:48:00 -07:00
|
|
|
|
* pDepthStencilState is [...] NULL if the pipeline has rasterization
|
|
|
|
|
|
* disabled or if the subpass of the render pass the pipeline is created
|
|
|
|
|
|
* against does not use a depth/stencil attachment.
|
2015-10-19 11:39:30 -07:00
|
|
|
|
*/
|
2021-05-03 11:09:27 +03:00
|
|
|
|
if (!raster_discard && subpass->depth_stencil_attachment) {
|
2016-06-09 14:48:00 -07:00
|
|
|
|
assert(pCreateInfo->pDepthStencilState);
|
|
|
|
|
|
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS) {
|
2015-10-19 11:39:30 -07:00
|
|
|
|
dynamic->depth_bounds.min =
|
|
|
|
|
|
pCreateInfo->pDepthStencilState->minDepthBounds;
|
|
|
|
|
|
dynamic->depth_bounds.max =
|
|
|
|
|
|
pCreateInfo->pDepthStencilState->maxDepthBounds;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK) {
|
2015-10-19 11:39:30 -07:00
|
|
|
|
dynamic->stencil_compare_mask.front =
|
2015-11-30 14:19:41 -08:00
|
|
|
|
pCreateInfo->pDepthStencilState->front.compareMask;
|
2015-10-19 11:39:30 -07:00
|
|
|
|
dynamic->stencil_compare_mask.back =
|
2015-11-30 14:19:41 -08:00
|
|
|
|
pCreateInfo->pDepthStencilState->back.compareMask;
|
2015-10-19 11:39:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK) {
|
2015-10-19 11:39:30 -07:00
|
|
|
|
dynamic->stencil_write_mask.front =
|
2015-11-30 14:19:41 -08:00
|
|
|
|
pCreateInfo->pDepthStencilState->front.writeMask;
|
2015-10-19 11:39:30 -07:00
|
|
|
|
dynamic->stencil_write_mask.back =
|
2015-11-30 14:19:41 -08:00
|
|
|
|
pCreateInfo->pDepthStencilState->back.writeMask;
|
2015-10-19 11:39:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-22 18:25:50 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE) {
|
2015-10-19 11:39:30 -07:00
|
|
|
|
dynamic->stencil_reference.front =
|
2015-11-30 14:19:41 -08:00
|
|
|
|
pCreateInfo->pDepthStencilState->front.reference;
|
2015-10-19 11:39:30 -07:00
|
|
|
|
dynamic->stencil_reference.back =
|
2015-11-30 14:19:41 -08:00
|
|
|
|
pCreateInfo->pDepthStencilState->back.reference;
|
2015-10-19 11:39:30 -07:00
|
|
|
|
}
|
2020-08-08 10:28:43 +03:00
|
|
|
|
|
|
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_DEPTH_TEST_ENABLE) {
|
|
|
|
|
|
dynamic->depth_test_enable =
|
|
|
|
|
|
pCreateInfo->pDepthStencilState->depthTestEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_DEPTH_WRITE_ENABLE) {
|
|
|
|
|
|
dynamic->depth_write_enable =
|
|
|
|
|
|
pCreateInfo->pDepthStencilState->depthWriteEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_DEPTH_COMPARE_OP) {
|
|
|
|
|
|
dynamic->depth_compare_op =
|
|
|
|
|
|
pCreateInfo->pDepthStencilState->depthCompareOp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE) {
|
|
|
|
|
|
dynamic->depth_bounds_test_enable =
|
|
|
|
|
|
pCreateInfo->pDepthStencilState->depthBoundsTestEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_STENCIL_TEST_ENABLE) {
|
|
|
|
|
|
dynamic->stencil_test_enable =
|
|
|
|
|
|
pCreateInfo->pDepthStencilState->stencilTestEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_STENCIL_OP) {
|
|
|
|
|
|
const VkPipelineDepthStencilStateCreateInfo *info =
|
|
|
|
|
|
pCreateInfo->pDepthStencilState;
|
|
|
|
|
|
memcpy(&dynamic->stencil_op.front, &info->front,
|
|
|
|
|
|
sizeof(dynamic->stencil_op.front));
|
|
|
|
|
|
memcpy(&dynamic->stencil_op.back, &info->back,
|
|
|
|
|
|
sizeof(dynamic->stencil_op.back));
|
|
|
|
|
|
}
|
2015-10-16 12:04:13 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-22 22:44:59 -05:00
|
|
|
|
const VkPipelineRasterizationLineStateCreateInfoEXT *line_state =
|
|
|
|
|
|
vk_find_struct_const(pCreateInfo->pRasterizationState->pNext,
|
|
|
|
|
|
PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT);
|
2021-07-28 20:32:15 -07:00
|
|
|
|
if (!raster_discard && line_state && line_state->stippledLineEnable) {
|
2019-05-22 22:44:59 -05:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE) {
|
|
|
|
|
|
dynamic->line_stipple.factor = line_state->lineStippleFactor;
|
|
|
|
|
|
dynamic->line_stipple.pattern = line_state->lineStipplePattern;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-16 11:08:46 +03:00
|
|
|
|
const VkPipelineMultisampleStateCreateInfo *ms_info =
|
2021-06-25 10:14:21 +02:00
|
|
|
|
pCreateInfo->pRasterizationState->rasterizerDiscardEnable ? NULL :
|
2021-04-16 11:08:46 +03:00
|
|
|
|
pCreateInfo->pMultisampleState;
|
2019-03-14 21:52:02 +02:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_SAMPLE_LOCATIONS) {
|
|
|
|
|
|
const VkPipelineSampleLocationsStateCreateInfoEXT *sl_info = ms_info ?
|
|
|
|
|
|
vk_find_struct_const(ms_info, PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT) : NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (sl_info) {
|
|
|
|
|
|
dynamic->sample_locations.samples =
|
|
|
|
|
|
sl_info->sampleLocationsInfo.sampleLocationsCount;
|
|
|
|
|
|
const VkSampleLocationEXT *positions =
|
|
|
|
|
|
sl_info->sampleLocationsInfo.pSampleLocations;
|
|
|
|
|
|
for (uint32_t i = 0; i < dynamic->sample_locations.samples; i++) {
|
|
|
|
|
|
dynamic->sample_locations.locations[i].x = positions[i].x;
|
|
|
|
|
|
dynamic->sample_locations.locations[i].y = positions[i].y;
|
|
|
|
|
|
}
|
2021-04-16 11:08:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/* Ensure we always have valid values for sample_locations. */
|
|
|
|
|
|
if (pipeline->base.device->vk.enabled_extensions.EXT_sample_locations &&
|
|
|
|
|
|
dynamic->sample_locations.samples == 0) {
|
|
|
|
|
|
dynamic->sample_locations.samples =
|
|
|
|
|
|
ms_info ? ms_info->rasterizationSamples : 1;
|
|
|
|
|
|
const struct intel_sample_position *positions =
|
|
|
|
|
|
intel_get_sample_positions(dynamic->sample_locations.samples);
|
|
|
|
|
|
for (uint32_t i = 0; i < dynamic->sample_locations.samples; i++) {
|
|
|
|
|
|
dynamic->sample_locations.locations[i].x = positions[i].x;
|
|
|
|
|
|
dynamic->sample_locations.locations[i].y = positions[i].y;
|
2019-03-14 21:52:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-31 19:40:21 +03:00
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_COLOR_BLEND_STATE) {
|
|
|
|
|
|
if (!pCreateInfo->pRasterizationState->rasterizerDiscardEnable &&
|
|
|
|
|
|
uses_color_att) {
|
|
|
|
|
|
assert(pCreateInfo->pColorBlendState);
|
|
|
|
|
|
const VkPipelineColorWriteCreateInfoEXT *color_write_info =
|
|
|
|
|
|
vk_find_struct_const(pCreateInfo->pColorBlendState->pNext,
|
|
|
|
|
|
PIPELINE_COLOR_WRITE_CREATE_INFO_EXT);
|
|
|
|
|
|
|
|
|
|
|
|
if (color_write_info) {
|
|
|
|
|
|
dynamic->color_writes = 0;
|
|
|
|
|
|
for (uint32_t i = 0; i < color_write_info->attachmentCount; i++) {
|
|
|
|
|
|
dynamic->color_writes |=
|
|
|
|
|
|
color_write_info->pColorWriteEnables[i] ? (1u << i) : 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-19 10:12:43 +03:00
|
|
|
|
const VkPipelineFragmentShadingRateStateCreateInfoKHR *fsr_state =
|
|
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
|
|
|
|
|
PIPELINE_FRAGMENT_SHADING_RATE_STATE_CREATE_INFO_KHR);
|
|
|
|
|
|
if (fsr_state) {
|
|
|
|
|
|
if (states & ANV_CMD_DIRTY_DYNAMIC_SHADING_RATE)
|
|
|
|
|
|
dynamic->fragment_shading_rate = fsr_state->fragmentSize;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-16 12:04:13 -07:00
|
|
|
|
pipeline->dynamic_state_mask = states;
|
2021-04-13 17:53:18 +03:00
|
|
|
|
|
2020-10-19 10:12:43 +03:00
|
|
|
|
/* Mark states that can either be dynamic or fully baked into the pipeline.
|
2021-04-13 17:53:18 +03:00
|
|
|
|
*/
|
2021-03-31 19:40:21 +03:00
|
|
|
|
pipeline->static_state_mask = states &
|
|
|
|
|
|
(ANV_CMD_DIRTY_DYNAMIC_SAMPLE_LOCATIONS |
|
2020-10-19 10:12:43 +03:00
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_COLOR_BLEND_STATE |
|
2021-05-03 11:09:27 +03:00
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_SHADING_RATE |
|
2021-06-02 15:33:26 +03:00
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_RASTERIZER_DISCARD_ENABLE |
|
2021-06-15 09:55:51 +03:00
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_LOGIC_OP |
|
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_PRIMITIVE_TOPOLOGY);
|
2015-10-07 09:28:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-16 20:31:39 -07:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_validate_create_info(const VkGraphicsPipelineCreateInfo *info)
|
|
|
|
|
|
{
|
2017-03-07 09:25:14 -08:00
|
|
|
|
#ifdef DEBUG
|
2015-10-16 20:31:39 -07:00
|
|
|
|
struct anv_render_pass *renderpass = NULL;
|
|
|
|
|
|
struct anv_subpass *subpass = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* Assert that all required members of VkGraphicsPipelineCreateInfo are
|
2016-09-29 11:42:43 -07:00
|
|
|
|
* present. See the Vulkan 1.0.28 spec, Section 9.2 Graphics Pipelines.
|
2015-10-16 20:31:39 -07:00
|
|
|
|
*/
|
|
|
|
|
|
assert(info->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
|
|
|
|
|
|
|
|
|
|
|
|
renderpass = anv_render_pass_from_handle(info->renderPass);
|
|
|
|
|
|
assert(renderpass);
|
|
|
|
|
|
|
2016-10-07 15:06:47 -07:00
|
|
|
|
assert(info->subpass < renderpass->subpass_count);
|
|
|
|
|
|
subpass = &renderpass->subpasses[info->subpass];
|
2015-10-16 20:31:39 -07:00
|
|
|
|
|
|
|
|
|
|
assert(info->stageCount >= 1);
|
2015-11-30 18:05:00 -08:00
|
|
|
|
assert(info->pRasterizationState);
|
2016-09-29 11:42:43 -07:00
|
|
|
|
if (!info->pRasterizationState->rasterizerDiscardEnable) {
|
|
|
|
|
|
assert(info->pViewportState);
|
|
|
|
|
|
assert(info->pMultisampleState);
|
2015-10-16 20:31:39 -07:00
|
|
|
|
|
2018-06-26 09:22:20 -07:00
|
|
|
|
if (subpass && subpass->depth_stencil_attachment)
|
2016-09-29 11:42:43 -07:00
|
|
|
|
assert(info->pDepthStencilState);
|
2015-10-16 20:31:39 -07:00
|
|
|
|
|
2018-05-07 08:42:56 +02:00
|
|
|
|
if (subpass && subpass->color_count > 0) {
|
|
|
|
|
|
bool all_color_unused = true;
|
|
|
|
|
|
for (int i = 0; i < subpass->color_count; i++) {
|
|
|
|
|
|
if (subpass->color_attachments[i].attachment != VK_ATTACHMENT_UNUSED)
|
|
|
|
|
|
all_color_unused = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* pColorBlendState is ignored if the pipeline has rasterization
|
|
|
|
|
|
* disabled or if the subpass of the render pass the pipeline is
|
|
|
|
|
|
* created against does not use any color attachments.
|
|
|
|
|
|
*/
|
|
|
|
|
|
assert(info->pColorBlendState || all_color_unused);
|
|
|
|
|
|
}
|
2016-09-29 11:42:43 -07:00
|
|
|
|
}
|
2015-10-16 20:31:39 -07:00
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < info->stageCount; ++i) {
|
|
|
|
|
|
switch (info->pStages[i].stage) {
|
2021-05-19 11:26:21 -07:00
|
|
|
|
case VK_SHADER_STAGE_VERTEX_BIT:
|
|
|
|
|
|
assert(info->pVertexInputState);
|
|
|
|
|
|
assert(info->pInputAssemblyState);
|
|
|
|
|
|
break;
|
2015-12-02 16:08:13 -08:00
|
|
|
|
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
|
|
|
|
|
|
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
|
2015-10-16 20:31:39 -07:00
|
|
|
|
assert(info->pTessellationState);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-03-07 09:25:14 -08:00
|
|
|
|
#endif
|
2015-10-16 20:31:39 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-22 16:56:48 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Calculate the desired L3 partitioning based on the current state of the
|
|
|
|
|
|
* pipeline. For now this simply returns the conservative defaults calculated
|
|
|
|
|
|
* by get_default_l3_weights(), but we could probably do better by gathering
|
|
|
|
|
|
* more statistics from the pipeline state (e.g. guess of expected URB usage
|
|
|
|
|
|
* and bound surfaces), or by using feed-back from performance counters.
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm)
|
|
|
|
|
|
{
|
2021-04-05 13:19:39 -07:00
|
|
|
|
const struct intel_device_info *devinfo = &pipeline->device->info;
|
2016-08-22 16:56:48 -07:00
|
|
|
|
|
2021-03-03 13:49:18 -08:00
|
|
|
|
const struct intel_l3_weights w =
|
|
|
|
|
|
intel_get_default_l3_weights(devinfo, true, needs_slm);
|
2016-08-22 16:56:48 -07:00
|
|
|
|
|
2021-03-03 13:49:18 -08:00
|
|
|
|
pipeline->l3_config = intel_get_l3_config(devinfo, w);
|
2016-08-22 16:56:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-15 09:55:51 +03:00
|
|
|
|
static VkLineRasterizationModeEXT
|
|
|
|
|
|
vk_line_rasterization_mode(const VkPipelineRasterizationLineStateCreateInfoEXT *line_info,
|
|
|
|
|
|
const VkPipelineMultisampleStateCreateInfo *ms_info)
|
|
|
|
|
|
{
|
|
|
|
|
|
VkLineRasterizationModeEXT line_mode =
|
|
|
|
|
|
line_info ? line_info->lineRasterizationMode :
|
|
|
|
|
|
VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
|
|
|
|
|
|
|
|
|
|
|
|
if (line_mode == VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT) {
|
|
|
|
|
|
if (ms_info && ms_info->rasterizationSamples > 1) {
|
|
|
|
|
|
return VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return line_mode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-20 22:53:54 -07:00
|
|
|
|
VkResult
|
2020-06-13 13:57:32 -05:00
|
|
|
|
anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline,
|
|
|
|
|
|
struct anv_device *device,
|
|
|
|
|
|
struct anv_pipeline_cache *cache,
|
|
|
|
|
|
const VkGraphicsPipelineCreateInfo *pCreateInfo,
|
|
|
|
|
|
const VkAllocationCallbacks *alloc)
|
2015-08-20 22:53:54 -07:00
|
|
|
|
{
|
2016-01-03 22:42:01 -08:00
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
2017-03-07 09:25:14 -08:00
|
|
|
|
anv_pipeline_validate_create_info(pCreateInfo);
|
2015-10-16 20:31:39 -07:00
|
|
|
|
|
2020-06-13 13:57:32 -05:00
|
|
|
|
result = anv_pipeline_init(&pipeline->base, device,
|
|
|
|
|
|
ANV_PIPELINE_GRAPHICS, pCreateInfo->flags,
|
|
|
|
|
|
alloc);
|
2016-01-03 22:42:01 -08:00
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return result;
|
2015-12-02 03:28:27 -08:00
|
|
|
|
|
2020-06-16 10:50:19 -05:00
|
|
|
|
anv_batch_set_storage(&pipeline->base.batch, ANV_NULL_ADDRESS,
|
|
|
|
|
|
pipeline->batch_data, sizeof(pipeline->batch_data));
|
2015-08-20 22:53:54 -07:00
|
|
|
|
|
2020-06-13 13:57:32 -05:00
|
|
|
|
ANV_FROM_HANDLE(anv_render_pass, render_pass, pCreateInfo->renderPass);
|
|
|
|
|
|
assert(pCreateInfo->subpass < render_pass->subpass_count);
|
|
|
|
|
|
pipeline->subpass = &render_pass->subpasses[pCreateInfo->subpass];
|
2019-04-24 19:56:39 -05:00
|
|
|
|
|
2020-01-03 13:23:32 -08:00
|
|
|
|
assert(pCreateInfo->pRasterizationState);
|
|
|
|
|
|
|
2020-10-19 10:12:43 +03:00
|
|
|
|
if (pCreateInfo->pDynamicState) {
|
|
|
|
|
|
/* Remove all of the states that are marked as dynamic */
|
|
|
|
|
|
uint32_t count = pCreateInfo->pDynamicState->dynamicStateCount;
|
|
|
|
|
|
for (uint32_t s = 0; s < count; s++) {
|
|
|
|
|
|
pipeline->dynamic_states |= anv_cmd_dirty_bit_for_vk_dynamic_state(
|
|
|
|
|
|
pCreateInfo->pDynamicState->pDynamicStates[s]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-09 12:12:29 -07:00
|
|
|
|
copy_non_dynamic_state(pipeline, pCreateInfo);
|
2020-10-19 10:12:43 +03:00
|
|
|
|
|
2020-01-03 13:23:32 -08:00
|
|
|
|
pipeline->depth_clamp_enable = pCreateInfo->pRasterizationState->depthClampEnable;
|
2015-10-07 09:28:21 -07:00
|
|
|
|
|
2019-01-14 18:06:33 +00:00
|
|
|
|
/* Previously we enabled depth clipping when !depthClampEnable.
|
|
|
|
|
|
* DepthClipStateCreateInfo now makes depth clipping explicit so if the
|
|
|
|
|
|
* clipping info is available, use its enable value to determine clipping,
|
|
|
|
|
|
* otherwise fallback to the previous !depthClampEnable logic.
|
|
|
|
|
|
*/
|
|
|
|
|
|
const VkPipelineRasterizationDepthClipStateCreateInfoEXT *clip_info =
|
|
|
|
|
|
vk_find_struct_const(pCreateInfo->pRasterizationState->pNext,
|
|
|
|
|
|
PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT);
|
|
|
|
|
|
pipeline->depth_clip_enable = clip_info ? clip_info->depthClipEnable : !pipeline->depth_clamp_enable;
|
|
|
|
|
|
|
2020-01-03 13:23:32 -08:00
|
|
|
|
pipeline->sample_shading_enable =
|
|
|
|
|
|
!pCreateInfo->pRasterizationState->rasterizerDiscardEnable &&
|
|
|
|
|
|
pCreateInfo->pMultisampleState &&
|
|
|
|
|
|
pCreateInfo->pMultisampleState->sampleShadingEnable;
|
2017-03-23 11:56:06 +01:00
|
|
|
|
|
2017-10-27 10:18:31 -07:00
|
|
|
|
result = anv_pipeline_compile_graphics(pipeline, cache, pCreateInfo);
|
|
|
|
|
|
if (result != VK_SUCCESS) {
|
2020-06-13 13:57:32 -05:00
|
|
|
|
anv_pipeline_finish(&pipeline->base, device, alloc);
|
2017-10-27 10:18:31 -07:00
|
|
|
|
return result;
|
2015-08-20 22:53:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-15 13:09:30 -07:00
|
|
|
|
assert(pipeline->shaders[MESA_SHADER_VERTEX]);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2020-03-03 15:31:50 -08:00
|
|
|
|
anv_pipeline_setup_l3_config(&pipeline->base, false);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
2015-08-20 22:53:54 -07:00
|
|
|
|
const VkPipelineVertexInputStateCreateInfo *vi_info =
|
|
|
|
|
|
pCreateInfo->pVertexInputState;
|
2015-12-29 13:03:01 -08:00
|
|
|
|
|
2016-10-07 15:29:47 -07:00
|
|
|
|
const uint64_t inputs_read = get_vs_prog_data(pipeline)->inputs_read;
|
2015-12-29 13:03:01 -08:00
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < vi_info->vertexAttributeDescriptionCount; i++) {
|
|
|
|
|
|
const VkVertexInputAttributeDescription *desc =
|
|
|
|
|
|
&vi_info->pVertexAttributeDescriptions[i];
|
|
|
|
|
|
|
2017-07-14 10:31:38 +00:00
|
|
|
|
if (inputs_read & (1ull << (VERT_ATTRIB_GENERIC0 + desc->location)))
|
2015-12-29 13:03:01 -08:00
|
|
|
|
pipeline->vb_used |= 1 << desc->binding;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-11-30 17:00:30 -08:00
|
|
|
|
for (uint32_t i = 0; i < vi_info->vertexBindingDescriptionCount; i++) {
|
2015-08-20 22:53:54 -07:00
|
|
|
|
const VkVertexInputBindingDescription *desc =
|
|
|
|
|
|
&vi_info->pVertexBindingDescriptions[i];
|
|
|
|
|
|
|
2018-07-02 12:44:49 -07:00
|
|
|
|
pipeline->vb[desc->binding].stride = desc->stride;
|
2015-08-20 22:53:54 -07:00
|
|
|
|
|
|
|
|
|
|
/* Step rate is programmed per vertex element (attribute), not
|
|
|
|
|
|
* binding. Set up a map of which bindings step per instance, for
|
|
|
|
|
|
* reference by vertex element setup. */
|
2015-11-30 13:28:09 -08:00
|
|
|
|
switch (desc->inputRate) {
|
2015-08-20 22:53:54 -07:00
|
|
|
|
default:
|
2015-11-30 13:28:09 -08:00
|
|
|
|
case VK_VERTEX_INPUT_RATE_VERTEX:
|
2018-07-02 12:44:49 -07:00
|
|
|
|
pipeline->vb[desc->binding].instanced = false;
|
2015-08-20 22:53:54 -07:00
|
|
|
|
break;
|
2015-11-30 13:28:09 -08:00
|
|
|
|
case VK_VERTEX_INPUT_RATE_INSTANCE:
|
2018-07-02 12:44:49 -07:00
|
|
|
|
pipeline->vb[desc->binding].instanced = true;
|
2015-08-20 22:53:54 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2018-07-02 12:49:06 -07:00
|
|
|
|
|
|
|
|
|
|
pipeline->vb[desc->binding].instance_divisor = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-02 12:57:44 -07:00
|
|
|
|
const VkPipelineVertexInputDivisorStateCreateInfoEXT *vi_div_state =
|
|
|
|
|
|
vk_find_struct_const(vi_info->pNext,
|
|
|
|
|
|
PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT);
|
|
|
|
|
|
if (vi_div_state) {
|
|
|
|
|
|
for (uint32_t i = 0; i < vi_div_state->vertexBindingDivisorCount; i++) {
|
|
|
|
|
|
const VkVertexInputBindingDivisorDescriptionEXT *desc =
|
|
|
|
|
|
&vi_div_state->pVertexBindingDivisors[i];
|
|
|
|
|
|
|
|
|
|
|
|
pipeline->vb[desc->binding].instance_divisor = desc->divisor;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-02 12:49:06 -07:00
|
|
|
|
|
|
|
|
|
|
/* Our implementation of VK_KHR_multiview uses instancing to draw the
|
|
|
|
|
|
* different views. If the client asks for instancing, we need to multiply
|
|
|
|
|
|
* the instance divisor by the number of views ensure that we repeat the
|
|
|
|
|
|
* client's per-instance data once for each view.
|
|
|
|
|
|
*/
|
anv/gen12: Lower VK_KHR_multiview using Primitive Replication
Identify if view_index is used only for position calculation, and use
Primitive Replication to implement Multiview in Gen12. This feature
allows storing per-view position information in a single execution of
the shader, treating position as an array.
The shader is transformed by adding a for-loop around it, that have an
iteration per active view (in the view_mask). Stores to the position
now store into the position array for the current index in the loop,
and load_view_index() will return the view index corresponding to the
current index in the loop.
The feature is controlled by setting the environment variable
ANV_PRIMITIVE_REPLICATION_MAX_VIEWS, which defaults to 2 if unset.
For pipelines with view counts larger than that, the regular
instancing will be used instead of Primitive Replication. To disable
it completely set the variable to 0.
v2: Don't assume position is set in vertex shader; remove only stores
for position; don't apply optimizations since other passes will
do; clone shader body without extract/reinsert; don't use
last_block (potentially stale). (Jason)
Fix view_index immediate to contain the view index, not its order.
Check for maximum number of views supported.
Add guard for gen12.
v3: Clone the entire shader function and change it before reinsert;
disable optimization when shader has memory writes. (Jason)
Use a single environment variable with _DEBUG on the name.
v4: Change to use new nir_deref_instr.
When removing stores, look for mode nir_var_shader_out instead
of the walking the list of outputs.
Ensure unused derefs are removed in the non-position part of the
shader.
Remove dead control flow when identifying if can use or not
primitive replication.
v5: Consider all the active shaders (including fragment) when deciding
that Primitive Replication can be used.
Change environment variable to ANV_PRIMITIVE_REPLICATION.
Squash the emission of 3DSTATE_PRIMITIVE_REPLICATION into this patch.
Disable Prim Rep in blorp_exec_3d.
v6: Use a loop around the shader, instead of manually unrolling, since
the regular unroll pass will kick in.
Document that we don't expect to see copy_deref or load_deref
involving the position variable.
Recover use_primitive_replication value when loading pipeline from
the cache.
Set VARYING_SLOT_LAYER to 0 in the shader. Earlier versions were
relying on ForceZeroRTAIndexEnable but that might not be
sufficient.
Disable Prim Rep in cmd_buffer_so_memcpy.
v7: Don't use Primitive Replication if position is not set, fallback
to instancing; change environment variable to be
ANV_PRIMITVE_REPLICATION_MAX_VIEWS and default it to 2 based on
experiments.
Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2313>
2018-03-27 10:10:34 -07:00
|
|
|
|
if (pipeline->subpass->view_mask && !pipeline->use_primitive_replication) {
|
2018-07-02 12:49:06 -07:00
|
|
|
|
const uint32_t view_count = anv_subpass_view_count(pipeline->subpass);
|
|
|
|
|
|
for (uint32_t vb = 0; vb < MAX_VBS; vb++) {
|
|
|
|
|
|
if (pipeline->vb[vb].instanced)
|
|
|
|
|
|
pipeline->vb[vb].instance_divisor *= view_count;
|
|
|
|
|
|
}
|
2015-08-20 22:53:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const VkPipelineInputAssemblyStateCreateInfo *ia_info =
|
|
|
|
|
|
pCreateInfo->pInputAssemblyState;
|
2016-09-25 15:29:16 -07:00
|
|
|
|
const VkPipelineTessellationStateCreateInfo *tess_info =
|
|
|
|
|
|
pCreateInfo->pTessellationState;
|
|
|
|
|
|
|
|
|
|
|
|
if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
|
|
|
|
|
|
pipeline->topology = _3DPRIM_PATCHLIST(tess_info->patchControlPoints);
|
|
|
|
|
|
else
|
2021-04-19 15:50:14 -07:00
|
|
|
|
pipeline->topology = vk_to_intel_primitive_type[ia_info->topology];
|
2015-08-20 22:53:54 -07:00
|
|
|
|
|
2021-06-15 09:55:51 +03:00
|
|
|
|
/* If rasterization is not enabled, ms_info must be ignored. */
|
|
|
|
|
|
const bool raster_enabled =
|
|
|
|
|
|
!pCreateInfo->pRasterizationState->rasterizerDiscardEnable ||
|
|
|
|
|
|
(pipeline->dynamic_states &
|
|
|
|
|
|
ANV_CMD_DIRTY_DYNAMIC_RASTERIZER_DISCARD_ENABLE);
|
|
|
|
|
|
|
|
|
|
|
|
const VkPipelineMultisampleStateCreateInfo *ms_info =
|
|
|
|
|
|
raster_enabled ? pCreateInfo->pMultisampleState : NULL;
|
|
|
|
|
|
|
|
|
|
|
|
const VkPipelineRasterizationLineStateCreateInfoEXT *line_info =
|
|
|
|
|
|
vk_find_struct_const(pCreateInfo->pRasterizationState->pNext,
|
|
|
|
|
|
PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT);
|
|
|
|
|
|
|
|
|
|
|
|
/* Store line mode, polygon mode and rasterization samples, these are used
|
|
|
|
|
|
* for dynamic primitive topology.
|
|
|
|
|
|
*/
|
|
|
|
|
|
pipeline->line_mode = vk_line_rasterization_mode(line_info, ms_info);
|
|
|
|
|
|
pipeline->polygon_mode = pCreateInfo->pRasterizationState->polygonMode;
|
|
|
|
|
|
pipeline->rasterization_samples =
|
|
|
|
|
|
ms_info ? ms_info->rasterizationSamples : 1;
|
|
|
|
|
|
|
2015-08-20 22:53:54 -07:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
2019-04-24 03:02:35 -05:00
|
|
|
|
|
2021-01-21 15:28:28 -06:00
|
|
|
|
static VkResult
|
|
|
|
|
|
compile_upload_rt_shader(struct anv_ray_tracing_pipeline *pipeline,
|
2021-04-03 12:01:19 +03:00
|
|
|
|
struct anv_pipeline_cache *cache,
|
2021-01-21 15:28:28 -06:00
|
|
|
|
nir_shader *nir,
|
|
|
|
|
|
struct anv_pipeline_stage *stage,
|
|
|
|
|
|
struct anv_shader_bin **shader_out,
|
|
|
|
|
|
void *mem_ctx)
|
|
|
|
|
|
{
|
|
|
|
|
|
const struct brw_compiler *compiler =
|
|
|
|
|
|
pipeline->base.device->physical->compiler;
|
|
|
|
|
|
const struct intel_device_info *devinfo = compiler->devinfo;
|
|
|
|
|
|
|
|
|
|
|
|
nir_shader **resume_shaders = NULL;
|
|
|
|
|
|
uint32_t num_resume_shaders = 0;
|
|
|
|
|
|
if (nir->info.stage != MESA_SHADER_COMPUTE) {
|
2021-05-28 15:06:09 +03:00
|
|
|
|
NIR_PASS_V(nir, nir_lower_shader_calls,
|
|
|
|
|
|
nir_address_format_64bit_global,
|
|
|
|
|
|
BRW_BTD_STACK_ALIGN,
|
2021-01-21 15:28:28 -06:00
|
|
|
|
&resume_shaders, &num_resume_shaders, mem_ctx);
|
2021-05-28 15:06:09 +03:00
|
|
|
|
NIR_PASS_V(nir, brw_nir_lower_shader_calls);
|
|
|
|
|
|
NIR_PASS_V(nir, brw_nir_lower_rt_intrinsics, devinfo);
|
2021-01-21 15:28:28 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-28 15:06:09 +03:00
|
|
|
|
for (unsigned i = 0; i < num_resume_shaders; i++) {
|
|
|
|
|
|
NIR_PASS_V(resume_shaders[i], brw_nir_lower_shader_calls);
|
2021-01-21 15:28:28 -06:00
|
|
|
|
NIR_PASS_V(resume_shaders[i], brw_nir_lower_rt_intrinsics, devinfo);
|
2021-05-28 15:06:09 +03:00
|
|
|
|
}
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
stage->code =
|
2021-01-21 15:28:28 -06:00
|
|
|
|
brw_compile_bs(compiler, pipeline->base.device, mem_ctx,
|
2021-04-02 17:18:47 +03:00
|
|
|
|
&stage->key.bs, &stage->prog_data.bs, nir,
|
|
|
|
|
|
num_resume_shaders, resume_shaders, stage->stats, NULL);
|
2021-04-03 12:01:19 +03:00
|
|
|
|
if (stage->code == NULL)
|
2021-01-21 15:28:28 -06:00
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
|
|
|
|
|
|
/* Ray-tracing shaders don't have a "real" bind map */
|
|
|
|
|
|
struct anv_pipeline_bind_map empty_bind_map = {};
|
|
|
|
|
|
|
2021-04-02 17:18:47 +03:00
|
|
|
|
const unsigned code_size = stage->prog_data.base.program_size;
|
2021-01-21 15:28:28 -06:00
|
|
|
|
struct anv_shader_bin *bin =
|
|
|
|
|
|
anv_device_upload_kernel(pipeline->base.device,
|
2021-04-03 12:01:19 +03:00
|
|
|
|
cache,
|
2021-01-21 15:28:28 -06:00
|
|
|
|
stage->stage,
|
2021-04-03 12:01:19 +03:00
|
|
|
|
&stage->cache_key, sizeof(stage->cache_key),
|
|
|
|
|
|
stage->code, code_size,
|
2021-04-02 17:18:47 +03:00
|
|
|
|
&stage->prog_data.base,
|
|
|
|
|
|
sizeof(stage->prog_data.bs),
|
|
|
|
|
|
stage->stats, 1,
|
2021-01-21 15:28:28 -06:00
|
|
|
|
NULL, &empty_bind_map);
|
|
|
|
|
|
if (bin == NULL)
|
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
|
|
|
|
|
|
/* TODO: Figure out executables for resume shaders */
|
|
|
|
|
|
anv_pipeline_add_executables(&pipeline->base, stage, bin);
|
|
|
|
|
|
util_dynarray_append(&pipeline->shaders, struct anv_shader_bin *, bin);
|
|
|
|
|
|
|
|
|
|
|
|
*shader_out = bin;
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-21 15:38:01 -06:00
|
|
|
|
static bool
|
|
|
|
|
|
is_rt_stack_size_dynamic(const VkRayTracingPipelineCreateInfoKHR *info)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (info->pDynamicState == NULL)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < info->pDynamicState->dynamicStateCount; i++) {
|
|
|
|
|
|
if (info->pDynamicState->pDynamicStates[i] ==
|
|
|
|
|
|
VK_DYNAMIC_STATE_RAY_TRACING_PIPELINE_STACK_SIZE_KHR)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
static void
|
|
|
|
|
|
anv_pipeline_compute_ray_tracing_stacks(struct anv_ray_tracing_pipeline *pipeline,
|
|
|
|
|
|
const VkRayTracingPipelineCreateInfoKHR *info,
|
|
|
|
|
|
uint32_t *stack_max)
|
2021-01-21 15:28:28 -06:00
|
|
|
|
{
|
2021-04-03 12:01:19 +03:00
|
|
|
|
if (is_rt_stack_size_dynamic(info)) {
|
|
|
|
|
|
pipeline->stack_size = 0; /* 0 means dynamic */
|
|
|
|
|
|
} else {
|
|
|
|
|
|
/* From the Vulkan spec:
|
|
|
|
|
|
*
|
|
|
|
|
|
* "If the stack size is not set explicitly, the stack size for a
|
|
|
|
|
|
* pipeline is:
|
|
|
|
|
|
*
|
|
|
|
|
|
* rayGenStackMax +
|
|
|
|
|
|
* min(1, maxPipelineRayRecursionDepth) ×
|
|
|
|
|
|
* max(closestHitStackMax, missStackMax,
|
|
|
|
|
|
* intersectionStackMax + anyHitStackMax) +
|
|
|
|
|
|
* max(0, maxPipelineRayRecursionDepth-1) ×
|
|
|
|
|
|
* max(closestHitStackMax, missStackMax) +
|
|
|
|
|
|
* 2 × callableStackMax"
|
|
|
|
|
|
*/
|
|
|
|
|
|
pipeline->stack_size =
|
|
|
|
|
|
stack_max[MESA_SHADER_RAYGEN] +
|
|
|
|
|
|
MIN2(1, info->maxPipelineRayRecursionDepth) *
|
|
|
|
|
|
MAX4(stack_max[MESA_SHADER_CLOSEST_HIT],
|
|
|
|
|
|
stack_max[MESA_SHADER_MISS],
|
|
|
|
|
|
stack_max[MESA_SHADER_INTERSECTION],
|
|
|
|
|
|
stack_max[MESA_SHADER_ANY_HIT]) +
|
|
|
|
|
|
MAX2(0, (int)info->maxPipelineRayRecursionDepth - 1) *
|
|
|
|
|
|
MAX2(stack_max[MESA_SHADER_CLOSEST_HIT],
|
|
|
|
|
|
stack_max[MESA_SHADER_MISS]) +
|
|
|
|
|
|
2 * stack_max[MESA_SHADER_CALLABLE];
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
/* This is an extremely unlikely case but we need to set it to some
|
|
|
|
|
|
* non-zero value so that we don't accidentally think it's dynamic.
|
|
|
|
|
|
* Our minimum stack size is 2KB anyway so we could set to any small
|
|
|
|
|
|
* value we like.
|
|
|
|
|
|
*/
|
|
|
|
|
|
if (pipeline->stack_size == 0)
|
|
|
|
|
|
pipeline->stack_size = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
static struct anv_pipeline_stage *
|
|
|
|
|
|
anv_pipeline_init_ray_tracing_stages(struct anv_ray_tracing_pipeline *pipeline,
|
|
|
|
|
|
const VkRayTracingPipelineCreateInfoKHR *info,
|
|
|
|
|
|
void *pipeline_ctx)
|
|
|
|
|
|
{
|
2021-01-21 15:28:28 -06:00
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
|
|
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
/* Create enough stage entries for all shader modules plus potential
|
|
|
|
|
|
* combinaisons in the groups.
|
|
|
|
|
|
*/
|
2021-01-21 15:28:28 -06:00
|
|
|
|
struct anv_pipeline_stage *stages =
|
|
|
|
|
|
rzalloc_array(pipeline_ctx, struct anv_pipeline_stage, info->stageCount);
|
2021-04-03 12:01:19 +03:00
|
|
|
|
|
2021-01-21 15:28:28 -06:00
|
|
|
|
for (uint32_t i = 0; i < info->stageCount; i++) {
|
|
|
|
|
|
const VkPipelineShaderStageCreateInfo *sinfo = &info->pStages[i];
|
|
|
|
|
|
if (sinfo->module == VK_NULL_HANDLE)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
|
|
|
|
|
stages[i] = (struct anv_pipeline_stage) {
|
|
|
|
|
|
.stage = vk_to_mesa_shader_stage(sinfo->stage),
|
|
|
|
|
|
.module = vk_shader_module_from_handle(sinfo->module),
|
|
|
|
|
|
.entrypoint = sinfo->pName,
|
|
|
|
|
|
.spec_info = sinfo->pSpecializationInfo,
|
|
|
|
|
|
.cache_key = {
|
|
|
|
|
|
.stage = vk_to_mesa_shader_stage(sinfo->stage),
|
|
|
|
|
|
},
|
|
|
|
|
|
.feedback = {
|
|
|
|
|
|
.flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
populate_bs_prog_key(&pipeline->base.device->info, sinfo->flags,
|
|
|
|
|
|
pipeline->base.device->robust_buffer_access,
|
|
|
|
|
|
&stages[i].key.bs);
|
|
|
|
|
|
|
2021-01-21 15:28:28 -06:00
|
|
|
|
anv_pipeline_hash_shader(stages[i].module,
|
|
|
|
|
|
stages[i].entrypoint,
|
|
|
|
|
|
stages[i].stage,
|
|
|
|
|
|
stages[i].spec_info,
|
|
|
|
|
|
stages[i].shader_sha1);
|
|
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
if (stages[i].stage != MESA_SHADER_INTERSECTION) {
|
|
|
|
|
|
anv_pipeline_hash_ray_tracing_shader(pipeline, layout, &stages[i],
|
|
|
|
|
|
stages[i].cache_key.sha1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stages[i].feedback.duration += os_time_get_nano() - stage_start;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < info->groupCount; i++) {
|
|
|
|
|
|
const VkRayTracingShaderGroupCreateInfoKHR *ginfo = &info->pGroups[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (ginfo->type != VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t intersection_idx = ginfo->intersectionShader;
|
|
|
|
|
|
assert(intersection_idx < info->stageCount);
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t any_hit_idx = ginfo->anyHitShader;
|
|
|
|
|
|
if (any_hit_idx != VK_SHADER_UNUSED_KHR) {
|
|
|
|
|
|
assert(any_hit_idx < info->stageCount);
|
|
|
|
|
|
anv_pipeline_hash_ray_tracing_combined_shader(pipeline,
|
|
|
|
|
|
layout,
|
|
|
|
|
|
&stages[intersection_idx],
|
|
|
|
|
|
&stages[any_hit_idx],
|
|
|
|
|
|
stages[intersection_idx].cache_key.sha1);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
anv_pipeline_hash_ray_tracing_shader(pipeline, layout,
|
|
|
|
|
|
&stages[intersection_idx],
|
|
|
|
|
|
stages[intersection_idx].cache_key.sha1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stages[intersection_idx].feedback.duration += os_time_get_nano() - stage_start;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return stages;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
anv_pipeline_load_cached_shaders(struct anv_ray_tracing_pipeline *pipeline,
|
|
|
|
|
|
struct anv_pipeline_cache *cache,
|
|
|
|
|
|
const VkRayTracingPipelineCreateInfoKHR *info,
|
|
|
|
|
|
struct anv_pipeline_stage *stages,
|
|
|
|
|
|
uint32_t *stack_max)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint32_t shaders = 0, cache_hits = 0;
|
|
|
|
|
|
for (uint32_t i = 0; i < info->stageCount; i++) {
|
|
|
|
|
|
if (stages[i].entrypoint == NULL)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
shaders++;
|
|
|
|
|
|
|
|
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
|
|
|
|
|
bool cache_hit;
|
|
|
|
|
|
stages[i].bin = anv_device_search_for_kernel(pipeline->base.device, cache,
|
|
|
|
|
|
&stages[i].cache_key,
|
|
|
|
|
|
sizeof(stages[i].cache_key),
|
|
|
|
|
|
&cache_hit);
|
|
|
|
|
|
if (cache_hit) {
|
|
|
|
|
|
cache_hits++;
|
|
|
|
|
|
stages[i].feedback.flags |=
|
|
|
|
|
|
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stages[i].bin != NULL) {
|
|
|
|
|
|
anv_pipeline_add_executables(&pipeline->base, &stages[i], stages[i].bin);
|
|
|
|
|
|
util_dynarray_append(&pipeline->shaders, struct anv_shader_bin *, stages[i].bin);
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t stack_size =
|
|
|
|
|
|
brw_bs_prog_data_const(stages[i].bin->prog_data)->max_stack_size;
|
|
|
|
|
|
stack_max[stages[i].stage] =
|
|
|
|
|
|
MAX2(stack_max[stages[i].stage], stack_size);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stages[i].feedback.duration += os_time_get_nano() - stage_start;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return cache_hits == shaders;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static VkResult
|
|
|
|
|
|
anv_pipeline_compile_ray_tracing(struct anv_ray_tracing_pipeline *pipeline,
|
|
|
|
|
|
struct anv_pipeline_cache *cache,
|
|
|
|
|
|
const VkRayTracingPipelineCreateInfoKHR *info)
|
|
|
|
|
|
{
|
|
|
|
|
|
const struct intel_device_info *devinfo = &pipeline->base.device->info;
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
VkPipelineCreationFeedbackEXT pipeline_feedback = {
|
|
|
|
|
|
.flags = VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT_EXT,
|
|
|
|
|
|
};
|
|
|
|
|
|
int64_t pipeline_start = os_time_get_nano();
|
|
|
|
|
|
|
|
|
|
|
|
void *pipeline_ctx = ralloc_context(NULL);
|
|
|
|
|
|
|
|
|
|
|
|
struct anv_pipeline_stage *stages =
|
|
|
|
|
|
anv_pipeline_init_ray_tracing_stages(pipeline, info, pipeline_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
|
|
|
|
|
|
|
|
|
|
|
|
const bool skip_cache_lookup =
|
|
|
|
|
|
(pipeline->base.flags & VK_PIPELINE_CREATE_CAPTURE_INTERNAL_REPRESENTATIONS_BIT_KHR);
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t stack_max[MESA_VULKAN_SHADER_STAGES] = {};
|
|
|
|
|
|
|
|
|
|
|
|
if (!skip_cache_lookup &&
|
|
|
|
|
|
anv_pipeline_load_cached_shaders(pipeline, cache, info, stages, stack_max)) {
|
|
|
|
|
|
pipeline_feedback.flags |=
|
|
|
|
|
|
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT_EXT;
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (info->flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT) {
|
|
|
|
|
|
ralloc_free(pipeline_ctx);
|
|
|
|
|
|
return VK_PIPELINE_COMPILE_REQUIRED_EXT;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < info->stageCount; i++) {
|
|
|
|
|
|
if (stages[i].entrypoint == NULL)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
|
|
|
|
|
stages[i].nir = anv_pipeline_stage_get_nir(&pipeline->base, cache,
|
|
|
|
|
|
pipeline_ctx, &stages[i]);
|
|
|
|
|
|
if (stages[i].nir == NULL) {
|
|
|
|
|
|
ralloc_free(pipeline_ctx);
|
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
anv_pipeline_lower_nir(&pipeline->base, pipeline_ctx, &stages[i], layout);
|
|
|
|
|
|
|
|
|
|
|
|
stages[i].feedback.duration += os_time_get_nano() - stage_start;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < info->stageCount; i++) {
|
2021-04-03 12:01:19 +03:00
|
|
|
|
if (stages[i].entrypoint == NULL)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
/* Shader found in cache already. */
|
|
|
|
|
|
if (stages[i].bin != NULL)
|
2021-01-21 15:28:28 -06:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
/* We handle intersection shaders as part of the group */
|
|
|
|
|
|
if (stages[i].stage == MESA_SHADER_INTERSECTION)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
int64_t stage_start = os_time_get_nano();
|
|
|
|
|
|
|
|
|
|
|
|
void *stage_ctx = ralloc_context(pipeline_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
nir_shader *nir = nir_shader_clone(stage_ctx, stages[i].nir);
|
|
|
|
|
|
switch (stages[i].stage) {
|
|
|
|
|
|
case MESA_SHADER_RAYGEN:
|
|
|
|
|
|
brw_nir_lower_raygen(nir);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_ANY_HIT:
|
|
|
|
|
|
brw_nir_lower_any_hit(nir, devinfo);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_CLOSEST_HIT:
|
|
|
|
|
|
brw_nir_lower_closest_hit(nir);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_MISS:
|
|
|
|
|
|
brw_nir_lower_miss(nir);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_INTERSECTION:
|
|
|
|
|
|
unreachable("These are handled later");
|
|
|
|
|
|
|
|
|
|
|
|
case MESA_SHADER_CALLABLE:
|
|
|
|
|
|
brw_nir_lower_callable(nir);
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
unreachable("Invalid ray-tracing shader stage");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
result = compile_upload_rt_shader(pipeline, cache, nir, &stages[i],
|
2021-01-21 15:28:28 -06:00
|
|
|
|
&stages[i].bin, stage_ctx);
|
|
|
|
|
|
if (result != VK_SUCCESS) {
|
|
|
|
|
|
ralloc_free(pipeline_ctx);
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-21 15:38:01 -06:00
|
|
|
|
uint32_t stack_size =
|
|
|
|
|
|
brw_bs_prog_data_const(stages[i].bin->prog_data)->max_stack_size;
|
|
|
|
|
|
stack_max[stages[i].stage] = MAX2(stack_max[stages[i].stage], stack_size);
|
|
|
|
|
|
|
2021-01-21 15:28:28 -06:00
|
|
|
|
ralloc_free(stage_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
stages[i].feedback.duration += os_time_get_nano() - stage_start;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < info->groupCount; i++) {
|
|
|
|
|
|
const VkRayTracingShaderGroupCreateInfoKHR *ginfo = &info->pGroups[i];
|
|
|
|
|
|
struct anv_rt_shader_group *group = &pipeline->groups[i];
|
|
|
|
|
|
group->type = ginfo->type;
|
|
|
|
|
|
switch (ginfo->type) {
|
|
|
|
|
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR:
|
|
|
|
|
|
assert(ginfo->generalShader < info->stageCount);
|
|
|
|
|
|
group->general = stages[ginfo->generalShader].bin;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR:
|
|
|
|
|
|
if (ginfo->anyHitShader < info->stageCount)
|
|
|
|
|
|
group->any_hit = stages[ginfo->anyHitShader].bin;
|
|
|
|
|
|
|
|
|
|
|
|
if (ginfo->closestHitShader < info->stageCount)
|
|
|
|
|
|
group->closest_hit = stages[ginfo->closestHitShader].bin;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR: {
|
|
|
|
|
|
if (ginfo->closestHitShader < info->stageCount)
|
|
|
|
|
|
group->closest_hit = stages[ginfo->closestHitShader].bin;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t intersection_idx = info->pGroups[i].intersectionShader;
|
|
|
|
|
|
assert(intersection_idx < info->stageCount);
|
2021-04-03 12:01:19 +03:00
|
|
|
|
|
|
|
|
|
|
/* Only compile this stage if not already found in the cache. */
|
|
|
|
|
|
if (stages[intersection_idx].bin == NULL) {
|
|
|
|
|
|
/* The any-hit and intersection shader have to be combined */
|
|
|
|
|
|
uint32_t any_hit_idx = info->pGroups[i].anyHitShader;
|
|
|
|
|
|
const nir_shader *any_hit = NULL;
|
|
|
|
|
|
if (any_hit_idx < info->stageCount)
|
|
|
|
|
|
any_hit = stages[any_hit_idx].nir;
|
|
|
|
|
|
|
|
|
|
|
|
void *group_ctx = ralloc_context(pipeline_ctx);
|
|
|
|
|
|
nir_shader *intersection =
|
|
|
|
|
|
nir_shader_clone(group_ctx, stages[intersection_idx].nir);
|
|
|
|
|
|
|
|
|
|
|
|
brw_nir_lower_combined_intersection_any_hit(intersection, any_hit,
|
|
|
|
|
|
devinfo);
|
|
|
|
|
|
|
|
|
|
|
|
result = compile_upload_rt_shader(pipeline, cache,
|
|
|
|
|
|
intersection,
|
|
|
|
|
|
&stages[intersection_idx],
|
|
|
|
|
|
&group->intersection,
|
|
|
|
|
|
group_ctx);
|
|
|
|
|
|
ralloc_free(group_ctx);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
return result;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
group->intersection = stages[intersection_idx].bin;
|
2021-01-21 15:28:28 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-21 15:38:01 -06:00
|
|
|
|
uint32_t stack_size =
|
|
|
|
|
|
brw_bs_prog_data_const(group->intersection->prog_data)->max_stack_size;
|
|
|
|
|
|
stack_max[MESA_SHADER_INTERSECTION] =
|
|
|
|
|
|
MAX2(stack_max[MESA_SHADER_INTERSECTION], stack_size);
|
|
|
|
|
|
|
2021-01-21 15:28:28 -06:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
unreachable("Invalid ray tracing shader group type");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
done:
|
2021-01-21 15:28:28 -06:00
|
|
|
|
ralloc_free(pipeline_ctx);
|
|
|
|
|
|
|
2021-04-03 12:01:19 +03:00
|
|
|
|
anv_pipeline_compute_ray_tracing_stacks(pipeline, info, stack_max);
|
2021-01-21 15:38:01 -06:00
|
|
|
|
|
2021-01-21 15:28:28 -06:00
|
|
|
|
pipeline_feedback.duration = os_time_get_nano() - pipeline_start;
|
|
|
|
|
|
|
|
|
|
|
|
const VkPipelineCreationFeedbackCreateInfoEXT *create_feedback =
|
|
|
|
|
|
vk_find_struct_const(info->pNext, PIPELINE_CREATION_FEEDBACK_CREATE_INFO_EXT);
|
|
|
|
|
|
if (create_feedback) {
|
|
|
|
|
|
*create_feedback->pPipelineCreationFeedback = pipeline_feedback;
|
|
|
|
|
|
|
|
|
|
|
|
assert(info->stageCount == create_feedback->pipelineStageCreationFeedbackCount);
|
|
|
|
|
|
for (uint32_t i = 0; i < info->stageCount; i++) {
|
|
|
|
|
|
gl_shader_stage s = vk_to_mesa_shader_stage(info->pStages[i].stage);
|
|
|
|
|
|
create_feedback->pPipelineStageCreationFeedbacks[i] = stages[s].feedback;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-06 18:56:54 -05:00
|
|
|
|
VkResult
|
2021-04-06 17:10:16 +03:00
|
|
|
|
anv_device_init_rt_shaders(struct anv_device *device)
|
2020-08-06 18:56:54 -05:00
|
|
|
|
{
|
2021-04-02 17:03:13 +03:00
|
|
|
|
if (!device->vk.enabled_extensions.KHR_ray_tracing_pipeline)
|
|
|
|
|
|
return VK_SUCCESS;
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
2021-04-02 17:03:13 +03:00
|
|
|
|
bool cache_hit;
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
2021-04-02 17:03:13 +03:00
|
|
|
|
struct brw_rt_trampoline {
|
|
|
|
|
|
char name[16];
|
|
|
|
|
|
struct brw_cs_prog_key key;
|
|
|
|
|
|
} trampoline_key = {
|
|
|
|
|
|
.name = "rt-trampoline",
|
|
|
|
|
|
.key = {
|
|
|
|
|
|
/* TODO: Other subgroup sizes? */
|
|
|
|
|
|
.base.subgroup_size_type = BRW_SUBGROUP_SIZE_REQUIRE_8,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
device->rt_trampoline =
|
|
|
|
|
|
anv_device_search_for_kernel(device, &device->default_pipeline_cache,
|
|
|
|
|
|
&trampoline_key, sizeof(trampoline_key),
|
|
|
|
|
|
&cache_hit);
|
|
|
|
|
|
if (device->rt_trampoline == NULL) {
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
2021-01-21 15:30:27 -06:00
|
|
|
|
void *tmp_ctx = ralloc_context(NULL);
|
|
|
|
|
|
nir_shader *trampoline_nir =
|
|
|
|
|
|
brw_nir_create_raygen_trampoline(device->physical->compiler, tmp_ctx);
|
|
|
|
|
|
|
2021-04-02 17:03:13 +03:00
|
|
|
|
struct anv_pipeline_bind_map bind_map = {
|
|
|
|
|
|
.surface_count = 0,
|
|
|
|
|
|
.sampler_count = 0,
|
2021-01-21 15:30:27 -06:00
|
|
|
|
};
|
2021-04-02 17:03:13 +03:00
|
|
|
|
uint32_t dummy_params[4] = { 0, };
|
|
|
|
|
|
struct brw_cs_prog_data trampoline_prog_data = {
|
2021-01-21 15:30:27 -06:00
|
|
|
|
.base.nr_params = 4,
|
2021-04-02 17:03:13 +03:00
|
|
|
|
.base.param = dummy_params,
|
2021-01-21 15:30:27 -06:00
|
|
|
|
.uses_inline_data = true,
|
|
|
|
|
|
.uses_btd_stack_ids = true,
|
|
|
|
|
|
};
|
|
|
|
|
|
struct brw_compile_cs_params params = {
|
|
|
|
|
|
.nir = trampoline_nir,
|
2021-04-02 17:03:13 +03:00
|
|
|
|
.key = &trampoline_key.key,
|
|
|
|
|
|
.prog_data = &trampoline_prog_data,
|
|
|
|
|
|
.log_data = device,
|
2021-01-21 15:30:27 -06:00
|
|
|
|
};
|
|
|
|
|
|
const unsigned *tramp_data =
|
|
|
|
|
|
brw_compile_cs(device->physical->compiler, tmp_ctx, ¶ms);
|
|
|
|
|
|
|
2021-04-02 17:03:13 +03:00
|
|
|
|
device->rt_trampoline =
|
|
|
|
|
|
anv_device_upload_kernel(device, &device->default_pipeline_cache,
|
|
|
|
|
|
MESA_SHADER_COMPUTE,
|
|
|
|
|
|
&trampoline_key, sizeof(trampoline_key),
|
|
|
|
|
|
tramp_data,
|
|
|
|
|
|
trampoline_prog_data.base.program_size,
|
|
|
|
|
|
&trampoline_prog_data.base,
|
|
|
|
|
|
sizeof(trampoline_prog_data),
|
|
|
|
|
|
NULL, 0, NULL, &bind_map);
|
|
|
|
|
|
|
2021-01-21 15:30:27 -06:00
|
|
|
|
ralloc_free(tmp_ctx);
|
2021-04-02 17:03:13 +03:00
|
|
|
|
|
|
|
|
|
|
if (device->rt_trampoline == NULL)
|
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
2021-01-21 15:30:27 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-06 17:10:16 +03:00
|
|
|
|
struct brw_rt_trivial_return {
|
|
|
|
|
|
char name[16];
|
|
|
|
|
|
struct brw_bs_prog_key key;
|
|
|
|
|
|
} return_key = {
|
|
|
|
|
|
.name = "rt-trivial-ret",
|
|
|
|
|
|
};
|
|
|
|
|
|
device->rt_trivial_return =
|
|
|
|
|
|
anv_device_search_for_kernel(device, &device->default_pipeline_cache,
|
|
|
|
|
|
&return_key, sizeof(return_key),
|
|
|
|
|
|
&cache_hit);
|
|
|
|
|
|
if (device->rt_trivial_return == NULL) {
|
|
|
|
|
|
void *tmp_ctx = ralloc_context(NULL);
|
|
|
|
|
|
nir_shader *trivial_return_nir =
|
|
|
|
|
|
brw_nir_create_trivial_return_shader(device->physical->compiler, tmp_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
NIR_PASS_V(trivial_return_nir, brw_nir_lower_rt_intrinsics, &device->info);
|
|
|
|
|
|
|
|
|
|
|
|
struct anv_pipeline_bind_map bind_map = {
|
|
|
|
|
|
.surface_count = 0,
|
|
|
|
|
|
.sampler_count = 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
struct brw_bs_prog_data return_prog_data = { 0, };
|
|
|
|
|
|
const unsigned *return_data =
|
|
|
|
|
|
brw_compile_bs(device->physical->compiler, device, tmp_ctx,
|
|
|
|
|
|
&return_key.key, &return_prog_data, trivial_return_nir,
|
|
|
|
|
|
0, 0, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
device->rt_trivial_return =
|
|
|
|
|
|
anv_device_upload_kernel(device, &device->default_pipeline_cache,
|
|
|
|
|
|
MESA_SHADER_CALLABLE,
|
|
|
|
|
|
&return_key, sizeof(return_key),
|
|
|
|
|
|
return_data, return_prog_data.base.program_size,
|
|
|
|
|
|
&return_prog_data.base, sizeof(return_prog_data),
|
|
|
|
|
|
NULL, 0, NULL, &bind_map);
|
|
|
|
|
|
|
|
|
|
|
|
ralloc_free(tmp_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
if (device->rt_trivial_return == NULL) {
|
|
|
|
|
|
anv_shader_bin_unref(device, device->rt_trampoline);
|
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-02 17:03:13 +03:00
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
anv_device_finish_rt_shaders(struct anv_device *device)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!device->vk.enabled_extensions.KHR_ray_tracing_pipeline)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
anv_shader_bin_unref(device, device->rt_trampoline);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult
|
|
|
|
|
|
anv_ray_tracing_pipeline_init(struct anv_ray_tracing_pipeline *pipeline,
|
|
|
|
|
|
struct anv_device *device,
|
|
|
|
|
|
struct anv_pipeline_cache *cache,
|
|
|
|
|
|
const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
|
|
|
|
|
|
const VkAllocationCallbacks *alloc)
|
|
|
|
|
|
{
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
util_dynarray_init(&pipeline->shaders, pipeline->base.mem_ctx);
|
|
|
|
|
|
|
2021-01-21 15:28:28 -06:00
|
|
|
|
result = anv_pipeline_compile_ray_tracing(pipeline, cache, pCreateInfo);
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
|
|
anv_pipeline_setup_l3_config(&pipeline->base, /* needs_slm */ false);
|
|
|
|
|
|
|
2020-08-06 18:56:54 -05:00
|
|
|
|
return VK_SUCCESS;
|
2021-01-21 15:28:28 -06:00
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
util_dynarray_foreach(&pipeline->shaders,
|
|
|
|
|
|
struct anv_shader_bin *, shader) {
|
|
|
|
|
|
anv_shader_bin_unref(device, *shader);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
2020-08-06 18:56:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:02:35 -05:00
|
|
|
|
#define WRITE_STR(field, ...) ({ \
|
|
|
|
|
|
memset(field, 0, sizeof(field)); \
|
|
|
|
|
|
UNUSED int i = snprintf(field, sizeof(field), __VA_ARGS__); \
|
|
|
|
|
|
assert(i > 0 && i < sizeof(field)); \
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
VkResult anv_GetPipelineExecutablePropertiesKHR(
|
|
|
|
|
|
VkDevice device,
|
|
|
|
|
|
const VkPipelineInfoKHR* pPipelineInfo,
|
|
|
|
|
|
uint32_t* pExecutableCount,
|
|
|
|
|
|
VkPipelineExecutablePropertiesKHR* pProperties)
|
|
|
|
|
|
{
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline, pipeline, pPipelineInfo->pipeline);
|
|
|
|
|
|
VK_OUTARRAY_MAKE(out, pProperties, pExecutableCount);
|
|
|
|
|
|
|
2020-03-03 10:19:15 -08:00
|
|
|
|
util_dynarray_foreach (&pipeline->executables, struct anv_pipeline_executable, exe) {
|
2019-04-24 03:02:35 -05:00
|
|
|
|
vk_outarray_append(&out, props) {
|
2020-03-03 10:19:15 -08:00
|
|
|
|
gl_shader_stage stage = exe->stage;
|
2019-04-24 03:02:35 -05:00
|
|
|
|
props->stages = mesa_to_vk_shader_stage(stage);
|
|
|
|
|
|
|
2020-03-03 10:19:15 -08:00
|
|
|
|
unsigned simd_width = exe->stats.dispatch_width;
|
2019-04-24 03:02:35 -05:00
|
|
|
|
if (stage == MESA_SHADER_FRAGMENT) {
|
|
|
|
|
|
WRITE_STR(props->name, "%s%d %s",
|
|
|
|
|
|
simd_width ? "SIMD" : "vec",
|
|
|
|
|
|
simd_width ? simd_width : 4,
|
|
|
|
|
|
_mesa_shader_stage_to_string(stage));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
WRITE_STR(props->name, "%s", _mesa_shader_stage_to_string(stage));
|
|
|
|
|
|
}
|
|
|
|
|
|
WRITE_STR(props->description, "%s%d %s shader",
|
|
|
|
|
|
simd_width ? "SIMD" : "vec",
|
|
|
|
|
|
simd_width ? simd_width : 4,
|
|
|
|
|
|
_mesa_shader_stage_to_string(stage));
|
|
|
|
|
|
|
|
|
|
|
|
/* The compiler gives us a dispatch width of 0 for vec4 but Vulkan
|
|
|
|
|
|
* wants a subgroup size of 1.
|
|
|
|
|
|
*/
|
|
|
|
|
|
props->subgroupSize = MAX2(simd_width, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return vk_outarray_status(&out);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-03 10:19:15 -08:00
|
|
|
|
static const struct anv_pipeline_executable *
|
|
|
|
|
|
anv_pipeline_get_executable(struct anv_pipeline *pipeline, uint32_t index)
|
|
|
|
|
|
{
|
|
|
|
|
|
assert(index < util_dynarray_num_elements(&pipeline->executables,
|
|
|
|
|
|
struct anv_pipeline_executable));
|
|
|
|
|
|
return util_dynarray_element(
|
|
|
|
|
|
&pipeline->executables, struct anv_pipeline_executable, index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:02:35 -05:00
|
|
|
|
VkResult anv_GetPipelineExecutableStatisticsKHR(
|
|
|
|
|
|
VkDevice device,
|
|
|
|
|
|
const VkPipelineExecutableInfoKHR* pExecutableInfo,
|
|
|
|
|
|
uint32_t* pStatisticCount,
|
|
|
|
|
|
VkPipelineExecutableStatisticKHR* pStatistics)
|
|
|
|
|
|
{
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline, pipeline, pExecutableInfo->pipeline);
|
|
|
|
|
|
VK_OUTARRAY_MAKE(out, pStatistics, pStatisticCount);
|
|
|
|
|
|
|
|
|
|
|
|
const struct anv_pipeline_executable *exe =
|
2020-03-03 10:19:15 -08:00
|
|
|
|
anv_pipeline_get_executable(pipeline, pExecutableInfo->executableIndex);
|
2020-03-03 13:43:39 -08:00
|
|
|
|
|
|
|
|
|
|
const struct brw_stage_prog_data *prog_data;
|
|
|
|
|
|
switch (pipeline->type) {
|
2020-03-03 15:31:50 -08:00
|
|
|
|
case ANV_PIPELINE_GRAPHICS: {
|
|
|
|
|
|
prog_data = anv_pipeline_to_graphics(pipeline)->shaders[exe->stage]->prog_data;
|
2020-03-03 13:43:39 -08:00
|
|
|
|
break;
|
2020-03-03 15:31:50 -08:00
|
|
|
|
}
|
|
|
|
|
|
case ANV_PIPELINE_COMPUTE: {
|
|
|
|
|
|
prog_data = anv_pipeline_to_compute(pipeline)->cs->prog_data;
|
2020-03-03 13:43:39 -08:00
|
|
|
|
break;
|
2020-03-03 15:31:50 -08:00
|
|
|
|
}
|
2020-03-03 13:43:39 -08:00
|
|
|
|
default:
|
|
|
|
|
|
unreachable("invalid pipeline type");
|
|
|
|
|
|
}
|
2019-04-24 03:02:35 -05:00
|
|
|
|
|
|
|
|
|
|
vk_outarray_append(&out, stat) {
|
|
|
|
|
|
WRITE_STR(stat->name, "Instruction Count");
|
|
|
|
|
|
WRITE_STR(stat->description,
|
|
|
|
|
|
"Number of GEN instructions in the final generated "
|
|
|
|
|
|
"shader executable.");
|
|
|
|
|
|
stat->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
|
|
|
|
|
|
stat->value.u64 = exe->stats.instructions;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-03 13:09:41 -05:00
|
|
|
|
vk_outarray_append(&out, stat) {
|
|
|
|
|
|
WRITE_STR(stat->name, "SEND Count");
|
|
|
|
|
|
WRITE_STR(stat->description,
|
|
|
|
|
|
"Number of instructions in the final generated shader "
|
|
|
|
|
|
"executable which access external units such as the "
|
|
|
|
|
|
"constant cache or the sampler.");
|
|
|
|
|
|
stat->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
|
|
|
|
|
|
stat->value.u64 = exe->stats.sends;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:02:35 -05:00
|
|
|
|
vk_outarray_append(&out, stat) {
|
|
|
|
|
|
WRITE_STR(stat->name, "Loop Count");
|
|
|
|
|
|
WRITE_STR(stat->description,
|
|
|
|
|
|
"Number of loops (not unrolled) in the final generated "
|
|
|
|
|
|
"shader executable.");
|
|
|
|
|
|
stat->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
|
|
|
|
|
|
stat->value.u64 = exe->stats.loops;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vk_outarray_append(&out, stat) {
|
|
|
|
|
|
WRITE_STR(stat->name, "Cycle Count");
|
|
|
|
|
|
WRITE_STR(stat->description,
|
|
|
|
|
|
"Estimate of the number of EU cycles required to execute "
|
|
|
|
|
|
"the final generated executable. This is an estimate only "
|
|
|
|
|
|
"and may vary greatly from actual run-time performance.");
|
|
|
|
|
|
stat->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
|
|
|
|
|
|
stat->value.u64 = exe->stats.cycles;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vk_outarray_append(&out, stat) {
|
|
|
|
|
|
WRITE_STR(stat->name, "Spill Count");
|
|
|
|
|
|
WRITE_STR(stat->description,
|
|
|
|
|
|
"Number of scratch spill operations. This gives a rough "
|
|
|
|
|
|
"estimate of the cost incurred due to spilling temporary "
|
|
|
|
|
|
"values to memory. If this is non-zero, you may want to "
|
|
|
|
|
|
"adjust your shader to reduce register pressure.");
|
|
|
|
|
|
stat->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
|
|
|
|
|
|
stat->value.u64 = exe->stats.spills;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vk_outarray_append(&out, stat) {
|
|
|
|
|
|
WRITE_STR(stat->name, "Fill Count");
|
|
|
|
|
|
WRITE_STR(stat->description,
|
|
|
|
|
|
"Number of scratch fill operations. This gives a rough "
|
|
|
|
|
|
"estimate of the cost incurred due to spilling temporary "
|
|
|
|
|
|
"values to memory. If this is non-zero, you may want to "
|
|
|
|
|
|
"adjust your shader to reduce register pressure.");
|
|
|
|
|
|
stat->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
|
|
|
|
|
|
stat->value.u64 = exe->stats.fills;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vk_outarray_append(&out, stat) {
|
|
|
|
|
|
WRITE_STR(stat->name, "Scratch Memory Size");
|
|
|
|
|
|
WRITE_STR(stat->description,
|
|
|
|
|
|
"Number of bytes of scratch memory required by the "
|
|
|
|
|
|
"generated shader executable. If this is non-zero, you "
|
|
|
|
|
|
"may want to adjust your shader to reduce register "
|
|
|
|
|
|
"pressure.");
|
|
|
|
|
|
stat->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
|
|
|
|
|
|
stat->value.u64 = prog_data->total_scratch;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-07 14:17:12 -07:00
|
|
|
|
if (gl_shader_stage_uses_workgroup(exe->stage)) {
|
2019-04-24 03:02:35 -05:00
|
|
|
|
vk_outarray_append(&out, stat) {
|
|
|
|
|
|
WRITE_STR(stat->name, "Workgroup Memory Size");
|
|
|
|
|
|
WRITE_STR(stat->description,
|
|
|
|
|
|
"Number of bytes of workgroup shared memory used by this "
|
2021-06-07 14:17:12 -07:00
|
|
|
|
"shader including any padding.");
|
2019-04-24 03:02:35 -05:00
|
|
|
|
stat->format = VK_PIPELINE_EXECUTABLE_STATISTIC_FORMAT_UINT64_KHR;
|
2020-10-14 14:52:37 -07:00
|
|
|
|
stat->value.u64 = prog_data->total_shared;
|
2019-04-24 03:02:35 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return vk_outarray_status(&out);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
|
write_ir_text(VkPipelineExecutableInternalRepresentationKHR* ir,
|
|
|
|
|
|
const char *data)
|
|
|
|
|
|
{
|
|
|
|
|
|
ir->isText = VK_TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
size_t data_len = strlen(data) + 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (ir->pData == NULL) {
|
|
|
|
|
|
ir->dataSize = data_len;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
strncpy(ir->pData, data, ir->dataSize);
|
|
|
|
|
|
if (ir->dataSize < data_len)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
ir->dataSize = data_len;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult anv_GetPipelineExecutableInternalRepresentationsKHR(
|
|
|
|
|
|
VkDevice device,
|
|
|
|
|
|
const VkPipelineExecutableInfoKHR* pExecutableInfo,
|
|
|
|
|
|
uint32_t* pInternalRepresentationCount,
|
|
|
|
|
|
VkPipelineExecutableInternalRepresentationKHR* pInternalRepresentations)
|
|
|
|
|
|
{
|
|
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline, pipeline, pExecutableInfo->pipeline);
|
|
|
|
|
|
VK_OUTARRAY_MAKE(out, pInternalRepresentations,
|
|
|
|
|
|
pInternalRepresentationCount);
|
|
|
|
|
|
bool incomplete_text = false;
|
|
|
|
|
|
|
|
|
|
|
|
const struct anv_pipeline_executable *exe =
|
2020-03-03 10:19:15 -08:00
|
|
|
|
anv_pipeline_get_executable(pipeline, pExecutableInfo->executableIndex);
|
2019-04-24 03:02:35 -05:00
|
|
|
|
|
2019-10-09 13:21:21 -05:00
|
|
|
|
if (exe->nir) {
|
|
|
|
|
|
vk_outarray_append(&out, ir) {
|
|
|
|
|
|
WRITE_STR(ir->name, "Final NIR");
|
|
|
|
|
|
WRITE_STR(ir->description,
|
|
|
|
|
|
"Final NIR before going into the back-end compiler");
|
|
|
|
|
|
|
|
|
|
|
|
if (!write_ir_text(ir, exe->nir))
|
|
|
|
|
|
incomplete_text = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-24 03:02:35 -05:00
|
|
|
|
if (exe->disasm) {
|
|
|
|
|
|
vk_outarray_append(&out, ir) {
|
|
|
|
|
|
WRITE_STR(ir->name, "GEN Assembly");
|
|
|
|
|
|
WRITE_STR(ir->description,
|
|
|
|
|
|
"Final GEN assembly for the generated shader binary");
|
|
|
|
|
|
|
|
|
|
|
|
if (!write_ir_text(ir, exe->disasm))
|
|
|
|
|
|
incomplete_text = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return incomplete_text ? VK_INCOMPLETE : vk_outarray_status(&out);
|
|
|
|
|
|
}
|
2020-08-05 16:53:12 -05:00
|
|
|
|
|
|
|
|
|
|
VkResult
|
|
|
|
|
|
anv_GetRayTracingShaderGroupHandlesKHR(
|
|
|
|
|
|
VkDevice device,
|
2021-01-21 15:37:21 -06:00
|
|
|
|
VkPipeline _pipeline,
|
2020-08-05 16:53:12 -05:00
|
|
|
|
uint32_t firstGroup,
|
|
|
|
|
|
uint32_t groupCount,
|
|
|
|
|
|
size_t dataSize,
|
|
|
|
|
|
void* pData)
|
|
|
|
|
|
{
|
2021-01-21 15:37:21 -06:00
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline, pipeline, _pipeline);
|
|
|
|
|
|
if (pipeline->type != ANV_PIPELINE_RAY_TRACING)
|
|
|
|
|
|
return vk_error(VK_ERROR_FEATURE_NOT_PRESENT);
|
|
|
|
|
|
|
|
|
|
|
|
struct anv_ray_tracing_pipeline *rt_pipeline =
|
|
|
|
|
|
anv_pipeline_to_ray_tracing(pipeline);
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < groupCount; i++) {
|
|
|
|
|
|
struct anv_rt_shader_group *group = &rt_pipeline->groups[firstGroup + i];
|
|
|
|
|
|
memcpy(pData, group->handle, sizeof(group->handle));
|
|
|
|
|
|
pData += sizeof(group->handle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
2020-08-05 16:53:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult
|
|
|
|
|
|
anv_GetRayTracingCaptureReplayShaderGroupHandlesKHR(
|
|
|
|
|
|
VkDevice device,
|
|
|
|
|
|
VkPipeline pipeline,
|
|
|
|
|
|
uint32_t firstGroup,
|
|
|
|
|
|
uint32_t groupCount,
|
|
|
|
|
|
size_t dataSize,
|
|
|
|
|
|
void* pData)
|
|
|
|
|
|
{
|
|
|
|
|
|
unreachable("Unimplemented");
|
|
|
|
|
|
return vk_error(VK_ERROR_FEATURE_NOT_PRESENT);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkDeviceSize
|
|
|
|
|
|
anv_GetRayTracingShaderGroupStackSizeKHR(
|
|
|
|
|
|
VkDevice device,
|
2021-01-21 15:38:01 -06:00
|
|
|
|
VkPipeline _pipeline,
|
2020-08-05 16:53:12 -05:00
|
|
|
|
uint32_t group,
|
|
|
|
|
|
VkShaderGroupShaderKHR groupShader)
|
|
|
|
|
|
{
|
2021-01-21 15:38:01 -06:00
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline, pipeline, _pipeline);
|
|
|
|
|
|
assert(pipeline->type == ANV_PIPELINE_RAY_TRACING);
|
|
|
|
|
|
|
|
|
|
|
|
struct anv_ray_tracing_pipeline *rt_pipeline =
|
|
|
|
|
|
anv_pipeline_to_ray_tracing(pipeline);
|
|
|
|
|
|
|
|
|
|
|
|
assert(group < rt_pipeline->group_count);
|
|
|
|
|
|
|
|
|
|
|
|
struct anv_shader_bin *bin;
|
|
|
|
|
|
switch (groupShader) {
|
|
|
|
|
|
case VK_SHADER_GROUP_SHADER_GENERAL_KHR:
|
|
|
|
|
|
bin = rt_pipeline->groups[group].general;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case VK_SHADER_GROUP_SHADER_CLOSEST_HIT_KHR:
|
|
|
|
|
|
bin = rt_pipeline->groups[group].closest_hit;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case VK_SHADER_GROUP_SHADER_ANY_HIT_KHR:
|
|
|
|
|
|
bin = rt_pipeline->groups[group].any_hit;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case VK_SHADER_GROUP_SHADER_INTERSECTION_KHR:
|
|
|
|
|
|
bin = rt_pipeline->groups[group].intersection;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
unreachable("Invalid VkShaderGroupShader enum");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bin == NULL)
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
return brw_bs_prog_data_const(bin->prog_data)->max_stack_size;
|
2020-08-05 16:53:12 -05:00
|
|
|
|
}
|