2015-11-18 22:58:40 +00: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-08-25 01:14:11 +01:00
|
|
|
#include "util/mesa-sha1.h"
|
2019-02-12 22:56:24 +00:00
|
|
|
#include "vk_util.h"
|
2016-08-25 01:14:11 +01:00
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
#include "anv_private.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Descriptor set layouts.
|
|
|
|
*/
|
|
|
|
|
2018-11-24 18:42:39 +00:00
|
|
|
static enum anv_descriptor_data
|
|
|
|
anv_descriptor_data_for_type(const struct anv_physical_device *device,
|
|
|
|
VkDescriptorType type)
|
|
|
|
{
|
|
|
|
enum anv_descriptor_data data = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
|
|
|
data = ANV_DESCRIPTOR_SAMPLER_STATE;
|
2019-02-07 20:10:33 +00:00
|
|
|
if (device->has_bindless_samplers)
|
|
|
|
data |= ANV_DESCRIPTOR_SAMPLED_IMAGE;
|
2018-11-24 18:42:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
|
|
|
data = ANV_DESCRIPTOR_SURFACE_STATE |
|
|
|
|
ANV_DESCRIPTOR_SAMPLER_STATE;
|
2019-02-07 20:10:33 +00:00
|
|
|
if (device->has_bindless_images || device->has_bindless_samplers)
|
|
|
|
data |= ANV_DESCRIPTOR_SAMPLED_IMAGE;
|
2018-11-24 18:42:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
2019-02-07 20:10:33 +00:00
|
|
|
data = ANV_DESCRIPTOR_SURFACE_STATE;
|
|
|
|
if (device->has_bindless_images)
|
|
|
|
data |= ANV_DESCRIPTOR_SAMPLED_IMAGE;
|
|
|
|
break;
|
|
|
|
|
2018-11-24 18:42:39 +00:00
|
|
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
|
|
|
data = ANV_DESCRIPTOR_SURFACE_STATE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
|
|
|
data = ANV_DESCRIPTOR_SURFACE_STATE;
|
2021-03-29 22:41:58 +01:00
|
|
|
if (device->info.ver < 9)
|
2018-11-24 18:42:39 +00:00
|
|
|
data |= ANV_DESCRIPTOR_IMAGE_PARAM;
|
2019-02-12 07:02:28 +00:00
|
|
|
if (device->has_bindless_images)
|
|
|
|
data |= ANV_DESCRIPTOR_STORAGE_IMAGE;
|
2018-11-24 18:42:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
|
|
|
data = ANV_DESCRIPTOR_SURFACE_STATE |
|
|
|
|
ANV_DESCRIPTOR_BUFFER_VIEW;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
|
|
|
data = ANV_DESCRIPTOR_SURFACE_STATE;
|
|
|
|
break;
|
|
|
|
|
2019-02-12 22:56:24 +00:00
|
|
|
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
|
|
|
|
data = ANV_DESCRIPTOR_INLINE_UNIFORM;
|
|
|
|
break;
|
|
|
|
|
2020-08-05 23:28:48 +01:00
|
|
|
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
|
|
|
|
data = ANV_DESCRIPTOR_ADDRESS_RANGE;
|
|
|
|
break;
|
|
|
|
|
2018-11-24 18:42:39 +00:00
|
|
|
default:
|
|
|
|
unreachable("Unsupported descriptor type");
|
|
|
|
}
|
|
|
|
|
2021-03-29 23:40:04 +01:00
|
|
|
/* On gfx8 and above when we have softpin enabled, we also need to push
|
2019-01-09 22:04:22 +00:00
|
|
|
* SSBO address ranges so that we can use A64 messages in the shader.
|
|
|
|
*/
|
|
|
|
if (device->has_a64_buffer_access &&
|
|
|
|
(type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER ||
|
2021-01-15 22:44:44 +00:00
|
|
|
type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC ||
|
|
|
|
type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ||
|
|
|
|
type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC))
|
2019-01-09 22:04:22 +00:00
|
|
|
data |= ANV_DESCRIPTOR_ADDRESS_RANGE;
|
|
|
|
|
2019-05-22 12:55:45 +01:00
|
|
|
/* On Ivy Bridge and Bay Trail, we need swizzles textures in the shader
|
|
|
|
* Do not handle VK_DESCRIPTOR_TYPE_STORAGE_IMAGE and
|
|
|
|
* VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT because they already must
|
|
|
|
* have identity swizzle.
|
|
|
|
*/
|
2021-05-14 17:04:46 +01:00
|
|
|
if (device->info.verx10 == 70 &&
|
2019-05-17 16:04:58 +01:00
|
|
|
(type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE ||
|
|
|
|
type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER))
|
|
|
|
data |= ANV_DESCRIPTOR_TEXTURE_SWIZZLE;
|
|
|
|
|
2018-11-24 18:42:39 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
static enum anv_descriptor_data
|
|
|
|
anv_descriptor_data_for_mutable_type(const struct anv_physical_device *device,
|
|
|
|
const VkMutableDescriptorTypeCreateInfoVALVE *mutable_info,
|
|
|
|
int binding)
|
|
|
|
{
|
|
|
|
enum anv_descriptor_data desc_data = 0;
|
|
|
|
|
|
|
|
if (!mutable_info || mutable_info->mutableDescriptorTypeListCount == 0) {
|
|
|
|
for(VkDescriptorType i = 0; i <= VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; i++) {
|
|
|
|
if (i == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC ||
|
|
|
|
i == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
|
|
|
|
i == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
desc_data |= anv_descriptor_data_for_type(device, i);
|
|
|
|
}
|
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
desc_data |= anv_descriptor_data_for_type(
|
|
|
|
device, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR);
|
2022-01-14 14:02:17 +00:00
|
|
|
|
|
|
|
return desc_data;
|
|
|
|
}
|
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
const VkMutableDescriptorTypeListVALVE *type_list =
|
|
|
|
&mutable_info->pMutableDescriptorTypeLists[binding];
|
|
|
|
for (uint32_t i = 0; i < type_list->descriptorTypeCount; i++) {
|
|
|
|
desc_data |=
|
|
|
|
anv_descriptor_data_for_type(device, type_list->pDescriptorTypes[i]);
|
|
|
|
}
|
2022-01-14 14:02:17 +00:00
|
|
|
|
|
|
|
return desc_data;
|
|
|
|
}
|
|
|
|
|
2018-11-19 20:28:39 +00:00
|
|
|
static unsigned
|
|
|
|
anv_descriptor_data_size(enum anv_descriptor_data data)
|
|
|
|
{
|
2018-11-22 00:26:27 +00:00
|
|
|
unsigned size = 0;
|
|
|
|
|
2019-02-07 20:10:33 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_SAMPLED_IMAGE)
|
|
|
|
size += sizeof(struct anv_sampled_image_descriptor);
|
|
|
|
|
2019-02-12 07:02:28 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_STORAGE_IMAGE)
|
|
|
|
size += sizeof(struct anv_storage_image_descriptor);
|
|
|
|
|
2018-11-22 00:26:27 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_IMAGE_PARAM)
|
|
|
|
size += BRW_IMAGE_PARAM_SIZE * 4;
|
|
|
|
|
2019-01-09 22:04:22 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_ADDRESS_RANGE)
|
|
|
|
size += sizeof(struct anv_address_range_descriptor);
|
|
|
|
|
2019-05-17 16:04:58 +01:00
|
|
|
if (data & ANV_DESCRIPTOR_TEXTURE_SWIZZLE)
|
|
|
|
size += sizeof(struct anv_texture_swizzle_descriptor);
|
|
|
|
|
2018-11-22 00:26:27 +00:00
|
|
|
return size;
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 20:52:41 +01:00
|
|
|
static bool
|
|
|
|
anv_needs_descriptor_buffer(VkDescriptorType desc_type,
|
|
|
|
enum anv_descriptor_data desc_data)
|
|
|
|
{
|
|
|
|
if (desc_type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT ||
|
|
|
|
anv_descriptor_data_size(desc_data) > 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-19 20:28:39 +00:00
|
|
|
/** Returns the size in bytes of each descriptor with the given layout */
|
2022-01-14 14:02:17 +00:00
|
|
|
static unsigned
|
2018-11-19 20:28:39 +00:00
|
|
|
anv_descriptor_size(const struct anv_descriptor_set_binding_layout *layout)
|
|
|
|
{
|
2019-02-12 22:56:24 +00:00
|
|
|
if (layout->data & ANV_DESCRIPTOR_INLINE_UNIFORM) {
|
|
|
|
assert(layout->data == ANV_DESCRIPTOR_INLINE_UNIFORM);
|
|
|
|
return layout->array_size;
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:10:33 +00:00
|
|
|
unsigned size = anv_descriptor_data_size(layout->data);
|
|
|
|
|
|
|
|
/* For multi-planar bindings, we make every descriptor consume the maximum
|
|
|
|
* number of planes so we don't have to bother with walking arrays and
|
|
|
|
* adding things up every time. Fortunately, YCbCr samplers aren't all
|
|
|
|
* that common and likely won't be in the middle of big arrays.
|
|
|
|
*/
|
|
|
|
if (layout->max_plane_count > 1)
|
|
|
|
size *= layout->max_plane_count;
|
|
|
|
|
|
|
|
return size;
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
/** Returns size in bytes of the biggest descriptor in the given layout */
|
|
|
|
static unsigned
|
|
|
|
anv_descriptor_size_for_mutable_type(const struct anv_physical_device *device,
|
|
|
|
const VkMutableDescriptorTypeCreateInfoVALVE *mutable_info,
|
|
|
|
int binding)
|
2018-11-19 20:28:39 +00:00
|
|
|
{
|
2022-01-14 14:02:17 +00:00
|
|
|
unsigned size = 0;
|
2019-02-07 20:10:33 +00:00
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
if (!mutable_info || mutable_info->mutableDescriptorTypeListCount == 0) {
|
|
|
|
for(VkDescriptorType i = 0; i <= VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; i++) {
|
|
|
|
|
|
|
|
if (i == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC ||
|
|
|
|
i == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
|
|
|
|
i == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
|
|
|
|
continue;
|
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
enum anv_descriptor_data desc_data =
|
|
|
|
anv_descriptor_data_for_type(device, i);
|
2022-01-14 14:02:17 +00:00
|
|
|
size = MAX2(size, anv_descriptor_data_size(desc_data));
|
|
|
|
}
|
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
enum anv_descriptor_data desc_data = anv_descriptor_data_for_type(
|
|
|
|
device, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR);
|
2022-01-14 14:02:17 +00:00
|
|
|
size = MAX2(size, anv_descriptor_data_size(desc_data));
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
const VkMutableDescriptorTypeListVALVE *type_list =
|
|
|
|
&mutable_info->pMutableDescriptorTypeLists[binding];
|
|
|
|
for (uint32_t i = 0; i < type_list->descriptorTypeCount; i++) {
|
|
|
|
enum anv_descriptor_data desc_data =
|
|
|
|
anv_descriptor_data_for_type(device, type_list->pDescriptorTypes[i]);
|
2022-01-14 14:02:17 +00:00
|
|
|
size = MAX2(size, anv_descriptor_data_size(desc_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 19:59:07 +00:00
|
|
|
static bool
|
|
|
|
anv_descriptor_data_supports_bindless(const struct anv_physical_device *pdevice,
|
|
|
|
enum anv_descriptor_data data,
|
|
|
|
bool sampler)
|
|
|
|
{
|
2019-01-09 22:04:22 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_ADDRESS_RANGE) {
|
|
|
|
assert(pdevice->has_a64_buffer_access);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:10:33 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_SAMPLED_IMAGE) {
|
|
|
|
assert(pdevice->has_bindless_images || pdevice->has_bindless_samplers);
|
|
|
|
return sampler ? pdevice->has_bindless_samplers :
|
|
|
|
pdevice->has_bindless_images;
|
|
|
|
}
|
|
|
|
|
2019-02-12 07:02:28 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_STORAGE_IMAGE) {
|
|
|
|
assert(pdevice->has_bindless_images);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-25 19:59:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
anv_descriptor_supports_bindless(const struct anv_physical_device *pdevice,
|
|
|
|
const struct anv_descriptor_set_binding_layout *binding,
|
|
|
|
bool sampler)
|
|
|
|
{
|
|
|
|
return anv_descriptor_data_supports_bindless(pdevice, binding->data,
|
|
|
|
sampler);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
anv_descriptor_requires_bindless(const struct anv_physical_device *pdevice,
|
|
|
|
const struct anv_descriptor_set_binding_layout *binding,
|
|
|
|
bool sampler)
|
|
|
|
{
|
|
|
|
if (pdevice->always_use_bindless)
|
|
|
|
return anv_descriptor_supports_bindless(pdevice, binding, sampler);
|
|
|
|
|
2019-02-27 22:08:20 +00:00
|
|
|
static const VkDescriptorBindingFlagBitsEXT flags_requiring_bindless =
|
|
|
|
VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT |
|
|
|
|
VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT |
|
|
|
|
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT;
|
|
|
|
|
|
|
|
return (binding->flags & flags_requiring_bindless) != 0;
|
2019-02-25 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 00:03:29 +01:00
|
|
|
void anv_GetDescriptorSetLayoutSupport(
|
2019-02-25 19:59:07 +00:00
|
|
|
VkDevice _device,
|
2017-10-06 00:03:29 +01:00
|
|
|
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
|
|
|
VkDescriptorSetLayoutSupport* pSupport)
|
|
|
|
{
|
2019-02-25 19:59:07 +00:00
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2020-01-18 04:23:30 +00:00
|
|
|
const struct anv_physical_device *pdevice = device->physical;
|
2019-02-25 19:59:07 +00:00
|
|
|
|
2021-01-21 22:58:50 +00:00
|
|
|
uint32_t surface_count[MESA_VULKAN_SHADER_STAGES] = { 0, };
|
2020-10-16 04:56:09 +01:00
|
|
|
VkDescriptorType varying_desc_type = VK_DESCRIPTOR_TYPE_MAX_ENUM;
|
2019-07-27 20:52:41 +01:00
|
|
|
bool needs_descriptor_buffer = false;
|
2017-10-06 00:03:29 +01:00
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
const VkDescriptorSetLayoutBindingFlagsCreateInfo *binding_flags_info =
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
|
|
|
DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO);
|
2022-01-14 14:02:17 +00:00
|
|
|
const VkMutableDescriptorTypeCreateInfoVALVE *mutable_info =
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
|
|
|
MUTABLE_DESCRIPTOR_TYPE_CREATE_INFO_VALVE);
|
2020-10-16 04:56:09 +01:00
|
|
|
|
2018-03-19 22:39:25 +00:00
|
|
|
for (uint32_t b = 0; b < pCreateInfo->bindingCount; b++) {
|
2017-10-06 00:03:29 +01:00
|
|
|
const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[b];
|
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
VkDescriptorBindingFlags flags = 0;
|
|
|
|
if (binding_flags_info && binding_flags_info->bindingCount > 0) {
|
|
|
|
assert(binding_flags_info->bindingCount == pCreateInfo->bindingCount);
|
|
|
|
flags = binding_flags_info->pBindingFlags[b];
|
|
|
|
}
|
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
enum anv_descriptor_data desc_data =
|
|
|
|
binding->descriptorType == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE ?
|
|
|
|
anv_descriptor_data_for_mutable_type(pdevice, mutable_info, b) :
|
|
|
|
anv_descriptor_data_for_type(pdevice, binding->descriptorType);
|
2019-02-25 19:59:07 +00:00
|
|
|
|
2019-07-27 20:52:41 +01:00
|
|
|
if (anv_needs_descriptor_buffer(binding->descriptorType, desc_data))
|
|
|
|
needs_descriptor_buffer = true;
|
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
if (flags & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT)
|
|
|
|
varying_desc_type = binding->descriptorType;
|
|
|
|
|
2017-10-06 00:03:29 +01:00
|
|
|
switch (binding->descriptorType) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
|
|
|
/* There is no real limit on samplers */
|
|
|
|
break;
|
|
|
|
|
2019-07-27 20:52:41 +01:00
|
|
|
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
|
|
|
|
/* Inline uniforms don't use a binding */
|
|
|
|
break;
|
|
|
|
|
2017-10-06 00:03:29 +01:00
|
|
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
2019-02-25 19:59:07 +00:00
|
|
|
if (anv_descriptor_data_supports_bindless(pdevice, desc_data, false))
|
|
|
|
break;
|
|
|
|
|
2017-10-06 00:03:29 +01:00
|
|
|
if (binding->pImmutableSamplers) {
|
|
|
|
for (uint32_t i = 0; i < binding->descriptorCount; i++) {
|
|
|
|
ANV_FROM_HANDLE(anv_sampler, sampler,
|
|
|
|
binding->pImmutableSamplers[i]);
|
|
|
|
anv_foreach_stage(s, binding->stageFlags)
|
|
|
|
surface_count[s] += sampler->n_planes;
|
|
|
|
}
|
2019-03-01 20:01:08 +00:00
|
|
|
} else {
|
|
|
|
anv_foreach_stage(s, binding->stageFlags)
|
|
|
|
surface_count[s] += binding->descriptorCount;
|
2017-10-06 00:03:29 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-02-25 19:59:07 +00:00
|
|
|
if (anv_descriptor_data_supports_bindless(pdevice, desc_data, false))
|
|
|
|
break;
|
|
|
|
|
2017-10-06 00:03:29 +01:00
|
|
|
anv_foreach_stage(s, binding->stageFlags)
|
|
|
|
surface_count[s] += binding->descriptorCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-21 22:58:50 +00:00
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(surface_count); s++) {
|
2019-07-27 20:52:41 +01:00
|
|
|
if (needs_descriptor_buffer)
|
|
|
|
surface_count[s] += 1;
|
|
|
|
}
|
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
VkDescriptorSetVariableDescriptorCountLayoutSupport *vdcls =
|
|
|
|
vk_find_struct(pSupport->pNext,
|
|
|
|
DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT);
|
|
|
|
if (vdcls != NULL) {
|
|
|
|
if (varying_desc_type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
|
|
|
vdcls->maxVariableDescriptorCount = MAX_INLINE_UNIFORM_BLOCK_SIZE;
|
|
|
|
} else if (varying_desc_type != VK_DESCRIPTOR_TYPE_MAX_ENUM) {
|
|
|
|
vdcls->maxVariableDescriptorCount = UINT16_MAX;
|
|
|
|
} else {
|
|
|
|
vdcls->maxVariableDescriptorCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:03:29 +01:00
|
|
|
bool supported = true;
|
2021-01-21 22:58:50 +00:00
|
|
|
for (unsigned s = 0; s < ARRAY_SIZE(surface_count); s++) {
|
2019-04-16 23:35:05 +01:00
|
|
|
/* Our maximum binding table size is 240 and we need to reserve 8 for
|
|
|
|
* render targets.
|
2017-10-06 00:03:29 +01:00
|
|
|
*/
|
2019-09-12 20:20:22 +01:00
|
|
|
if (surface_count[s] > MAX_BINDING_TABLE_SIZE - MAX_RTS)
|
2017-10-06 00:03:29 +01:00
|
|
|
supported = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pSupport->supported = supported;
|
|
|
|
}
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
VkResult anv_CreateDescriptorSetLayout(
|
|
|
|
VkDevice _device,
|
|
|
|
const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
|
2015-12-02 11:28:27 +00:00
|
|
|
const VkAllocationCallbacks* pAllocator,
|
2015-11-18 22:58:40 +00:00
|
|
|
VkDescriptorSetLayout* pSetLayout)
|
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
|
|
|
|
|
2021-03-29 11:10:46 +01:00
|
|
|
uint32_t num_bindings = 0;
|
2015-11-18 22:58:40 +00:00
|
|
|
uint32_t immutable_sampler_count = 0;
|
2015-12-01 20:05:21 +00:00
|
|
|
for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {
|
2021-03-29 11:10:46 +01:00
|
|
|
num_bindings = MAX2(num_bindings, pCreateInfo->pBindings[j].binding + 1);
|
2019-01-19 15:40:12 +00:00
|
|
|
|
|
|
|
/* From the Vulkan 1.1.97 spec for VkDescriptorSetLayoutBinding:
|
|
|
|
*
|
|
|
|
* "If descriptorType specifies a VK_DESCRIPTOR_TYPE_SAMPLER or
|
|
|
|
* VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER type descriptor, then
|
|
|
|
* pImmutableSamplers can be used to initialize a set of immutable
|
|
|
|
* samplers. [...] If descriptorType is not one of these descriptor
|
|
|
|
* types, then pImmutableSamplers is ignored.
|
|
|
|
*
|
|
|
|
* We need to be careful here and only parse pImmutableSamplers if we
|
|
|
|
* have one of the right descriptor types.
|
|
|
|
*/
|
|
|
|
VkDescriptorType desc_type = pCreateInfo->pBindings[j].descriptorType;
|
|
|
|
if ((desc_type == VK_DESCRIPTOR_TYPE_SAMPLER ||
|
|
|
|
desc_type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) &&
|
|
|
|
pCreateInfo->pBindings[j].pImmutableSamplers)
|
2016-01-05 19:44:16 +00:00
|
|
|
immutable_sampler_count += pCreateInfo->pBindings[j].descriptorCount;
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-25 08:43:22 +00:00
|
|
|
/* We need to allocate decriptor set layouts off the device allocator
|
|
|
|
* with DEVICE scope because they are reference counted and may not be
|
|
|
|
* destroyed when vkDestroyDescriptorSetLayout is called.
|
|
|
|
*/
|
2021-03-10 14:16:00 +00:00
|
|
|
VK_MULTIALLOC(ma);
|
2021-03-11 02:20:37 +00:00
|
|
|
VK_MULTIALLOC_DECL(&ma, struct anv_descriptor_set_layout, set_layout, 1);
|
|
|
|
VK_MULTIALLOC_DECL(&ma, struct anv_descriptor_set_binding_layout,
|
2021-03-29 11:10:46 +01:00
|
|
|
bindings, num_bindings);
|
2021-03-11 02:20:37 +00:00
|
|
|
VK_MULTIALLOC_DECL(&ma, struct anv_sampler *, samplers,
|
|
|
|
immutable_sampler_count);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2021-04-08 22:12:27 +01:00
|
|
|
if (!vk_object_multizalloc(&device->vk, &ma, NULL,
|
|
|
|
VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT))
|
2021-09-24 18:06:32 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2018-01-25 08:43:22 +00:00
|
|
|
set_layout->ref_cnt = 1;
|
2021-03-29 11:10:46 +01:00
|
|
|
set_layout->binding_count = num_bindings;
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2021-03-29 11:10:46 +01:00
|
|
|
for (uint32_t b = 0; b < num_bindings; b++) {
|
2015-12-16 00:24:19 +00:00
|
|
|
/* Initialize all binding_layout entries to -1 */
|
|
|
|
memset(&set_layout->binding[b], -1, sizeof(set_layout->binding[b]));
|
|
|
|
|
2018-10-02 21:35:59 +01:00
|
|
|
set_layout->binding[b].flags = 0;
|
2018-11-24 18:42:39 +00:00
|
|
|
set_layout->binding[b].data = 0;
|
2019-02-07 16:16:24 +00:00
|
|
|
set_layout->binding[b].max_plane_count = 0;
|
2016-06-06 17:12:20 +01:00
|
|
|
set_layout->binding[b].array_size = 0;
|
2015-12-16 00:24:19 +00:00
|
|
|
set_layout->binding[b].immutable_samplers = NULL;
|
|
|
|
}
|
2015-11-18 22:58:40 +00:00
|
|
|
|
|
|
|
/* Initialize all samplers to 0 */
|
|
|
|
memset(samplers, 0, immutable_sampler_count * sizeof(*samplers));
|
|
|
|
|
2019-02-06 23:16:34 +00:00
|
|
|
uint32_t buffer_view_count = 0;
|
2015-11-18 22:58:40 +00:00
|
|
|
uint32_t dynamic_offset_count = 0;
|
2018-11-19 20:28:39 +00:00
|
|
|
uint32_t descriptor_buffer_size = 0;
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {
|
2016-01-05 19:44:16 +00:00
|
|
|
const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[j];
|
2015-12-01 20:05:21 +00:00
|
|
|
uint32_t b = binding->binding;
|
2019-04-19 20:45:34 +01:00
|
|
|
/* We temporarily store pCreateInfo->pBindings[] index (plus one) in the
|
2016-06-06 17:15:03 +01:00
|
|
|
* immutable_samplers pointer. This provides us with a quick-and-dirty
|
|
|
|
* way to sort the bindings by binding number.
|
|
|
|
*/
|
2019-04-19 20:45:34 +01:00
|
|
|
set_layout->binding[b].immutable_samplers = (void *)(uintptr_t)(j + 1);
|
2016-06-06 17:15:03 +01:00
|
|
|
}
|
|
|
|
|
2018-10-02 21:35:59 +01:00
|
|
|
const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT *binding_flags_info =
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
|
|
|
DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT);
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
const VkMutableDescriptorTypeCreateInfoVALVE *mutable_info =
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
|
|
|
MUTABLE_DESCRIPTOR_TYPE_CREATE_INFO_VALVE);
|
|
|
|
|
2021-03-29 11:10:46 +01:00
|
|
|
for (uint32_t b = 0; b < num_bindings; b++) {
|
2019-04-19 20:45:34 +01:00
|
|
|
/* We stashed the pCreateInfo->pBindings[] index (plus one) in the
|
|
|
|
* immutable_samplers pointer. Check for NULL (empty binding) and then
|
|
|
|
* reset it and compute the index.
|
2019-01-19 15:40:12 +00:00
|
|
|
*/
|
2019-04-19 20:45:34 +01:00
|
|
|
if (set_layout->binding[b].immutable_samplers == NULL)
|
|
|
|
continue;
|
|
|
|
const uint32_t info_idx =
|
|
|
|
(uintptr_t)(void *)set_layout->binding[b].immutable_samplers - 1;
|
2019-01-19 15:40:12 +00:00
|
|
|
set_layout->binding[b].immutable_samplers = NULL;
|
|
|
|
|
2019-04-19 20:45:34 +01:00
|
|
|
const VkDescriptorSetLayoutBinding *binding =
|
|
|
|
&pCreateInfo->pBindings[info_idx];
|
|
|
|
|
2018-01-11 10:15:30 +00:00
|
|
|
if (binding->descriptorCount == 0)
|
|
|
|
continue;
|
|
|
|
|
2016-06-06 17:12:50 +01:00
|
|
|
set_layout->binding[b].type = binding->descriptorType;
|
2018-10-02 21:35:59 +01:00
|
|
|
|
2019-04-19 20:43:01 +01:00
|
|
|
if (binding_flags_info && binding_flags_info->bindingCount > 0) {
|
|
|
|
assert(binding_flags_info->bindingCount == pCreateInfo->bindingCount);
|
2018-10-02 21:35:59 +01:00
|
|
|
set_layout->binding[b].flags =
|
2019-04-19 20:45:34 +01:00
|
|
|
binding_flags_info->pBindingFlags[info_idx];
|
2020-10-16 04:56:09 +01:00
|
|
|
|
|
|
|
/* From the Vulkan spec:
|
|
|
|
*
|
|
|
|
* "If VkDescriptorSetLayoutCreateInfo::flags includes
|
|
|
|
* VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR, then
|
|
|
|
* all elements of pBindingFlags must not include
|
|
|
|
* VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
|
|
|
|
* VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT, or
|
|
|
|
* VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT"
|
|
|
|
*/
|
|
|
|
if (pCreateInfo->flags &
|
|
|
|
VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR) {
|
|
|
|
assert(!(set_layout->binding[b].flags &
|
|
|
|
(VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT |
|
|
|
|
VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT |
|
|
|
|
VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT)));
|
|
|
|
}
|
2018-10-02 21:35:59 +01:00
|
|
|
}
|
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
set_layout->binding[b].data =
|
|
|
|
binding->descriptorType == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE ?
|
|
|
|
anv_descriptor_data_for_mutable_type(device->physical, mutable_info, b) :
|
|
|
|
anv_descriptor_data_for_type(device->physical, binding->descriptorType);
|
2022-01-14 14:02:17 +00:00
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
set_layout->binding[b].array_size = binding->descriptorCount;
|
2020-10-16 04:56:09 +01:00
|
|
|
set_layout->binding[b].descriptor_index = set_layout->descriptor_count;
|
|
|
|
set_layout->descriptor_count += binding->descriptorCount;
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2018-11-24 18:42:39 +00:00
|
|
|
if (set_layout->binding[b].data & ANV_DESCRIPTOR_BUFFER_VIEW) {
|
|
|
|
set_layout->binding[b].buffer_view_index = buffer_view_count;
|
|
|
|
buffer_view_count += binding->descriptorCount;
|
|
|
|
}
|
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
switch (binding->descriptorType) {
|
2015-11-18 22:58:40 +00:00
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
2022-01-14 14:02:17 +00:00
|
|
|
case VK_DESCRIPTOR_TYPE_MUTABLE_VALVE:
|
2019-02-07 16:16:24 +00:00
|
|
|
set_layout->binding[b].max_plane_count = 1;
|
2019-01-19 15:40:12 +00:00
|
|
|
if (binding->pImmutableSamplers) {
|
|
|
|
set_layout->binding[b].immutable_samplers = samplers;
|
|
|
|
samplers += binding->descriptorCount;
|
|
|
|
|
2019-02-07 16:16:24 +00:00
|
|
|
for (uint32_t i = 0; i < binding->descriptorCount; i++) {
|
|
|
|
ANV_FROM_HANDLE(anv_sampler, sampler,
|
|
|
|
binding->pImmutableSamplers[i]);
|
|
|
|
|
|
|
|
set_layout->binding[b].immutable_samplers[i] = sampler;
|
|
|
|
if (set_layout->binding[b].max_plane_count < sampler->n_planes)
|
|
|
|
set_layout->binding[b].max_plane_count = sampler->n_planes;
|
|
|
|
}
|
2019-01-19 15:40:12 +00:00
|
|
|
}
|
2015-11-18 22:58:40 +00:00
|
|
|
break;
|
2019-02-07 16:16:24 +00:00
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
set_layout->binding[b].max_plane_count = 1;
|
|
|
|
break;
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
switch (binding->descriptorType) {
|
2015-11-18 22:58:40 +00:00
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
|
|
|
set_layout->binding[b].dynamic_offset_index = dynamic_offset_count;
|
2020-08-04 15:25:37 +01:00
|
|
|
set_layout->dynamic_offset_stages[dynamic_offset_count] = binding->stageFlags;
|
2015-12-01 20:05:21 +00:00
|
|
|
dynamic_offset_count += binding->descriptorCount;
|
2019-11-07 17:44:08 +00:00
|
|
|
assert(dynamic_offset_count < MAX_DYNAMIC_BUFFERS);
|
2015-11-18 22:58:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-12-15 00:51:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
2015-11-17 06:26:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
set_layout->binding[b].descriptor_stride =
|
|
|
|
binding->descriptorType == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE ?
|
|
|
|
anv_descriptor_size_for_mutable_type(device->physical, mutable_info, b) :
|
|
|
|
anv_descriptor_size(&set_layout->binding[b]);
|
2022-01-14 14:02:17 +00:00
|
|
|
|
2019-02-12 22:56:24 +00:00
|
|
|
if (binding->descriptorType ==
|
|
|
|
VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
|
|
|
/* Inline uniform blocks are specified to use the descriptor array
|
|
|
|
* size as the size in bytes of the block.
|
|
|
|
*/
|
2021-03-25 18:07:17 +00:00
|
|
|
descriptor_buffer_size = align_u32(descriptor_buffer_size,
|
|
|
|
ANV_UBO_ALIGNMENT);
|
2019-02-12 22:56:24 +00:00
|
|
|
set_layout->binding[b].descriptor_offset = descriptor_buffer_size;
|
|
|
|
descriptor_buffer_size += binding->descriptorCount;
|
|
|
|
} else {
|
|
|
|
set_layout->binding[b].descriptor_offset = descriptor_buffer_size;
|
2022-01-31 07:51:00 +00:00
|
|
|
descriptor_buffer_size +=
|
|
|
|
set_layout->binding[b].descriptor_stride * binding->descriptorCount;
|
2019-02-12 22:56:24 +00:00
|
|
|
}
|
2018-11-19 20:28:39 +00:00
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
set_layout->shader_stages |= binding->stageFlags;
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 23:16:34 +00:00
|
|
|
set_layout->buffer_view_count = buffer_view_count;
|
2015-11-18 22:58:40 +00:00
|
|
|
set_layout->dynamic_offset_count = dynamic_offset_count;
|
2018-11-19 20:28:39 +00:00
|
|
|
set_layout->descriptor_buffer_size = descriptor_buffer_size;
|
2015-11-18 22:58:40 +00:00
|
|
|
|
|
|
|
*pSetLayout = anv_descriptor_set_layout_to_handle(set_layout);
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-04-21 18:33:16 +01:00
|
|
|
void
|
|
|
|
anv_descriptor_set_layout_destroy(struct anv_device *device,
|
|
|
|
struct anv_descriptor_set_layout *layout)
|
|
|
|
{
|
|
|
|
assert(layout->ref_cnt == 0);
|
2021-04-08 22:12:27 +01:00
|
|
|
vk_object_free(&device->vk, NULL, layout);
|
2020-04-21 18:33:16 +01:00
|
|
|
}
|
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
static const struct anv_descriptor_set_binding_layout *
|
|
|
|
set_layout_dynamic_binding(const struct anv_descriptor_set_layout *set_layout)
|
|
|
|
{
|
|
|
|
if (set_layout->binding_count == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
const struct anv_descriptor_set_binding_layout *last_binding =
|
|
|
|
&set_layout->binding[set_layout->binding_count - 1];
|
|
|
|
if (!(last_binding->flags & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return last_binding;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
set_layout_descriptor_count(const struct anv_descriptor_set_layout *set_layout,
|
|
|
|
uint32_t var_desc_count)
|
|
|
|
{
|
|
|
|
const struct anv_descriptor_set_binding_layout *dynamic_binding =
|
|
|
|
set_layout_dynamic_binding(set_layout);
|
|
|
|
if (dynamic_binding == NULL)
|
|
|
|
return set_layout->descriptor_count;
|
|
|
|
|
|
|
|
assert(var_desc_count <= dynamic_binding->array_size);
|
|
|
|
uint32_t shrink = dynamic_binding->array_size - var_desc_count;
|
|
|
|
|
|
|
|
if (dynamic_binding->type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
|
|
|
|
return set_layout->descriptor_count;
|
|
|
|
|
|
|
|
return set_layout->descriptor_count - shrink;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
set_layout_buffer_view_count(const struct anv_descriptor_set_layout *set_layout,
|
|
|
|
uint32_t var_desc_count)
|
|
|
|
{
|
|
|
|
const struct anv_descriptor_set_binding_layout *dynamic_binding =
|
|
|
|
set_layout_dynamic_binding(set_layout);
|
|
|
|
if (dynamic_binding == NULL)
|
|
|
|
return set_layout->buffer_view_count;
|
|
|
|
|
|
|
|
assert(var_desc_count <= dynamic_binding->array_size);
|
|
|
|
uint32_t shrink = dynamic_binding->array_size - var_desc_count;
|
|
|
|
|
|
|
|
if (!(dynamic_binding->data & ANV_DESCRIPTOR_BUFFER_VIEW))
|
|
|
|
return set_layout->buffer_view_count;
|
|
|
|
|
|
|
|
return set_layout->buffer_view_count - shrink;
|
|
|
|
}
|
|
|
|
|
2021-03-18 23:53:08 +00:00
|
|
|
uint32_t
|
|
|
|
anv_descriptor_set_layout_descriptor_buffer_size(const struct anv_descriptor_set_layout *set_layout,
|
|
|
|
uint32_t var_desc_count)
|
2020-10-16 04:56:09 +01:00
|
|
|
{
|
|
|
|
const struct anv_descriptor_set_binding_layout *dynamic_binding =
|
|
|
|
set_layout_dynamic_binding(set_layout);
|
|
|
|
if (dynamic_binding == NULL)
|
2021-03-24 22:23:16 +00:00
|
|
|
return ALIGN(set_layout->descriptor_buffer_size, ANV_UBO_ALIGNMENT);
|
2020-10-16 04:56:09 +01:00
|
|
|
|
|
|
|
assert(var_desc_count <= dynamic_binding->array_size);
|
|
|
|
uint32_t shrink = dynamic_binding->array_size - var_desc_count;
|
2021-03-24 22:23:16 +00:00
|
|
|
uint32_t set_size;
|
2020-10-16 04:56:09 +01:00
|
|
|
|
|
|
|
if (dynamic_binding->type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
|
|
|
/* Inline uniform blocks are specified to use the descriptor array
|
|
|
|
* size as the size in bytes of the block.
|
|
|
|
*/
|
2021-03-24 22:23:16 +00:00
|
|
|
set_size = set_layout->descriptor_buffer_size - shrink;
|
2020-10-16 04:56:09 +01:00
|
|
|
} else {
|
2021-03-24 22:23:16 +00:00
|
|
|
set_size = set_layout->descriptor_buffer_size -
|
2022-01-14 14:02:17 +00:00
|
|
|
shrink * dynamic_binding->descriptor_stride;
|
2020-10-16 04:56:09 +01:00
|
|
|
}
|
2021-03-24 22:23:16 +00:00
|
|
|
|
|
|
|
return ALIGN(set_size, ANV_UBO_ALIGNMENT);
|
2020-10-16 04:56:09 +01:00
|
|
|
}
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
void anv_DestroyDescriptorSetLayout(
|
|
|
|
VkDevice _device,
|
2015-12-02 11:28:27 +00:00
|
|
|
VkDescriptorSetLayout _set_layout,
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
2015-11-18 22:58:40 +00:00
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set_layout, set_layout, _set_layout);
|
|
|
|
|
2016-11-11 05:32:32 +00:00
|
|
|
if (!set_layout)
|
|
|
|
return;
|
|
|
|
|
2018-01-25 08:43:22 +00:00
|
|
|
anv_descriptor_set_layout_unref(device, set_layout);
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 04:03:49 +01:00
|
|
|
#define SHA1_UPDATE_VALUE(ctx, x) _mesa_sha1_update(ctx, &(x), sizeof(x));
|
|
|
|
|
|
|
|
static void
|
|
|
|
sha1_update_immutable_sampler(struct mesa_sha1 *ctx,
|
|
|
|
const struct anv_sampler *sampler)
|
|
|
|
{
|
|
|
|
if (!sampler->conversion)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* The only thing that affects the shader is ycbcr conversion */
|
|
|
|
_mesa_sha1_update(ctx, sampler->conversion,
|
|
|
|
sizeof(*sampler->conversion));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sha1_update_descriptor_set_binding_layout(struct mesa_sha1 *ctx,
|
|
|
|
const struct anv_descriptor_set_binding_layout *layout)
|
|
|
|
{
|
2018-10-02 21:35:59 +01:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->flags);
|
2018-11-24 18:42:39 +00:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->data);
|
2019-02-07 16:16:24 +00:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->max_plane_count);
|
2018-06-30 04:03:49 +01:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->array_size);
|
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->descriptor_index);
|
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->dynamic_offset_index);
|
2019-02-06 23:16:34 +00:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->buffer_view_index);
|
2018-11-19 20:28:39 +00:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->descriptor_offset);
|
2018-06-30 04:03:49 +01:00
|
|
|
|
|
|
|
if (layout->immutable_samplers) {
|
|
|
|
for (uint16_t i = 0; i < layout->array_size; i++)
|
|
|
|
sha1_update_immutable_sampler(ctx, layout->immutable_samplers[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-25 01:14:11 +01:00
|
|
|
static void
|
|
|
|
sha1_update_descriptor_set_layout(struct mesa_sha1 *ctx,
|
|
|
|
const struct anv_descriptor_set_layout *layout)
|
|
|
|
{
|
2018-06-30 04:03:49 +01:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->binding_count);
|
2020-10-16 04:56:09 +01:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->descriptor_count);
|
2018-06-30 04:03:49 +01:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->shader_stages);
|
2019-02-06 23:16:34 +00:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->buffer_view_count);
|
2018-06-30 04:03:49 +01:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->dynamic_offset_count);
|
2018-11-19 20:28:39 +00:00
|
|
|
SHA1_UPDATE_VALUE(ctx, layout->descriptor_buffer_size);
|
2018-06-30 04:03:49 +01:00
|
|
|
|
|
|
|
for (uint16_t i = 0; i < layout->binding_count; i++)
|
|
|
|
sha1_update_descriptor_set_binding_layout(ctx, &layout->binding[i]);
|
2016-08-25 01:14:11 +01:00
|
|
|
}
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
/*
|
|
|
|
* Pipeline layouts. These have nothing to do with the pipeline. They are
|
2017-01-16 16:05:07 +00:00
|
|
|
* just multiple descriptor set layouts pasted together
|
2015-11-18 22:58:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
VkResult anv_CreatePipelineLayout(
|
|
|
|
VkDevice _device,
|
|
|
|
const VkPipelineLayoutCreateInfo* pCreateInfo,
|
2015-12-02 11:28:27 +00:00
|
|
|
const VkAllocationCallbacks* pAllocator,
|
2015-11-18 22:58:40 +00:00
|
|
|
VkPipelineLayout* pPipelineLayout)
|
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2016-02-18 02:03:21 +00:00
|
|
|
struct anv_pipeline_layout *layout;
|
2015-11-18 22:58:40 +00:00
|
|
|
|
|
|
|
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO);
|
|
|
|
|
2021-04-08 22:12:27 +01:00
|
|
|
layout = vk_object_alloc(&device->vk, pAllocator, sizeof(*layout),
|
|
|
|
VK_OBJECT_TYPE_PIPELINE_LAYOUT);
|
2016-02-18 02:03:21 +00:00
|
|
|
if (layout == NULL)
|
2021-09-24 18:06:32 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2016-02-18 02:03:21 +00:00
|
|
|
|
|
|
|
layout->num_sets = pCreateInfo->setLayoutCount;
|
2015-11-18 22:58:40 +00:00
|
|
|
|
|
|
|
unsigned dynamic_offset_count = 0;
|
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
for (uint32_t set = 0; set < pCreateInfo->setLayoutCount; set++) {
|
2015-11-18 22:58:40 +00:00
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set_layout, set_layout,
|
|
|
|
pCreateInfo->pSetLayouts[set]);
|
2016-02-18 02:03:21 +00:00
|
|
|
layout->set[set].layout = set_layout;
|
2018-01-25 08:43:22 +00:00
|
|
|
anv_descriptor_set_layout_ref(set_layout);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2016-02-18 02:03:21 +00:00
|
|
|
layout->set[set].dynamic_offset_start = dynamic_offset_count;
|
2015-11-18 22:58:40 +00:00
|
|
|
for (uint32_t b = 0; b < set_layout->binding_count; b++) {
|
2016-02-23 01:13:46 +00:00
|
|
|
if (set_layout->binding[b].dynamic_offset_index < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dynamic_offset_count += set_layout->binding[b].array_size;
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-07 17:44:08 +00:00
|
|
|
assert(dynamic_offset_count < MAX_DYNAMIC_BUFFERS);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2017-01-24 21:21:09 +00:00
|
|
|
struct mesa_sha1 ctx;
|
|
|
|
_mesa_sha1_init(&ctx);
|
2016-08-25 01:14:11 +01:00
|
|
|
for (unsigned s = 0; s < layout->num_sets; s++) {
|
2017-01-24 21:21:09 +00:00
|
|
|
sha1_update_descriptor_set_layout(&ctx, layout->set[s].layout);
|
|
|
|
_mesa_sha1_update(&ctx, &layout->set[s].dynamic_offset_start,
|
2016-08-25 01:14:11 +01:00
|
|
|
sizeof(layout->set[s].dynamic_offset_start));
|
|
|
|
}
|
2017-01-24 21:21:09 +00:00
|
|
|
_mesa_sha1_update(&ctx, &layout->num_sets, sizeof(layout->num_sets));
|
|
|
|
_mesa_sha1_final(&ctx, layout->sha1);
|
2016-08-25 01:14:11 +01:00
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
*pPipelineLayout = anv_pipeline_layout_to_handle(layout);
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void anv_DestroyPipelineLayout(
|
|
|
|
VkDevice _device,
|
2015-12-02 11:28:27 +00:00
|
|
|
VkPipelineLayout _pipelineLayout,
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
2015-11-18 22:58:40 +00:00
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
ANV_FROM_HANDLE(anv_pipeline_layout, pipeline_layout, _pipelineLayout);
|
|
|
|
|
2016-11-11 05:32:32 +00:00
|
|
|
if (!pipeline_layout)
|
|
|
|
return;
|
|
|
|
|
2018-01-25 08:43:22 +00:00
|
|
|
for (uint32_t i = 0; i < pipeline_layout->num_sets; i++)
|
|
|
|
anv_descriptor_set_layout_unref(device, pipeline_layout->set[i].layout);
|
|
|
|
|
2021-04-08 22:12:27 +01:00
|
|
|
vk_object_free(&device->vk, pAllocator, pipeline_layout);
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-02-12 06:46:28 +00:00
|
|
|
* Descriptor pools.
|
|
|
|
*
|
|
|
|
* These are implemented using a big pool of memory and a free-list for the
|
|
|
|
* host memory allocations and a state_stream and a free list for the buffer
|
|
|
|
* view surface state. The spec allows us to fail to allocate due to
|
|
|
|
* fragmentation in all cases but two: 1) after pool reset, allocating up
|
|
|
|
* until the pool size with no freeing must succeed and 2) allocating and
|
|
|
|
* freeing only descriptor sets with the same layout. Case 1) is easy enogh,
|
|
|
|
* and the free lists lets us recycle blocks for case 2).
|
2015-11-18 22:58:40 +00:00
|
|
|
*/
|
|
|
|
|
2018-11-19 20:28:39 +00:00
|
|
|
/* The vma heap reserves 0 to mean NULL; we have to offset by some ammount to
|
|
|
|
* ensure we can allocate the entire BO without hitting zero. The actual
|
|
|
|
* amount doesn't matter.
|
|
|
|
*/
|
|
|
|
#define POOL_HEAP_OFFSET 64
|
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
#define EMPTY 1
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
VkResult anv_CreateDescriptorPool(
|
2016-02-12 06:46:28 +00:00
|
|
|
VkDevice _device,
|
2015-11-18 22:58:40 +00:00
|
|
|
const VkDescriptorPoolCreateInfo* pCreateInfo,
|
2015-12-02 11:28:27 +00:00
|
|
|
const VkAllocationCallbacks* pAllocator,
|
2015-11-18 22:58:40 +00:00
|
|
|
VkDescriptorPool* pDescriptorPool)
|
|
|
|
{
|
2016-02-12 06:46:28 +00:00
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
struct anv_descriptor_pool *pool;
|
|
|
|
|
2021-09-03 09:39:50 +01:00
|
|
|
const VkDescriptorPoolInlineUniformBlockCreateInfo *inline_info =
|
2019-02-12 22:56:24 +00:00
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
2021-09-03 09:39:50 +01:00
|
|
|
DESCRIPTOR_POOL_INLINE_UNIFORM_BLOCK_CREATE_INFO);
|
2022-01-14 14:02:17 +00:00
|
|
|
const VkMutableDescriptorTypeCreateInfoVALVE *mutable_info =
|
|
|
|
vk_find_struct_const(pCreateInfo->pNext,
|
|
|
|
MUTABLE_DESCRIPTOR_TYPE_CREATE_INFO_VALVE);
|
2019-02-12 22:56:24 +00:00
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
uint32_t descriptor_count = 0;
|
2019-02-06 23:16:34 +00:00
|
|
|
uint32_t buffer_view_count = 0;
|
2018-11-19 20:28:39 +00:00
|
|
|
uint32_t descriptor_bo_size = 0;
|
2022-01-14 14:02:17 +00:00
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; i++) {
|
2022-01-31 07:51:00 +00:00
|
|
|
enum anv_descriptor_data desc_data =
|
|
|
|
pCreateInfo->pPoolSizes[i].type == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE ?
|
|
|
|
anv_descriptor_data_for_mutable_type(device->physical, mutable_info, i) :
|
|
|
|
anv_descriptor_data_for_type(device->physical, pCreateInfo->pPoolSizes[i].type);
|
2018-11-24 18:42:39 +00:00
|
|
|
|
|
|
|
if (desc_data & ANV_DESCRIPTOR_BUFFER_VIEW)
|
2019-02-06 23:16:34 +00:00
|
|
|
buffer_view_count += pCreateInfo->pPoolSizes[i].descriptorCount;
|
2018-11-24 18:42:39 +00:00
|
|
|
|
2022-01-31 07:51:00 +00:00
|
|
|
unsigned desc_data_size =
|
|
|
|
pCreateInfo->pPoolSizes[i].type == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE ?
|
|
|
|
anv_descriptor_size_for_mutable_type(device->physical, mutable_info, i) :
|
|
|
|
anv_descriptor_data_size(desc_data);
|
2022-01-14 14:02:17 +00:00
|
|
|
|
|
|
|
desc_data_size *= pCreateInfo->pPoolSizes[i].descriptorCount;
|
2019-02-12 22:56:24 +00:00
|
|
|
|
2019-02-07 20:10:33 +00:00
|
|
|
/* Combined image sampler descriptors can take up to 3 slots if they
|
|
|
|
* hold a YCbCr image.
|
|
|
|
*/
|
|
|
|
if (pCreateInfo->pPoolSizes[i].type ==
|
|
|
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
|
|
|
|
desc_data_size *= 3;
|
|
|
|
|
2019-02-12 22:56:24 +00:00
|
|
|
if (pCreateInfo->pPoolSizes[i].type ==
|
|
|
|
VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
|
|
|
|
/* Inline uniform blocks are specified to use the descriptor array
|
|
|
|
* size as the size in bytes of the block.
|
|
|
|
*/
|
|
|
|
assert(inline_info);
|
|
|
|
desc_data_size += pCreateInfo->pPoolSizes[i].descriptorCount;
|
|
|
|
}
|
|
|
|
|
2018-11-19 20:28:39 +00:00
|
|
|
descriptor_bo_size += desc_data_size;
|
|
|
|
|
2018-11-24 18:42:39 +00:00
|
|
|
descriptor_count += pCreateInfo->pPoolSizes[i].descriptorCount;
|
2016-02-12 06:46:28 +00:00
|
|
|
}
|
2018-11-19 20:28:39 +00:00
|
|
|
/* We have to align descriptor buffer allocations to 32B so that we can
|
|
|
|
* push descriptor buffers. This means that each descriptor buffer
|
|
|
|
* allocated may burn up to 32B of extra space to get the right alignment.
|
|
|
|
* (Technically, it's at most 28B because we're always going to start at
|
|
|
|
* least 4B aligned but we're being conservative here.) Allocate enough
|
|
|
|
* extra space that we can chop it into maxSets pieces and align each one
|
|
|
|
* of them to 32B.
|
|
|
|
*/
|
2021-03-24 22:23:16 +00:00
|
|
|
descriptor_bo_size += ANV_UBO_ALIGNMENT * pCreateInfo->maxSets;
|
2021-03-25 18:07:17 +00:00
|
|
|
/* We align inline uniform blocks to ANV_UBO_ALIGNMENT */
|
|
|
|
if (inline_info) {
|
|
|
|
descriptor_bo_size +=
|
|
|
|
ANV_UBO_ALIGNMENT * inline_info->maxInlineUniformBlockBindings;
|
|
|
|
}
|
2019-04-24 03:40:31 +01:00
|
|
|
descriptor_bo_size = ALIGN(descriptor_bo_size, 4096);
|
2016-02-12 06:46:28 +00:00
|
|
|
|
2017-01-26 11:06:53 +00:00
|
|
|
const size_t pool_size =
|
2016-02-24 05:23:06 +00:00
|
|
|
pCreateInfo->maxSets * sizeof(struct anv_descriptor_set) +
|
|
|
|
descriptor_count * sizeof(struct anv_descriptor) +
|
2019-02-06 23:16:34 +00:00
|
|
|
buffer_view_count * sizeof(struct anv_buffer_view);
|
2017-01-26 11:06:53 +00:00
|
|
|
const size_t total_size = sizeof(*pool) + pool_size;
|
2016-02-12 06:46:28 +00:00
|
|
|
|
2021-04-08 22:12:27 +01:00
|
|
|
pool = vk_object_alloc(&device->vk, pAllocator, total_size,
|
|
|
|
VK_OBJECT_TYPE_DESCRIPTOR_POOL);
|
2016-02-12 06:46:28 +00:00
|
|
|
if (!pool)
|
2021-09-24 18:06:32 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2016-02-12 06:46:28 +00:00
|
|
|
|
2017-01-26 11:06:53 +00:00
|
|
|
pool->size = pool_size;
|
2016-02-12 06:46:28 +00:00
|
|
|
pool->next = 0;
|
|
|
|
pool->free_list = EMPTY;
|
2022-03-04 10:52:04 +00:00
|
|
|
pool->host_only = pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_VALVE;
|
2016-02-12 06:46:28 +00:00
|
|
|
|
2018-11-19 20:28:39 +00:00
|
|
|
if (descriptor_bo_size > 0) {
|
2019-10-25 23:15:31 +01:00
|
|
|
VkResult result = anv_device_alloc_bo(device,
|
2020-06-17 13:37:33 +01:00
|
|
|
"descriptors",
|
2019-10-25 23:15:31 +01:00
|
|
|
descriptor_bo_size,
|
|
|
|
ANV_BO_ALLOC_MAPPED |
|
|
|
|
ANV_BO_ALLOC_SNOOPED,
|
2019-12-02 21:22:38 +00:00
|
|
|
0 /* explicit_address */,
|
2019-10-25 23:15:31 +01:00
|
|
|
&pool->bo);
|
2018-11-19 20:28:39 +00:00
|
|
|
if (result != VK_SUCCESS) {
|
2021-04-08 22:12:27 +01:00
|
|
|
vk_object_free(&device->vk, pAllocator, pool);
|
2018-11-19 20:28:39 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
util_vma_heap_init(&pool->bo_heap, POOL_HEAP_OFFSET, descriptor_bo_size);
|
|
|
|
} else {
|
2019-10-25 23:15:31 +01:00
|
|
|
pool->bo = NULL;
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
anv_state_stream_init(&pool->surface_state_stream,
|
2017-04-24 01:22:26 +01:00
|
|
|
&device->surface_state_pool, 4096);
|
2016-02-12 06:46:28 +00:00
|
|
|
pool->surface_state_free_list = NULL;
|
|
|
|
|
2019-03-04 12:22:36 +00:00
|
|
|
list_inithead(&pool->desc_sets);
|
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
*pDescriptorPool = anv_descriptor_pool_to_handle(pool);
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void anv_DestroyDescriptorPool(
|
|
|
|
VkDevice _device,
|
2015-12-02 11:28:27 +00:00
|
|
|
VkDescriptorPool _pool,
|
|
|
|
const VkAllocationCallbacks* pAllocator)
|
2015-11-18 22:58:40 +00:00
|
|
|
{
|
2016-02-12 06:46:28 +00:00
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_pool, pool, _pool);
|
|
|
|
|
2016-11-11 05:32:32 +00:00
|
|
|
if (!pool)
|
|
|
|
return;
|
|
|
|
|
2019-04-24 03:46:32 +01:00
|
|
|
list_for_each_entry_safe(struct anv_descriptor_set, set,
|
|
|
|
&pool->desc_sets, pool_link) {
|
2019-04-25 20:15:26 +01:00
|
|
|
anv_descriptor_set_layout_unref(device, set->layout);
|
2019-04-24 03:46:32 +01:00
|
|
|
}
|
|
|
|
|
2020-11-26 14:37:01 +00:00
|
|
|
if (pool->bo) {
|
|
|
|
util_vma_heap_finish(&pool->bo_heap);
|
2019-10-25 23:15:31 +01:00
|
|
|
anv_device_release_bo(device, pool->bo);
|
2020-11-26 14:37:01 +00:00
|
|
|
}
|
2016-02-12 06:46:28 +00:00
|
|
|
anv_state_stream_finish(&pool->surface_state_stream);
|
2019-03-04 12:22:36 +00:00
|
|
|
|
2021-04-08 22:12:27 +01:00
|
|
|
vk_object_free(&device->vk, pAllocator, pool);
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VkResult anv_ResetDescriptorPool(
|
2016-02-12 06:46:28 +00:00
|
|
|
VkDevice _device,
|
2015-12-01 20:05:21 +00:00
|
|
|
VkDescriptorPool descriptorPool,
|
|
|
|
VkDescriptorPoolResetFlags flags)
|
2015-11-18 22:58:40 +00:00
|
|
|
{
|
2016-02-12 06:46:28 +00:00
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_pool, pool, descriptorPool);
|
|
|
|
|
2019-03-12 15:13:47 +00:00
|
|
|
list_for_each_entry_safe(struct anv_descriptor_set, set,
|
|
|
|
&pool->desc_sets, pool_link) {
|
2019-04-25 20:15:26 +01:00
|
|
|
anv_descriptor_set_layout_unref(device, set->layout);
|
2019-03-12 15:13:47 +00:00
|
|
|
}
|
2019-04-25 20:15:26 +01:00
|
|
|
list_inithead(&pool->desc_sets);
|
2019-03-12 15:13:47 +00:00
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
pool->next = 0;
|
|
|
|
pool->free_list = EMPTY;
|
2018-11-19 20:28:39 +00:00
|
|
|
|
2019-10-25 23:15:31 +01:00
|
|
|
if (pool->bo) {
|
2018-11-19 20:28:39 +00:00
|
|
|
util_vma_heap_finish(&pool->bo_heap);
|
2019-10-25 23:15:31 +01:00
|
|
|
util_vma_heap_init(&pool->bo_heap, POOL_HEAP_OFFSET, pool->bo->size);
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
anv_state_stream_finish(&pool->surface_state_stream);
|
|
|
|
anv_state_stream_init(&pool->surface_state_stream,
|
2017-04-24 01:22:26 +01:00
|
|
|
&device->surface_state_pool, 4096);
|
2016-02-12 06:46:28 +00:00
|
|
|
pool->surface_state_free_list = NULL;
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
struct pool_free_list_entry {
|
|
|
|
uint32_t next;
|
|
|
|
uint32_t size;
|
|
|
|
};
|
|
|
|
|
2018-11-19 21:15:56 +00:00
|
|
|
static VkResult
|
|
|
|
anv_descriptor_pool_alloc_set(struct anv_descriptor_pool *pool,
|
|
|
|
uint32_t size,
|
|
|
|
struct anv_descriptor_set **set)
|
2015-11-18 22:58:40 +00:00
|
|
|
{
|
2016-02-12 06:46:28 +00:00
|
|
|
if (size <= pool->size - pool->next) {
|
2018-11-19 21:15:56 +00:00
|
|
|
*set = (struct anv_descriptor_set *) (pool->data + pool->next);
|
2020-07-27 10:06:17 +01:00
|
|
|
(*set)->size = size;
|
2016-02-12 06:46:28 +00:00
|
|
|
pool->next += size;
|
2018-11-19 21:15:56 +00:00
|
|
|
return VK_SUCCESS;
|
2016-02-12 06:46:28 +00:00
|
|
|
} else {
|
|
|
|
struct pool_free_list_entry *entry;
|
|
|
|
uint32_t *link = &pool->free_list;
|
|
|
|
for (uint32_t f = pool->free_list; f != EMPTY; f = entry->next) {
|
|
|
|
entry = (struct pool_free_list_entry *) (pool->data + f);
|
|
|
|
if (size <= entry->size) {
|
|
|
|
*link = entry->next;
|
2018-11-19 21:15:56 +00:00
|
|
|
*set = (struct anv_descriptor_set *) entry;
|
2020-07-27 10:06:17 +01:00
|
|
|
(*set)->size = entry->size;
|
2018-11-19 21:15:56 +00:00
|
|
|
return VK_SUCCESS;
|
2016-02-12 06:46:28 +00:00
|
|
|
}
|
|
|
|
link = &entry->next;
|
|
|
|
}
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2017-01-21 15:40:22 +00:00
|
|
|
if (pool->free_list != EMPTY) {
|
2021-10-06 15:12:43 +01:00
|
|
|
return VK_ERROR_FRAGMENTED_POOL;
|
2017-01-21 15:40:22 +00:00
|
|
|
} else {
|
2021-10-06 15:12:43 +01:00
|
|
|
return VK_ERROR_OUT_OF_POOL_MEMORY;
|
2017-01-21 15:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-19 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
anv_descriptor_pool_free_set(struct anv_descriptor_pool *pool,
|
|
|
|
struct anv_descriptor_set *set)
|
|
|
|
{
|
|
|
|
/* Put the descriptor set allocation back on the free list. */
|
|
|
|
const uint32_t index = (char *) set - pool->data;
|
|
|
|
if (index + set->size == pool->next) {
|
|
|
|
pool->next = index;
|
|
|
|
} else {
|
|
|
|
struct pool_free_list_entry *entry = (struct pool_free_list_entry *) set;
|
|
|
|
entry->next = pool->free_list;
|
|
|
|
entry->size = set->size;
|
|
|
|
pool->free_list = (char *) entry - pool->data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct surface_state_free_list_entry {
|
|
|
|
void *next;
|
|
|
|
struct anv_state state;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct anv_state
|
|
|
|
anv_descriptor_pool_alloc_state(struct anv_descriptor_pool *pool)
|
|
|
|
{
|
2022-03-04 10:52:04 +00:00
|
|
|
assert(!pool->host_only);
|
2022-01-24 14:54:35 +00:00
|
|
|
|
2018-11-19 21:15:56 +00:00
|
|
|
struct surface_state_free_list_entry *entry =
|
|
|
|
pool->surface_state_free_list;
|
|
|
|
|
|
|
|
if (entry) {
|
|
|
|
struct anv_state state = entry->state;
|
|
|
|
pool->surface_state_free_list = entry->next;
|
|
|
|
assert(state.alloc_size == 64);
|
|
|
|
return state;
|
|
|
|
} else {
|
|
|
|
return anv_state_stream_alloc(&pool->surface_state_stream, 64, 64);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
anv_descriptor_pool_free_state(struct anv_descriptor_pool *pool,
|
|
|
|
struct anv_state state)
|
|
|
|
{
|
2022-01-24 14:54:35 +00:00
|
|
|
assert(state.alloc_size);
|
2018-11-19 21:15:56 +00:00
|
|
|
/* Put the buffer view surface state back on the free list. */
|
|
|
|
struct surface_state_free_list_entry *entry = state.map;
|
|
|
|
entry->next = pool->surface_state_free_list;
|
|
|
|
entry->state = state;
|
|
|
|
pool->surface_state_free_list = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2020-10-16 04:56:09 +01:00
|
|
|
anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout,
|
|
|
|
uint32_t var_desc_count)
|
2018-11-19 21:15:56 +00:00
|
|
|
{
|
2020-10-16 04:56:09 +01:00
|
|
|
const uint32_t descriptor_count =
|
|
|
|
set_layout_descriptor_count(layout, var_desc_count);
|
|
|
|
const uint32_t buffer_view_count =
|
|
|
|
set_layout_buffer_view_count(layout, var_desc_count);
|
|
|
|
|
|
|
|
return sizeof(struct anv_descriptor_set) +
|
|
|
|
descriptor_count * sizeof(struct anv_descriptor) +
|
|
|
|
buffer_view_count * sizeof(struct anv_buffer_view);
|
2018-11-19 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2022-03-08 13:59:38 +00:00
|
|
|
static VkResult
|
2018-11-19 21:15:56 +00:00
|
|
|
anv_descriptor_set_create(struct anv_device *device,
|
|
|
|
struct anv_descriptor_pool *pool,
|
|
|
|
struct anv_descriptor_set_layout *layout,
|
2020-10-16 04:56:09 +01:00
|
|
|
uint32_t var_desc_count,
|
2018-11-19 21:15:56 +00:00
|
|
|
struct anv_descriptor_set **out_set)
|
|
|
|
{
|
|
|
|
struct anv_descriptor_set *set;
|
2020-10-16 04:56:09 +01:00
|
|
|
const size_t size = anv_descriptor_set_layout_size(layout, var_desc_count);
|
2018-11-19 21:15:56 +00:00
|
|
|
|
|
|
|
VkResult result = anv_descriptor_pool_alloc_set(pool, size, &set);
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
return result;
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
uint32_t descriptor_buffer_size =
|
2021-03-18 23:53:08 +00:00
|
|
|
anv_descriptor_set_layout_descriptor_buffer_size(layout, var_desc_count);
|
2022-01-24 14:54:35 +00:00
|
|
|
|
|
|
|
set->desc_surface_state = ANV_STATE_NULL;
|
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
if (descriptor_buffer_size) {
|
2018-11-19 20:28:39 +00:00
|
|
|
uint64_t pool_vma_offset =
|
2021-03-24 22:23:16 +00:00
|
|
|
util_vma_heap_alloc(&pool->bo_heap, descriptor_buffer_size,
|
|
|
|
ANV_UBO_ALIGNMENT);
|
2018-11-19 20:28:39 +00:00
|
|
|
if (pool_vma_offset == 0) {
|
2020-05-14 04:57:46 +01:00
|
|
|
anv_descriptor_pool_free_set(pool, set);
|
2021-09-24 18:06:32 +01:00
|
|
|
return vk_error(pool, VK_ERROR_FRAGMENTED_POOL);
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
|
|
|
assert(pool_vma_offset >= POOL_HEAP_OFFSET &&
|
|
|
|
pool_vma_offset - POOL_HEAP_OFFSET <= INT32_MAX);
|
|
|
|
set->desc_mem.offset = pool_vma_offset - POOL_HEAP_OFFSET;
|
2021-03-24 22:23:16 +00:00
|
|
|
set->desc_mem.alloc_size = descriptor_buffer_size;
|
2019-10-25 23:15:31 +01:00
|
|
|
set->desc_mem.map = pool->bo->map + set->desc_mem.offset;
|
2018-11-19 20:28:39 +00:00
|
|
|
|
2021-06-28 11:56:31 +01:00
|
|
|
set->desc_addr = (struct anv_address) {
|
|
|
|
.bo = pool->bo,
|
|
|
|
.offset = set->desc_mem.offset,
|
|
|
|
};
|
|
|
|
|
2020-02-21 18:36:41 +00:00
|
|
|
enum isl_format format =
|
|
|
|
anv_isl_format_for_descriptor_type(device,
|
|
|
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
|
|
|
|
2022-03-04 10:52:04 +00:00
|
|
|
if (!pool->host_only) {
|
2022-01-24 14:54:35 +00:00
|
|
|
set->desc_surface_state = anv_descriptor_pool_alloc_state(pool);
|
|
|
|
anv_fill_buffer_surface_state(device, set->desc_surface_state, format,
|
|
|
|
ISL_SURF_USAGE_CONSTANT_BUFFER_BIT,
|
|
|
|
set->desc_addr,
|
|
|
|
descriptor_buffer_size, 1);
|
|
|
|
}
|
2018-11-19 20:28:39 +00:00
|
|
|
} else {
|
|
|
|
set->desc_mem = ANV_STATE_NULL;
|
2021-06-28 11:56:31 +01:00
|
|
|
set->desc_addr = (struct anv_address) { .bo = NULL, .offset = 0 };
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 18:33:16 +01:00
|
|
|
vk_object_base_init(&device->vk, &set->base,
|
|
|
|
VK_OBJECT_TYPE_DESCRIPTOR_SET);
|
2018-11-19 20:28:39 +00:00
|
|
|
set->pool = pool;
|
2015-11-18 22:58:40 +00:00
|
|
|
set->layout = layout;
|
2018-01-25 08:43:22 +00:00
|
|
|
anv_descriptor_set_layout_ref(layout);
|
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
set->buffer_view_count =
|
|
|
|
set_layout_buffer_view_count(layout, var_desc_count);
|
|
|
|
set->descriptor_count =
|
|
|
|
set_layout_descriptor_count(layout, var_desc_count);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
set->buffer_views =
|
|
|
|
(struct anv_buffer_view *) &set->descriptors[set->descriptor_count];
|
2020-10-16 18:52:46 +01:00
|
|
|
|
2016-07-12 01:33:24 +01:00
|
|
|
/* By defining the descriptors to be zero now, we can later verify that
|
|
|
|
* a descriptor has not been populated with user data.
|
|
|
|
*/
|
2020-10-16 04:56:09 +01:00
|
|
|
memset(set->descriptors, 0,
|
|
|
|
sizeof(struct anv_descriptor) * set->descriptor_count);
|
2016-07-12 01:33:24 +01:00
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
/* Go through and fill out immutable samplers if we have any */
|
|
|
|
for (uint32_t b = 0; b < layout->binding_count; b++) {
|
|
|
|
if (layout->binding[b].immutable_samplers) {
|
2016-02-23 05:39:14 +00:00
|
|
|
for (uint32_t i = 0; i < layout->binding[b].array_size; i++) {
|
|
|
|
/* The type will get changed to COMBINED_IMAGE_SAMPLER in
|
|
|
|
* UpdateDescriptorSets if needed. However, if the descriptor
|
|
|
|
* set has an immutable sampler, UpdateDescriptorSets may never
|
|
|
|
* touch it, so we need to make sure it's 100% valid now.
|
2019-02-08 04:34:57 +00:00
|
|
|
*
|
|
|
|
* We don't need to actually provide a sampler because the helper
|
|
|
|
* will always write in the immutable sampler regardless of what
|
|
|
|
* is in the sampler parameter.
|
2016-02-23 05:39:14 +00:00
|
|
|
*/
|
2020-01-03 17:20:22 +00:00
|
|
|
VkDescriptorImageInfo info = { };
|
2019-02-08 04:34:57 +00:00
|
|
|
anv_descriptor_set_write_image_view(device, set, &info,
|
|
|
|
VK_DESCRIPTOR_TYPE_SAMPLER,
|
|
|
|
b, i);
|
2016-02-23 05:39:14 +00:00
|
|
|
}
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 14:54:35 +00:00
|
|
|
/* Allocate null surface state for the buffer views since
|
|
|
|
* we lazy allocate this in the write anyway.
|
|
|
|
*/
|
2022-03-04 10:52:04 +00:00
|
|
|
if (!pool->host_only) {
|
2022-03-08 14:56:50 +00:00
|
|
|
for (uint32_t b = 0; b < set->buffer_view_count; b++) {
|
|
|
|
set->buffer_views[b].surface_state =
|
|
|
|
anv_descriptor_pool_alloc_state(pool);
|
|
|
|
}
|
2015-12-21 08:03:28 +00:00
|
|
|
}
|
2016-02-12 06:46:28 +00:00
|
|
|
|
2019-04-24 04:13:55 +01:00
|
|
|
list_addtail(&set->pool_link, &pool->desc_sets);
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
*out_set = set;
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-03-08 13:59:38 +00:00
|
|
|
static void
|
2015-11-18 22:58:40 +00:00
|
|
|
anv_descriptor_set_destroy(struct anv_device *device,
|
2016-02-12 06:46:28 +00:00
|
|
|
struct anv_descriptor_pool *pool,
|
2015-11-18 22:58:40 +00:00
|
|
|
struct anv_descriptor_set *set)
|
|
|
|
{
|
2018-01-25 08:43:22 +00:00
|
|
|
anv_descriptor_set_layout_unref(device, set->layout);
|
|
|
|
|
2018-11-19 20:28:39 +00:00
|
|
|
if (set->desc_mem.alloc_size) {
|
|
|
|
util_vma_heap_free(&pool->bo_heap,
|
|
|
|
(uint64_t)set->desc_mem.offset + POOL_HEAP_OFFSET,
|
|
|
|
set->desc_mem.alloc_size);
|
2022-01-24 14:54:35 +00:00
|
|
|
if (set->desc_surface_state.alloc_size)
|
|
|
|
anv_descriptor_pool_free_state(pool, set->desc_surface_state);
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 10:52:04 +00:00
|
|
|
if (!pool->host_only) {
|
2022-03-08 14:56:50 +00:00
|
|
|
for (uint32_t b = 0; b < set->buffer_view_count; b++) {
|
|
|
|
if (set->buffer_views[b].surface_state.alloc_size)
|
|
|
|
anv_descriptor_pool_free_state(pool, set->buffer_views[b].surface_state);
|
|
|
|
}
|
2022-01-24 14:54:35 +00:00
|
|
|
}
|
2015-12-21 08:03:28 +00:00
|
|
|
|
2019-04-24 04:13:55 +01:00
|
|
|
list_del(&set->pool_link);
|
|
|
|
|
2020-04-21 18:33:16 +01:00
|
|
|
vk_object_base_finish(&set->base);
|
2018-11-19 21:15:56 +00:00
|
|
|
anv_descriptor_pool_free_set(pool, set);
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
VkResult anv_AllocateDescriptorSets(
|
2015-11-18 22:58:40 +00:00
|
|
|
VkDevice _device,
|
2015-12-01 20:05:21 +00:00
|
|
|
const VkDescriptorSetAllocateInfo* pAllocateInfo,
|
2015-11-18 22:58:40 +00:00
|
|
|
VkDescriptorSet* pDescriptorSets)
|
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2016-02-12 06:46:28 +00:00
|
|
|
ANV_FROM_HANDLE(anv_descriptor_pool, pool, pAllocateInfo->descriptorPool);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
|
|
|
VkResult result = VK_SUCCESS;
|
|
|
|
struct anv_descriptor_set *set;
|
|
|
|
uint32_t i;
|
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
const VkDescriptorSetVariableDescriptorCountAllocateInfo *vdcai =
|
|
|
|
vk_find_struct_const(pAllocateInfo->pNext,
|
|
|
|
DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO);
|
|
|
|
|
2016-01-14 15:41:45 +00:00
|
|
|
for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
|
2015-12-01 20:05:21 +00:00
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set_layout, layout,
|
|
|
|
pAllocateInfo->pSetLayouts[i]);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2020-10-16 04:56:09 +01:00
|
|
|
uint32_t var_desc_count = 0;
|
|
|
|
if (vdcai != NULL && vdcai->descriptorSetCount > 0) {
|
|
|
|
assert(vdcai->descriptorSetCount == pAllocateInfo->descriptorSetCount);
|
|
|
|
var_desc_count = vdcai->pDescriptorCounts[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
result = anv_descriptor_set_create(device, pool, layout,
|
|
|
|
var_desc_count, &set);
|
2015-11-18 22:58:40 +00:00
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pDescriptorSets[i] = anv_descriptor_set_to_handle(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
2015-12-01 20:05:21 +00:00
|
|
|
anv_FreeDescriptorSets(_device, pAllocateInfo->descriptorPool,
|
|
|
|
i, pDescriptorSets);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkResult anv_FreeDescriptorSets(
|
|
|
|
VkDevice _device,
|
|
|
|
VkDescriptorPool descriptorPool,
|
|
|
|
uint32_t count,
|
|
|
|
const VkDescriptorSet* pDescriptorSets)
|
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
2016-02-12 06:46:28 +00:00
|
|
|
ANV_FROM_HANDLE(anv_descriptor_pool, pool, descriptorPool);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set, set, pDescriptorSets[i]);
|
|
|
|
|
2016-11-11 05:32:32 +00:00
|
|
|
if (!set)
|
|
|
|
continue;
|
|
|
|
|
2016-02-12 06:46:28 +00:00
|
|
|
anv_descriptor_set_destroy(device, pool, set);
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-11-22 00:26:27 +00:00
|
|
|
static void
|
|
|
|
anv_descriptor_set_write_image_param(uint32_t *param_desc_map,
|
|
|
|
const struct brw_image_param *param)
|
|
|
|
{
|
|
|
|
#define WRITE_PARAM_FIELD(field, FIELD) \
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(param->field); i++) \
|
|
|
|
param_desc_map[BRW_IMAGE_PARAM_##FIELD##_OFFSET + i] = param->field[i]
|
|
|
|
|
|
|
|
WRITE_PARAM_FIELD(offset, OFFSET);
|
|
|
|
WRITE_PARAM_FIELD(size, SIZE);
|
|
|
|
WRITE_PARAM_FIELD(stride, STRIDE);
|
|
|
|
WRITE_PARAM_FIELD(tiling, TILING);
|
|
|
|
WRITE_PARAM_FIELD(swizzling, SWIZZLING);
|
|
|
|
WRITE_PARAM_FIELD(size, SIZE);
|
|
|
|
|
|
|
|
#undef WRITE_PARAM_FIELD
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:10:33 +00:00
|
|
|
static uint32_t
|
|
|
|
anv_surface_state_to_handle(struct anv_state state)
|
|
|
|
{
|
|
|
|
/* Bits 31:12 of the bindless surface offset in the extended message
|
|
|
|
* descriptor is bits 25:6 of the byte-based address.
|
|
|
|
*/
|
|
|
|
assert(state.offset >= 0);
|
|
|
|
uint32_t offset = state.offset;
|
|
|
|
assert((offset & 0x3f) == 0 && offset < (1 << 26));
|
|
|
|
return offset << 6;
|
|
|
|
}
|
|
|
|
|
2017-01-23 15:33:37 +00:00
|
|
|
void
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_image_view(struct anv_device *device,
|
|
|
|
struct anv_descriptor_set *set,
|
2017-01-31 19:13:44 +00:00
|
|
|
const VkDescriptorImageInfo * const info,
|
2017-01-23 15:33:37 +00:00
|
|
|
VkDescriptorType type,
|
|
|
|
uint32_t binding,
|
|
|
|
uint32_t element)
|
|
|
|
{
|
|
|
|
const struct anv_descriptor_set_binding_layout *bind_layout =
|
|
|
|
&set->layout->binding[binding];
|
|
|
|
struct anv_descriptor *desc =
|
|
|
|
&set->descriptors[bind_layout->descriptor_index + element];
|
|
|
|
struct anv_image_view *image_view = NULL;
|
|
|
|
struct anv_sampler *sampler = NULL;
|
|
|
|
|
2019-02-08 04:34:57 +00:00
|
|
|
/* We get called with just VK_DESCRIPTOR_TYPE_SAMPLER as part of descriptor
|
|
|
|
* set initialization to set the bindless samplers.
|
|
|
|
*/
|
|
|
|
assert(type == bind_layout->type ||
|
2022-01-14 14:02:17 +00:00
|
|
|
type == VK_DESCRIPTOR_TYPE_SAMPLER ||
|
|
|
|
bind_layout->type == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE);
|
2017-01-23 15:33:37 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
2020-04-22 16:47:00 +01:00
|
|
|
sampler = bind_layout->immutable_samplers ?
|
|
|
|
bind_layout->immutable_samplers[element] :
|
|
|
|
anv_sampler_from_handle(info->sampler);
|
2017-01-23 15:33:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
2017-01-31 19:13:44 +00:00
|
|
|
image_view = anv_image_view_from_handle(info->imageView);
|
2020-04-22 16:47:00 +01:00
|
|
|
sampler = bind_layout->immutable_samplers ?
|
|
|
|
bind_layout->immutable_samplers[element] :
|
|
|
|
anv_sampler_from_handle(info->sampler);
|
2017-01-23 15:33:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
2017-01-31 19:13:44 +00:00
|
|
|
image_view = anv_image_view_from_handle(info->imageView);
|
2017-01-23 15:33:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("invalid descriptor type");
|
|
|
|
}
|
|
|
|
|
|
|
|
*desc = (struct anv_descriptor) {
|
|
|
|
.type = type,
|
2017-07-11 16:53:42 +01:00
|
|
|
.layout = info->imageLayout,
|
2017-01-23 15:33:37 +00:00
|
|
|
.image_view = image_view,
|
|
|
|
.sampler = sampler,
|
|
|
|
};
|
2018-11-22 00:26:27 +00:00
|
|
|
|
2022-03-04 10:52:04 +00:00
|
|
|
if (set->pool && set->pool->host_only)
|
2022-01-24 14:54:35 +00:00
|
|
|
return;
|
|
|
|
|
2018-11-22 00:26:27 +00:00
|
|
|
void *desc_map = set->desc_mem.map + bind_layout->descriptor_offset +
|
2022-01-14 14:02:17 +00:00
|
|
|
element * bind_layout->descriptor_stride;
|
|
|
|
memset(desc_map, 0, bind_layout->descriptor_stride);
|
|
|
|
enum anv_descriptor_data data =
|
|
|
|
bind_layout->type == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE ?
|
|
|
|
anv_descriptor_data_for_type(device->physical, type) :
|
|
|
|
bind_layout->data;
|
2018-11-22 00:26:27 +00:00
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
|
|
|
|
if (data & ANV_DESCRIPTOR_SAMPLED_IMAGE) {
|
2019-02-07 20:10:33 +00:00
|
|
|
struct anv_sampled_image_descriptor desc_data[3];
|
|
|
|
memset(desc_data, 0, sizeof(desc_data));
|
|
|
|
|
|
|
|
if (image_view) {
|
|
|
|
for (unsigned p = 0; p < image_view->n_planes; p++) {
|
|
|
|
struct anv_surface_state sstate =
|
|
|
|
(desc->layout == VK_IMAGE_LAYOUT_GENERAL) ?
|
|
|
|
image_view->planes[p].general_sampler_surface_state :
|
|
|
|
image_view->planes[p].optimal_sampler_surface_state;
|
|
|
|
desc_data[p].image = anv_surface_state_to_handle(sstate.state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sampler) {
|
|
|
|
for (unsigned p = 0; p < sampler->n_planes; p++)
|
|
|
|
desc_data[p].sampler = sampler->bindless_state.offset + p * 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We may have max_plane_count < 0 if this isn't a sampled image but it
|
|
|
|
* can be no more than the size of our array of handles.
|
|
|
|
*/
|
|
|
|
assert(bind_layout->max_plane_count <= ARRAY_SIZE(desc_data));
|
|
|
|
memcpy(desc_map, desc_data,
|
|
|
|
MAX2(1, bind_layout->max_plane_count) * sizeof(desc_data[0]));
|
|
|
|
}
|
|
|
|
|
2020-02-07 03:18:59 +00:00
|
|
|
if (image_view == NULL)
|
|
|
|
return;
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_STORAGE_IMAGE) {
|
|
|
|
assert(!(data & ANV_DESCRIPTOR_IMAGE_PARAM));
|
2019-02-12 07:02:28 +00:00
|
|
|
assert(image_view->n_planes == 1);
|
|
|
|
struct anv_storage_image_descriptor desc_data = {
|
2021-10-06 22:37:03 +01:00
|
|
|
.vanilla = anv_surface_state_to_handle(
|
2019-02-12 07:02:28 +00:00
|
|
|
image_view->planes[0].storage_surface_state.state),
|
2021-10-06 22:37:03 +01:00
|
|
|
.lowered = anv_surface_state_to_handle(
|
|
|
|
image_view->planes[0].lowered_storage_surface_state.state),
|
2019-02-12 07:02:28 +00:00
|
|
|
};
|
|
|
|
memcpy(desc_map, &desc_data, sizeof(desc_data));
|
|
|
|
}
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_IMAGE_PARAM) {
|
2018-11-22 00:26:27 +00:00
|
|
|
/* Storage images can only ever have one plane */
|
|
|
|
assert(image_view->n_planes == 1);
|
|
|
|
const struct brw_image_param *image_param =
|
2021-10-06 22:37:03 +01:00
|
|
|
&image_view->planes[0].lowered_storage_image_param;
|
2018-11-22 00:26:27 +00:00
|
|
|
|
|
|
|
anv_descriptor_set_write_image_param(desc_map, image_param);
|
|
|
|
}
|
2019-05-17 16:04:58 +01:00
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_TEXTURE_SWIZZLE) {
|
|
|
|
assert(!(data & ANV_DESCRIPTOR_SAMPLED_IMAGE));
|
2019-05-17 16:04:58 +01:00
|
|
|
assert(image_view);
|
|
|
|
struct anv_texture_swizzle_descriptor desc_data[3];
|
|
|
|
memset(desc_data, 0, sizeof(desc_data));
|
|
|
|
|
|
|
|
for (unsigned p = 0; p < image_view->n_planes; p++) {
|
|
|
|
desc_data[p] = (struct anv_texture_swizzle_descriptor) {
|
|
|
|
.swizzle = {
|
|
|
|
(uint8_t)image_view->planes[p].isl.swizzle.r,
|
|
|
|
(uint8_t)image_view->planes[p].isl.swizzle.g,
|
|
|
|
(uint8_t)image_view->planes[p].isl.swizzle.b,
|
|
|
|
(uint8_t)image_view->planes[p].isl.swizzle.a,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
memcpy(desc_map, desc_data,
|
|
|
|
MAX2(1, bind_layout->max_plane_count) * sizeof(desc_data[0]));
|
|
|
|
}
|
2017-01-23 15:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_buffer_view(struct anv_device *device,
|
|
|
|
struct anv_descriptor_set *set,
|
2017-01-23 15:33:37 +00:00
|
|
|
VkDescriptorType type,
|
|
|
|
struct anv_buffer_view *buffer_view,
|
|
|
|
uint32_t binding,
|
|
|
|
uint32_t element)
|
|
|
|
{
|
|
|
|
const struct anv_descriptor_set_binding_layout *bind_layout =
|
|
|
|
&set->layout->binding[binding];
|
|
|
|
struct anv_descriptor *desc =
|
|
|
|
&set->descriptors[bind_layout->descriptor_index + element];
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
assert(type == bind_layout->type ||
|
|
|
|
bind_layout->type == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE);
|
|
|
|
|
2022-01-24 14:54:35 +00:00
|
|
|
*desc = (struct anv_descriptor) {
|
|
|
|
.type = type,
|
|
|
|
.buffer_view = buffer_view,
|
|
|
|
};
|
|
|
|
|
2022-03-04 10:52:04 +00:00
|
|
|
if (set->pool && set->pool->host_only)
|
2022-01-24 14:54:35 +00:00
|
|
|
return;
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
enum anv_descriptor_data data =
|
|
|
|
bind_layout->type == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE ?
|
|
|
|
anv_descriptor_data_for_type(device->physical, type) :
|
|
|
|
bind_layout->data;
|
2017-01-23 15:33:37 +00:00
|
|
|
|
2020-02-07 03:18:59 +00:00
|
|
|
void *desc_map = set->desc_mem.map + bind_layout->descriptor_offset +
|
2022-01-14 14:02:17 +00:00
|
|
|
element * bind_layout->descriptor_stride;
|
2020-02-07 03:18:59 +00:00
|
|
|
|
|
|
|
if (buffer_view == NULL) {
|
2022-01-14 14:02:17 +00:00
|
|
|
memset(desc_map, 0, bind_layout->descriptor_stride);
|
2020-02-07 03:18:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_SAMPLED_IMAGE) {
|
2019-02-07 20:10:33 +00:00
|
|
|
struct anv_sampled_image_descriptor desc_data = {
|
|
|
|
.image = anv_surface_state_to_handle(buffer_view->surface_state),
|
|
|
|
};
|
|
|
|
memcpy(desc_map, &desc_data, sizeof(desc_data));
|
|
|
|
}
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_STORAGE_IMAGE) {
|
|
|
|
assert(!(data & ANV_DESCRIPTOR_IMAGE_PARAM));
|
2019-02-12 07:02:28 +00:00
|
|
|
struct anv_storage_image_descriptor desc_data = {
|
2021-10-06 22:37:03 +01:00
|
|
|
.vanilla = anv_surface_state_to_handle(
|
2019-02-12 07:02:28 +00:00
|
|
|
buffer_view->storage_surface_state),
|
2021-10-06 22:37:03 +01:00
|
|
|
.lowered = anv_surface_state_to_handle(
|
|
|
|
buffer_view->lowered_storage_surface_state),
|
2019-02-12 07:02:28 +00:00
|
|
|
};
|
|
|
|
memcpy(desc_map, &desc_data, sizeof(desc_data));
|
|
|
|
}
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_IMAGE_PARAM) {
|
2018-11-22 00:26:27 +00:00
|
|
|
anv_descriptor_set_write_image_param(desc_map,
|
2021-10-06 22:37:03 +01:00
|
|
|
&buffer_view->lowered_storage_image_param);
|
2018-11-22 00:26:27 +00:00
|
|
|
}
|
2017-01-23 15:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_buffer(struct anv_device *device,
|
|
|
|
struct anv_descriptor_set *set,
|
2017-01-17 17:43:08 +00:00
|
|
|
struct anv_state_stream *alloc_stream,
|
2017-01-23 15:33:37 +00:00
|
|
|
VkDescriptorType type,
|
|
|
|
struct anv_buffer *buffer,
|
|
|
|
uint32_t binding,
|
|
|
|
uint32_t element,
|
|
|
|
VkDeviceSize offset,
|
|
|
|
VkDeviceSize range)
|
|
|
|
{
|
2022-01-24 14:54:35 +00:00
|
|
|
assert(alloc_stream || set->pool);
|
|
|
|
|
2017-01-23 15:33:37 +00:00
|
|
|
const struct anv_descriptor_set_binding_layout *bind_layout =
|
|
|
|
&set->layout->binding[binding];
|
|
|
|
struct anv_descriptor *desc =
|
|
|
|
&set->descriptors[bind_layout->descriptor_index + element];
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
assert(type == bind_layout->type ||
|
|
|
|
bind_layout->type == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE);
|
2017-01-23 15:33:37 +00:00
|
|
|
|
2022-02-08 11:43:05 +00:00
|
|
|
*desc = (struct anv_descriptor) {
|
|
|
|
.type = type,
|
|
|
|
.offset = offset,
|
|
|
|
.range = range,
|
|
|
|
.buffer = buffer,
|
|
|
|
};
|
|
|
|
|
2022-03-04 10:52:04 +00:00
|
|
|
if (set->pool && set->pool->host_only)
|
2022-01-24 14:54:35 +00:00
|
|
|
return;
|
|
|
|
|
2020-02-07 03:18:59 +00:00
|
|
|
void *desc_map = set->desc_mem.map + bind_layout->descriptor_offset +
|
2022-01-14 14:02:17 +00:00
|
|
|
element * bind_layout->descriptor_stride;
|
2020-02-07 03:18:59 +00:00
|
|
|
|
|
|
|
if (buffer == NULL) {
|
2022-01-14 14:02:17 +00:00
|
|
|
memset(desc_map, 0, bind_layout->descriptor_stride);
|
2020-02-07 03:18:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:04:22 +00:00
|
|
|
struct anv_address bind_addr = anv_address_add(buffer->address, offset);
|
|
|
|
uint64_t bind_range = anv_buffer_get_range(buffer, offset, range);
|
2022-01-14 14:02:17 +00:00
|
|
|
enum anv_descriptor_data data =
|
|
|
|
bind_layout->type == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE ?
|
|
|
|
anv_descriptor_data_for_type(device->physical, type) :
|
|
|
|
bind_layout->data;
|
2019-01-09 22:04:22 +00:00
|
|
|
|
2020-02-11 16:12:06 +00:00
|
|
|
/* We report a bounds checking alignment of 32B for the sake of block
|
|
|
|
* messages which read an entire register worth at a time.
|
|
|
|
*/
|
|
|
|
if (type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ||
|
|
|
|
type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)
|
2020-05-07 10:25:50 +01:00
|
|
|
bind_range = align_u64(bind_range, ANV_UBO_ALIGNMENT);
|
2020-02-11 16:12:06 +00:00
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
if (data & ANV_DESCRIPTOR_ADDRESS_RANGE) {
|
2020-01-29 04:25:48 +00:00
|
|
|
struct anv_address_range_descriptor desc_data = {
|
2019-01-09 22:04:22 +00:00
|
|
|
.address = anv_address_physical(bind_addr),
|
|
|
|
.range = bind_range,
|
|
|
|
};
|
2020-01-29 04:25:48 +00:00
|
|
|
memcpy(desc_map, &desc_data, sizeof(desc_data));
|
2019-01-09 22:04:22 +00:00
|
|
|
}
|
2022-02-08 11:43:05 +00:00
|
|
|
|
|
|
|
if (type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
|
|
|
|
type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(data & ANV_DESCRIPTOR_BUFFER_VIEW);
|
|
|
|
struct anv_buffer_view *bview =
|
|
|
|
&set->buffer_views[bind_layout->buffer_view_index + element];
|
|
|
|
|
|
|
|
bview->format = anv_isl_format_for_descriptor_type(device, type);
|
|
|
|
bview->range = bind_range;
|
|
|
|
bview->address = bind_addr;
|
|
|
|
|
|
|
|
/* If we're writing descriptors through a push command, we need to
|
|
|
|
* allocate the surface state from the command buffer. Otherwise it will
|
|
|
|
* be allocated by the descriptor pool when calling
|
|
|
|
* vkAllocateDescriptorSets. */
|
2022-01-24 14:54:35 +00:00
|
|
|
if (alloc_stream) {
|
2022-02-08 11:43:05 +00:00
|
|
|
bview->surface_state = anv_state_stream_alloc(alloc_stream, 64, 64);
|
2022-01-24 14:54:35 +00:00
|
|
|
}
|
2022-02-08 11:43:05 +00:00
|
|
|
|
2022-03-08 14:56:50 +00:00
|
|
|
assert(bview->surface_state.alloc_size);
|
|
|
|
|
2022-02-08 11:43:05 +00:00
|
|
|
isl_surf_usage_flags_t usage =
|
|
|
|
(type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ||
|
|
|
|
type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ?
|
|
|
|
ISL_SURF_USAGE_CONSTANT_BUFFER_BIT :
|
|
|
|
ISL_SURF_USAGE_STORAGE_BIT;
|
|
|
|
|
|
|
|
anv_fill_buffer_surface_state(device, bview->surface_state,
|
|
|
|
bview->format, usage,
|
|
|
|
bind_addr, bind_range, 1);
|
|
|
|
desc->set_buffer_view = bview;
|
2017-01-23 15:33:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-12 22:56:24 +00:00
|
|
|
void
|
|
|
|
anv_descriptor_set_write_inline_uniform_data(struct anv_device *device,
|
|
|
|
struct anv_descriptor_set *set,
|
|
|
|
uint32_t binding,
|
|
|
|
const void *data,
|
|
|
|
size_t offset,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
const struct anv_descriptor_set_binding_layout *bind_layout =
|
|
|
|
&set->layout->binding[binding];
|
|
|
|
|
|
|
|
assert(bind_layout->data & ANV_DESCRIPTOR_INLINE_UNIFORM);
|
|
|
|
|
|
|
|
void *desc_map = set->desc_mem.map + bind_layout->descriptor_offset;
|
|
|
|
|
|
|
|
memcpy(desc_map + offset, data, size);
|
|
|
|
}
|
|
|
|
|
2020-08-05 23:28:48 +01:00
|
|
|
void
|
|
|
|
anv_descriptor_set_write_acceleration_structure(struct anv_device *device,
|
|
|
|
struct anv_descriptor_set *set,
|
|
|
|
struct anv_acceleration_structure *accel,
|
|
|
|
uint32_t binding,
|
|
|
|
uint32_t element)
|
|
|
|
{
|
|
|
|
const struct anv_descriptor_set_binding_layout *bind_layout =
|
|
|
|
&set->layout->binding[binding];
|
|
|
|
struct anv_descriptor *desc =
|
|
|
|
&set->descriptors[bind_layout->descriptor_index + element];
|
|
|
|
|
2022-01-14 14:02:17 +00:00
|
|
|
assert(bind_layout->data & ANV_DESCRIPTOR_ADDRESS_RANGE);
|
2020-08-05 23:28:48 +01:00
|
|
|
*desc = (struct anv_descriptor) {
|
|
|
|
.type = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR,
|
2022-03-07 08:29:19 +00:00
|
|
|
.accel_struct = accel,
|
2020-08-05 23:28:48 +01:00
|
|
|
};
|
|
|
|
|
2022-03-04 10:52:04 +00:00
|
|
|
if (set->pool && set->pool->host_only)
|
2022-03-07 08:29:19 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-05 23:28:48 +01:00
|
|
|
struct anv_address_range_descriptor desc_data = { };
|
|
|
|
if (accel != NULL) {
|
|
|
|
desc_data.address = anv_address_physical(accel->address);
|
|
|
|
desc_data.range = accel->size;
|
|
|
|
}
|
2022-01-14 14:02:17 +00:00
|
|
|
assert(sizeof(desc_data) <= bind_layout->descriptor_stride);
|
2020-08-05 23:28:48 +01:00
|
|
|
|
|
|
|
void *desc_map = set->desc_mem.map + bind_layout->descriptor_offset +
|
2022-01-14 14:02:17 +00:00
|
|
|
element * bind_layout->descriptor_stride;
|
2020-08-05 23:28:48 +01:00
|
|
|
memcpy(desc_map, &desc_data, sizeof(desc_data));
|
|
|
|
}
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
void anv_UpdateDescriptorSets(
|
2015-12-21 08:03:28 +00:00
|
|
|
VkDevice _device,
|
2015-12-01 20:05:21 +00:00
|
|
|
uint32_t descriptorWriteCount,
|
2015-11-18 22:58:40 +00:00
|
|
|
const VkWriteDescriptorSet* pDescriptorWrites,
|
2015-12-01 20:05:21 +00:00
|
|
|
uint32_t descriptorCopyCount,
|
2015-11-18 22:58:40 +00:00
|
|
|
const VkCopyDescriptorSet* pDescriptorCopies)
|
|
|
|
{
|
2015-12-21 08:03:28 +00:00
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
for (uint32_t i = 0; i < descriptorWriteCount; i++) {
|
2015-11-18 22:58:40 +00:00
|
|
|
const VkWriteDescriptorSet *write = &pDescriptorWrites[i];
|
2015-12-01 20:05:21 +00:00
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set, set, write->dstSet);
|
2016-06-06 17:12:50 +01:00
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
switch (write->descriptorType) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
2016-11-15 23:25:55 +00:00
|
|
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
2015-12-01 20:05:21 +00:00
|
|
|
for (uint32_t j = 0; j < write->descriptorCount; j++) {
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_image_view(device, set,
|
2017-01-31 19:13:44 +00:00
|
|
|
write->pImageInfo + j,
|
2017-01-23 15:33:37 +00:00
|
|
|
write->descriptorType,
|
|
|
|
write->dstBinding,
|
|
|
|
write->dstArrayElement + j);
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
2015-12-13 00:11:23 +00:00
|
|
|
for (uint32_t j = 0; j < write->descriptorCount; j++) {
|
|
|
|
ANV_FROM_HANDLE(anv_buffer_view, bview,
|
|
|
|
write->pTexelBufferView[j]);
|
|
|
|
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_buffer_view(device, set,
|
2017-01-23 15:33:37 +00:00
|
|
|
write->descriptorType,
|
|
|
|
bview,
|
|
|
|
write->dstBinding,
|
|
|
|
write->dstArrayElement + j);
|
2015-12-13 00:11:23 +00:00
|
|
|
}
|
2015-11-18 22:58:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
2015-12-01 20:05:21 +00:00
|
|
|
for (uint32_t j = 0; j < write->descriptorCount; j++) {
|
|
|
|
ANV_FROM_HANDLE(anv_buffer, buffer, write->pBufferInfo[j].buffer);
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_buffer(device, set,
|
2017-01-17 17:43:08 +00:00
|
|
|
NULL,
|
2017-01-23 15:33:37 +00:00
|
|
|
write->descriptorType,
|
|
|
|
buffer,
|
|
|
|
write->dstBinding,
|
|
|
|
write->dstArrayElement + j,
|
|
|
|
write->pBufferInfo[j].offset,
|
|
|
|
write->pBufferInfo[j].range);
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
2017-01-23 15:33:37 +00:00
|
|
|
break;
|
2015-11-18 22:58:40 +00:00
|
|
|
|
2019-02-12 22:56:24 +00:00
|
|
|
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: {
|
2021-09-03 09:39:50 +01:00
|
|
|
const VkWriteDescriptorSetInlineUniformBlock *inline_write =
|
2019-02-12 22:56:24 +00:00
|
|
|
vk_find_struct_const(write->pNext,
|
2021-09-03 09:39:50 +01:00
|
|
|
WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK);
|
2019-02-12 22:56:24 +00:00
|
|
|
assert(inline_write->dataSize == write->descriptorCount);
|
|
|
|
anv_descriptor_set_write_inline_uniform_data(device, set,
|
|
|
|
write->dstBinding,
|
|
|
|
inline_write->pData,
|
|
|
|
write->dstArrayElement,
|
|
|
|
inline_write->dataSize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-08-05 23:28:48 +01:00
|
|
|
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: {
|
|
|
|
const VkWriteDescriptorSetAccelerationStructureKHR *accel_write =
|
|
|
|
vk_find_struct_const(write, WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR);
|
|
|
|
assert(accel_write->accelerationStructureCount ==
|
|
|
|
write->descriptorCount);
|
|
|
|
for (uint32_t j = 0; j < write->descriptorCount; j++) {
|
|
|
|
ANV_FROM_HANDLE(anv_acceleration_structure, accel,
|
|
|
|
accel_write->pAccelerationStructures[j]);
|
|
|
|
anv_descriptor_set_write_acceleration_structure(device, set, accel,
|
|
|
|
write->dstBinding,
|
|
|
|
write->dstArrayElement + j);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-18 22:58:40 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-01 20:05:21 +00:00
|
|
|
for (uint32_t i = 0; i < descriptorCopyCount; i++) {
|
2015-11-18 22:58:40 +00:00
|
|
|
const VkCopyDescriptorSet *copy = &pDescriptorCopies[i];
|
2017-09-16 13:23:43 +01:00
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set, src, copy->srcSet);
|
2016-02-03 10:50:06 +00:00
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set, dst, copy->dstSet);
|
|
|
|
|
|
|
|
const struct anv_descriptor_set_binding_layout *src_layout =
|
|
|
|
&src->layout->binding[copy->srcBinding];
|
|
|
|
struct anv_descriptor *src_desc =
|
|
|
|
&src->descriptors[src_layout->descriptor_index];
|
|
|
|
src_desc += copy->srcArrayElement;
|
|
|
|
|
|
|
|
const struct anv_descriptor_set_binding_layout *dst_layout =
|
|
|
|
&dst->layout->binding[copy->dstBinding];
|
|
|
|
struct anv_descriptor *dst_desc =
|
|
|
|
&dst->descriptors[dst_layout->descriptor_index];
|
|
|
|
dst_desc += copy->dstArrayElement;
|
|
|
|
|
2022-02-08 11:43:05 +00:00
|
|
|
if (src_layout->type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK) {
|
|
|
|
anv_descriptor_set_write_inline_uniform_data(device, dst,
|
|
|
|
copy->dstBinding,
|
|
|
|
src->desc_mem.map + src_layout->descriptor_offset + copy->srcArrayElement,
|
|
|
|
copy->dstArrayElement,
|
|
|
|
copy->descriptorCount);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy CPU side data */
|
|
|
|
for (uint32_t j = 0; j < copy->descriptorCount; j++) {
|
|
|
|
switch(src_desc[j].type) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: {
|
|
|
|
VkDescriptorImageInfo info = {
|
|
|
|
.sampler = anv_sampler_to_handle(src_desc[j].sampler),
|
|
|
|
.imageView = anv_image_view_to_handle(src_desc[j].image_view),
|
|
|
|
.imageLayout = src_desc[j].layout
|
|
|
|
};
|
|
|
|
anv_descriptor_set_write_image_view(device, dst,
|
|
|
|
&info,
|
|
|
|
src_desc[j].type,
|
|
|
|
copy->dstBinding,
|
|
|
|
copy->dstArrayElement + j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: {
|
|
|
|
anv_descriptor_set_write_buffer_view(device, dst,
|
|
|
|
src_desc[j].type,
|
|
|
|
src_desc[j].buffer_view,
|
|
|
|
copy->dstBinding,
|
|
|
|
copy->dstArrayElement + j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
|
|
|
|
anv_descriptor_set_write_buffer(device, dst,
|
|
|
|
NULL,
|
|
|
|
src_desc[j].type,
|
|
|
|
src_desc[j].buffer,
|
|
|
|
copy->dstBinding,
|
|
|
|
copy->dstArrayElement + j,
|
|
|
|
src_desc[j].offset,
|
|
|
|
src_desc[j].range);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: {
|
|
|
|
anv_descriptor_set_write_acceleration_structure(device, dst,
|
2022-03-07 08:29:19 +00:00
|
|
|
src_desc[j].accel_struct,
|
2022-02-08 11:43:05 +00:00
|
|
|
copy->dstBinding,
|
|
|
|
copy->dstArrayElement + j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-11-19 20:28:39 +00:00
|
|
|
}
|
2015-11-18 22:58:40 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-17 16:38:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Descriptor update templates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_template(struct anv_device *device,
|
|
|
|
struct anv_descriptor_set *set,
|
2017-01-17 16:38:01 +00:00
|
|
|
struct anv_state_stream *alloc_stream,
|
|
|
|
const struct anv_descriptor_update_template *template,
|
|
|
|
const void *data)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < template->entry_count; i++) {
|
|
|
|
const struct anv_descriptor_template_entry *entry =
|
|
|
|
&template->entries[i];
|
|
|
|
|
|
|
|
switch (entry->type) {
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
|
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
|
|
|
for (uint32_t j = 0; j < entry->array_count; j++) {
|
|
|
|
const VkDescriptorImageInfo *info =
|
|
|
|
data + entry->offset + j * entry->stride;
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_image_view(device, set,
|
2017-01-31 19:13:44 +00:00
|
|
|
info, entry->type,
|
2017-01-17 16:38:01 +00:00
|
|
|
entry->binding,
|
|
|
|
entry->array_element + j);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
|
|
|
for (uint32_t j = 0; j < entry->array_count; j++) {
|
|
|
|
const VkBufferView *_bview =
|
|
|
|
data + entry->offset + j * entry->stride;
|
|
|
|
ANV_FROM_HANDLE(anv_buffer_view, bview, *_bview);
|
|
|
|
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_buffer_view(device, set,
|
2017-01-17 16:38:01 +00:00
|
|
|
entry->type,
|
|
|
|
bview,
|
|
|
|
entry->binding,
|
|
|
|
entry->array_element + j);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
|
|
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
|
|
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
|
|
|
for (uint32_t j = 0; j < entry->array_count; j++) {
|
|
|
|
const VkDescriptorBufferInfo *info =
|
|
|
|
data + entry->offset + j * entry->stride;
|
|
|
|
ANV_FROM_HANDLE(anv_buffer, buffer, info->buffer);
|
|
|
|
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_buffer(device, set,
|
2017-01-17 16:38:01 +00:00
|
|
|
alloc_stream,
|
|
|
|
entry->type,
|
|
|
|
buffer,
|
|
|
|
entry->binding,
|
|
|
|
entry->array_element + j,
|
|
|
|
info->offset, info->range);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-02-12 22:56:24 +00:00
|
|
|
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
|
|
|
|
anv_descriptor_set_write_inline_uniform_data(device, set,
|
|
|
|
entry->binding,
|
|
|
|
data + entry->offset,
|
|
|
|
entry->array_element,
|
|
|
|
entry->array_count);
|
|
|
|
break;
|
|
|
|
|
2017-01-17 16:38:01 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-20 20:18:10 +01:00
|
|
|
VkResult anv_CreateDescriptorUpdateTemplate(
|
2017-01-17 16:38:01 +00:00
|
|
|
VkDevice _device,
|
2017-09-20 21:16:26 +01:00
|
|
|
const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo,
|
2017-01-17 16:38:01 +00:00
|
|
|
const VkAllocationCallbacks* pAllocator,
|
2017-09-20 21:16:26 +01:00
|
|
|
VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate)
|
2017-01-17 16:38:01 +00:00
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
struct anv_descriptor_update_template *template;
|
|
|
|
|
|
|
|
size_t size = sizeof(*template) +
|
|
|
|
pCreateInfo->descriptorUpdateEntryCount * sizeof(template->entries[0]);
|
2021-04-08 22:12:27 +01:00
|
|
|
template = vk_object_alloc(&device->vk, pAllocator, size,
|
|
|
|
VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE);
|
2017-01-17 16:38:01 +00:00
|
|
|
if (template == NULL)
|
2021-09-24 18:06:32 +01:00
|
|
|
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
2017-01-17 16:38:01 +00:00
|
|
|
|
2017-12-15 22:02:27 +00:00
|
|
|
template->bind_point = pCreateInfo->pipelineBindPoint;
|
|
|
|
|
2017-09-20 21:16:26 +01:00
|
|
|
if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET)
|
2017-01-17 16:38:01 +00:00
|
|
|
template->set = pCreateInfo->set;
|
|
|
|
|
|
|
|
template->entry_count = pCreateInfo->descriptorUpdateEntryCount;
|
|
|
|
for (uint32_t i = 0; i < template->entry_count; i++) {
|
2019-01-08 18:04:54 +00:00
|
|
|
const VkDescriptorUpdateTemplateEntry *pEntry =
|
2017-01-17 16:38:01 +00:00
|
|
|
&pCreateInfo->pDescriptorUpdateEntries[i];
|
|
|
|
|
|
|
|
template->entries[i] = (struct anv_descriptor_template_entry) {
|
|
|
|
.type = pEntry->descriptorType,
|
|
|
|
.binding = pEntry->dstBinding,
|
|
|
|
.array_element = pEntry->dstArrayElement,
|
|
|
|
.array_count = pEntry->descriptorCount,
|
|
|
|
.offset = pEntry->offset,
|
|
|
|
.stride = pEntry->stride,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
*pDescriptorUpdateTemplate =
|
|
|
|
anv_descriptor_update_template_to_handle(template);
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-09-20 20:18:10 +01:00
|
|
|
void anv_DestroyDescriptorUpdateTemplate(
|
2017-01-17 16:38:01 +00:00
|
|
|
VkDevice _device,
|
2017-09-20 21:16:26 +01:00
|
|
|
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
|
2017-01-17 16:38:01 +00:00
|
|
|
const VkAllocationCallbacks* pAllocator)
|
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_update_template, template,
|
|
|
|
descriptorUpdateTemplate);
|
|
|
|
|
2021-02-12 07:36:58 +00:00
|
|
|
if (!template)
|
|
|
|
return;
|
|
|
|
|
2021-04-08 22:12:27 +01:00
|
|
|
vk_object_free(&device->vk, pAllocator, template);
|
2017-01-17 16:38:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 20:18:10 +01:00
|
|
|
void anv_UpdateDescriptorSetWithTemplate(
|
2017-01-17 16:38:01 +00:00
|
|
|
VkDevice _device,
|
|
|
|
VkDescriptorSet descriptorSet,
|
2017-09-20 21:16:26 +01:00
|
|
|
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
|
2017-01-17 16:38:01 +00:00
|
|
|
const void* pData)
|
|
|
|
{
|
|
|
|
ANV_FROM_HANDLE(anv_device, device, _device);
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_set, set, descriptorSet);
|
|
|
|
ANV_FROM_HANDLE(anv_descriptor_update_template, template,
|
|
|
|
descriptorUpdateTemplate);
|
|
|
|
|
2018-11-22 00:00:56 +00:00
|
|
|
anv_descriptor_set_write_template(device, set, NULL, template, pData);
|
2017-01-17 16:38:01 +00:00
|
|
|
}
|