2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include "util/mesa-sha1.h"
32 #include "anv_private.h"
35 * Descriptor set layouts.
38 VkResult
anv_CreateDescriptorSetLayout(
40 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
41 const VkAllocationCallbacks
* pAllocator
,
42 VkDescriptorSetLayout
* pSetLayout
)
44 ANV_FROM_HANDLE(anv_device
, device
, _device
);
45 struct anv_descriptor_set_layout
*set_layout
;
47 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
49 uint32_t max_binding
= 0;
50 uint32_t immutable_sampler_count
= 0;
51 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
52 max_binding
= MAX2(max_binding
, pCreateInfo
->pBindings
[j
].binding
);
53 if (pCreateInfo
->pBindings
[j
].pImmutableSamplers
)
54 immutable_sampler_count
+= pCreateInfo
->pBindings
[j
].descriptorCount
;
57 size_t size
= sizeof(struct anv_descriptor_set_layout
) +
58 (max_binding
+ 1) * sizeof(set_layout
->binding
[0]) +
59 immutable_sampler_count
* sizeof(struct anv_sampler
*);
61 set_layout
= anv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
62 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
64 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
66 /* We just allocate all the samplers at the end of the struct */
67 struct anv_sampler
**samplers
=
68 (struct anv_sampler
**)&set_layout
->binding
[max_binding
+ 1];
70 set_layout
->binding_count
= max_binding
+ 1;
71 set_layout
->shader_stages
= 0;
74 for (uint32_t b
= 0; b
<= max_binding
; b
++) {
75 /* Initialize all binding_layout entries to -1 */
76 memset(&set_layout
->binding
[b
], -1, sizeof(set_layout
->binding
[b
]));
78 set_layout
->binding
[b
].array_size
= 0;
79 set_layout
->binding
[b
].immutable_samplers
= NULL
;
82 /* Initialize all samplers to 0 */
83 memset(samplers
, 0, immutable_sampler_count
* sizeof(*samplers
));
85 uint32_t sampler_count
[MESA_SHADER_STAGES
] = { 0, };
86 uint32_t surface_count
[MESA_SHADER_STAGES
] = { 0, };
87 uint32_t image_count
[MESA_SHADER_STAGES
] = { 0, };
88 uint32_t buffer_count
= 0;
89 uint32_t dynamic_offset_count
= 0;
91 for (uint32_t j
= 0; j
< pCreateInfo
->bindingCount
; j
++) {
92 const VkDescriptorSetLayoutBinding
*binding
= &pCreateInfo
->pBindings
[j
];
93 uint32_t b
= binding
->binding
;
94 /* We temporarily store the pointer to the binding in the
95 * immutable_samplers pointer. This provides us with a quick-and-dirty
96 * way to sort the bindings by binding number.
98 set_layout
->binding
[b
].immutable_samplers
= (void *)binding
;
101 for (uint32_t b
= 0; b
<= max_binding
; b
++) {
102 const VkDescriptorSetLayoutBinding
*binding
=
103 (void *)set_layout
->binding
[b
].immutable_samplers
;
108 assert(binding
->descriptorCount
> 0);
110 set_layout
->binding
[b
].type
= binding
->descriptorType
;
112 set_layout
->binding
[b
].array_size
= binding
->descriptorCount
;
113 set_layout
->binding
[b
].descriptor_index
= set_layout
->size
;
114 set_layout
->size
+= binding
->descriptorCount
;
116 switch (binding
->descriptorType
) {
117 case VK_DESCRIPTOR_TYPE_SAMPLER
:
118 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
119 anv_foreach_stage(s
, binding
->stageFlags
) {
120 set_layout
->binding
[b
].stage
[s
].sampler_index
= sampler_count
[s
];
121 sampler_count
[s
] += binding
->descriptorCount
;
128 switch (binding
->descriptorType
) {
129 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
130 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
131 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
132 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
133 set_layout
->binding
[b
].buffer_index
= buffer_count
;
134 buffer_count
+= binding
->descriptorCount
;
137 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
138 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
139 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
140 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
141 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
142 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
143 anv_foreach_stage(s
, binding
->stageFlags
) {
144 set_layout
->binding
[b
].stage
[s
].surface_index
= surface_count
[s
];
145 surface_count
[s
] += binding
->descriptorCount
;
152 switch (binding
->descriptorType
) {
153 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
154 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
155 set_layout
->binding
[b
].dynamic_offset_index
= dynamic_offset_count
;
156 dynamic_offset_count
+= binding
->descriptorCount
;
162 switch (binding
->descriptorType
) {
163 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
164 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
165 anv_foreach_stage(s
, binding
->stageFlags
) {
166 set_layout
->binding
[b
].stage
[s
].image_index
= image_count
[s
];
167 image_count
[s
] += binding
->descriptorCount
;
174 if (binding
->pImmutableSamplers
) {
175 set_layout
->binding
[b
].immutable_samplers
= samplers
;
176 samplers
+= binding
->descriptorCount
;
178 for (uint32_t i
= 0; i
< binding
->descriptorCount
; i
++)
179 set_layout
->binding
[b
].immutable_samplers
[i
] =
180 anv_sampler_from_handle(binding
->pImmutableSamplers
[i
]);
182 set_layout
->binding
[b
].immutable_samplers
= NULL
;
185 set_layout
->shader_stages
|= binding
->stageFlags
;
188 set_layout
->buffer_count
= buffer_count
;
189 set_layout
->dynamic_offset_count
= dynamic_offset_count
;
191 *pSetLayout
= anv_descriptor_set_layout_to_handle(set_layout
);
196 void anv_DestroyDescriptorSetLayout(
198 VkDescriptorSetLayout _set_layout
,
199 const VkAllocationCallbacks
* pAllocator
)
201 ANV_FROM_HANDLE(anv_device
, device
, _device
);
202 ANV_FROM_HANDLE(anv_descriptor_set_layout
, set_layout
, _set_layout
);
204 anv_free2(&device
->alloc
, pAllocator
, set_layout
);
208 sha1_update_descriptor_set_layout(struct mesa_sha1
*ctx
,
209 const struct anv_descriptor_set_layout
*layout
)
211 size_t size
= sizeof(*layout
) +
212 sizeof(layout
->binding
[0]) * layout
->binding_count
;
213 _mesa_sha1_update(ctx
, layout
, size
);
217 * Pipeline layouts. These have nothing to do with the pipeline. They are
218 * just muttiple descriptor set layouts pasted together
221 VkResult
anv_CreatePipelineLayout(
223 const VkPipelineLayoutCreateInfo
* pCreateInfo
,
224 const VkAllocationCallbacks
* pAllocator
,
225 VkPipelineLayout
* pPipelineLayout
)
227 ANV_FROM_HANDLE(anv_device
, device
, _device
);
228 struct anv_pipeline_layout
*layout
;
230 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
);
232 layout
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*layout
), 8,
233 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
235 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
237 layout
->num_sets
= pCreateInfo
->setLayoutCount
;
239 unsigned dynamic_offset_count
= 0;
241 memset(layout
->stage
, 0, sizeof(layout
->stage
));
242 for (uint32_t set
= 0; set
< pCreateInfo
->setLayoutCount
; set
++) {
243 ANV_FROM_HANDLE(anv_descriptor_set_layout
, set_layout
,
244 pCreateInfo
->pSetLayouts
[set
]);
245 layout
->set
[set
].layout
= set_layout
;
247 layout
->set
[set
].dynamic_offset_start
= dynamic_offset_count
;
248 for (uint32_t b
= 0; b
< set_layout
->binding_count
; b
++) {
249 if (set_layout
->binding
[b
].dynamic_offset_index
< 0)
252 dynamic_offset_count
+= set_layout
->binding
[b
].array_size
;
253 for (gl_shader_stage s
= 0; s
< MESA_SHADER_STAGES
; s
++) {
254 if (set_layout
->binding
[b
].stage
[s
].surface_index
>= 0)
255 layout
->stage
[s
].has_dynamic_offsets
= true;
260 struct mesa_sha1
*ctx
= _mesa_sha1_init();
261 for (unsigned s
= 0; s
< layout
->num_sets
; s
++) {
262 sha1_update_descriptor_set_layout(ctx
, layout
->set
[s
].layout
);
263 _mesa_sha1_update(ctx
, &layout
->set
[s
].dynamic_offset_start
,
264 sizeof(layout
->set
[s
].dynamic_offset_start
));
266 _mesa_sha1_update(ctx
, &layout
->num_sets
, sizeof(layout
->num_sets
));
267 for (unsigned s
= 0; s
< MESA_SHADER_STAGES
; s
++) {
268 _mesa_sha1_update(ctx
, &layout
->stage
[s
].has_dynamic_offsets
,
269 sizeof(layout
->stage
[s
].has_dynamic_offsets
));
271 _mesa_sha1_final(ctx
, layout
->sha1
);
273 *pPipelineLayout
= anv_pipeline_layout_to_handle(layout
);
278 void anv_DestroyPipelineLayout(
280 VkPipelineLayout _pipelineLayout
,
281 const VkAllocationCallbacks
* pAllocator
)
283 ANV_FROM_HANDLE(anv_device
, device
, _device
);
284 ANV_FROM_HANDLE(anv_pipeline_layout
, pipeline_layout
, _pipelineLayout
);
286 anv_free2(&device
->alloc
, pAllocator
, pipeline_layout
);
292 * These are implemented using a big pool of memory and a free-list for the
293 * host memory allocations and a state_stream and a free list for the buffer
294 * view surface state. The spec allows us to fail to allocate due to
295 * fragmentation in all cases but two: 1) after pool reset, allocating up
296 * until the pool size with no freeing must succeed and 2) allocating and
297 * freeing only descriptor sets with the same layout. Case 1) is easy enogh,
298 * and the free lists lets us recycle blocks for case 2).
303 VkResult
anv_CreateDescriptorPool(
305 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
306 const VkAllocationCallbacks
* pAllocator
,
307 VkDescriptorPool
* pDescriptorPool
)
309 ANV_FROM_HANDLE(anv_device
, device
, _device
);
310 struct anv_descriptor_pool
*pool
;
312 uint32_t descriptor_count
= 0;
313 uint32_t buffer_count
= 0;
314 for (uint32_t i
= 0; i
< pCreateInfo
->poolSizeCount
; i
++) {
315 switch (pCreateInfo
->pPoolSizes
[i
].type
) {
316 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
317 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
318 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
319 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
320 buffer_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
322 descriptor_count
+= pCreateInfo
->pPoolSizes
[i
].descriptorCount
;
329 pCreateInfo
->maxSets
* sizeof(struct anv_descriptor_set
) +
330 descriptor_count
* sizeof(struct anv_descriptor
) +
331 buffer_count
* sizeof(struct anv_buffer_view
);
333 pool
= anv_alloc2(&device
->alloc
, pAllocator
, size
, 8,
334 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
336 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
340 pool
->free_list
= EMPTY
;
342 anv_state_stream_init(&pool
->surface_state_stream
,
343 &device
->surface_state_block_pool
);
344 pool
->surface_state_free_list
= NULL
;
346 *pDescriptorPool
= anv_descriptor_pool_to_handle(pool
);
351 void anv_DestroyDescriptorPool(
353 VkDescriptorPool _pool
,
354 const VkAllocationCallbacks
* pAllocator
)
356 ANV_FROM_HANDLE(anv_device
, device
, _device
);
357 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, _pool
);
359 anv_state_stream_finish(&pool
->surface_state_stream
);
360 anv_free2(&device
->alloc
, pAllocator
, pool
);
363 VkResult
anv_ResetDescriptorPool(
365 VkDescriptorPool descriptorPool
,
366 VkDescriptorPoolResetFlags flags
)
368 ANV_FROM_HANDLE(anv_device
, device
, _device
);
369 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, descriptorPool
);
372 pool
->free_list
= EMPTY
;
373 anv_state_stream_finish(&pool
->surface_state_stream
);
374 anv_state_stream_init(&pool
->surface_state_stream
,
375 &device
->surface_state_block_pool
);
376 pool
->surface_state_free_list
= NULL
;
381 struct pool_free_list_entry
{
387 layout_size(const struct anv_descriptor_set_layout
*layout
)
390 sizeof(struct anv_descriptor_set
) +
391 layout
->size
* sizeof(struct anv_descriptor
) +
392 layout
->buffer_count
* sizeof(struct anv_buffer_view
);
395 struct surface_state_free_list_entry
{
401 anv_descriptor_set_create(struct anv_device
*device
,
402 struct anv_descriptor_pool
*pool
,
403 const struct anv_descriptor_set_layout
*layout
,
404 struct anv_descriptor_set
**out_set
)
406 struct anv_descriptor_set
*set
;
407 const size_t size
= layout_size(layout
);
410 if (size
<= pool
->size
- pool
->next
) {
411 set
= (struct anv_descriptor_set
*) (pool
->data
+ pool
->next
);
414 struct pool_free_list_entry
*entry
;
415 uint32_t *link
= &pool
->free_list
;
416 for (uint32_t f
= pool
->free_list
; f
!= EMPTY
; f
= entry
->next
) {
417 entry
= (struct pool_free_list_entry
*) (pool
->data
+ f
);
418 if (size
<= entry
->size
) {
420 set
= (struct anv_descriptor_set
*) entry
;
428 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
431 set
->layout
= layout
;
433 (struct anv_buffer_view
*) &set
->descriptors
[layout
->size
];
434 set
->buffer_count
= layout
->buffer_count
;
436 /* By defining the descriptors to be zero now, we can later verify that
437 * a descriptor has not been populated with user data.
439 memset(set
->descriptors
, 0, sizeof(struct anv_descriptor
) * layout
->size
);
441 /* Go through and fill out immutable samplers if we have any */
442 struct anv_descriptor
*desc
= set
->descriptors
;
443 for (uint32_t b
= 0; b
< layout
->binding_count
; b
++) {
444 if (layout
->binding
[b
].immutable_samplers
) {
445 for (uint32_t i
= 0; i
< layout
->binding
[b
].array_size
; i
++) {
446 /* The type will get changed to COMBINED_IMAGE_SAMPLER in
447 * UpdateDescriptorSets if needed. However, if the descriptor
448 * set has an immutable sampler, UpdateDescriptorSets may never
449 * touch it, so we need to make sure it's 100% valid now.
451 desc
[i
] = (struct anv_descriptor
) {
452 .type
= VK_DESCRIPTOR_TYPE_SAMPLER
,
453 .sampler
= layout
->binding
[b
].immutable_samplers
[i
],
457 desc
+= layout
->binding
[b
].array_size
;
460 /* Allocate surface state for the buffer views. */
461 for (uint32_t b
= 0; b
< layout
->buffer_count
; b
++) {
462 struct surface_state_free_list_entry
*entry
=
463 pool
->surface_state_free_list
;
464 struct anv_state state
;
468 state
.offset
= entry
->offset
;
469 state
.alloc_size
= 64;
470 pool
->surface_state_free_list
= entry
->next
;
472 state
= anv_state_stream_alloc(&pool
->surface_state_stream
, 64, 64);
475 set
->buffer_views
[b
].surface_state
= state
;
484 anv_descriptor_set_destroy(struct anv_device
*device
,
485 struct anv_descriptor_pool
*pool
,
486 struct anv_descriptor_set
*set
)
488 /* Put the buffer view surface state back on the free list. */
489 for (uint32_t b
= 0; b
< set
->buffer_count
; b
++) {
490 struct surface_state_free_list_entry
*entry
=
491 set
->buffer_views
[b
].surface_state
.map
;
492 entry
->next
= pool
->surface_state_free_list
;
493 pool
->surface_state_free_list
= entry
;
496 /* Put the descriptor set allocation back on the free list. */
497 const uint32_t index
= (char *) set
- pool
->data
;
498 if (index
+ set
->size
== pool
->next
) {
501 struct pool_free_list_entry
*entry
= (struct pool_free_list_entry
*) set
;
502 entry
->next
= pool
->free_list
;
503 entry
->size
= set
->size
;
504 pool
->free_list
= (char *) entry
- pool
->data
;
508 VkResult
anv_AllocateDescriptorSets(
510 const VkDescriptorSetAllocateInfo
* pAllocateInfo
,
511 VkDescriptorSet
* pDescriptorSets
)
513 ANV_FROM_HANDLE(anv_device
, device
, _device
);
514 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, pAllocateInfo
->descriptorPool
);
516 VkResult result
= VK_SUCCESS
;
517 struct anv_descriptor_set
*set
;
520 for (i
= 0; i
< pAllocateInfo
->descriptorSetCount
; i
++) {
521 ANV_FROM_HANDLE(anv_descriptor_set_layout
, layout
,
522 pAllocateInfo
->pSetLayouts
[i
]);
524 result
= anv_descriptor_set_create(device
, pool
, layout
, &set
);
525 if (result
!= VK_SUCCESS
)
528 pDescriptorSets
[i
] = anv_descriptor_set_to_handle(set
);
531 if (result
!= VK_SUCCESS
)
532 anv_FreeDescriptorSets(_device
, pAllocateInfo
->descriptorPool
,
538 VkResult
anv_FreeDescriptorSets(
540 VkDescriptorPool descriptorPool
,
542 const VkDescriptorSet
* pDescriptorSets
)
544 ANV_FROM_HANDLE(anv_device
, device
, _device
);
545 ANV_FROM_HANDLE(anv_descriptor_pool
, pool
, descriptorPool
);
547 for (uint32_t i
= 0; i
< count
; i
++) {
548 ANV_FROM_HANDLE(anv_descriptor_set
, set
, pDescriptorSets
[i
]);
550 anv_descriptor_set_destroy(device
, pool
, set
);
556 void anv_UpdateDescriptorSets(
558 uint32_t descriptorWriteCount
,
559 const VkWriteDescriptorSet
* pDescriptorWrites
,
560 uint32_t descriptorCopyCount
,
561 const VkCopyDescriptorSet
* pDescriptorCopies
)
563 ANV_FROM_HANDLE(anv_device
, device
, _device
);
565 for (uint32_t i
= 0; i
< descriptorWriteCount
; i
++) {
566 const VkWriteDescriptorSet
*write
= &pDescriptorWrites
[i
];
567 ANV_FROM_HANDLE(anv_descriptor_set
, set
, write
->dstSet
);
568 const struct anv_descriptor_set_binding_layout
*bind_layout
=
569 &set
->layout
->binding
[write
->dstBinding
];
570 struct anv_descriptor
*desc
=
571 &set
->descriptors
[bind_layout
->descriptor_index
];
572 desc
+= write
->dstArrayElement
;
574 assert(write
->descriptorType
== bind_layout
->type
);
576 switch (write
->descriptorType
) {
577 case VK_DESCRIPTOR_TYPE_SAMPLER
:
578 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
579 ANV_FROM_HANDLE(anv_sampler
, sampler
,
580 write
->pImageInfo
[j
].sampler
);
582 desc
[j
] = (struct anv_descriptor
) {
583 .type
= VK_DESCRIPTOR_TYPE_SAMPLER
,
589 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
590 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
591 ANV_FROM_HANDLE(anv_image_view
, iview
,
592 write
->pImageInfo
[j
].imageView
);
593 ANV_FROM_HANDLE(anv_sampler
, sampler
,
594 write
->pImageInfo
[j
].sampler
);
596 desc
[j
].type
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
;
597 desc
[j
].image_view
= iview
;
599 /* If this descriptor has an immutable sampler, we don't want
603 desc
[j
].sampler
= sampler
;
607 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
608 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
609 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
610 ANV_FROM_HANDLE(anv_image_view
, iview
,
611 write
->pImageInfo
[j
].imageView
);
613 desc
[j
] = (struct anv_descriptor
) {
614 .type
= write
->descriptorType
,
620 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
621 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
622 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
623 ANV_FROM_HANDLE(anv_buffer_view
, bview
,
624 write
->pTexelBufferView
[j
]);
626 desc
[j
] = (struct anv_descriptor
) {
627 .type
= write
->descriptorType
,
628 .buffer_view
= bview
,
633 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
:
634 anv_finishme("input attachments not implemented");
637 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
638 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
639 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
640 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
641 for (uint32_t j
= 0; j
< write
->descriptorCount
; j
++) {
642 assert(write
->pBufferInfo
[j
].buffer
);
643 ANV_FROM_HANDLE(anv_buffer
, buffer
, write
->pBufferInfo
[j
].buffer
);
646 struct anv_buffer_view
*view
=
647 &set
->buffer_views
[bind_layout
->buffer_index
];
648 view
+= write
->dstArrayElement
+ j
;
651 anv_isl_format_for_descriptor_type(write
->descriptorType
);
652 view
->bo
= buffer
->bo
;
653 view
->offset
= buffer
->offset
+ write
->pBufferInfo
[j
].offset
;
655 /* For buffers with dynamic offsets, we use the full possible
656 * range in the surface state and do the actual range-checking
659 if (bind_layout
->dynamic_offset_index
>= 0 ||
660 write
->pBufferInfo
[j
].range
== VK_WHOLE_SIZE
)
661 view
->range
= buffer
->size
- write
->pBufferInfo
[j
].offset
;
663 view
->range
= write
->pBufferInfo
[j
].range
;
665 anv_fill_buffer_surface_state(device
, view
->surface_state
,
667 view
->offset
, view
->range
, 1);
669 desc
[j
] = (struct anv_descriptor
) {
670 .type
= write
->descriptorType
,
681 for (uint32_t i
= 0; i
< descriptorCopyCount
; i
++) {
682 const VkCopyDescriptorSet
*copy
= &pDescriptorCopies
[i
];
683 ANV_FROM_HANDLE(anv_descriptor_set
, src
, copy
->dstSet
);
684 ANV_FROM_HANDLE(anv_descriptor_set
, dst
, copy
->dstSet
);
686 const struct anv_descriptor_set_binding_layout
*src_layout
=
687 &src
->layout
->binding
[copy
->srcBinding
];
688 struct anv_descriptor
*src_desc
=
689 &src
->descriptors
[src_layout
->descriptor_index
];
690 src_desc
+= copy
->srcArrayElement
;
692 const struct anv_descriptor_set_binding_layout
*dst_layout
=
693 &dst
->layout
->binding
[copy
->dstBinding
];
694 struct anv_descriptor
*dst_desc
=
695 &dst
->descriptors
[dst_layout
->descriptor_index
];
696 dst_desc
+= copy
->dstArrayElement
;
698 for (uint32_t j
= 0; j
< copy
->descriptorCount
; j
++)
699 dst_desc
[j
] = src_desc
[j
];