panvk: Move CreateDescriptorSetLayout to per-arch
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16276>
This commit is contained in:
parent
ad565f6b70
commit
8af805a475
|
@ -38,144 +38,6 @@
|
||||||
|
|
||||||
#include "pan_bo.h"
|
#include "pan_bo.h"
|
||||||
|
|
||||||
VkResult
|
|
||||||
panvk_CreateDescriptorSetLayout(VkDevice _device,
|
|
||||||
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
|
|
||||||
const VkAllocationCallbacks *pAllocator,
|
|
||||||
VkDescriptorSetLayout *pSetLayout)
|
|
||||||
{
|
|
||||||
VK_FROM_HANDLE(panvk_device, device, _device);
|
|
||||||
struct panvk_descriptor_set_layout *set_layout;
|
|
||||||
VkDescriptorSetLayoutBinding *bindings = NULL;
|
|
||||||
unsigned num_bindings = 0;
|
|
||||||
VkResult result;
|
|
||||||
|
|
||||||
if (pCreateInfo->bindingCount) {
|
|
||||||
result =
|
|
||||||
vk_create_sorted_bindings(pCreateInfo->pBindings,
|
|
||||||
pCreateInfo->bindingCount,
|
|
||||||
&bindings);
|
|
||||||
if (result != VK_SUCCESS)
|
|
||||||
return vk_error(device, result);
|
|
||||||
|
|
||||||
num_bindings = bindings[pCreateInfo->bindingCount - 1].binding + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned num_immutable_samplers = 0;
|
|
||||||
for (unsigned i = 0; i < pCreateInfo->bindingCount; i++) {
|
|
||||||
if (bindings[i].pImmutableSamplers)
|
|
||||||
num_immutable_samplers += bindings[i].descriptorCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = sizeof(*set_layout) +
|
|
||||||
(sizeof(struct panvk_descriptor_set_binding_layout) *
|
|
||||||
num_bindings) +
|
|
||||||
(sizeof(struct panvk_sampler *) * num_immutable_samplers);
|
|
||||||
set_layout = vk_object_zalloc(&device->vk, NULL, size,
|
|
||||||
VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);
|
|
||||||
if (!set_layout) {
|
|
||||||
result = VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
||||||
goto err_free_bindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct panvk_sampler **immutable_samplers =
|
|
||||||
(struct panvk_sampler **)((uint8_t *)set_layout + sizeof(*set_layout) +
|
|
||||||
(sizeof(struct panvk_descriptor_set_binding_layout) *
|
|
||||||
num_bindings));
|
|
||||||
|
|
||||||
set_layout->flags = pCreateInfo->flags;
|
|
||||||
set_layout->binding_count = num_bindings;
|
|
||||||
|
|
||||||
unsigned sampler_idx = 0, tex_idx = 0, ubo_idx = 0, ssbo_idx = 0;
|
|
||||||
unsigned dyn_ubo_idx = 0, dyn_ssbo_idx = 0, desc_idx = 0, img_idx = 0;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < pCreateInfo->bindingCount; i++) {
|
|
||||||
const VkDescriptorSetLayoutBinding *binding = &bindings[i];
|
|
||||||
struct panvk_descriptor_set_binding_layout *binding_layout =
|
|
||||||
&set_layout->bindings[binding->binding];
|
|
||||||
|
|
||||||
binding_layout->type = binding->descriptorType;
|
|
||||||
binding_layout->array_size = binding->descriptorCount;
|
|
||||||
binding_layout->shader_stages = binding->stageFlags;
|
|
||||||
if (binding->pImmutableSamplers) {
|
|
||||||
binding_layout->immutable_samplers = immutable_samplers;
|
|
||||||
immutable_samplers += binding_layout->array_size;
|
|
||||||
for (unsigned j = 0; j < binding_layout->array_size; j++) {
|
|
||||||
VK_FROM_HANDLE(panvk_sampler, sampler, binding->pImmutableSamplers[j]);
|
|
||||||
binding_layout->immutable_samplers[j] = sampler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
binding_layout->desc_idx = desc_idx;
|
|
||||||
desc_idx += binding->descriptorCount;
|
|
||||||
switch (binding_layout->type) {
|
|
||||||
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
|
||||||
binding_layout->sampler_idx = sampler_idx;
|
|
||||||
sampler_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
|
||||||
binding_layout->sampler_idx = sampler_idx;
|
|
||||||
binding_layout->tex_idx = tex_idx;
|
|
||||||
sampler_idx += binding_layout->array_size;
|
|
||||||
tex_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
||||||
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
|
||||||
binding_layout->tex_idx = tex_idx;
|
|
||||||
tex_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
||||||
binding_layout->tex_idx = tex_idx;
|
|
||||||
tex_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
|
||||||
binding_layout->dyn_ubo_idx = dyn_ubo_idx;
|
|
||||||
dyn_ubo_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
||||||
binding_layout->ubo_idx = ubo_idx;
|
|
||||||
ubo_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
|
||||||
binding_layout->dyn_ssbo_idx = dyn_ssbo_idx;
|
|
||||||
dyn_ssbo_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
|
||||||
binding_layout->ssbo_idx = ssbo_idx;
|
|
||||||
ssbo_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
||||||
binding_layout->img_idx = img_idx;
|
|
||||||
img_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
|
||||||
binding_layout->img_idx = img_idx;
|
|
||||||
img_idx += binding_layout->array_size;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
unreachable("Invalid descriptor type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set_layout->num_descs = desc_idx;
|
|
||||||
set_layout->num_samplers = sampler_idx;
|
|
||||||
set_layout->num_textures = tex_idx;
|
|
||||||
set_layout->num_ubos = ubo_idx;
|
|
||||||
set_layout->num_dyn_ubos = dyn_ubo_idx;
|
|
||||||
set_layout->num_ssbos = ssbo_idx;
|
|
||||||
set_layout->num_dyn_ssbos = dyn_ssbo_idx;
|
|
||||||
set_layout->num_imgs = img_idx;
|
|
||||||
p_atomic_set(&set_layout->refcount, 1);
|
|
||||||
|
|
||||||
free(bindings);
|
|
||||||
*pSetLayout = panvk_descriptor_set_layout_to_handle(set_layout);
|
|
||||||
return VK_SUCCESS;
|
|
||||||
|
|
||||||
err_free_bindings:
|
|
||||||
free(bindings);
|
|
||||||
return vk_error(device, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
panvk_descriptor_set_layout_destroy(struct panvk_device *device,
|
panvk_descriptor_set_layout_destroy(struct panvk_device *device,
|
||||||
struct panvk_descriptor_set_layout *layout)
|
struct panvk_descriptor_set_layout *layout)
|
||||||
|
|
|
@ -42,6 +42,144 @@
|
||||||
#include "pan_bo.h"
|
#include "pan_bo.h"
|
||||||
#include "panvk_cs.h"
|
#include "panvk_cs.h"
|
||||||
|
|
||||||
|
VkResult
|
||||||
|
panvk_per_arch(CreateDescriptorSetLayout)(VkDevice _device,
|
||||||
|
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
|
||||||
|
const VkAllocationCallbacks *pAllocator,
|
||||||
|
VkDescriptorSetLayout *pSetLayout)
|
||||||
|
{
|
||||||
|
VK_FROM_HANDLE(panvk_device, device, _device);
|
||||||
|
struct panvk_descriptor_set_layout *set_layout;
|
||||||
|
VkDescriptorSetLayoutBinding *bindings = NULL;
|
||||||
|
unsigned num_bindings = 0;
|
||||||
|
VkResult result;
|
||||||
|
|
||||||
|
if (pCreateInfo->bindingCount) {
|
||||||
|
result =
|
||||||
|
vk_create_sorted_bindings(pCreateInfo->pBindings,
|
||||||
|
pCreateInfo->bindingCount,
|
||||||
|
&bindings);
|
||||||
|
if (result != VK_SUCCESS)
|
||||||
|
return vk_error(device, result);
|
||||||
|
|
||||||
|
num_bindings = bindings[pCreateInfo->bindingCount - 1].binding + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned num_immutable_samplers = 0;
|
||||||
|
for (unsigned i = 0; i < pCreateInfo->bindingCount; i++) {
|
||||||
|
if (bindings[i].pImmutableSamplers)
|
||||||
|
num_immutable_samplers += bindings[i].descriptorCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = sizeof(*set_layout) +
|
||||||
|
(sizeof(struct panvk_descriptor_set_binding_layout) *
|
||||||
|
num_bindings) +
|
||||||
|
(sizeof(struct panvk_sampler *) * num_immutable_samplers);
|
||||||
|
set_layout = vk_object_zalloc(&device->vk, NULL, size,
|
||||||
|
VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);
|
||||||
|
if (!set_layout) {
|
||||||
|
result = VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||||
|
goto err_free_bindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct panvk_sampler **immutable_samplers =
|
||||||
|
(struct panvk_sampler **)((uint8_t *)set_layout + sizeof(*set_layout) +
|
||||||
|
(sizeof(struct panvk_descriptor_set_binding_layout) *
|
||||||
|
num_bindings));
|
||||||
|
|
||||||
|
set_layout->flags = pCreateInfo->flags;
|
||||||
|
set_layout->binding_count = num_bindings;
|
||||||
|
|
||||||
|
unsigned sampler_idx = 0, tex_idx = 0, ubo_idx = 0, ssbo_idx = 0;
|
||||||
|
unsigned dyn_ubo_idx = 0, dyn_ssbo_idx = 0, desc_idx = 0, img_idx = 0;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < pCreateInfo->bindingCount; i++) {
|
||||||
|
const VkDescriptorSetLayoutBinding *binding = &bindings[i];
|
||||||
|
struct panvk_descriptor_set_binding_layout *binding_layout =
|
||||||
|
&set_layout->bindings[binding->binding];
|
||||||
|
|
||||||
|
binding_layout->type = binding->descriptorType;
|
||||||
|
binding_layout->array_size = binding->descriptorCount;
|
||||||
|
binding_layout->shader_stages = binding->stageFlags;
|
||||||
|
if (binding->pImmutableSamplers) {
|
||||||
|
binding_layout->immutable_samplers = immutable_samplers;
|
||||||
|
immutable_samplers += binding_layout->array_size;
|
||||||
|
for (unsigned j = 0; j < binding_layout->array_size; j++) {
|
||||||
|
VK_FROM_HANDLE(panvk_sampler, sampler, binding->pImmutableSamplers[j]);
|
||||||
|
binding_layout->immutable_samplers[j] = sampler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
binding_layout->desc_idx = desc_idx;
|
||||||
|
desc_idx += binding->descriptorCount;
|
||||||
|
switch (binding_layout->type) {
|
||||||
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
||||||
|
binding_layout->sampler_idx = sampler_idx;
|
||||||
|
sampler_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
||||||
|
binding_layout->sampler_idx = sampler_idx;
|
||||||
|
binding_layout->tex_idx = tex_idx;
|
||||||
|
sampler_idx += binding_layout->array_size;
|
||||||
|
tex_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
||||||
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
||||||
|
binding_layout->tex_idx = tex_idx;
|
||||||
|
tex_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
||||||
|
binding_layout->tex_idx = tex_idx;
|
||||||
|
tex_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
||||||
|
binding_layout->dyn_ubo_idx = dyn_ubo_idx;
|
||||||
|
dyn_ubo_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
||||||
|
binding_layout->ubo_idx = ubo_idx;
|
||||||
|
ubo_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
||||||
|
binding_layout->dyn_ssbo_idx = dyn_ssbo_idx;
|
||||||
|
dyn_ssbo_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
||||||
|
binding_layout->ssbo_idx = ssbo_idx;
|
||||||
|
ssbo_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
||||||
|
binding_layout->img_idx = img_idx;
|
||||||
|
img_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
||||||
|
binding_layout->img_idx = img_idx;
|
||||||
|
img_idx += binding_layout->array_size;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
unreachable("Invalid descriptor type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set_layout->num_descs = desc_idx;
|
||||||
|
set_layout->num_samplers = sampler_idx;
|
||||||
|
set_layout->num_textures = tex_idx;
|
||||||
|
set_layout->num_ubos = ubo_idx;
|
||||||
|
set_layout->num_dyn_ubos = dyn_ubo_idx;
|
||||||
|
set_layout->num_ssbos = ssbo_idx;
|
||||||
|
set_layout->num_dyn_ssbos = dyn_ssbo_idx;
|
||||||
|
set_layout->num_imgs = img_idx;
|
||||||
|
p_atomic_set(&set_layout->refcount, 1);
|
||||||
|
|
||||||
|
free(bindings);
|
||||||
|
*pSetLayout = panvk_descriptor_set_layout_to_handle(set_layout);
|
||||||
|
return VK_SUCCESS;
|
||||||
|
|
||||||
|
err_free_bindings:
|
||||||
|
free(bindings);
|
||||||
|
return vk_error(device, result);
|
||||||
|
}
|
||||||
|
|
||||||
static VkResult
|
static VkResult
|
||||||
panvk_per_arch(descriptor_set_create)(struct panvk_device *device,
|
panvk_per_arch(descriptor_set_create)(struct panvk_device *device,
|
||||||
struct panvk_descriptor_pool *pool,
|
struct panvk_descriptor_pool *pool,
|
||||||
|
|
Loading…
Reference in New Issue