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"
34 VkResult
radv_CreateDescriptorSetLayout(
36 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
37 const VkAllocationCallbacks
* pAllocator
,
38 VkDescriptorSetLayout
* pSetLayout
)
40 RADV_FROM_HANDLE(radv_device
, device
, _device
);
41 struct radv_descriptor_set_layout
*set_layout
;
43 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
45 uint32_t max_binding
= 0;
46 uint32_t immutable_sampler_count
= 0;
47 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
48 max_binding
= MAX(max_binding
, pCreateInfo
->pBindings
[j
].binding
);
49 if (pCreateInfo
->pBindings
[j
].pImmutableSamplers
)
50 immutable_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
53 size_t size
= sizeof(struct radv_descriptor_set_layout
) +
54 (max_binding
+ 1) * sizeof(set_layout
->binding
[0]) +
55 immutable_sampler_count
* sizeof(struct radv_sampler
*);
57 set_layout
= radv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
58 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
60 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
62 /* We just allocate all the samplers at the end of the struct */
63 struct radv_sampler
**samplers
=
64 (struct radv_sampler
**)&set_layout
->binding
[max_binding
+ 1];
66 set_layout
->binding_count
= max_binding
+ 1;
67 set_layout
->shader_stages
= 0;
70 memset(set_layout
->binding
, 0, size
- sizeof(struct radv_descriptor_set_layout
));
72 uint32_t buffer_count
= 0;
73 uint32_t dynamic_offset_count
= 0;
75 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
76 const VkDescriptorSetLayoutBinding
*binding
= &pCreateInfo
->pBindings
[j
];
77 uint32_t b
= binding
->binding
;
80 switch (binding
->descriptorType
) {
81 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
82 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
83 set_layout
->binding
[b
].dynamic_offset_count
= 1;
84 set_layout
->dynamic_shader_stages
|= binding
->stageFlags
;
85 set_layout
->binding
[b
].size
= 0;
86 set_layout
->binding
[b
].buffer_count
= 1;
89 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
90 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
91 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
92 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
93 set_layout
->binding
[b
].size
= 16;
94 set_layout
->binding
[b
].buffer_count
= 1;
97 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
98 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
99 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
100 /* main descriptor + fmask descriptor */
101 set_layout
->binding
[b
].size
= 64;
102 set_layout
->binding
[b
].buffer_count
= 1;
105 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
106 /* main descriptor + fmask descriptor + sampler */
107 set_layout
->binding
[b
].size
= 96;
108 set_layout
->binding
[b
].buffer_count
= 1;
111 case VK_DESCRIPTOR_TYPE_SAMPLER
:
112 set_layout
->binding
[b
].size
= 16;
119 set_layout
->size
= align(set_layout
->size
, alignment
);
120 assert(binding
->descriptorCount
> 0);
121 set_layout
->binding
[b
].type
= binding
->descriptorType
;
122 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
123 set_layout
->binding
[b
].offset
= set_layout
->size
;
124 set_layout
->binding
[b
].buffer_offset
= buffer_count
;
125 set_layout
->binding
[b
].dynamic_offset_offset
= dynamic_offset_count
;
127 set_layout
->size
+= binding
->descriptorCount
* set_layout
->binding
[b
].size
;
128 buffer_count
+= binding
->descriptorCount
* set_layout
->binding
[b
].buffer_count
;
129 dynamic_offset_count
+= binding
->descriptorCount
*
130 set_layout
->binding
[b
].dynamic_offset_count
;
133 if (binding
->pImmutableSamplers
) {
134 set_layout
->binding
[b
].immutable_samplers
= samplers
;
135 samplers
+= binding
->descriptorCount
;
137 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
138 set_layout
->binding
[b
].immutable_samplers
[i
] =
139 radv_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
141 set_layout
->binding
[b
].immutable_samplers
= NULL
;
144 set_layout
->shader_stages
|= binding
->stageFlags
;
147 set_layout
->buffer_count
= buffer_count
;
148 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
150 *pSetLayout
= radv_descriptor_set_layout_to_handle(set_layout
);
155 void radv_DestroyDescriptorSetLayout(
157 VkDescriptorSetLayout _set_layout
,
158 const VkAllocationCallbacks
* pAllocator
)
160 RADV_FROM_HANDLE(radv_device
, device
, _device
);
161 RADV_FROM_HANDLE(radv_descriptor_set_layout
, set_layout
, _set_layout
);
166 radv_free2(&device
->alloc
, pAllocator
, set_layout
);
170 * Pipeline layouts. These have nothing to do with the pipeline. They are
171 * just muttiple descriptor set layouts pasted together
174 VkResult
radv_CreatePipelineLayout(
176 const VkPipelineLayoutCreateInfo
* pCreateInfo
,
177 const VkAllocationCallbacks
* pAllocator
,
178 VkPipelineLayout
* pPipelineLayout
)
180 RADV_FROM_HANDLE(radv_device
, device
, _device
);
181 struct radv_pipeline_layout
*layout
;
182 struct mesa_sha1
*ctx
;
184 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
186 layout
= radv_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
187 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
189 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
191 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
193 unsigned dynamic_offset_count
= 0;
196 ctx
= _mesa_sha1_init();
197 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
198 RADV_FROM_HANDLE(radv_descriptor_set_layout
, set_layout
,
199 pCreateInfo
->pSetLayouts
[set
]);
200 layout
->set
[set
].layout
= set_layout
;
202 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
203 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
204 dynamic_offset_count
+= set_layout
->binding
[b
].array_size
* set_layout
->binding
[b
].dynamic_offset_count
;
206 _mesa_sha1_update(ctx
, set_layout
->binding
,
207 sizeof(set_layout
->binding
[0]) * set_layout
->binding_count
);
210 layout
->dynamic_offset_count
= dynamic_offset_count
;
211 layout
->push_constant_size
= 0;
212 for (unsigned i
= 0; i
< pCreateInfo
->pushConstantRangeCount
; ++i
) {
213 const VkPushConstantRange
*range
= pCreateInfo
->pPushConstantRanges
+ i
;
214 layout
->push_constant_size
= MAX2(layout
->push_constant_size
,
215 range
->offset
+ range
->size
);
218 layout
->push_constant_size
= align(layout
->push_constant_size
, 16);
219 _mesa_sha1_update(ctx
, &layout
->push_constant_size
,
220 sizeof(layout
->push_constant_size
));
221 _mesa_sha1_final(ctx
, layout
->sha1
);
222 *pPipelineLayout
= radv_pipeline_layout_to_handle(layout
);
227 void radv_DestroyPipelineLayout(
229 VkPipelineLayout _pipelineLayout
,
230 const VkAllocationCallbacks
* pAllocator
)
232 RADV_FROM_HANDLE(radv_device
, device
, _device
);
233 RADV_FROM_HANDLE(radv_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
235 if (!pipeline_layout
)
237 radv_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
243 radv_descriptor_set_create(struct radv_device
*device
,
244 struct radv_descriptor_pool
*pool
,
245 struct radv_cmd_buffer
*cmd_buffer
,
246 const struct radv_descriptor_set_layout
*layout
,
247 struct radv_descriptor_set
**out_set
)
249 struct radv_descriptor_set
*set
;
250 unsigned mem_size
= sizeof(struct radv_descriptor_set
) +
251 sizeof(struct radeon_winsys_bo
*) * layout
->buffer_count
;
252 set
= radv_alloc2(&device
->alloc
, NULL
, mem_size
, 8,
253 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
256 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
258 memset(set
, 0, mem_size
);
260 if (layout
->dynamic_offset_count
) {
261 unsigned size
= sizeof(struct radv_descriptor_range
) *
262 layout
->dynamic_offset_count
;
263 set
->dynamic_descriptors
= radv_alloc2(&device
->alloc
, NULL
, size
, 8,
264 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
266 if (!set
->dynamic_descriptors
) {
267 radv_free2(&device
->alloc
, NULL
, set
);
268 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
272 set
->layout
= layout
;
274 uint32_t layout_size
= align_u32(layout
->size
, 32);
275 set
->size
= layout
->size
;
277 if (pool
->current_offset
+ layout_size
<= pool
->size
) {
279 set
->mapped_ptr
= (uint32_t*)(pool
->mapped_ptr
+ pool
->current_offset
);
280 set
->va
= device
->ws
->buffer_get_va(set
->bo
) + pool
->current_offset
;
281 pool
->current_offset
+= layout_size
;
284 int entry
= pool
->free_list
, prev_entry
= -1;
287 if (pool
->free_nodes
[entry
].size
>= layout_size
) {
289 pool
->free_nodes
[prev_entry
].next
= pool
->free_nodes
[entry
].next
;
291 pool
->free_list
= pool
->free_nodes
[entry
].next
;
295 entry
= pool
->free_nodes
[entry
].next
;
299 radv_free2(&device
->alloc
, NULL
, set
);
300 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
302 offset
= pool
->free_nodes
[entry
].offset
;
303 pool
->free_nodes
[entry
].next
= pool
->full_list
;
304 pool
->full_list
= entry
;
307 set
->mapped_ptr
= (uint32_t*)(pool
->mapped_ptr
+ offset
);
308 set
->va
= device
->ws
->buffer_get_va(set
->bo
) + offset
;
312 if (!radv_cmd_buffer_upload_alloc(cmd_buffer
, set
->size
, 32,
314 (void**)&set
->mapped_ptr
)) {
315 radv_free2(&device
->alloc
, NULL
, set
->dynamic_descriptors
);
316 radv_free2(&device
->alloc
, NULL
, set
);
317 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
320 set
->va
= device
->ws
->buffer_get_va(cmd_buffer
->upload
.upload_bo
);
321 set
->va
+= bo_offset
;
326 list_add(&set
->descriptor_pool
, &pool
->descriptor_sets
);
328 list_inithead(&set
->descriptor_pool
);
330 for (unsigned i
= 0; i
< layout
->binding_count
; ++i
) {
331 if (!layout
->binding
[i
].immutable_samplers
)
334 unsigned offset
= layout
->binding
[i
].offset
/ 4;
335 if (layout
->binding
[i
].type
== VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
)
338 for (unsigned j
= 0; j
< layout
->binding
[i
].array_size
; ++j
) {
339 struct radv_sampler
* sampler
= layout
->binding
[i
].immutable_samplers
[j
];
341 memcpy(set
->mapped_ptr
+ offset
, &sampler
->state
, 16);
342 offset
+= layout
->binding
[i
].size
/ 4;
351 radv_descriptor_set_destroy(struct radv_device
*device
,
352 struct radv_descriptor_pool
*pool
,
353 struct radv_descriptor_set
*set
,
356 if (free_bo
&& set
->size
) {
357 assert(pool
->full_list
>= 0);
358 int next
= pool
->free_nodes
[pool
->full_list
].next
;
359 pool
->free_nodes
[pool
->full_list
].next
= pool
->free_list
;
360 pool
->free_nodes
[pool
->full_list
].offset
= (uint8_t*)set
->mapped_ptr
- pool
->mapped_ptr
;
361 pool
->free_nodes
[pool
->full_list
].size
= align_u32(set
->size
, 32);
362 pool
->free_list
= pool
->full_list
;
363 pool
->full_list
= next
;
365 if (set
->dynamic_descriptors
)
366 radv_free2(&device
->alloc
, NULL
, set
->dynamic_descriptors
);
367 if (!list_empty(&set
->descriptor_pool
))
368 list_del(&set
->descriptor_pool
);
369 radv_free2(&device
->alloc
, NULL
, set
);
373 radv_temp_descriptor_set_create(struct radv_device
*device
,
374 struct radv_cmd_buffer
*cmd_buffer
,
375 VkDescriptorSetLayout _layout
,
376 VkDescriptorSet
*_set
)
378 RADV_FROM_HANDLE(radv_descriptor_set_layout
, layout
, _layout
);
379 struct radv_descriptor_set
*set
;
382 ret
= radv_descriptor_set_create(device
, NULL
, cmd_buffer
, layout
, &set
);
383 *_set
= radv_descriptor_set_to_handle(set
);
388 radv_temp_descriptor_set_destroy(struct radv_device
*device
,
389 VkDescriptorSet _set
)
391 RADV_FROM_HANDLE(radv_descriptor_set
, set
, _set
);
393 radv_descriptor_set_destroy(device
, NULL
, set
, false);
396 VkResult
radv_CreateDescriptorPool(
398 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
399 const VkAllocationCallbacks
* pAllocator
,
400 VkDescriptorPool
* pDescriptorPool
)
402 RADV_FROM_HANDLE(radv_device
, device
, _device
);
403 struct radv_descriptor_pool
*pool
;
404 unsigned max_sets
= pCreateInfo
->maxSets
* 2;
405 int size
= sizeof(struct radv_descriptor_pool
) +
406 max_sets
* sizeof(struct radv_descriptor_pool_free_node
);
407 uint64_t bo_size
= 0;
408 pool
= radv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
409 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
411 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
413 memset(pool
, 0, sizeof(*pool
));
415 pool
->free_list
= -1;
417 pool
->free_nodes
[max_sets
- 1].next
= -1;
418 pool
->max_sets
= max_sets
;
420 for (int i
= 0; i
+ 1 < max_sets
; ++i
)
421 pool
->free_nodes
[i
].next
= i
+ 1;
423 for (unsigned i
= 0; i
< pCreateInfo
->poolSizeCount
; ++i
) {
424 switch(pCreateInfo
->pPoolSizes
[i
].type
) {
425 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
426 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
428 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
429 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
430 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
431 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
432 case VK_DESCRIPTOR_TYPE_SAMPLER
:
433 /* 32 as we may need to align for images */
434 bo_size
+= 32 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
436 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
437 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
438 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
439 bo_size
+= 64 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
441 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
442 bo_size
+= 96 * pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
445 unreachable("unknown descriptor type\n");
451 pool
->bo
= device
->ws
->buffer_create(device
->ws
, bo_size
,
452 32, RADEON_DOMAIN_VRAM
, 0);
453 pool
->mapped_ptr
= (uint8_t*)device
->ws
->buffer_map(pool
->bo
);
455 pool
->size
= bo_size
;
457 list_inithead(&pool
->descriptor_sets
);
458 *pDescriptorPool
= radv_descriptor_pool_to_handle(pool
);
462 void radv_DestroyDescriptorPool(
464 VkDescriptorPool _pool
,
465 const VkAllocationCallbacks
* pAllocator
)
467 RADV_FROM_HANDLE(radv_device
, device
, _device
);
468 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, _pool
);
473 list_for_each_entry_safe(struct radv_descriptor_set
, set
,
474 &pool
->descriptor_sets
, descriptor_pool
) {
475 radv_descriptor_set_destroy(device
, pool
, set
, false);
479 device
->ws
->buffer_destroy(pool
->bo
);
480 radv_free2(&device
->alloc
, pAllocator
, pool
);
483 VkResult
radv_ResetDescriptorPool(
485 VkDescriptorPool descriptorPool
,
486 VkDescriptorPoolResetFlags flags
)
488 RADV_FROM_HANDLE(radv_device
, device
, _device
);
489 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, descriptorPool
);
491 list_for_each_entry_safe(struct radv_descriptor_set
, set
,
492 &pool
->descriptor_sets
, descriptor_pool
) {
493 radv_descriptor_set_destroy(device
, pool
, set
, false);
496 pool
->current_offset
= 0;
497 pool
->free_list
= -1;
499 pool
->free_nodes
[pool
->max_sets
- 1].next
= -1;
501 for (int i
= 0; i
+ 1 < pool
->max_sets
; ++i
)
502 pool
->free_nodes
[i
].next
= i
+ 1;
507 VkResult
radv_AllocateDescriptorSets(
509 const VkDescriptorSetAllocateInfo
* pAllocateInfo
,
510 VkDescriptorSet
* pDescriptorSets
)
512 RADV_FROM_HANDLE(radv_device
, device
, _device
);
513 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
515 VkResult result
= VK_SUCCESS
;
517 struct radv_descriptor_set
*set
;
519 /* allocate a set of buffers for each shader to contain descriptors */
520 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
521 RADV_FROM_HANDLE(radv_descriptor_set_layout
, layout
,
522 pAllocateInfo
->pSetLayouts
[i
]);
524 result
= radv_descriptor_set_create(device
, pool
, NULL
, layout
, &set
);
525 if (result
!= VK_SUCCESS
)
528 pDescriptorSets
[i
] = radv_descriptor_set_to_handle(set
);
531 if (result
!= VK_SUCCESS
)
532 radv_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
537 VkResult
radv_FreeDescriptorSets(
539 VkDescriptorPool descriptorPool
,
541 const VkDescriptorSet
* pDescriptorSets
)
543 RADV_FROM_HANDLE(radv_device
, device
, _device
);
544 RADV_FROM_HANDLE(radv_descriptor_pool
, pool
, descriptorPool
);
546 for (uint32_t i
= 0; i
< count
; i
++) {
547 RADV_FROM_HANDLE(radv_descriptor_set
, set
, pDescriptorSets
[i
]);
550 radv_descriptor_set_destroy(device
, pool
, set
, true);
555 static void write_texel_buffer_descriptor(struct radv_device
*device
,
557 struct radeon_winsys_bo
**buffer_list
,
558 const VkBufferView _buffer_view
)
560 RADV_FROM_HANDLE(radv_buffer_view
, buffer_view
, _buffer_view
);
562 memcpy(dst
, buffer_view
->state
, 4 * 4);
563 *buffer_list
= buffer_view
->bo
;
566 static void write_buffer_descriptor(struct radv_device
*device
,
568 struct radeon_winsys_bo
**buffer_list
,
569 const VkDescriptorBufferInfo
*buffer_info
)
571 RADV_FROM_HANDLE(radv_buffer
, buffer
, buffer_info
->buffer
);
572 uint64_t va
= device
->ws
->buffer_get_va(buffer
->bo
);
573 uint32_t range
= buffer_info
->range
;
575 if (buffer_info
->range
== VK_WHOLE_SIZE
)
576 range
= buffer
->size
- buffer_info
->offset
;
578 va
+= buffer_info
->offset
+ buffer
->offset
;
580 dst
[1] = S_008F04_BASE_ADDRESS_HI(va
>> 32);
582 dst
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
583 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
584 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
585 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
586 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
587 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
);
589 *buffer_list
= buffer
->bo
;
592 static void write_dynamic_buffer_descriptor(struct radv_device
*device
,
593 struct radv_descriptor_range
*range
,
594 struct radeon_winsys_bo
**buffer_list
,
595 const VkDescriptorBufferInfo
*buffer_info
)
597 RADV_FROM_HANDLE(radv_buffer
, buffer
, buffer_info
->buffer
);
598 uint64_t va
= device
->ws
->buffer_get_va(buffer
->bo
);
599 unsigned size
= buffer_info
->range
;
601 if (buffer_info
->range
== VK_WHOLE_SIZE
)
602 size
= buffer
->size
- buffer_info
->offset
;
604 va
+= buffer_info
->offset
+ buffer
->offset
;
608 *buffer_list
= buffer
->bo
;
612 write_image_descriptor(struct radv_device
*device
,
614 struct radeon_winsys_bo
**buffer_list
,
615 const VkDescriptorImageInfo
*image_info
)
617 RADV_FROM_HANDLE(radv_image_view
, iview
, image_info
->imageView
);
618 memcpy(dst
, iview
->descriptor
, 8 * 4);
619 memcpy(dst
+ 8, iview
->fmask_descriptor
, 8 * 4);
620 *buffer_list
= iview
->bo
;
624 write_combined_image_sampler_descriptor(struct radv_device
*device
,
626 struct radeon_winsys_bo
**buffer_list
,
627 const VkDescriptorImageInfo
*image_info
,
630 RADV_FROM_HANDLE(radv_sampler
, sampler
, image_info
->sampler
);
632 write_image_descriptor(device
, dst
, buffer_list
, image_info
);
633 /* copy over sampler state */
635 memcpy(dst
+ 16, sampler
->state
, 16);
639 write_sampler_descriptor(struct radv_device
*device
,
641 const VkDescriptorImageInfo
*image_info
)
643 RADV_FROM_HANDLE(radv_sampler
, sampler
, image_info
->sampler
);
645 memcpy(dst
, sampler
->state
, 16);
648 void radv_UpdateDescriptorSets(
650 uint32_t descriptorWriteCount
,
651 const VkWriteDescriptorSet
* pDescriptorWrites
,
652 uint32_t descriptorCopyCount
,
653 const VkCopyDescriptorSet
* pDescriptorCopies
)
655 RADV_FROM_HANDLE(radv_device
, device
, _device
);
657 for (i
= 0; i
< descriptorWriteCount
; i
++) {
658 const VkWriteDescriptorSet
*writeset
= &pDescriptorWrites
[i
];
659 RADV_FROM_HANDLE(radv_descriptor_set
, set
, writeset
->dstSet
);
660 const struct radv_descriptor_set_binding_layout
*binding_layout
=
661 set
->layout
->binding
+ writeset
->dstBinding
;
662 uint32_t *ptr
= set
->mapped_ptr
;
663 struct radeon_winsys_bo
**buffer_list
= set
->descriptors
;
665 ptr
+= binding_layout
->offset
/ 4;
666 ptr
+= binding_layout
->size
* writeset
->dstArrayElement
/ 4;
667 buffer_list
+= binding_layout
->buffer_offset
;
668 buffer_list
+= binding_layout
->buffer_count
* writeset
->dstArrayElement
;
669 for (j
= 0; j
< writeset
->descriptorCount
; ++j
) {
670 switch(writeset
->descriptorType
) {
671 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
672 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: {
673 unsigned idx
= writeset
->dstArrayElement
+ j
;
674 idx
+= binding_layout
->dynamic_offset_offset
;
675 write_dynamic_buffer_descriptor(device
, set
->dynamic_descriptors
+ idx
,
676 buffer_list
, writeset
->pBufferInfo
+ j
);
679 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
680 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
681 write_buffer_descriptor(device
, ptr
, buffer_list
,
682 writeset
->pBufferInfo
+ j
);
684 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
685 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
686 write_texel_buffer_descriptor(device
, ptr
, buffer_list
,
687 writeset
->pTexelBufferView
[j
]);
689 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
690 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
691 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
692 write_image_descriptor(device
, ptr
, buffer_list
,
693 writeset
->pImageInfo
+ j
);
695 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
696 write_combined_image_sampler_descriptor(device
, ptr
, buffer_list
,
697 writeset
->pImageInfo
+ j
,
698 !binding_layout
->immutable_samplers
);
700 case VK_DESCRIPTOR_TYPE_SAMPLER
:
701 assert(!binding_layout
->immutable_samplers
);
702 write_sampler_descriptor(device
, ptr
,
703 writeset
->pImageInfo
+ j
);
706 unreachable("unimplemented descriptor type");
709 ptr
+= binding_layout
->size
/ 4;
710 buffer_list
+= binding_layout
->buffer_count
;
714 if (descriptorCopyCount
)
715 radv_finishme("copy descriptors");