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"
|
2016-08-22 16:56:48 -07:00
|
|
|
#include "common/gen_l3_config.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"
|
2015-10-19 22:06:59 -07:00
|
|
|
#include "anv_nir.h"
|
2016-04-14 10:28:45 -07:00
|
|
|
#include "spirv/nir_spirv.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-07-08 17:29:49 -07:00
|
|
|
VkResult anv_CreateShaderModule(
|
|
|
|
|
VkDevice _device,
|
|
|
|
|
const VkShaderModuleCreateInfo* pCreateInfo,
|
2015-12-02 03:28:27 -08:00
|
|
|
const VkAllocationCallbacks* pAllocator,
|
2015-07-15 13:55:28 -07:00
|
|
|
VkShaderModule* pShaderModule)
|
2015-07-08 17:29:49 -07:00
|
|
|
{
|
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
struct anv_shader_module *module;
|
|
|
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);
|
|
|
|
|
assert(pCreateInfo->flags == 0);
|
|
|
|
|
|
2016-10-14 13:31:35 +10:00
|
|
|
module = vk_alloc2(&device->alloc, pAllocator,
|
2015-12-02 03:28:27 -08:00
|
|
|
sizeof(*module) + pCreateInfo->codeSize, 8,
|
|
|
|
|
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
2015-07-08 17:29:49 -07:00
|
|
|
if (module == NULL)
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
|
|
|
|
|
module->size = pCreateInfo->codeSize;
|
|
|
|
|
memcpy(module->data, pCreateInfo->pCode, module->size);
|
|
|
|
|
|
2016-02-10 09:43:03 -08:00
|
|
|
_mesa_sha1_compute(module->data, module->size, module->sha1);
|
|
|
|
|
|
2015-07-09 20:28:08 -07:00
|
|
|
*pShaderModule = anv_shader_module_to_handle(module);
|
2015-07-08 17:29:49 -07:00
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-05 20:50:51 -07:00
|
|
|
void anv_DestroyShaderModule(
|
2015-07-14 10:12:10 -07:00
|
|
|
VkDevice _device,
|
2015-12-02 03:28:27 -08:00
|
|
|
VkShaderModule _module,
|
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
2015-07-14 10:12:10 -07:00
|
|
|
{
|
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
ANV_FROM_HANDLE(anv_shader_module, module, _module);
|
|
|
|
|
|
2016-11-10 21:32:32 -08:00
|
|
|
if (!module)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-10-14 13:31:35 +10:00
|
|
|
vk_free2(&device->alloc, pAllocator, module);
|
2015-07-14 10:12:10 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
#define SPIR_V_MAGIC_NUMBER 0x07230203
|
|
|
|
|
|
2017-07-12 12:34:00 -07:00
|
|
|
static const uint64_t stage_to_debug[] = {
|
|
|
|
|
[MESA_SHADER_VERTEX] = DEBUG_VS,
|
|
|
|
|
[MESA_SHADER_TESS_CTRL] = DEBUG_TCS,
|
|
|
|
|
[MESA_SHADER_TESS_EVAL] = DEBUG_TES,
|
|
|
|
|
[MESA_SHADER_GEOMETRY] = DEBUG_GS,
|
|
|
|
|
[MESA_SHADER_FRAGMENT] = DEBUG_WM,
|
|
|
|
|
[MESA_SHADER_COMPUTE] = DEBUG_CS,
|
|
|
|
|
};
|
|
|
|
|
|
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 *
|
2017-03-23 11:56:06 +01:00
|
|
|
anv_shader_compile_to_nir(struct anv_pipeline *pipeline,
|
2017-09-28 21:51:48 -07:00
|
|
|
void *mem_ctx,
|
2015-12-02 14:35:07 -08:00
|
|
|
struct anv_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
|
|
|
{
|
2017-03-23 11:56:06 +01:00
|
|
|
const struct anv_device *device = pipeline->device;
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
const struct brw_compiler *compiler =
|
|
|
|
|
device->instance->physicalDevice.compiler;
|
|
|
|
|
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;
|
|
|
|
|
struct nir_spirv_specialization *spec_entries = NULL;
|
|
|
|
|
if (spec_info && spec_info->mapEntryCount > 0) {
|
|
|
|
|
num_spec_entries = spec_info->mapEntryCount;
|
|
|
|
|
spec_entries = malloc(num_spec_entries * sizeof(*spec_entries));
|
|
|
|
|
for (uint32_t i = 0; i < num_spec_entries; i++) {
|
|
|
|
|
VkSpecializationMapEntry entry = spec_info->pMapEntries[i];
|
|
|
|
|
const void *data = spec_info->pData + entry.offset;
|
|
|
|
|
assert(data + entry.size <= spec_info->pData + spec_info->dataSize);
|
|
|
|
|
|
|
|
|
|
spec_entries[i].id = spec_info->pMapEntries[i].constantID;
|
2016-11-14 12:08:32 +01:00
|
|
|
if (spec_info->dataSize == 8)
|
|
|
|
|
spec_entries[i].data64 = *(const uint64_t *)data;
|
|
|
|
|
else
|
|
|
|
|
spec_entries[i].data32 = *(const uint32_t *)data;
|
2016-01-12 16:30:43 -08:00
|
|
|
}
|
2016-10-07 21:50:31 -07:00
|
|
|
}
|
2016-01-12 16:30:43 -08:00
|
|
|
|
2017-10-18 17:28:19 -07:00
|
|
|
struct spirv_to_nir_options spirv_options = {
|
2017-10-18 18:02:49 -07:00
|
|
|
.lower_workgroup_access_to_offsets = true,
|
2017-10-18 17:28:19 -07:00
|
|
|
.caps = {
|
|
|
|
|
.float64 = device->instance->physicalDevice.info.gen >= 8,
|
|
|
|
|
.int64 = device->instance->physicalDevice.info.gen >= 8,
|
|
|
|
|
.tessellation = true,
|
2017-09-21 13:54:55 -07:00
|
|
|
.device_group = true,
|
2017-10-18 17:28:19 -07:00
|
|
|
.draw_parameters = true,
|
|
|
|
|
.image_write_without_format = true,
|
|
|
|
|
.multiview = true,
|
|
|
|
|
.variable_pointers = true,
|
2017-07-01 08:32:17 +02:00
|
|
|
.storage_16bit = device->instance->physicalDevice.info.gen >= 8,
|
2018-03-02 11:12:38 +01:00
|
|
|
.int16 = device->instance->physicalDevice.info.gen >= 8,
|
2018-04-26 12:11:20 -07:00
|
|
|
.shader_viewport_index_layer = true,
|
2017-04-28 01:22:39 -07:00
|
|
|
.subgroup_arithmetic = true,
|
|
|
|
|
.subgroup_basic = true,
|
|
|
|
|
.subgroup_ballot = true,
|
|
|
|
|
.subgroup_quad = true,
|
|
|
|
|
.subgroup_shuffle = true,
|
|
|
|
|
.subgroup_vote = true,
|
2018-03-19 23:06:45 -07:00
|
|
|
.stencil_export = device->instance->physicalDevice.info.gen >= 9,
|
2017-10-18 17:28:19 -07:00
|
|
|
},
|
2017-01-04 13:11:35 +01:00
|
|
|
};
|
|
|
|
|
|
2016-10-07 21:50:31 -07:00
|
|
|
nir_function *entry_point =
|
|
|
|
|
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);
|
2016-10-07 21:50:31 -07:00
|
|
|
nir_shader *nir = entry_point->shader;
|
2017-09-14 19:52:38 -07:00
|
|
|
assert(nir->info.stage == stage);
|
2016-10-07 21:50:31 -07:00
|
|
|
nir_validate_shader(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
|
|
|
|
2017-07-12 12:34:00 -07:00
|
|
|
if (unlikely(INTEL_DEBUG & stage_to_debug[stage])) {
|
|
|
|
|
fprintf(stderr, "NIR (from SPIR-V) for %s shader:\n",
|
|
|
|
|
gl_shader_stage_name(stage));
|
|
|
|
|
nir_print_shader(nir, stderr);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-19 10:50:40 -07:00
|
|
|
NIR_PASS_V(nir, nir_lower_deref_instrs, ~0);
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2017-01-06 17:22:56 -08:00
|
|
|
NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_local);
|
|
|
|
|
NIR_PASS_V(nir, nir_lower_returns);
|
|
|
|
|
NIR_PASS_V(nir, nir_inline_functions);
|
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) {
|
|
|
|
|
if (func != entry_point)
|
|
|
|
|
exec_node_remove(&func->node);
|
|
|
|
|
}
|
|
|
|
|
assert(exec_list_length(&nir->functions) == 1);
|
|
|
|
|
entry_point->name = ralloc_strdup(entry_point, "main");
|
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
|
|
|
*/
|
2018-03-22 18:37:42 -07:00
|
|
|
NIR_PASS_V(nir, nir_lower_constant_initializers, ~0);
|
2018-01-16 09:37:11 +01:00
|
|
|
|
2017-01-06 17:22:56 -08:00
|
|
|
NIR_PASS_V(nir, nir_remove_dead_variables,
|
|
|
|
|
nir_var_shader_in | nir_var_shader_out | nir_var_system_value);
|
2016-06-16 10:57:39 -07:00
|
|
|
|
2017-01-11 15:10:48 -08:00
|
|
|
if (stage == MESA_SHADER_FRAGMENT)
|
2017-03-23 11:56:06 +01:00
|
|
|
NIR_PASS_V(nir, nir_lower_wpos_center, pipeline->sample_shading_enable);
|
2017-01-11 15:10:48 -08:00
|
|
|
|
2017-01-06 17:22:56 -08:00
|
|
|
NIR_PASS_V(nir, nir_propagate_invariant);
|
|
|
|
|
NIR_PASS_V(nir, nir_lower_io_to_temporaries,
|
|
|
|
|
entry_point->impl, true, false);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
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
|
|
|
|
2016-04-13 20:25:39 -07:00
|
|
|
nir = brw_preprocess_nir(compiler, nir);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2016-11-14 14:23:36 -08:00
|
|
|
if (stage == MESA_SHADER_FRAGMENT)
|
2017-01-06 17:22:56 -08:00
|
|
|
NIR_PASS_V(nir, anv_nir_lower_input_attachments);
|
2016-11-14 14:23:36 -08:00
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
return nir;
|
|
|
|
|
}
|
2015-07-14 10:16:22 -07:00
|
|
|
|
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;
|
|
|
|
|
|
2015-12-02 03:28:27 -08:00
|
|
|
anv_reloc_list_finish(&pipeline->batch_relocs,
|
|
|
|
|
pAllocator ? pAllocator : &device->alloc);
|
2015-11-13 21:49:39 -08:00
|
|
|
if (pipeline->blend_state.map)
|
|
|
|
|
anv_state_pool_free(&device->dynamic_state_pool, pipeline->blend_state);
|
2016-08-25 01:49:49 -07:00
|
|
|
|
|
|
|
|
for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
|
|
|
|
|
if (pipeline->shaders[s])
|
|
|
|
|
anv_shader_bin_unref(device, pipeline->shaders[s]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 13:31:35 +10:00
|
|
|
vk_free2(&device->alloc, pAllocator, pipeline);
|
2015-07-14 10:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-20 22:53:54 -07:00
|
|
|
static const uint32_t vk_to_gen_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
|
2016-08-22 15:01:08 -07:00
|
|
|
populate_sampler_prog_key(const struct gen_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.
|
|
|
|
|
*/
|
|
|
|
|
if (devinfo->gen >= 9)
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-08-22 15:01:08 -07:00
|
|
|
populate_vs_prog_key(const struct gen_device_info *devinfo,
|
2015-10-19 22:06:59 -07:00
|
|
|
struct brw_vs_prog_key *key)
|
|
|
|
|
{
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
|
|
|
populate_sampler_prog_key(devinfo, &key->tex);
|
|
|
|
|
|
|
|
|
|
/* XXX: Handle vertex input work-arounds */
|
|
|
|
|
|
|
|
|
|
/* XXX: Handle sampler_prog_key */
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 18:45:48 -07:00
|
|
|
static void
|
2016-08-22 15:01:08 -07:00
|
|
|
populate_gs_prog_key(const struct gen_device_info *devinfo,
|
2015-10-21 18:45:48 -07:00
|
|
|
struct brw_gs_prog_key *key)
|
|
|
|
|
{
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
|
|
|
populate_sampler_prog_key(devinfo, &key->tex);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
static void
|
2017-01-10 12:46:25 +00:00
|
|
|
populate_wm_prog_key(const struct anv_pipeline *pipeline,
|
2015-10-19 22:06:59 -07:00
|
|
|
const VkGraphicsPipelineCreateInfo *info,
|
|
|
|
|
struct brw_wm_prog_key *key)
|
|
|
|
|
{
|
2017-01-10 12:46:25 +00:00
|
|
|
const struct gen_device_info *devinfo = &pipeline->device->info;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
|
|
|
populate_sampler_prog_key(devinfo, &key->tex);
|
|
|
|
|
|
2017-01-10 12:46:25 +00:00
|
|
|
/* TODO: we could set this to 0 based on the information in nir_shader, but
|
|
|
|
|
* this function is called before spirv_to_nir. */
|
|
|
|
|
const struct brw_vue_map *vue_map =
|
2017-01-12 17:07:08 -08:00
|
|
|
&anv_pipeline_get_last_vue_prog_data(pipeline)->vue_map;
|
2017-01-10 12:46:25 +00:00
|
|
|
key->input_slots_valid = vue_map->slots_valid;
|
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;
|
|
|
|
|
|
2017-03-22 15:36:46 -07:00
|
|
|
key->nr_color_regions = pipeline->subpass->color_count;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
key->replicate_alpha = key->nr_color_regions > 1 &&
|
2015-11-30 17:20:49 -08:00
|
|
|
info->pMultisampleState &&
|
|
|
|
|
info->pMultisampleState->alphaToCoverageEnable;
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-03-23 11:56:06 +01:00
|
|
|
if (info->pMultisampleState) {
|
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-03-23 11:56:06 +01:00
|
|
|
if (info->pMultisampleState->rasterizationSamples > 1) {
|
|
|
|
|
key->persample_interp =
|
|
|
|
|
(info->pMultisampleState->minSampleShading *
|
|
|
|
|
info->pMultisampleState->rasterizationSamples) > 1;
|
|
|
|
|
key->multisample_fbo = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
key->frag_coord_adds_sample_pos =
|
|
|
|
|
info->pMultisampleState->sampleShadingEnable;
|
2015-10-19 22:06:59 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-08-22 15:01:08 -07:00
|
|
|
populate_cs_prog_key(const struct gen_device_info *devinfo,
|
2015-10-19 22:06:59 -07:00
|
|
|
struct brw_cs_prog_key *key)
|
|
|
|
|
{
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
|
|
|
populate_sampler_prog_key(devinfo, &key->tex);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 06:25:06 -07:00
|
|
|
static void
|
|
|
|
|
anv_pipeline_hash_shader(struct anv_pipeline *pipeline,
|
2018-01-25 10:25:00 +01:00
|
|
|
struct anv_pipeline_layout *layout,
|
2017-04-27 06:25:06 -07:00
|
|
|
struct anv_shader_module *module,
|
|
|
|
|
const char *entrypoint,
|
|
|
|
|
gl_shader_stage stage,
|
|
|
|
|
const VkSpecializationInfo *spec_info,
|
|
|
|
|
const void *key, size_t key_size,
|
|
|
|
|
unsigned char *sha1_out)
|
|
|
|
|
{
|
|
|
|
|
struct mesa_sha1 ctx;
|
|
|
|
|
|
|
|
|
|
_mesa_sha1_init(&ctx);
|
2017-03-22 15:37:17 -07:00
|
|
|
if (stage != MESA_SHADER_COMPUTE) {
|
|
|
|
|
_mesa_sha1_update(&ctx, &pipeline->subpass->view_mask,
|
|
|
|
|
sizeof(pipeline->subpass->view_mask));
|
|
|
|
|
}
|
2018-01-25 10:25:00 +01:00
|
|
|
if (layout)
|
|
|
|
|
_mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
|
2017-04-27 06:25:06 -07:00
|
|
|
_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);
|
|
|
|
|
}
|
|
|
|
|
_mesa_sha1_update(&ctx, key, key_size);
|
|
|
|
|
_mesa_sha1_final(&ctx, sha1_out);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
static nir_shader *
|
|
|
|
|
anv_pipeline_compile(struct anv_pipeline *pipeline,
|
2017-09-28 21:51:48 -07:00
|
|
|
void *mem_ctx,
|
2018-01-25 10:25:00 +01:00
|
|
|
struct anv_pipeline_layout *layout,
|
2015-12-02 14:35:07 -08:00
|
|
|
struct anv_shader_module *module,
|
|
|
|
|
const char *entrypoint,
|
2015-12-02 16:08:13 -08:00
|
|
|
gl_shader_stage stage,
|
2016-01-12 16:30:43 -08:00
|
|
|
const VkSpecializationInfo *spec_info,
|
2016-03-04 12:56:14 -08:00
|
|
|
struct brw_stage_prog_data *prog_data,
|
|
|
|
|
struct anv_pipeline_bind_map *map)
|
2015-10-19 22:06:59 -07:00
|
|
|
{
|
2017-12-01 16:10:48 -08:00
|
|
|
const struct brw_compiler *compiler =
|
|
|
|
|
pipeline->device->instance->physicalDevice.compiler;
|
|
|
|
|
|
2017-09-28 21:51:48 -07:00
|
|
|
nir_shader *nir = anv_shader_compile_to_nir(pipeline, mem_ctx,
|
2016-01-12 16:30:43 -08:00
|
|
|
module, entrypoint, stage,
|
|
|
|
|
spec_info);
|
2015-10-19 22:06:59 -07:00
|
|
|
if (nir == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
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
|
|
|
|
2017-01-06 17:22:56 -08:00
|
|
|
NIR_PASS_V(nir, anv_nir_lower_push_constants);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-03-22 15:37:17 -07:00
|
|
|
if (stage != MESA_SHADER_COMPUTE)
|
|
|
|
|
NIR_PASS_V(nir, anv_nir_lower_multiview, pipeline->subpass->view_mask);
|
|
|
|
|
|
2017-10-18 18:02:49 -07:00
|
|
|
if (stage == MESA_SHADER_COMPUTE)
|
2017-08-21 17:41:28 -07:00
|
|
|
prog_data->total_shared = nir->num_shared;
|
|
|
|
|
|
2017-03-22 15:24:06 -07:00
|
|
|
nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
|
|
|
|
|
|
2015-10-29 22:24:54 -07:00
|
|
|
if (nir->num_uniforms > 0) {
|
2017-09-29 11:18:04 -07:00
|
|
|
assert(prog_data->nr_params == 0);
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
/* If the shader uses any push constants at all, we'll just give
|
|
|
|
|
* them the maximum possible number
|
|
|
|
|
*/
|
2016-07-13 11:35:24 -07:00
|
|
|
assert(nir->num_uniforms <= MAX_PUSH_CONSTANTS_SIZE);
|
2017-09-29 11:09:04 -07:00
|
|
|
nir->num_uniforms = MAX_PUSH_CONSTANTS_SIZE;
|
2015-10-19 22:06:59 -07:00
|
|
|
prog_data->nr_params += MAX_PUSH_CONSTANTS_SIZE / sizeof(float);
|
2017-09-29 10:06:17 -07:00
|
|
|
prog_data->param = ralloc_array(mem_ctx, uint32_t, prog_data->nr_params);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
/* We now set the param values to be offsets into a
|
|
|
|
|
* anv_push_constant_data structure. Since the compiler doesn't
|
|
|
|
|
* actually dereference any of the gl_constant_value pointers in the
|
|
|
|
|
* params array, it doesn't really matter what we put here.
|
|
|
|
|
*/
|
|
|
|
|
struct anv_push_constants *null_data = NULL;
|
2017-09-29 11:18:04 -07:00
|
|
|
/* Fill out the push constants section of the param array */
|
|
|
|
|
for (unsigned i = 0; i < MAX_PUSH_CONSTANTS_SIZE / sizeof(float); i++) {
|
|
|
|
|
prog_data->param[i] = ANV_PARAM_PUSH(
|
|
|
|
|
(uintptr_t)&null_data->client_data[i * sizeof(float)]);
|
2015-10-19 22:06:59 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 11:18:04 -07:00
|
|
|
if (nir->info.num_ssbos > 0 || nir->info.num_images > 0)
|
|
|
|
|
pipeline->needs_data_cache = true;
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
/* Apply the actual pipeline layout to UBOs, SSBOs, and textures */
|
2018-01-25 10:25:00 +01:00
|
|
|
if (layout)
|
|
|
|
|
anv_nir_apply_pipeline_layout(pipeline, layout, nir, prog_data, map);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-12-01 16:10:48 -08:00
|
|
|
if (stage != MESA_SHADER_COMPUTE)
|
|
|
|
|
brw_nir_analyze_ubo_ranges(compiler, nir, prog_data->ubo_ranges);
|
|
|
|
|
|
2017-09-29 11:09:04 -07:00
|
|
|
assert(nir->num_uniforms == prog_data->nr_params * 4);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
return nir;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 18:07:48 -08:00
|
|
|
static void
|
|
|
|
|
anv_fill_binding_table(struct brw_stage_prog_data *prog_data, unsigned bias)
|
|
|
|
|
{
|
|
|
|
|
prog_data->binding_table.size_bytes = 0;
|
|
|
|
|
prog_data->binding_table.texture_start = bias;
|
2016-07-20 20:06:09 -07:00
|
|
|
prog_data->binding_table.gather_texture_start = bias;
|
2016-03-07 18:07:48 -08:00
|
|
|
prog_data->binding_table.ubo_start = bias;
|
|
|
|
|
prog_data->binding_table.ssbo_start = bias;
|
|
|
|
|
prog_data->binding_table.image_start = bias;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
static struct anv_shader_bin *
|
|
|
|
|
anv_pipeline_upload_kernel(struct anv_pipeline *pipeline,
|
|
|
|
|
struct anv_pipeline_cache *cache,
|
|
|
|
|
const void *key_data, uint32_t key_size,
|
|
|
|
|
const void *kernel_data, uint32_t kernel_size,
|
2016-11-01 16:03:12 -07:00
|
|
|
const struct brw_stage_prog_data *prog_data,
|
|
|
|
|
uint32_t prog_data_size,
|
2016-08-25 01:49:49 -07:00
|
|
|
const struct anv_pipeline_bind_map *bind_map)
|
|
|
|
|
{
|
|
|
|
|
if (cache) {
|
|
|
|
|
return anv_pipeline_cache_upload_kernel(cache, key_data, key_size,
|
|
|
|
|
kernel_data, kernel_size,
|
|
|
|
|
prog_data, prog_data_size,
|
|
|
|
|
bind_map);
|
|
|
|
|
} else {
|
|
|
|
|
return anv_shader_bin_create(pipeline->device, key_data, key_size,
|
|
|
|
|
kernel_data, kernel_size,
|
2016-11-01 15:10:29 -07:00
|
|
|
prog_data, prog_data_size,
|
|
|
|
|
prog_data->param, bind_map);
|
2016-08-25 01:49:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
static void
|
|
|
|
|
anv_pipeline_add_compiled_stage(struct anv_pipeline *pipeline,
|
2015-12-02 16:08:13 -08:00
|
|
|
gl_shader_stage stage,
|
2016-08-25 01:49:49 -07:00
|
|
|
struct anv_shader_bin *shader)
|
2015-10-19 22:06:59 -07:00
|
|
|
{
|
2016-08-25 01:49:49 -07:00
|
|
|
pipeline->shaders[stage] = shader;
|
2015-10-19 22:06:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static VkResult
|
|
|
|
|
anv_pipeline_compile_vs(struct anv_pipeline *pipeline,
|
2016-01-05 12:00:54 -08:00
|
|
|
struct anv_pipeline_cache *cache,
|
2015-10-19 22:06:59 -07:00
|
|
|
const VkGraphicsPipelineCreateInfo *info,
|
2015-12-02 14:35:07 -08:00
|
|
|
struct anv_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
|
|
|
{
|
|
|
|
|
const struct brw_compiler *compiler =
|
|
|
|
|
pipeline->device->instance->physicalDevice.compiler;
|
|
|
|
|
struct brw_vs_prog_key key;
|
2016-08-25 01:49:49 -07:00
|
|
|
struct anv_shader_bin *bin = NULL;
|
2016-03-04 10:59:21 -08:00
|
|
|
unsigned char sha1[20];
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
populate_vs_prog_key(&pipeline->device->info, &key);
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
if (cache) {
|
2018-01-25 10:25:00 +01:00
|
|
|
anv_pipeline_hash_shader(pipeline, layout, module, entrypoint,
|
2017-04-27 06:25:06 -07:00
|
|
|
MESA_SHADER_VERTEX, spec_info,
|
|
|
|
|
&key, sizeof(key), sha1);
|
2016-08-25 01:49:49 -07:00
|
|
|
bin = anv_pipeline_cache_search(cache, sha1, 20);
|
2016-02-10 09:43:03 -08:00
|
|
|
}
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
if (bin == NULL) {
|
2017-08-25 20:22:11 -07:00
|
|
|
struct brw_vs_prog_data prog_data = {};
|
2016-03-04 12:56:14 -08:00
|
|
|
struct anv_pipeline_binding surface_to_descriptor[256];
|
|
|
|
|
struct anv_pipeline_binding sampler_to_descriptor[256];
|
|
|
|
|
|
2017-10-11 12:28:20 -07:00
|
|
|
struct anv_pipeline_bind_map map = {
|
2016-03-04 12:56:14 -08:00
|
|
|
.surface_to_descriptor = surface_to_descriptor,
|
|
|
|
|
.sampler_to_descriptor = sampler_to_descriptor
|
|
|
|
|
};
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-09-28 21:51:48 -07:00
|
|
|
void *mem_ctx = ralloc_context(NULL);
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, layout,
|
2017-09-28 21:51:48 -07:00
|
|
|
module, entrypoint,
|
2016-02-10 09:43:03 -08:00
|
|
|
MESA_SHADER_VERTEX, spec_info,
|
2016-03-04 12:56:14 -08:00
|
|
|
&prog_data.base.base, &map);
|
2017-09-28 21:51:48 -07:00
|
|
|
if (nir == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
2016-02-10 09:43:03 -08:00
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
2017-09-28 21:51:48 -07:00
|
|
|
}
|
2016-02-10 09:43:03 -08:00
|
|
|
|
2016-03-07 18:07:48 -08:00
|
|
|
anv_fill_binding_table(&prog_data.base.base, 0);
|
|
|
|
|
|
2016-02-10 09:43:03 -08:00
|
|
|
brw_compute_vue_map(&pipeline->device->info,
|
2016-03-04 08:15:16 -08:00
|
|
|
&prog_data.base.vue_map,
|
2017-05-08 09:20:21 -07:00
|
|
|
nir->info.outputs_written,
|
|
|
|
|
nir->info.separate_shader);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2016-02-10 09:43:03 -08:00
|
|
|
const unsigned *shader_code =
|
2016-03-04 08:15:16 -08:00
|
|
|
brw_compile_vs(compiler, NULL, mem_ctx, &key, &prog_data, nir,
|
i965: Drop support for the legacy SNORM -> Float equation.
Older OpenGL defines two equations for converting from signed-normalized
to floating point data. These are:
f = (2c + 1)/(2^b - 1) (equation 2.2)
f = max{c/2^(b-1) - 1), -1.0} (equation 2.3)
Both OpenGL 4.2+ and OpenGL ES 3.0+ mandate that equation 2.3 is to be
used in all scenarios, and remove equation 2.2. DirectX uses equation
2.3 as well. Intel hardware only supports equation 2.3, so Gen7.5+
systems that use the vertex fetcher hardware to do the conversions
always get formula 2.3.
This can make a big difference for 10-10-10-2 formats - the 2-bit value
can represent 0 with equation 2.3, and cannot with equation 2.2.
Ivybridge and older were using equation 2.2 for OpenGL, and 2.3 for ES.
Now that Ivybridge supports OpenGL 4.2, this is wrong - we need to use
the new rules, at least in core profile. That would leave Gen4-6 doing
something different than all other hardware, which seems...lame.
With context version promotion, applications that requested a pre-4.2
context may get promoted to 4.2, and thus get the new rules. Zero cases
have been reported of this being a problem. However, we've received a
report that following the old rules breaks expectations. SuperTuxKart
apparently renders the cars red when following equation 2.2, and works
correctly when following equation 2.3:
https://github.com/supertuxkart/stk-code/issues/2885#issuecomment-353858405
So, this patch deletes the legacy equation 2.2 support entirely, making
all hardware and APIs consistently use the new equation 2.3 rules.
If we ever find an application that truly requires the old formula, then
we'd likely want that application to work on modern hardware, too. We'd
likely restore this support as a driconf option. Until then, drop it.
This commit will regress Piglit's draw-vertices-2101010 test on
pre-Haswell without the corresponding Piglit patch to accept either
formula (commit 35daaa1695ea01eb85bc02f9be9b6ebd1a7113a1):
draw-vertices-2101010: Accept either SNORM conversion formula.
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
2017-12-25 19:10:22 -08:00
|
|
|
-1, NULL);
|
2016-02-10 09:43:03 -08:00
|
|
|
if (shader_code == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-10-21 20:55:45 -07:00
|
|
|
unsigned code_size = prog_data.base.base.program_size;
|
2016-08-25 01:49:49 -07:00
|
|
|
bin = anv_pipeline_upload_kernel(pipeline, cache, sha1, 20,
|
|
|
|
|
shader_code, code_size,
|
2016-11-01 16:03:12 -07:00
|
|
|
&prog_data.base.base, sizeof(prog_data),
|
|
|
|
|
&map);
|
2016-08-25 01:49:49 -07:00
|
|
|
if (!bin) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
anv_pipeline_add_compiled_stage(pipeline, MESA_SHADER_VERTEX, bin);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static VkResult
|
|
|
|
|
anv_pipeline_compile_tcs_tes(struct anv_pipeline *pipeline,
|
|
|
|
|
struct anv_pipeline_cache *cache,
|
|
|
|
|
const VkGraphicsPipelineCreateInfo *info,
|
|
|
|
|
struct anv_shader_module *tcs_module,
|
|
|
|
|
const char *tcs_entrypoint,
|
|
|
|
|
const VkSpecializationInfo *tcs_spec_info,
|
|
|
|
|
struct anv_shader_module *tes_module,
|
|
|
|
|
const char *tes_entrypoint,
|
|
|
|
|
const VkSpecializationInfo *tes_spec_info)
|
|
|
|
|
{
|
|
|
|
|
const struct gen_device_info *devinfo = &pipeline->device->info;
|
|
|
|
|
const struct brw_compiler *compiler =
|
|
|
|
|
pipeline->device->instance->physicalDevice.compiler;
|
2017-08-25 20:22:11 -07:00
|
|
|
struct brw_tcs_prog_key tcs_key = {};
|
|
|
|
|
struct brw_tes_prog_key tes_key = {};
|
2016-09-25 17:43:06 -07:00
|
|
|
struct anv_shader_bin *tcs_bin = NULL;
|
|
|
|
|
struct anv_shader_bin *tes_bin = NULL;
|
|
|
|
|
unsigned char tcs_sha1[40];
|
|
|
|
|
unsigned char tes_sha1[40];
|
|
|
|
|
|
|
|
|
|
populate_sampler_prog_key(&pipeline->device->info, &tcs_key.tex);
|
|
|
|
|
populate_sampler_prog_key(&pipeline->device->info, &tes_key.tex);
|
|
|
|
|
tcs_key.input_vertices = info->pTessellationState->patchControlPoints;
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
|
|
|
|
|
|
2016-09-25 17:43:06 -07:00
|
|
|
if (cache) {
|
2018-01-25 10:25:00 +01:00
|
|
|
anv_pipeline_hash_shader(pipeline, layout, tcs_module, tcs_entrypoint,
|
2017-04-27 06:25:06 -07:00
|
|
|
MESA_SHADER_TESS_CTRL, tcs_spec_info,
|
|
|
|
|
&tcs_key, sizeof(tcs_key), tcs_sha1);
|
2018-01-25 10:25:00 +01:00
|
|
|
anv_pipeline_hash_shader(pipeline, layout, tes_module, tes_entrypoint,
|
2017-04-27 06:25:06 -07:00
|
|
|
MESA_SHADER_TESS_EVAL, tes_spec_info,
|
|
|
|
|
&tes_key, sizeof(tes_key), tes_sha1);
|
2016-09-25 17:43:06 -07:00
|
|
|
memcpy(&tcs_sha1[20], tes_sha1, 20);
|
|
|
|
|
memcpy(&tes_sha1[20], tcs_sha1, 20);
|
|
|
|
|
tcs_bin = anv_pipeline_cache_search(cache, tcs_sha1, sizeof(tcs_sha1));
|
|
|
|
|
tes_bin = anv_pipeline_cache_search(cache, tes_sha1, sizeof(tes_sha1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tcs_bin == NULL || tes_bin == NULL) {
|
2017-08-25 20:22:11 -07:00
|
|
|
struct brw_tcs_prog_data tcs_prog_data = {};
|
|
|
|
|
struct brw_tes_prog_data tes_prog_data = {};
|
2016-09-25 17:43:06 -07:00
|
|
|
struct anv_pipeline_binding tcs_surface_to_descriptor[256];
|
|
|
|
|
struct anv_pipeline_binding tcs_sampler_to_descriptor[256];
|
|
|
|
|
struct anv_pipeline_binding tes_surface_to_descriptor[256];
|
|
|
|
|
struct anv_pipeline_binding tes_sampler_to_descriptor[256];
|
|
|
|
|
|
2017-10-11 12:28:20 -07:00
|
|
|
struct anv_pipeline_bind_map tcs_map = {
|
2016-09-25 17:43:06 -07:00
|
|
|
.surface_to_descriptor = tcs_surface_to_descriptor,
|
|
|
|
|
.sampler_to_descriptor = tcs_sampler_to_descriptor
|
|
|
|
|
};
|
2017-10-11 12:28:20 -07:00
|
|
|
struct anv_pipeline_bind_map tes_map = {
|
2016-09-25 17:43:06 -07:00
|
|
|
.surface_to_descriptor = tes_surface_to_descriptor,
|
|
|
|
|
.sampler_to_descriptor = tes_sampler_to_descriptor
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-28 21:51:48 -07:00
|
|
|
void *mem_ctx = ralloc_context(NULL);
|
|
|
|
|
|
2016-09-25 17:43:06 -07:00
|
|
|
nir_shader *tcs_nir =
|
2018-01-25 10:25:00 +01:00
|
|
|
anv_pipeline_compile(pipeline, mem_ctx, layout,
|
|
|
|
|
tcs_module, tcs_entrypoint,
|
2016-09-25 17:43:06 -07:00
|
|
|
MESA_SHADER_TESS_CTRL, tcs_spec_info,
|
|
|
|
|
&tcs_prog_data.base.base, &tcs_map);
|
|
|
|
|
nir_shader *tes_nir =
|
2018-01-25 10:25:00 +01:00
|
|
|
anv_pipeline_compile(pipeline, mem_ctx, layout,
|
|
|
|
|
tes_module, tes_entrypoint,
|
2016-09-25 17:43:06 -07:00
|
|
|
MESA_SHADER_TESS_EVAL, tes_spec_info,
|
|
|
|
|
&tes_prog_data.base.base, &tes_map);
|
2017-09-28 21:51:48 -07:00
|
|
|
if (tcs_nir == NULL || tes_nir == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
2016-09-25 17:43:06 -07:00
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
2017-09-28 21:51:48 -07:00
|
|
|
}
|
2016-09-25 17:43:06 -07:00
|
|
|
|
|
|
|
|
nir_lower_tes_patch_vertices(tes_nir,
|
2017-05-08 09:20:21 -07:00
|
|
|
tcs_nir->info.tess.tcs_vertices_out);
|
2016-09-25 17:43:06 -07:00
|
|
|
|
|
|
|
|
/* Copy TCS info into the TES info */
|
2017-05-08 09:20:21 -07:00
|
|
|
merge_tess_info(&tes_nir->info, &tcs_nir->info);
|
2016-09-25 17:43:06 -07:00
|
|
|
|
|
|
|
|
anv_fill_binding_table(&tcs_prog_data.base.base, 0);
|
|
|
|
|
anv_fill_binding_table(&tes_prog_data.base.base, 0);
|
|
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
|
*/
|
2017-05-08 09:20:21 -07:00
|
|
|
tcs_key.tes_primitive_mode = tes_nir->info.tess.primitive_mode;
|
|
|
|
|
tcs_key.outputs_written = tcs_nir->info.outputs_written;
|
|
|
|
|
tcs_key.patch_outputs_written = tcs_nir->info.patch_outputs_written;
|
2016-09-25 17:43:06 -07:00
|
|
|
tcs_key.quads_workaround =
|
|
|
|
|
devinfo->gen < 9 &&
|
2017-05-08 09:20:21 -07:00
|
|
|
tes_nir->info.tess.primitive_mode == 7 /* GL_QUADS */ &&
|
|
|
|
|
tes_nir->info.tess.spacing == TESS_SPACING_EQUAL;
|
2016-09-25 17:43:06 -07:00
|
|
|
|
|
|
|
|
tes_key.inputs_read = tcs_key.outputs_written;
|
|
|
|
|
tes_key.patch_inputs_read = tcs_key.patch_outputs_written;
|
|
|
|
|
|
|
|
|
|
const int shader_time_index = -1;
|
|
|
|
|
const unsigned *shader_code;
|
|
|
|
|
|
|
|
|
|
shader_code =
|
|
|
|
|
brw_compile_tcs(compiler, NULL, mem_ctx, &tcs_key, &tcs_prog_data,
|
2017-10-21 20:55:45 -07:00
|
|
|
tcs_nir, shader_time_index, NULL);
|
2016-09-25 17:43:06 -07:00
|
|
|
if (shader_code == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-21 20:55:45 -07:00
|
|
|
unsigned code_size = tcs_prog_data.base.base.program_size;
|
2016-09-25 17:43:06 -07:00
|
|
|
tcs_bin = anv_pipeline_upload_kernel(pipeline, cache,
|
|
|
|
|
tcs_sha1, sizeof(tcs_sha1),
|
|
|
|
|
shader_code, code_size,
|
|
|
|
|
&tcs_prog_data.base.base,
|
|
|
|
|
sizeof(tcs_prog_data),
|
|
|
|
|
&tcs_map);
|
|
|
|
|
if (!tcs_bin) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shader_code =
|
|
|
|
|
brw_compile_tes(compiler, NULL, mem_ctx, &tes_key,
|
|
|
|
|
&tcs_prog_data.base.vue_map, &tes_prog_data, tes_nir,
|
2017-10-21 20:55:45 -07:00
|
|
|
NULL, shader_time_index, NULL);
|
2016-09-25 17:43:06 -07:00
|
|
|
if (shader_code == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-21 20:55:45 -07:00
|
|
|
code_size = tes_prog_data.base.base.program_size;
|
2016-09-25 17:43:06 -07:00
|
|
|
tes_bin = anv_pipeline_upload_kernel(pipeline, cache,
|
|
|
|
|
tes_sha1, sizeof(tes_sha1),
|
|
|
|
|
shader_code, code_size,
|
|
|
|
|
&tes_prog_data.base.base,
|
|
|
|
|
sizeof(tes_prog_data),
|
|
|
|
|
&tes_map);
|
|
|
|
|
if (!tes_bin) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
anv_pipeline_add_compiled_stage(pipeline, MESA_SHADER_TESS_CTRL, tcs_bin);
|
|
|
|
|
anv_pipeline_add_compiled_stage(pipeline, MESA_SHADER_TESS_EVAL, tes_bin);
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 18:45:48 -07:00
|
|
|
static VkResult
|
|
|
|
|
anv_pipeline_compile_gs(struct anv_pipeline *pipeline,
|
2016-01-05 12:00:54 -08:00
|
|
|
struct anv_pipeline_cache *cache,
|
2015-10-21 18:45:48 -07:00
|
|
|
const VkGraphicsPipelineCreateInfo *info,
|
2015-12-02 14:35:07 -08:00
|
|
|
struct anv_shader_module *module,
|
2016-01-12 16:30:43 -08:00
|
|
|
const char *entrypoint,
|
|
|
|
|
const VkSpecializationInfo *spec_info)
|
2015-10-21 18:45:48 -07:00
|
|
|
{
|
|
|
|
|
const struct brw_compiler *compiler =
|
|
|
|
|
pipeline->device->instance->physicalDevice.compiler;
|
|
|
|
|
struct brw_gs_prog_key key;
|
2016-08-25 01:49:49 -07:00
|
|
|
struct anv_shader_bin *bin = NULL;
|
2016-03-04 10:59:21 -08:00
|
|
|
unsigned char sha1[20];
|
2015-10-21 18:45:48 -07:00
|
|
|
|
|
|
|
|
populate_gs_prog_key(&pipeline->device->info, &key);
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
if (cache) {
|
2018-01-25 10:25:00 +01:00
|
|
|
anv_pipeline_hash_shader(pipeline, layout, module, entrypoint,
|
2017-04-27 06:25:06 -07:00
|
|
|
MESA_SHADER_GEOMETRY, spec_info,
|
|
|
|
|
&key, sizeof(key), sha1);
|
2016-08-25 01:49:49 -07:00
|
|
|
bin = anv_pipeline_cache_search(cache, sha1, 20);
|
2016-02-10 09:43:03 -08:00
|
|
|
}
|
2015-10-21 18:45:48 -07:00
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
if (bin == NULL) {
|
2017-08-25 20:22:11 -07:00
|
|
|
struct brw_gs_prog_data prog_data = {};
|
2016-03-04 12:56:14 -08:00
|
|
|
struct anv_pipeline_binding surface_to_descriptor[256];
|
|
|
|
|
struct anv_pipeline_binding sampler_to_descriptor[256];
|
|
|
|
|
|
2017-10-11 12:28:20 -07:00
|
|
|
struct anv_pipeline_bind_map map = {
|
2016-03-04 12:56:14 -08:00
|
|
|
.surface_to_descriptor = surface_to_descriptor,
|
|
|
|
|
.sampler_to_descriptor = sampler_to_descriptor
|
|
|
|
|
};
|
2015-10-21 18:45:48 -07:00
|
|
|
|
2017-09-28 21:51:48 -07:00
|
|
|
void *mem_ctx = ralloc_context(NULL);
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, layout,
|
2017-09-28 21:51:48 -07:00
|
|
|
module, entrypoint,
|
2016-02-10 09:43:03 -08:00
|
|
|
MESA_SHADER_GEOMETRY, spec_info,
|
2016-03-04 12:56:14 -08:00
|
|
|
&prog_data.base.base, &map);
|
2017-09-28 21:51:48 -07:00
|
|
|
if (nir == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
2016-02-10 09:43:03 -08:00
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
2017-09-28 21:51:48 -07:00
|
|
|
}
|
2016-02-10 09:43:03 -08:00
|
|
|
|
2016-03-07 18:07:48 -08:00
|
|
|
anv_fill_binding_table(&prog_data.base.base, 0);
|
|
|
|
|
|
2016-02-10 09:43:03 -08:00
|
|
|
brw_compute_vue_map(&pipeline->device->info,
|
2016-03-04 08:15:16 -08:00
|
|
|
&prog_data.base.vue_map,
|
2017-05-08 09:20:21 -07:00
|
|
|
nir->info.outputs_written,
|
|
|
|
|
nir->info.separate_shader);
|
2016-01-19 12:02:53 -08:00
|
|
|
|
2016-02-10 09:43:03 -08:00
|
|
|
const unsigned *shader_code =
|
2016-03-04 08:15:16 -08:00
|
|
|
brw_compile_gs(compiler, NULL, mem_ctx, &key, &prog_data, nir,
|
2017-10-21 20:55:45 -07:00
|
|
|
NULL, -1, NULL);
|
2016-02-10 09:43:03 -08:00
|
|
|
if (shader_code == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: SIMD8 GS */
|
2017-10-21 20:55:45 -07:00
|
|
|
const unsigned code_size = prog_data.base.base.program_size;
|
2016-08-25 01:49:49 -07:00
|
|
|
bin = anv_pipeline_upload_kernel(pipeline, cache, sha1, 20,
|
|
|
|
|
shader_code, code_size,
|
2016-11-01 16:03:12 -07:00
|
|
|
&prog_data.base.base, sizeof(prog_data),
|
|
|
|
|
&map);
|
2016-08-25 01:49:49 -07:00
|
|
|
if (!bin) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
2015-10-21 18:45:48 -07:00
|
|
|
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
anv_pipeline_add_compiled_stage(pipeline, MESA_SHADER_GEOMETRY, bin);
|
2015-10-21 18:45:48 -07:00
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
static VkResult
|
|
|
|
|
anv_pipeline_compile_fs(struct anv_pipeline *pipeline,
|
2016-01-05 12:00:54 -08:00
|
|
|
struct anv_pipeline_cache *cache,
|
2015-10-19 22:06:59 -07:00
|
|
|
const VkGraphicsPipelineCreateInfo *info,
|
2015-12-02 14:35:07 -08:00
|
|
|
struct anv_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
|
|
|
{
|
|
|
|
|
const struct brw_compiler *compiler =
|
|
|
|
|
pipeline->device->instance->physicalDevice.compiler;
|
|
|
|
|
struct brw_wm_prog_key key;
|
2016-08-25 01:49:49 -07:00
|
|
|
struct anv_shader_bin *bin = NULL;
|
2016-03-04 10:59:21 -08:00
|
|
|
unsigned char sha1[20];
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-01-10 12:46:25 +00:00
|
|
|
populate_wm_prog_key(pipeline, info, &key);
|
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);
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
if (cache) {
|
2018-01-25 10:25:00 +01:00
|
|
|
anv_pipeline_hash_shader(pipeline, layout, module, entrypoint,
|
2017-04-27 06:25:06 -07:00
|
|
|
MESA_SHADER_FRAGMENT, spec_info,
|
|
|
|
|
&key, sizeof(key), sha1);
|
2016-08-25 01:49:49 -07:00
|
|
|
bin = anv_pipeline_cache_search(cache, sha1, 20);
|
2016-02-10 09:43:03 -08:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
if (bin == NULL) {
|
2017-08-25 20:22:11 -07:00
|
|
|
struct brw_wm_prog_data prog_data = {};
|
2016-03-04 12:56:14 -08:00
|
|
|
struct anv_pipeline_binding surface_to_descriptor[256];
|
|
|
|
|
struct anv_pipeline_binding sampler_to_descriptor[256];
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-10-11 12:28:20 -07:00
|
|
|
struct anv_pipeline_bind_map map = {
|
2016-03-07 17:28:00 -08:00
|
|
|
.surface_to_descriptor = surface_to_descriptor + 8,
|
2016-03-04 12:56:14 -08:00
|
|
|
.sampler_to_descriptor = sampler_to_descriptor
|
|
|
|
|
};
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-09-28 21:51:48 -07:00
|
|
|
void *mem_ctx = ralloc_context(NULL);
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, layout,
|
2017-09-28 21:51:48 -07:00
|
|
|
module, entrypoint,
|
2016-02-10 09:43:03 -08:00
|
|
|
MESA_SHADER_FRAGMENT, spec_info,
|
2016-03-04 12:56:14 -08:00
|
|
|
&prog_data.base, &map);
|
2017-09-28 21:51:48 -07:00
|
|
|
if (nir == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
2016-02-10 09:43:03 -08:00
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
2017-09-28 21:51:48 -07:00
|
|
|
}
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2016-03-07 17:28:00 -08:00
|
|
|
unsigned num_rts = 0;
|
2017-10-31 11:47:57 +01:00
|
|
|
const int max_rt = FRAG_RESULT_DATA7 - FRAG_RESULT_DATA0 + 1;
|
|
|
|
|
struct anv_pipeline_binding rt_bindings[max_rt];
|
2016-08-24 19:09:57 -07:00
|
|
|
nir_function_impl *impl = nir_shader_get_entrypoint(nir);
|
2017-10-31 11:47:57 +01:00
|
|
|
int rt_to_bindings[max_rt];
|
|
|
|
|
memset(rt_to_bindings, -1, sizeof(rt_to_bindings));
|
|
|
|
|
bool rt_used[max_rt];
|
|
|
|
|
memset(rt_used, 0, sizeof(rt_used));
|
|
|
|
|
|
|
|
|
|
/* Flag used render targets */
|
|
|
|
|
nir_foreach_variable_safe(var, &nir->outputs) {
|
|
|
|
|
if (var->data.location < FRAG_RESULT_DATA0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const unsigned rt = var->data.location - FRAG_RESULT_DATA0;
|
|
|
|
|
/* Out-of-bounds */
|
|
|
|
|
if (rt >= key.nr_color_regions)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const unsigned array_len =
|
|
|
|
|
glsl_type_is_array(var->type) ? glsl_get_length(var->type) : 1;
|
|
|
|
|
assert(rt + array_len <= max_rt);
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < array_len; i++)
|
|
|
|
|
rt_used[rt + i] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set new, compacted, location */
|
|
|
|
|
for (unsigned i = 0; i < max_rt; i++) {
|
|
|
|
|
if (!rt_used[i])
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
rt_to_bindings[i] = num_rts;
|
|
|
|
|
rt_bindings[rt_to_bindings[i]] = (struct anv_pipeline_binding) {
|
|
|
|
|
.set = ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS,
|
|
|
|
|
.binding = 0,
|
|
|
|
|
.index = i,
|
|
|
|
|
};
|
|
|
|
|
num_rts++;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 13:46:44 -08:00
|
|
|
nir_foreach_variable_safe(var, &nir->outputs) {
|
|
|
|
|
if (var->data.location < FRAG_RESULT_DATA0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-10-31 11:47:57 +01:00
|
|
|
const unsigned rt = var->data.location - FRAG_RESULT_DATA0;
|
2016-02-17 13:46:44 -08:00
|
|
|
if (rt >= key.nr_color_regions) {
|
2016-03-07 17:28:00 -08:00
|
|
|
/* Out-of-bounds, throw it away */
|
2016-02-17 13:46:44 -08:00
|
|
|
var->data.mode = nir_var_local;
|
|
|
|
|
exec_node_remove(&var->node);
|
|
|
|
|
exec_list_push_tail(&impl->locals, &var->node);
|
2016-03-07 17:28:00 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 11:47:57 +01:00
|
|
|
/* Give it the new location */
|
|
|
|
|
assert(rt_to_bindings[rt] != -1);
|
|
|
|
|
var->data.location = rt_to_bindings[rt] + FRAG_RESULT_DATA0;
|
2016-03-07 17:28:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (num_rts == 0) {
|
|
|
|
|
/* If we have no render targets, we need a null render target */
|
|
|
|
|
rt_bindings[0] = (struct anv_pipeline_binding) {
|
|
|
|
|
.set = ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS,
|
2016-06-06 11:12:27 -07:00
|
|
|
.binding = 0,
|
2017-08-25 17:31:14 +02:00
|
|
|
.index = UINT32_MAX,
|
2016-03-07 17:28:00 -08:00
|
|
|
};
|
|
|
|
|
num_rts = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 11:47:57 +01:00
|
|
|
assert(num_rts <= max_rt);
|
2016-03-07 17:28:00 -08:00
|
|
|
map.surface_to_descriptor -= num_rts;
|
|
|
|
|
map.surface_count += num_rts;
|
|
|
|
|
assert(map.surface_count <= 256);
|
|
|
|
|
memcpy(map.surface_to_descriptor, rt_bindings,
|
|
|
|
|
num_rts * sizeof(*rt_bindings));
|
|
|
|
|
|
|
|
|
|
anv_fill_binding_table(&prog_data.base, num_rts);
|
2016-03-07 18:07:48 -08:00
|
|
|
|
2016-02-10 09:43:03 -08:00
|
|
|
const unsigned *shader_code =
|
2016-03-04 08:15:16 -08:00
|
|
|
brw_compile_fs(compiler, NULL, mem_ctx, &key, &prog_data, nir,
|
2017-10-21 20:55:45 -07:00
|
|
|
NULL, -1, -1, true, false, NULL, NULL);
|
2016-02-10 09:43:03 -08:00
|
|
|
if (shader_code == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-10-21 20:55:45 -07:00
|
|
|
unsigned code_size = prog_data.base.program_size;
|
2016-08-25 01:49:49 -07:00
|
|
|
bin = anv_pipeline_upload_kernel(pipeline, cache, sha1, 20,
|
|
|
|
|
shader_code, code_size,
|
2016-11-01 16:03:12 -07:00
|
|
|
&prog_data.base, sizeof(prog_data),
|
|
|
|
|
&map);
|
2016-08-25 01:49:49 -07:00
|
|
|
if (!bin) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
anv_pipeline_add_compiled_stage(pipeline, MESA_SHADER_FRAGMENT, bin);
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult
|
|
|
|
|
anv_pipeline_compile_cs(struct anv_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,
|
2015-12-02 14:35:07 -08:00
|
|
|
struct anv_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
|
|
|
{
|
|
|
|
|
const struct brw_compiler *compiler =
|
|
|
|
|
pipeline->device->instance->physicalDevice.compiler;
|
|
|
|
|
struct brw_cs_prog_key key;
|
2016-08-25 01:49:49 -07:00
|
|
|
struct anv_shader_bin *bin = NULL;
|
2016-03-04 10:59:21 -08:00
|
|
|
unsigned char sha1[20];
|
2015-10-19 22:06:59 -07:00
|
|
|
|
|
|
|
|
populate_cs_prog_key(&pipeline->device->info, &key);
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, layout, info->layout);
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
if (cache) {
|
2018-01-25 10:25:00 +01:00
|
|
|
anv_pipeline_hash_shader(pipeline, layout, module, entrypoint,
|
2017-04-27 06:25:06 -07:00
|
|
|
MESA_SHADER_COMPUTE, spec_info,
|
|
|
|
|
&key, sizeof(key), sha1);
|
2016-08-25 01:49:49 -07:00
|
|
|
bin = anv_pipeline_cache_search(cache, sha1, 20);
|
2016-02-10 09:43:03 -08:00
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
if (bin == NULL) {
|
2017-08-25 20:22:11 -07:00
|
|
|
struct brw_cs_prog_data prog_data = {};
|
2016-03-04 12:56:14 -08:00
|
|
|
struct anv_pipeline_binding surface_to_descriptor[256];
|
|
|
|
|
struct anv_pipeline_binding sampler_to_descriptor[256];
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-10-11 12:28:20 -07:00
|
|
|
struct anv_pipeline_bind_map map = {
|
2016-03-04 12:56:14 -08:00
|
|
|
.surface_to_descriptor = surface_to_descriptor,
|
|
|
|
|
.sampler_to_descriptor = sampler_to_descriptor
|
|
|
|
|
};
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-09-28 21:51:48 -07:00
|
|
|
void *mem_ctx = ralloc_context(NULL);
|
|
|
|
|
|
2018-01-25 10:25:00 +01:00
|
|
|
nir_shader *nir = anv_pipeline_compile(pipeline, mem_ctx, layout,
|
2017-09-28 21:51:48 -07:00
|
|
|
module, entrypoint,
|
2016-02-10 09:43:03 -08:00
|
|
|
MESA_SHADER_COMPUTE, spec_info,
|
2016-03-04 12:56:14 -08:00
|
|
|
&prog_data.base, &map);
|
2017-09-28 21:51:48 -07:00
|
|
|
if (nir == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
2016-02-10 09:43:03 -08:00
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
2017-09-28 21:51:48 -07:00
|
|
|
}
|
2015-12-18 01:42:46 -08:00
|
|
|
|
2017-10-03 15:23:07 -07:00
|
|
|
NIR_PASS_V(nir, anv_nir_add_base_work_group_id, &prog_data);
|
|
|
|
|
|
2016-03-07 18:07:48 -08:00
|
|
|
anv_fill_binding_table(&prog_data.base, 1);
|
|
|
|
|
|
2016-02-10 09:43:03 -08:00
|
|
|
const unsigned *shader_code =
|
2016-03-04 08:15:16 -08:00
|
|
|
brw_compile_cs(compiler, NULL, mem_ctx, &key, &prog_data, nir,
|
2017-10-21 20:55:45 -07:00
|
|
|
-1, NULL);
|
2016-02-10 09:43:03 -08:00
|
|
|
if (shader_code == NULL) {
|
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
|
|
|
|
|
}
|
2015-10-19 22:06:59 -07:00
|
|
|
|
2017-10-21 20:55:45 -07:00
|
|
|
const unsigned code_size = prog_data.base.program_size;
|
2016-08-25 01:49:49 -07:00
|
|
|
bin = anv_pipeline_upload_kernel(pipeline, cache, sha1, 20,
|
|
|
|
|
shader_code, code_size,
|
2016-11-01 16:03:12 -07:00
|
|
|
&prog_data.base, sizeof(prog_data),
|
|
|
|
|
&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
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:49:49 -07:00
|
|
|
anv_pipeline_add_compiled_stage(pipeline, MESA_SHADER_COMPUTE, 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
|
2016-06-09 12:12:29 -07:00
|
|
|
copy_non_dynamic_state(struct anv_pipeline *pipeline,
|
|
|
|
|
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
|
|
|
|
2015-10-16 12:04:13 -07: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++)
|
|
|
|
|
states &= ~(1 << pCreateInfo->pDynamicState->pDynamicStates[s]);
|
|
|
|
|
}
|
2015-10-07 09:28:21 -07:00
|
|
|
|
|
|
|
|
struct anv_dynamic_state *dynamic = &pipeline->dynamic_state;
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
if (!pCreateInfo->pRasterizationState->rasterizerDiscardEnable) {
|
|
|
|
|
assert(pCreateInfo->pViewportState);
|
|
|
|
|
|
|
|
|
|
dynamic->viewport.count = pCreateInfo->pViewportState->viewportCount;
|
|
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_VIEWPORT)) {
|
|
|
|
|
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;
|
|
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_SCISSOR)) {
|
|
|
|
|
typed_memcpy(dynamic->scissor.scissors,
|
|
|
|
|
pCreateInfo->pViewportState->pScissors,
|
|
|
|
|
pCreateInfo->pViewportState->scissorCount);
|
|
|
|
|
}
|
2015-10-16 12:04:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_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
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uses_color_att &&
|
|
|
|
|
!pCreateInfo->pRasterizationState->rasterizerDiscardEnable) {
|
2015-10-16 12:04:13 -07:00
|
|
|
assert(pCreateInfo->pColorBlendState);
|
2016-06-09 14:48:00 -07:00
|
|
|
|
|
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_BLEND_CONSTANTS))
|
|
|
|
|
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
|
|
|
*/
|
2016-06-09 14:48:00 -07:00
|
|
|
if (!pCreateInfo->pRasterizationState->rasterizerDiscardEnable &&
|
2017-01-31 16:12:50 -08:00
|
|
|
subpass->depth_stencil_attachment.attachment != VK_ATTACHMENT_UNUSED) {
|
2016-06-09 14:48:00 -07:00
|
|
|
assert(pCreateInfo->pDepthStencilState);
|
|
|
|
|
|
2015-10-19 11:39:30 -07:00
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_DEPTH_BOUNDS)) {
|
|
|
|
|
dynamic->depth_bounds.min =
|
|
|
|
|
pCreateInfo->pDepthStencilState->minDepthBounds;
|
|
|
|
|
dynamic->depth_bounds.max =
|
|
|
|
|
pCreateInfo->pDepthStencilState->maxDepthBounds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK)) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_STENCIL_WRITE_MASK)) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (states & (1 << VK_DYNAMIC_STATE_STENCIL_REFERENCE)) {
|
|
|
|
|
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
|
|
|
}
|
2015-10-16 12:04:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pipeline->dynamic_state_mask = states;
|
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);
|
|
|
|
|
assert(info->pVertexInputState);
|
|
|
|
|
assert(info->pInputAssemblyState);
|
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
|
|
|
|
2017-01-31 16:12:50 -08:00
|
|
|
if (subpass && subpass->depth_stencil_attachment.attachment != VK_ATTACHMENT_UNUSED)
|
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) {
|
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)
|
|
|
|
|
{
|
|
|
|
|
const struct gen_device_info *devinfo = &pipeline->device->info;
|
|
|
|
|
|
|
|
|
|
const struct gen_l3_weights w =
|
|
|
|
|
gen_get_default_l3_weights(devinfo, pipeline->needs_data_cache, needs_slm);
|
|
|
|
|
|
|
|
|
|
pipeline->urb.l3_config = gen_get_l3_config(devinfo, w);
|
|
|
|
|
pipeline->urb.total_size =
|
|
|
|
|
gen_get_l3_config_urb_size(devinfo, pipeline->urb.l3_config);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-20 22:53:54 -07:00
|
|
|
VkResult
|
2016-01-05 12:00:54 -08:00
|
|
|
anv_pipeline_init(struct anv_pipeline *pipeline,
|
|
|
|
|
struct anv_device *device,
|
|
|
|
|
struct anv_pipeline_cache *cache,
|
2015-08-20 22:53:54 -07:00
|
|
|
const VkGraphicsPipelineCreateInfo *pCreateInfo,
|
2015-12-02 03:28:27 -08:00
|
|
|
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
|
|
|
|
2015-12-02 03:28:27 -08:00
|
|
|
if (alloc == NULL)
|
|
|
|
|
alloc = &device->alloc;
|
|
|
|
|
|
2015-08-20 22:53:54 -07:00
|
|
|
pipeline->device = device;
|
2017-03-22 15:36:46 -07: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];
|
|
|
|
|
|
2016-01-03 22:42:01 -08:00
|
|
|
result = anv_reloc_list_init(&pipeline->batch_relocs, alloc);
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
return result;
|
2015-12-02 03:28:27 -08:00
|
|
|
|
|
|
|
|
pipeline->batch.alloc = alloc;
|
2015-08-20 22:53:54 -07:00
|
|
|
pipeline->batch.next = pipeline->batch.start = pipeline->batch_data;
|
|
|
|
|
pipeline->batch.end = pipeline->batch.start + sizeof(pipeline->batch_data);
|
|
|
|
|
pipeline->batch.relocs = &pipeline->batch_relocs;
|
2017-03-09 14:37:26 +01:00
|
|
|
pipeline->batch.status = VK_SUCCESS;
|
2015-08-20 22:53:54 -07:00
|
|
|
|
2016-06-09 12:12:29 -07:00
|
|
|
copy_non_dynamic_state(pipeline, pCreateInfo);
|
2016-06-14 08:40:49 -07:00
|
|
|
pipeline->depth_clamp_enable = pCreateInfo->pRasterizationState &&
|
|
|
|
|
pCreateInfo->pRasterizationState->depthClampEnable;
|
2015-10-07 09:28:21 -07:00
|
|
|
|
2017-03-23 11:56:06 +01:00
|
|
|
pipeline->sample_shading_enable = pCreateInfo->pMultisampleState &&
|
|
|
|
|
pCreateInfo->pMultisampleState->sampleShadingEnable;
|
|
|
|
|
|
2016-04-02 13:44:55 -07:00
|
|
|
pipeline->needs_data_cache = false;
|
|
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
/* When we free the pipeline, we detect stages based on the NULL status
|
|
|
|
|
* of various prog_data pointers. Make them NULL by default.
|
|
|
|
|
*/
|
2016-08-25 01:49:49 -07:00
|
|
|
memset(pipeline->shaders, 0, sizeof(pipeline->shaders));
|
2015-08-20 22:53:54 -07:00
|
|
|
|
2015-10-19 22:06:59 -07:00
|
|
|
pipeline->active_stages = 0;
|
|
|
|
|
|
2017-08-25 20:22:11 -07:00
|
|
|
const VkPipelineShaderStageCreateInfo *pStages[MESA_SHADER_STAGES] = {};
|
|
|
|
|
struct anv_shader_module *modules[MESA_SHADER_STAGES] = {};
|
2015-10-19 22:06:59 -07:00
|
|
|
for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
|
2018-03-15 13:09:30 -07:00
|
|
|
VkShaderStageFlagBits vk_stage = pCreateInfo->pStages[i].stage;
|
|
|
|
|
gl_shader_stage stage = vk_to_mesa_shader_stage(vk_stage);
|
2016-02-24 15:41:24 -08:00
|
|
|
pStages[stage] = &pCreateInfo->pStages[i];
|
|
|
|
|
modules[stage] = anv_shader_module_from_handle(pStages[stage]->module);
|
2018-03-15 13:09:30 -07:00
|
|
|
pipeline->active_stages |= vk_stage;
|
2016-02-24 15:41:24 -08:00
|
|
|
}
|
|
|
|
|
|
2018-03-15 13:09:30 -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);
|
|
|
|
|
|
2016-02-24 15:41:24 -08:00
|
|
|
if (modules[MESA_SHADER_VERTEX]) {
|
2016-08-29 08:30:37 -07:00
|
|
|
result = anv_pipeline_compile_vs(pipeline, cache, pCreateInfo,
|
|
|
|
|
modules[MESA_SHADER_VERTEX],
|
|
|
|
|
pStages[MESA_SHADER_VERTEX]->pName,
|
|
|
|
|
pStages[MESA_SHADER_VERTEX]->pSpecializationInfo);
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
goto compile_fail;
|
2016-02-24 15:41:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-25 17:43:06 -07:00
|
|
|
if (modules[MESA_SHADER_TESS_EVAL]) {
|
2018-03-15 13:09:29 -07:00
|
|
|
result = anv_pipeline_compile_tcs_tes(pipeline, cache, pCreateInfo,
|
|
|
|
|
modules[MESA_SHADER_TESS_CTRL],
|
|
|
|
|
pStages[MESA_SHADER_TESS_CTRL]->pName,
|
|
|
|
|
pStages[MESA_SHADER_TESS_CTRL]->pSpecializationInfo,
|
|
|
|
|
modules[MESA_SHADER_TESS_EVAL],
|
|
|
|
|
pStages[MESA_SHADER_TESS_EVAL]->pName,
|
|
|
|
|
pStages[MESA_SHADER_TESS_EVAL]->pSpecializationInfo);
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
goto compile_fail;
|
2016-09-25 17:43:06 -07:00
|
|
|
}
|
2016-03-06 22:06:24 -08:00
|
|
|
|
2016-02-24 15:41:24 -08:00
|
|
|
if (modules[MESA_SHADER_GEOMETRY]) {
|
2016-08-29 08:30:37 -07:00
|
|
|
result = anv_pipeline_compile_gs(pipeline, cache, pCreateInfo,
|
|
|
|
|
modules[MESA_SHADER_GEOMETRY],
|
|
|
|
|
pStages[MESA_SHADER_GEOMETRY]->pName,
|
|
|
|
|
pStages[MESA_SHADER_GEOMETRY]->pSpecializationInfo);
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
goto compile_fail;
|
2016-02-24 15:41:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (modules[MESA_SHADER_FRAGMENT]) {
|
2016-10-07 15:29:47 -07:00
|
|
|
result = anv_pipeline_compile_fs(pipeline, cache, pCreateInfo,
|
2016-08-29 08:30:37 -07:00
|
|
|
modules[MESA_SHADER_FRAGMENT],
|
|
|
|
|
pStages[MESA_SHADER_FRAGMENT]->pName,
|
|
|
|
|
pStages[MESA_SHADER_FRAGMENT]->pSpecializationInfo);
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
goto compile_fail;
|
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
|
|
|
|
2016-08-22 16:56:48 -07:00
|
|
|
anv_pipeline_setup_l3_config(pipeline, 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
|
|
|
|
2015-08-20 22:53:54 -07:00
|
|
|
pipeline->vb_used = 0;
|
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];
|
|
|
|
|
|
2015-11-30 17:00:30 -08:00
|
|
|
pipeline->binding_stride[desc->binding] = 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:
|
2015-08-20 22:53:54 -07:00
|
|
|
pipeline->instancing_enable[desc->binding] = false;
|
|
|
|
|
break;
|
2015-11-30 13:28:09 -08:00
|
|
|
case VK_VERTEX_INPUT_RATE_INSTANCE:
|
2015-08-20 22:53:54 -07:00
|
|
|
pipeline->instancing_enable[desc->binding] = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VkPipelineInputAssemblyStateCreateInfo *ia_info =
|
|
|
|
|
pCreateInfo->pInputAssemblyState;
|
2016-09-25 15:29:16 -07:00
|
|
|
const VkPipelineTessellationStateCreateInfo *tess_info =
|
|
|
|
|
pCreateInfo->pTessellationState;
|
2015-08-20 22:53:54 -07:00
|
|
|
pipeline->primitive_restart = ia_info->primitiveRestartEnable;
|
2016-09-25 15:29:16 -07:00
|
|
|
|
|
|
|
|
if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
|
|
|
|
|
pipeline->topology = _3DPRIM_PATCHLIST(tess_info->patchControlPoints);
|
|
|
|
|
else
|
|
|
|
|
pipeline->topology = vk_to_gen_primitive_type[ia_info->topology];
|
2015-08-20 22:53:54 -07:00
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
2016-08-29 08:30:37 -07:00
|
|
|
|
|
|
|
|
compile_fail:
|
2016-08-25 01:49:49 -07:00
|
|
|
for (unsigned s = 0; s < MESA_SHADER_STAGES; s++) {
|
|
|
|
|
if (pipeline->shaders[s])
|
|
|
|
|
anv_shader_bin_unref(device, pipeline->shaders[s]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 08:30:37 -07:00
|
|
|
anv_reloc_list_finish(&pipeline->batch_relocs, alloc);
|
|
|
|
|
|
|
|
|
|
return result;
|
2015-08-20 22:53:54 -07:00
|
|
|
}
|