2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include "util/mesa-sha1.h"
31 #include "radv_private.h"
36 static bool has_equal_immutable_samplers(const VkSampler
*samplers
, uint32_t count
)
40 for(uint32_t i
= 1; i
< count
; ++i
) {
41 if (memcmp(radv_sampler_from_handle(samplers
[0])->state
,
42 radv_sampler_from_handle(samplers
[i
])->state
, 16)) {
49 static int binding_compare(const void* av
, const void *bv
)
51 const VkDescriptorSetLayoutBinding
*a
= (const VkDescriptorSetLayoutBinding
*)av
;
52 const VkDescriptorSetLayoutBinding
*b
= (const VkDescriptorSetLayoutBinding
*)bv
;
54 return (a
->binding
< b
->binding
) ? -1 : (a
->binding
> b
->binding
) ? 1 : 0;
57 static VkDescriptorSetLayoutBinding
*
58 create_sorted_bindings(const VkDescriptorSetLayoutBinding
*bindings
, unsigned count
) {
59 VkDescriptorSetLayoutBinding
*sorted_bindings
= malloc(count
* sizeof(VkDescriptorSetLayoutBinding
));
63 memcpy(sorted_bindings
, bindings
, count
* sizeof(VkDescriptorSetLayoutBinding
));
65 qsort(sorted_bindings
, count
, sizeof(VkDescriptorSetLayoutBinding
), binding_compare
);
67 return sorted_bindings
;
70 VkResult
radv_CreateDescriptorSetLayout(
72 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
73 const VkAllocationCallbacks
* pAllocator
,
74 VkDescriptorSetLayout
* pSetLayout
)
76 RADV_FROM_HANDLE(radv_device
, device
, _device
);
77 struct radv_descriptor_set_layout
*set_layout
;
79 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
80 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
81 vk_find_struct_const(pCreateInfo
->pNext
, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
83 uint32_t max_binding
= 0;
84 uint32_t immutable_sampler_count
= 0;
85 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
86 max_binding
= MAX2(max_binding
, pCreateInfo
->pBindings
[j
].binding
);
87 if (pCreateInfo
->pBindings
[j
].pImmutableSamplers
)
88 immutable_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
91 uint32_t samplers_offset
= sizeof(struct radv_descriptor_set_layout
) +
92 (max_binding
+ 1) * sizeof(set_layout
->binding
[0]);
93 size_t size
= samplers_offset
+ immutable_sampler_count
* 4 * sizeof(uint32_t);
95 set_layout
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
96 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
98 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
100 set_layout
->flags
= pCreateInfo
->flags
;
102 /* We just allocate all the samplers at the end of the struct */
103 uint32_t *samplers
= (uint32_t*)&set_layout
->binding
[max_binding
+ 1];
105 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(pCreateInfo
->pBindings
,
106 pCreateInfo
->bindingCount
);
108 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
109 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
112 set_layout
->binding_count
= max_binding
+ 1;
113 set_layout
->shader_stages
= 0;
114 set_layout
->dynamic_shader_stages
= 0;
115 set_layout
->has_immutable_samplers
= false;
116 set_layout
->size
= 0;
118 memset(set_layout
->binding
, 0, size
- sizeof(struct radv_descriptor_set_layout
));
120 uint32_t buffer_count
= 0;
121 uint32_t dynamic_offset_count
= 0;
123 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
124 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ j
;
125 uint32_t b
= binding
->binding
;
127 unsigned binding_buffer_count
= 0;
129 switch (binding
->descriptorType
) {
130 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
131 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
132 assert(!(pCreateInfo
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
133 set_layout
->binding
[b
].dynamic_offset_count
= 1;
134 set_layout
->dynamic_shader_stages
|= binding
->stageFlags
;
135 set_layout
->binding
[b
].size
= 0;
136 binding_buffer_count
= 1;
139 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
140 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
141 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
142 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
143 set_layout
->binding
[b
].size
= 16;
144 binding_buffer_count
= 1;
147 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
148 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
149 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
150 /* main descriptor + fmask descriptor */
151 set_layout
->binding
[b
].size
= 64;
152 binding_buffer_count
= 1;
155 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
156 /* main descriptor + fmask descriptor + sampler */
157 set_layout
->binding
[b
].size
= 96;
158 binding_buffer_count
= 1;
161 case VK_DESCRIPTOR_TYPE_SAMPLER
:
162 set_layout
->binding
[b
].size
= 16;
166 unreachable("unknown descriptor type\n");
170 set_layout
->size
= align(set_layout
->size
, alignment
);
171 set_layout
->binding
[b
].type
= binding
->descriptorType
;
172 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
173 set_layout
->binding
[b
].offset
= set_layout
->size
;
174 set_layout
->binding
[b
].buffer_offset
= buffer_count
;
175 set_layout
->binding
[b
].dynamic_offset_offset
= dynamic_offset_count
;
177 if (variable_flags
&& binding
->binding
< variable_flags
->bindingCount
&&
178 (variable_flags
->pBindingFlags
[binding
->binding
] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
179 assert(!binding
->pImmutableSamplers
); /* Terribly ill defined how many samplers are valid */
180 assert(binding
->binding
== max_binding
);
182 set_layout
->has_variable_descriptors
= true;
185 if (binding
->pImmutableSamplers
) {
186 set_layout
->binding
[b
].immutable_samplers_offset
= samplers_offset
;
187 set_layout
->binding
[b
].immutable_samplers_equal
=
188 has_equal_immutable_samplers(binding
->pImmutableSamplers
, binding
->descriptorCount
);
189 set_layout
->has_immutable_samplers
= true;
192 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
193 memcpy(samplers
+ 4 * i
, &radv_sampler_from_handle(binding
->pImmutableSamplers
[i
])->state
, 16);
195 /* Don't reserve space for the samplers if they're not accessed. */
196 if (set_layout
->binding
[b
].immutable_samplers_equal
) {
197 if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
198 set_layout
->binding
[b
].size
-= 32;
199 else if (binding
->descriptorType
== VK_DESCRIPTOR_TYPE_SAMPLER
)
200 set_layout
->binding
[b
].size
-= 16;
202 samplers
+= 4 * binding
->descriptorCount
;
203 samplers_offset
+= 4 * sizeof(uint32_t) * binding
->descriptorCount
;
206 set_layout
->size
+= binding
->descriptorCount
* set_layout
->binding
[b
].size
;
207 buffer_count
+= binding
->descriptorCount
* binding_buffer_count
;
208 dynamic_offset_count
+= binding
->descriptorCount
*
209 set_layout
->binding
[b
].dynamic_offset_count
;
210 set_layout
->shader_stages
|= binding
->stageFlags
;
215 set_layout
->buffer_count
= buffer_count
;
216 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
218 *pSetLayout
= radv_descriptor_set_layout_to_handle(set_layout
);
223 void radv_DestroyDescriptorSetLayout(
225 VkDescriptorSetLayout _set_layout
,
226 const VkAllocationCallbacks
* pAllocator
)
228 RADV_FROM_HANDLE(radv_device
, device
, _device
);
229 RADV_FROM_HANDLE(radv_descriptor_set_layout
, set_layout
, _set_layout
);
234 vk_free2(&device
->alloc
, pAllocator
, set_layout
);
237 void radv_GetDescriptorSetLayoutSupport(VkDevice device
,
238 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
239 VkDescriptorSetLayoutSupport
* pSupport
)
241 VkDescriptorSetLayoutBinding
*bindings
= create_sorted_bindings(pCreateInfo
->pBindings
,
242 pCreateInfo
->bindingCount
);
244 pSupport
->supported
= false;
248 const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT
*variable_flags
=
249 vk_find_struct_const(pCreateInfo
->pNext
, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT
);
250 VkDescriptorSetVariableDescriptorCountLayoutSupportEXT
*variable_count
=
251 vk_find_struct((void*)pCreateInfo
->pNext
, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT
);
252 if (variable_count
) {
253 variable_count
->maxVariableDescriptorCount
= 0;
256 bool supported
= true;
258 for (uint32_t i
= 0; i
< pCreateInfo
->bindingCount
; i
++) {
259 const VkDescriptorSetLayoutBinding
*binding
= bindings
+ i
;
261 uint64_t descriptor_size
= 0;
262 uint64_t descriptor_alignment
= 1;
263 switch (binding
->descriptorType
) {
264 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
265 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
267 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
268 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
269 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
270 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
271 descriptor_size
= 16;
272 descriptor_alignment
= 16;
274 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
275 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
276 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
277 descriptor_size
= 64;
278 descriptor_alignment
= 32;
280 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
281 if (!has_equal_immutable_samplers(binding
->pImmutableSamplers
, binding
->descriptorCount
)) {
282 descriptor_size
= 64;
284 descriptor_size
= 96;
286 descriptor_alignment
= 32;
288 case VK_DESCRIPTOR_TYPE_SAMPLER
:
289 if (!has_equal_immutable_samplers(binding
->pImmutableSamplers
, binding
->descriptorCount
)) {
290 descriptor_size
= 16;
291 descriptor_alignment
= 16;
295 unreachable("unknown descriptor type\n");
299 if (size
&& !align_u64(size
, descriptor_alignment
)) {
302 size
= align_u64(size
, descriptor_alignment
);
304 uint64_t max_count
= UINT64_MAX
;
306 max_count
= (UINT64_MAX
- size
) / descriptor_size
;
308 if (max_count
< binding
->descriptorCount
) {
311 if (variable_flags
&& binding
->binding
<variable_flags
->bindingCount
&& variable_count
&&
312 (variable_flags
->pBindingFlags
[binding
->binding
] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
)) {
313 variable_count
->maxVariableDescriptorCount
= MIN2(UINT32_MAX
, max_count
);
315 size
+= binding
->descriptorCount
* descriptor_size
;
320 pSupport
->supported
= supported
;
324 * Pipeline layouts. These have nothing to do with the pipeline. They are
325 * just multiple descriptor set layouts pasted together.
328 VkResult
radv_CreatePipelineLayout(
330 const VkPipelineLayoutCreateInfo
* pCreateInfo
,
331 const VkAllocationCallbacks
* pAllocator
,
332 VkPipelineLayout
* pPipelineLayout
)
334 RADV_FROM_HANDLE(radv_device
, device
, _device
);
335 struct radv_pipeline_layout
*layout
;
336 struct mesa_sha1 ctx
;
338 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
340 layout
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
341 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
343 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
345 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
347 unsigned dynamic_offset_count
= 0;
348 uint16_t dynamic_shader_stages
= 0;
351 _mesa_sha1_init(&ctx
);
352 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
353 RADV_FROM_HANDLE(radv_descriptor_set_layout
, set_layout
,
354 pCreateInfo
->pSetLayouts
[set
]);
355 layout
->set
[set
].layout
= set_layout
;
357 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
358 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
359 dynamic_offset_count
+= set_layout
->binding
[b
].array_size
* set_layout
->binding
[b
].dynamic_offset_count
;
360 dynamic_shader_stages
|= set_layout
->dynamic_shader_stages
;
361 if (set_layout
->binding
[b
].immutable_samplers_offset
)
362 _mesa_sha1_update(&ctx
, radv_immutable_samplers(set_layout
, set_layout
->binding
+ b
),
363 set_layout
->binding
[b
].array_size
* 4 * sizeof(uint32_t));
365 _mesa_sha1_update(&ctx
, set_layout
->binding
,
366 sizeof(set_layout
->binding
[0]) * set_layout
->binding_count
);
369 layout
->dynamic_offset_count
= dynamic_offset_count
;
370 layout
->dynamic_shader_stages
= dynamic_shader_stages
;
371 layout
->push_constant_size
= 0;
373 for (unsigned i
= 0; i
< pCreateInfo
->pushConstantRangeCount
; ++i
) {
374 const VkPushConstantRange
*range
= pCreateInfo
->pPushConstantRanges
+ i
;
375 layout
->push_constant_size
= MAX2(layout
->push_constant_size
,
376 range
->offset
+ range
->size
);
379 layout
->push_constant_size
= align(layout
->push_constant_size
, 16);
380 _mesa_sha1_update(&ctx
, &layout
->push_constant_size
,
381 sizeof(layout
->push_constant_size
));
382 _mesa_sha1_final(&ctx
, layout
->sha1
);
383 *pPipelineLayout
= radv_pipeline_layout_to_handle(layout
);
388 void radv_DestroyPipelineLayout(
390 VkPipelineLayout _pipelineLayout
,
391 const VkAllocationCallbacks
* pAllocator
)
393 RADV_FROM_HANDLE(radv_device
, device
, _device
);
394 RADV_FROM_HANDLE(radv_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
396 if (!pipeline_layout
)
398 vk_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
404 radv_descriptor_set_create(struct radv_device
*device
,
405 struct radv_descriptor_pool
*pool
,
406 const struct radv_descriptor_set_layout
*layout
,
407 const uint32_t *variable_count
,
408 struct radv_descriptor_set
**out_set
)
410 struct radv_descriptor_set
*set
;
411 unsigned range_offset
= sizeof(struct radv_descriptor_set
) +
412 sizeof(struct radeon_winsys_bo
*) * layout
->buffer_count
;
413 unsigned mem_size
= range_offset
+
414 sizeof(struct radv_descriptor_range
) * layout
->dynamic_offset_count
;
416 if (pool
->host_memory_base
) {
417 if (pool
->host_memory_end
- pool
->host_memory_ptr
< mem_size
)
418 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
420 set
= (struct radv_descriptor_set
*)pool
->host_memory_ptr
;
421 pool
->host_memory_ptr
+= mem_size
;
423 set
= vk_alloc2(&device
->alloc
, NULL
, mem_size
, 8,
424 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
427 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
430 memset(set
, 0, mem_size
);
432 if (layout
->dynamic_offset_count
) {
433 set
->dynamic_descriptors
= (struct radv_descriptor_range
*)((uint8_t*)set
+ range_offset
);
436 set
->layout
= layout
;
437 uint32_t layout_size
= align_u32(layout
->size
, 32);
439 set
->size
= layout_size
;
441 if (!pool
->host_memory_base
&& pool
->entry_count
== pool
->max_entry_count
) {
442 vk_free2(&device
->alloc
, NULL
, set
);
443 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
446 /* try to allocate linearly first, so that we don't spend
447 * time looking for gaps if the app only allocates &
448 * resets via the pool. */
449 if (pool
->current_offset
+ layout_size
<= pool
->size
) {
451 set
->mapped_ptr
= (uint32_t*)(pool
->mapped_ptr
+ pool
->current_offset
);
452 set
->va
= radv_buffer_get_va(set
->bo
) + pool
->current_offset
;
453 if (!pool
->host_memory_base
) {
454 pool
->entries
[pool
->entry_count
].offset
= pool
->current_offset
;
455 pool
->entries
[pool
->entry_count
].size
= layout_size
;
456 pool
->entries
[pool
->entry_count
].set
= set
;
459 pool
->current_offset
+= layout_size
;
460 } else if (!pool
->host_memory_base
) {
464 for (index
= 0; index
< pool
->entry_count
; ++index
) {
465 if (pool
->entries
[index
].offset
- offset
>= layout_size
)
467 offset
= pool
->entries
[index
].offset
+ pool
->entries
[index
].size
;
470 if (pool
->size
- offset
< layout_size
) {
471 vk_free2(&device
->alloc
, NULL
, set
);
472 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
475 set
->mapped_ptr
= (uint32_t*)(pool
->mapped_ptr
+ offset
);
476 set
->va
= radv_buffer_get_va(set
->bo
) + offset
;
477 memmove(&pool
->entries
[index
+ 1], &pool
->entries
[index
],
478 sizeof(pool
->entries
[0]) * (pool
->entry_count
- index
));
479 pool
->entries
[index
].offset
= offset
;
480 pool
->entries
[index
].size
= layout_size
;
481 pool
->entries
[index
].set
= set
;
484 return vk_error(device
->instance
, VK_ERROR_OUT_OF_POOL_MEMORY
);
487 if (layout
->has_immutable_samplers
) {
488 for (unsigned i
= 0; i
< layout
->binding_count
; ++i
) {
489 if (!layout
->binding
[i
].immutable_samplers_offset
||
490 layout
->binding
[i
].immutable_samplers_equal
)
493 unsigned offset
= layout
->binding
[i
].offset
/ 4;
494 if (layout
->binding
[i
].type
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
497 const uint32_t *samplers
= (const uint32_t*)((const char*)layout
+ layout
->binding
[i
].immutable_samplers_offset
);
498 for (unsigned j
= 0; j
< layout
->binding
[i
].array_size
; ++j
) {
499 memcpy(set
->mapped_ptr
+ offset
, samplers
+ 4 * j
, 16);
500 offset
+= layout
->binding
[i
].size
/ 4;
510 radv_descriptor_set_destroy(struct radv_device
*device
,
511 struct radv_descriptor_pool
*pool
,
512 struct radv_descriptor_set
*set
,
515 assert(!pool
->host_memory_base
);
517 if (free_bo
&& set
->size
&& !pool
->host_memory_base
) {
518 uint32_t offset
= (uint8_t*)set
->mapped_ptr
- pool
->mapped_ptr
;
519 for (int i
= 0; i
< pool
->entry_count
; ++i
) {
520 if (pool
->entries
[i
].offset
== offset
) {
521 memmove(&pool
->entries
[i
], &pool
->entries
[i
+1],
522 sizeof(pool
->entries
[i
]) * (pool
->entry_count
- i
- 1));
528 vk_free2(&device
->alloc
, NULL
, set
);
531 VkResult
radv_CreateDescriptorPool(
533 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
534 const VkAllocationCallbacks
* pAllocator
,
535 VkDescriptorPool
* pDescriptorPool
)
537 RADV_FROM_HANDLE(radv_device
, device
, _device
);
538 struct radv_descriptor_pool
*pool
;
539 uint64_t size
= sizeof(struct radv_descriptor_pool
);
540 uint64_t bo_size
= 0, bo_count
= 0, range_count
= 0;
543 for (unsigned i
= 0; i
< pCreateInfo
->poolSizeCount
; ++i
) {
544 if (pCreateInfo
->pPoolSizes
[i
].type
!= VK_DESCRIPTOR_TYPE_SAMPLER
)
545 bo_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
547 switch(pCreateInfo
->pPoolSizes
[i
].type
) {
548 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
549 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
550 range_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
552 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
553 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
554 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
555 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
556 case VK_DESCRIPTOR_TYPE_SAMPLER
:
557 /* 32 as we may need to align for images */
558 bo_size
+= 32 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
560 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
561 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
562 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
563 bo_size
+= 64 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
565 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
566 bo_size
+= 96 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
569 unreachable("unknown descriptor type\n");
574 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
575 uint64_t host_size
= pCreateInfo
->maxSets
* sizeof(struct radv_descriptor_set
);
576 host_size
+= sizeof(struct radeon_winsys_bo
*) * bo_count
;
577 host_size
+= sizeof(struct radv_descriptor_range
) * range_count
;
580 size
+= sizeof(struct radv_descriptor_pool_entry
) * pCreateInfo
->maxSets
;
583 pool
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
584 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
586 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
588 memset(pool
, 0, sizeof(*pool
));
590 if (!(pCreateInfo
->flags
& VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT
)) {
591 pool
->host_memory_base
= (uint8_t*)pool
+ sizeof(struct radv_descriptor_pool
);
592 pool
->host_memory_ptr
= pool
->host_memory_base
;
593 pool
->host_memory_end
= (uint8_t*)pool
+ size
;
597 pool
->bo
= device
->ws
->buffer_create(device
->ws
, bo_size
, 32,
599 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
600 RADEON_FLAG_READ_ONLY
|
602 pool
->mapped_ptr
= (uint8_t*)device
->ws
->buffer_map(pool
->bo
);
604 pool
->size
= bo_size
;
605 pool
->max_entry_count
= pCreateInfo
->maxSets
;
607 *pDescriptorPool
= radv_descriptor_pool_to_handle(pool
);
611 void radv_DestroyDescriptorPool(
613 VkDescriptorPool _pool
,
614 const VkAllocationCallbacks
* pAllocator
)
616 RADV_FROM_HANDLE(radv_device
, device
, _device
);
617 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, _pool
);
622 if (!pool
->host_memory_base
) {
623 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
624 radv_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
629 device
->ws
->buffer_destroy(pool
->bo
);
630 vk_free2(&device
->alloc
, pAllocator
, pool
);
633 VkResult
radv_ResetDescriptorPool(
635 VkDescriptorPool descriptorPool
,
636 VkDescriptorPoolResetFlags flags
)
638 RADV_FROM_HANDLE(radv_device
, device
, _device
);
639 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, descriptorPool
);
641 if (!pool
->host_memory_base
) {
642 for(int i
= 0; i
< pool
->entry_count
; ++i
) {
643 radv_descriptor_set_destroy(device
, pool
, pool
->entries
[i
].set
, false);
645 pool
->entry_count
= 0;
648 pool
->current_offset
= 0;
649 pool
->host_memory_ptr
= pool
->host_memory_base
;
654 VkResult
radv_AllocateDescriptorSets(
656 const VkDescriptorSetAllocateInfo
* pAllocateInfo
,
657 VkDescriptorSet
* pDescriptorSets
)
659 RADV_FROM_HANDLE(radv_device
, device
, _device
);
660 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
662 VkResult result
= VK_SUCCESS
;
664 struct radv_descriptor_set
*set
= NULL
;
666 const VkDescriptorSetVariableDescriptorCountAllocateInfoEXT
*variable_counts
=
667 vk_find_struct_const(pAllocateInfo
->pNext
, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT
);
668 const uint32_t zero
= 0;
670 /* allocate a set of buffers for each shader to contain descriptors */
671 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
672 RADV_FROM_HANDLE(radv_descriptor_set_layout
, layout
,
673 pAllocateInfo
->pSetLayouts
[i
]);
675 const uint32_t *variable_count
= NULL
;
676 if (variable_counts
) {
677 if (i
< variable_counts
->descriptorSetCount
)
678 variable_count
= variable_counts
->pDescriptorCounts
+ i
;
680 variable_count
= &zero
;
683 assert(!(layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
685 result
= radv_descriptor_set_create(device
, pool
, layout
, variable_count
, &set
);
686 if (result
!= VK_SUCCESS
)
689 pDescriptorSets
[i
] = radv_descriptor_set_to_handle(set
);
692 if (result
!= VK_SUCCESS
)
693 radv_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
698 VkResult
radv_FreeDescriptorSets(
700 VkDescriptorPool descriptorPool
,
702 const VkDescriptorSet
* pDescriptorSets
)
704 RADV_FROM_HANDLE(radv_device
, device
, _device
);
705 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, descriptorPool
);
707 for (uint32_t i
= 0; i
< count
; i
++) {
708 RADV_FROM_HANDLE(radv_descriptor_set
, set
, pDescriptorSets
[i
]);
710 if (set
&& !pool
->host_memory_base
)
711 radv_descriptor_set_destroy(device
, pool
, set
, true);
716 static void write_texel_buffer_descriptor(struct radv_device
*device
,
717 struct radv_cmd_buffer
*cmd_buffer
,
719 struct radeon_winsys_bo
**buffer_list
,
720 const VkBufferView _buffer_view
)
722 RADV_FROM_HANDLE(radv_buffer_view
, buffer_view
, _buffer_view
);
724 memcpy(dst
, buffer_view
->state
, 4 * 4);
727 radv_cs_add_buffer(device
->ws
, cmd_buffer
->cs
, buffer_view
->bo
);
729 *buffer_list
= buffer_view
->bo
;
732 static void write_buffer_descriptor(struct radv_device
*device
,
733 struct radv_cmd_buffer
*cmd_buffer
,
735 struct radeon_winsys_bo
**buffer_list
,
736 const VkDescriptorBufferInfo
*buffer_info
)
738 RADV_FROM_HANDLE(radv_buffer
, buffer
, buffer_info
->buffer
);
739 uint64_t va
= radv_buffer_get_va(buffer
->bo
);
740 uint32_t range
= buffer_info
->range
;
742 if (buffer_info
->range
== VK_WHOLE_SIZE
)
743 range
= buffer
->size
- buffer_info
->offset
;
745 va
+= buffer_info
->offset
+ buffer
->offset
;
747 dst
[1] = S_008F04_BASE_ADDRESS_HI(va
>> 32);
749 dst
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
750 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
751 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
752 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
753 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
754 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
757 radv_cs_add_buffer(device
->ws
, cmd_buffer
->cs
, buffer
->bo
);
759 *buffer_list
= buffer
->bo
;
762 static void write_dynamic_buffer_descriptor(struct radv_device
*device
,
763 struct radv_descriptor_range
*range
,
764 struct radeon_winsys_bo
**buffer_list
,
765 const VkDescriptorBufferInfo
*buffer_info
)
767 RADV_FROM_HANDLE(radv_buffer
, buffer
, buffer_info
->buffer
);
768 uint64_t va
= radv_buffer_get_va(buffer
->bo
);
769 unsigned size
= buffer_info
->range
;
771 if (buffer_info
->range
== VK_WHOLE_SIZE
)
772 size
= buffer
->size
- buffer_info
->offset
;
774 va
+= buffer_info
->offset
+ buffer
->offset
;
778 *buffer_list
= buffer
->bo
;
782 write_image_descriptor(struct radv_device
*device
,
783 struct radv_cmd_buffer
*cmd_buffer
,
785 struct radeon_winsys_bo
**buffer_list
,
786 VkDescriptorType descriptor_type
,
787 const VkDescriptorImageInfo
*image_info
)
789 RADV_FROM_HANDLE(radv_image_view
, iview
, image_info
->imageView
);
790 uint32_t *descriptor
;
792 if (descriptor_type
== VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
) {
793 descriptor
= iview
->storage_descriptor
;
795 descriptor
= iview
->descriptor
;
798 memcpy(dst
, descriptor
, 16 * 4);
801 radv_cs_add_buffer(device
->ws
, cmd_buffer
->cs
, iview
->bo
);
803 *buffer_list
= iview
->bo
;
807 write_combined_image_sampler_descriptor(struct radv_device
*device
,
808 struct radv_cmd_buffer
*cmd_buffer
,
810 struct radeon_winsys_bo
**buffer_list
,
811 VkDescriptorType descriptor_type
,
812 const VkDescriptorImageInfo
*image_info
,
815 RADV_FROM_HANDLE(radv_sampler
, sampler
, image_info
->sampler
);
817 write_image_descriptor(device
, cmd_buffer
, dst
, buffer_list
, descriptor_type
, image_info
);
818 /* copy over sampler state */
820 memcpy(dst
+ 16, sampler
->state
, 16);
824 write_sampler_descriptor(struct radv_device
*device
,
826 const VkDescriptorImageInfo
*image_info
)
828 RADV_FROM_HANDLE(radv_sampler
, sampler
, image_info
->sampler
);
830 memcpy(dst
, sampler
->state
, 16);
833 void radv_update_descriptor_sets(
834 struct radv_device
* device
,
835 struct radv_cmd_buffer
* cmd_buffer
,
836 VkDescriptorSet dstSetOverride
,
837 uint32_t descriptorWriteCount
,
838 const VkWriteDescriptorSet
* pDescriptorWrites
,
839 uint32_t descriptorCopyCount
,
840 const VkCopyDescriptorSet
* pDescriptorCopies
)
843 for (i
= 0; i
< descriptorWriteCount
; i
++) {
844 const VkWriteDescriptorSet
*writeset
= &pDescriptorWrites
[i
];
845 RADV_FROM_HANDLE(radv_descriptor_set
, set
,
846 dstSetOverride
? dstSetOverride
: writeset
->dstSet
);
847 const struct radv_descriptor_set_binding_layout
*binding_layout
=
848 set
->layout
->binding
+ writeset
->dstBinding
;
849 uint32_t *ptr
= set
->mapped_ptr
;
850 struct radeon_winsys_bo
**buffer_list
= set
->descriptors
;
851 /* Immutable samplers are not copied into push descriptors when they are
852 * allocated, so if we are writing push descriptors we have to copy the
853 * immutable samplers into them now.
855 const bool copy_immutable_samplers
= cmd_buffer
&&
856 binding_layout
->immutable_samplers_offset
&& !binding_layout
->immutable_samplers_equal
;
857 const uint32_t *samplers
= radv_immutable_samplers(set
->layout
, binding_layout
);
859 ptr
+= binding_layout
->offset
/ 4;
860 ptr
+= binding_layout
->size
* writeset
->dstArrayElement
/ 4;
861 buffer_list
+= binding_layout
->buffer_offset
;
862 buffer_list
+= writeset
->dstArrayElement
;
863 for (j
= 0; j
< writeset
->descriptorCount
; ++j
) {
864 switch(writeset
->descriptorType
) {
865 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
866 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
867 unsigned idx
= writeset
->dstArrayElement
+ j
;
868 idx
+= binding_layout
->dynamic_offset_offset
;
869 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
870 write_dynamic_buffer_descriptor(device
, set
->dynamic_descriptors
+ idx
,
871 buffer_list
, writeset
->pBufferInfo
+ j
);
874 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
875 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
876 write_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
877 writeset
->pBufferInfo
+ j
);
879 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
880 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
881 write_texel_buffer_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
882 writeset
->pTexelBufferView
[j
]);
884 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
885 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
886 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
887 write_image_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
888 writeset
->descriptorType
,
889 writeset
->pImageInfo
+ j
);
891 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
892 write_combined_image_sampler_descriptor(device
, cmd_buffer
, ptr
, buffer_list
,
893 writeset
->descriptorType
,
894 writeset
->pImageInfo
+ j
,
895 !binding_layout
->immutable_samplers_offset
);
896 if (copy_immutable_samplers
) {
897 const unsigned idx
= writeset
->dstArrayElement
+ j
;
898 memcpy(ptr
+ 16, samplers
+ 4 * idx
, 16);
901 case VK_DESCRIPTOR_TYPE_SAMPLER
:
902 if (!binding_layout
->immutable_samplers_offset
) {
903 write_sampler_descriptor(device
, ptr
,
904 writeset
->pImageInfo
+ j
);
905 } else if (copy_immutable_samplers
) {
906 unsigned idx
= writeset
->dstArrayElement
+ j
;
907 memcpy(ptr
, samplers
+ 4 * idx
, 16);
911 unreachable("unimplemented descriptor type");
914 ptr
+= binding_layout
->size
/ 4;
920 for (i
= 0; i
< descriptorCopyCount
; i
++) {
921 const VkCopyDescriptorSet
*copyset
= &pDescriptorCopies
[i
];
922 RADV_FROM_HANDLE(radv_descriptor_set
, src_set
,
924 RADV_FROM_HANDLE(radv_descriptor_set
, dst_set
,
926 const struct radv_descriptor_set_binding_layout
*src_binding_layout
=
927 src_set
->layout
->binding
+ copyset
->srcBinding
;
928 const struct radv_descriptor_set_binding_layout
*dst_binding_layout
=
929 dst_set
->layout
->binding
+ copyset
->dstBinding
;
930 uint32_t *src_ptr
= src_set
->mapped_ptr
;
931 uint32_t *dst_ptr
= dst_set
->mapped_ptr
;
932 struct radeon_winsys_bo
**src_buffer_list
= src_set
->descriptors
;
933 struct radeon_winsys_bo
**dst_buffer_list
= dst_set
->descriptors
;
935 src_ptr
+= src_binding_layout
->offset
/ 4;
936 dst_ptr
+= dst_binding_layout
->offset
/ 4;
938 src_ptr
+= src_binding_layout
->size
* copyset
->srcArrayElement
/ 4;
939 dst_ptr
+= dst_binding_layout
->size
* copyset
->dstArrayElement
/ 4;
941 src_buffer_list
+= src_binding_layout
->buffer_offset
;
942 src_buffer_list
+= copyset
->srcArrayElement
;
944 dst_buffer_list
+= dst_binding_layout
->buffer_offset
;
945 dst_buffer_list
+= copyset
->dstArrayElement
;
947 for (j
= 0; j
< copyset
->descriptorCount
; ++j
) {
948 switch (src_binding_layout
->type
) {
949 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
950 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
951 unsigned src_idx
= copyset
->srcArrayElement
+ j
;
952 unsigned dst_idx
= copyset
->dstArrayElement
+ j
;
953 struct radv_descriptor_range
*src_range
, *dst_range
;
954 src_idx
+= src_binding_layout
->dynamic_offset_offset
;
955 dst_idx
+= dst_binding_layout
->dynamic_offset_offset
;
957 src_range
= src_set
->dynamic_descriptors
+ src_idx
;
958 dst_range
= dst_set
->dynamic_descriptors
+ dst_idx
;
959 *dst_range
= *src_range
;
963 memcpy(dst_ptr
, src_ptr
, src_binding_layout
->size
);
965 src_ptr
+= src_binding_layout
->size
/ 4;
966 dst_ptr
+= dst_binding_layout
->size
/ 4;
967 dst_buffer_list
[j
] = src_buffer_list
[j
];
974 void radv_UpdateDescriptorSets(
976 uint32_t descriptorWriteCount
,
977 const VkWriteDescriptorSet
* pDescriptorWrites
,
978 uint32_t descriptorCopyCount
,
979 const VkCopyDescriptorSet
* pDescriptorCopies
)
981 RADV_FROM_HANDLE(radv_device
, device
, _device
);
983 radv_update_descriptor_sets(device
, NULL
, VK_NULL_HANDLE
, descriptorWriteCount
, pDescriptorWrites
,
984 descriptorCopyCount
, pDescriptorCopies
);
987 VkResult
radv_CreateDescriptorUpdateTemplate(VkDevice _device
,
988 const VkDescriptorUpdateTemplateCreateInfo
*pCreateInfo
,
989 const VkAllocationCallbacks
*pAllocator
,
990 VkDescriptorUpdateTemplate
*pDescriptorUpdateTemplate
)
992 RADV_FROM_HANDLE(radv_device
, device
, _device
);
993 RADV_FROM_HANDLE(radv_descriptor_set_layout
, set_layout
, pCreateInfo
->descriptorSetLayout
);
994 const uint32_t entry_count
= pCreateInfo
->descriptorUpdateEntryCount
;
995 const size_t size
= sizeof(struct radv_descriptor_update_template
) +
996 sizeof(struct radv_descriptor_update_template_entry
) * entry_count
;
997 struct radv_descriptor_update_template
*templ
;
1000 templ
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1002 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1004 templ
->entry_count
= entry_count
;
1005 templ
->bind_point
= pCreateInfo
->pipelineBindPoint
;
1007 for (i
= 0; i
< entry_count
; i
++) {
1008 const VkDescriptorUpdateTemplateEntry
*entry
= &pCreateInfo
->pDescriptorUpdateEntries
[i
];
1009 const struct radv_descriptor_set_binding_layout
*binding_layout
=
1010 set_layout
->binding
+ entry
->dstBinding
;
1011 const uint32_t buffer_offset
= binding_layout
->buffer_offset
+ entry
->dstArrayElement
;
1012 const uint32_t *immutable_samplers
= NULL
;
1013 uint32_t dst_offset
;
1014 uint32_t dst_stride
;
1016 /* dst_offset is an offset into dynamic_descriptors when the descriptor
1017 is dynamic, and an offset into mapped_ptr otherwise */
1018 switch (entry
->descriptorType
) {
1019 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1020 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1021 assert(pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET
);
1022 dst_offset
= binding_layout
->dynamic_offset_offset
+ entry
->dstArrayElement
;
1023 dst_stride
= 0; /* Not used */
1026 switch (entry
->descriptorType
) {
1027 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1028 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1029 /* Immutable samplers are copied into push descriptors when they are pushed */
1030 if (pCreateInfo
->templateType
== VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR
&&
1031 binding_layout
->immutable_samplers_offset
&& !binding_layout
->immutable_samplers_equal
) {
1032 immutable_samplers
= radv_immutable_samplers(set_layout
, binding_layout
) + entry
->dstArrayElement
* 4;
1038 dst_offset
= binding_layout
->offset
/ 4 + binding_layout
->size
* entry
->dstArrayElement
/ 4;
1039 dst_stride
= binding_layout
->size
/ 4;
1043 templ
->entry
[i
] = (struct radv_descriptor_update_template_entry
) {
1044 .descriptor_type
= entry
->descriptorType
,
1045 .descriptor_count
= entry
->descriptorCount
,
1046 .src_offset
= entry
->offset
,
1047 .src_stride
= entry
->stride
,
1048 .dst_offset
= dst_offset
,
1049 .dst_stride
= dst_stride
,
1050 .buffer_offset
= buffer_offset
,
1051 .has_sampler
= !binding_layout
->immutable_samplers_offset
,
1052 .immutable_samplers
= immutable_samplers
1056 *pDescriptorUpdateTemplate
= radv_descriptor_update_template_to_handle(templ
);
1060 void radv_DestroyDescriptorUpdateTemplate(VkDevice _device
,
1061 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1062 const VkAllocationCallbacks
*pAllocator
)
1064 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1065 RADV_FROM_HANDLE(radv_descriptor_update_template
, templ
, descriptorUpdateTemplate
);
1070 vk_free2(&device
->alloc
, pAllocator
, templ
);
1073 void radv_update_descriptor_set_with_template(struct radv_device
*device
,
1074 struct radv_cmd_buffer
*cmd_buffer
,
1075 struct radv_descriptor_set
*set
,
1076 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1079 RADV_FROM_HANDLE(radv_descriptor_update_template
, templ
, descriptorUpdateTemplate
);
1082 for (i
= 0; i
< templ
->entry_count
; ++i
) {
1083 struct radeon_winsys_bo
**buffer_list
= set
->descriptors
+ templ
->entry
[i
].buffer_offset
;
1084 uint32_t *pDst
= set
->mapped_ptr
+ templ
->entry
[i
].dst_offset
;
1085 const uint8_t *pSrc
= ((const uint8_t *) pData
) + templ
->entry
[i
].src_offset
;
1088 for (j
= 0; j
< templ
->entry
[i
].descriptor_count
; ++j
) {
1089 switch (templ
->entry
[i
].descriptor_type
) {
1090 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1091 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
1092 const unsigned idx
= templ
->entry
[i
].dst_offset
+ j
;
1093 assert(!(set
->layout
->flags
& VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR
));
1094 write_dynamic_buffer_descriptor(device
, set
->dynamic_descriptors
+ idx
,
1095 buffer_list
, (struct VkDescriptorBufferInfo
*) pSrc
);
1098 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1099 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1100 write_buffer_descriptor(device
, cmd_buffer
, pDst
, buffer_list
,
1101 (struct VkDescriptorBufferInfo
*) pSrc
);
1103 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1104 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1105 write_texel_buffer_descriptor(device
, cmd_buffer
, pDst
, buffer_list
,
1106 *(VkBufferView
*) pSrc
);
1108 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1109 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1110 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
1111 write_image_descriptor(device
, cmd_buffer
, pDst
, buffer_list
,
1112 templ
->entry
[i
].descriptor_type
,
1113 (struct VkDescriptorImageInfo
*) pSrc
);
1115 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1116 write_combined_image_sampler_descriptor(device
, cmd_buffer
, pDst
, buffer_list
,
1117 templ
->entry
[i
].descriptor_type
,
1118 (struct VkDescriptorImageInfo
*) pSrc
,
1119 templ
->entry
[i
].has_sampler
);
1120 if (templ
->entry
[i
].immutable_samplers
)
1121 memcpy(pDst
+ 16, templ
->entry
[i
].immutable_samplers
+ 4 * j
, 16);
1123 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1124 if (templ
->entry
[i
].has_sampler
)
1125 write_sampler_descriptor(device
, pDst
,
1126 (struct VkDescriptorImageInfo
*) pSrc
);
1127 else if (templ
->entry
[i
].immutable_samplers
)
1128 memcpy(pDst
, templ
->entry
[i
].immutable_samplers
+ 4 * j
, 16);
1131 unreachable("unimplemented descriptor type");
1134 pSrc
+= templ
->entry
[i
].src_stride
;
1135 pDst
+= templ
->entry
[i
].dst_stride
;
1141 void radv_UpdateDescriptorSetWithTemplate(VkDevice _device
,
1142 VkDescriptorSet descriptorSet
,
1143 VkDescriptorUpdateTemplate descriptorUpdateTemplate
,
1146 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1147 RADV_FROM_HANDLE(radv_descriptor_set
, set
, descriptorSet
);
1149 radv_update_descriptor_set_with_template(device
, NULL
, set
, descriptorUpdateTemplate
, pData
);
1153 VkResult
radv_CreateSamplerYcbcrConversion(VkDevice device
,
1154 const VkSamplerYcbcrConversionCreateInfo
* pCreateInfo
,
1155 const VkAllocationCallbacks
* pAllocator
,
1156 VkSamplerYcbcrConversion
* pYcbcrConversion
)
1158 *pYcbcrConversion
= VK_NULL_HANDLE
;
1163 void radv_DestroySamplerYcbcrConversion(VkDevice device
,
1164 VkSamplerYcbcrConversion ycbcrConversion
,
1165 const VkAllocationCallbacks
* pAllocator
)