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
33 anv_env_get_int(const char *name
)
35 const char *val
= getenv(name
);
40 return strtol(val
, NULL
, 0);
44 fill_physical_device(struct anv_physical_device
*device
,
45 struct anv_instance
*instance
,
50 fd
= open("/dev/dri/renderD128", O_RDWR
| O_CLOEXEC
);
52 return vk_error(VK_ERROR_UNAVAILABLE
);
54 device
->instance
= instance
;
57 device
->chipset_id
= anv_env_get_int("INTEL_DEVID_OVERRIDE");
58 device
->no_hw
= false;
59 if (device
->chipset_id
) {
60 /* INTEL_DEVID_OVERRIDE implies INTEL_NO_HW. */
63 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
65 if (!device
->chipset_id
)
68 device
->name
= brw_get_device_name(device
->chipset_id
);
69 device
->info
= brw_get_device_info(device
->chipset_id
, -1);
73 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
))
76 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
))
79 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_LLC
))
82 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CONSTANTS
))
92 return vk_error(VK_ERROR_UNAVAILABLE
);
95 static void *default_alloc(
99 VkSystemAllocType allocType
)
104 static void default_free(
111 static const VkAllocCallbacks default_alloc_callbacks
= {
113 .pfnAlloc
= default_alloc
,
114 .pfnFree
= default_free
117 VkResult
anv_CreateInstance(
118 const VkInstanceCreateInfo
* pCreateInfo
,
119 VkInstance
* pInstance
)
121 struct anv_instance
*instance
;
122 const VkAllocCallbacks
*alloc_callbacks
= &default_alloc_callbacks
;
123 void *user_data
= NULL
;
126 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
128 if (pCreateInfo
->pAllocCb
) {
129 alloc_callbacks
= pCreateInfo
->pAllocCb
;
130 user_data
= pCreateInfo
->pAllocCb
->pUserData
;
132 instance
= alloc_callbacks
->pfnAlloc(user_data
, sizeof(*instance
), 8,
133 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
135 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
137 instance
->pAllocUserData
= alloc_callbacks
->pUserData
;
138 instance
->pfnAlloc
= alloc_callbacks
->pfnAlloc
;
139 instance
->pfnFree
= alloc_callbacks
->pfnFree
;
140 instance
->apiVersion
= pCreateInfo
->pAppInfo
->apiVersion
;
142 instance
->physicalDeviceCount
= 0;
143 result
= fill_physical_device(&instance
->physicalDevice
,
144 instance
, "/dev/dri/renderD128");
146 if (result
!= VK_SUCCESS
)
149 instance
->physicalDeviceCount
++;
150 *pInstance
= (VkInstance
) instance
;
155 VkResult
anv_DestroyInstance(
156 VkInstance _instance
)
158 struct anv_instance
*instance
= (struct anv_instance
*) _instance
;
160 instance
->pfnFree(instance
->pAllocUserData
, instance
);
165 VkResult
anv_EnumeratePhysicalDevices(
166 VkInstance _instance
,
167 uint32_t* pPhysicalDeviceCount
,
168 VkPhysicalDevice
* pPhysicalDevices
)
170 struct anv_instance
*instance
= (struct anv_instance
*) _instance
;
172 if (*pPhysicalDeviceCount
>= 1)
173 pPhysicalDevices
[0] = (VkPhysicalDevice
) &instance
->physicalDevice
;
174 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
179 VkResult
anv_GetPhysicalDeviceInfo(
180 VkPhysicalDevice physicalDevice
,
181 VkPhysicalDeviceInfoType infoType
,
185 struct anv_physical_device
*device
= (struct anv_physical_device
*) physicalDevice
;
186 VkPhysicalDeviceProperties
*properties
;
187 VkPhysicalDevicePerformance
*performance
;
188 VkPhysicalDeviceQueueProperties
*queue_properties
;
189 VkPhysicalDeviceMemoryProperties
*memory_properties
;
190 VkDisplayPropertiesWSI
*display_properties
;
191 uint64_t ns_per_tick
= 80;
193 switch ((uint32_t) infoType
) {
194 case VK_PHYSICAL_DEVICE_INFO_TYPE_PROPERTIES
:
197 *pDataSize
= sizeof(*properties
);
201 properties
->apiVersion
= 1;
202 properties
->driverVersion
= 1;
203 properties
->vendorId
= 0x8086;
204 properties
->deviceId
= device
->chipset_id
;
205 properties
->deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
;
206 strcpy(properties
->deviceName
, device
->name
);
207 properties
->maxInlineMemoryUpdateSize
= 0;
208 properties
->maxBoundDescriptorSets
= MAX_SETS
;
209 properties
->maxThreadGroupSize
= 512;
210 properties
->timestampFrequency
= 1000 * 1000 * 1000 / ns_per_tick
;
211 properties
->multiColorAttachmentClears
= true;
212 properties
->maxDescriptorSets
= 8;
213 properties
->maxViewports
= 16;
214 properties
->maxColorAttachments
= 8;
217 case VK_PHYSICAL_DEVICE_INFO_TYPE_PERFORMANCE
:
220 *pDataSize
= sizeof(*performance
);
224 performance
->maxDeviceClock
= 1.0;
225 performance
->aluPerClock
= 1.0;
226 performance
->texPerClock
= 1.0;
227 performance
->primsPerClock
= 1.0;
228 performance
->pixelsPerClock
= 1.0;
231 case VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES
:
232 queue_properties
= pData
;
234 *pDataSize
= sizeof(*queue_properties
);
238 queue_properties
->queueFlags
= 0;
239 queue_properties
->queueCount
= 1;
240 queue_properties
->maxAtomicCounters
= 0;
241 queue_properties
->supportsTimestamps
= true;
242 queue_properties
->maxMemReferences
= 256;
245 case VK_PHYSICAL_DEVICE_INFO_TYPE_MEMORY_PROPERTIES
:
246 memory_properties
= pData
;
248 *pDataSize
= sizeof(*memory_properties
);
252 memory_properties
->supportsMigration
= false;
253 memory_properties
->supportsPinning
= false;
256 case VK_PHYSICAL_DEVICE_INFO_TYPE_DISPLAY_PROPERTIES_WSI
:
257 anv_finishme("VK_PHYSICAL_DEVICE_INFO_TYPE_DISPLAY_PROPERTIES_WSI");
259 *pDataSize
= sizeof(*display_properties
);
263 display_properties
= pData
;
264 display_properties
->display
= 0;
265 display_properties
->physicalResolution
= (VkExtent2D
) { 0, 0 };
268 case VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PRESENT_PROPERTIES_WSI
:
269 anv_finishme("VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PRESENT_PROPERTIES_WSI");
274 return VK_UNSUPPORTED
;
279 void * vkGetProcAddr(
280 VkPhysicalDevice physicalDevice
,
283 return anv_lookup_entrypoint(pName
);
287 parse_debug_flags(struct anv_device
*device
)
289 const char *debug
, *p
, *end
;
291 debug
= getenv("INTEL_DEBUG");
292 device
->dump_aub
= false;
294 for (p
= debug
; *p
; p
= end
+ 1) {
295 end
= strchrnul(p
, ',');
296 if (end
- p
== 3 && memcmp(p
, "aub", 3) == 0)
297 device
->dump_aub
= true;
298 if (end
- p
== 5 && memcmp(p
, "no_hw", 5) == 0)
299 device
->no_hw
= true;
306 static const uint32_t BATCH_SIZE
= 8192;
308 VkResult
anv_CreateDevice(
309 VkPhysicalDevice _physicalDevice
,
310 const VkDeviceCreateInfo
* pCreateInfo
,
313 struct anv_physical_device
*physicalDevice
=
314 (struct anv_physical_device
*) _physicalDevice
;
315 struct anv_instance
*instance
= physicalDevice
->instance
;
316 struct anv_device
*device
;
318 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
320 device
= instance
->pfnAlloc(instance
->pAllocUserData
,
322 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
324 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
326 device
->no_hw
= physicalDevice
->no_hw
;
327 parse_debug_flags(device
);
329 device
->instance
= physicalDevice
->instance
;
330 device
->fd
= open("/dev/dri/renderD128", O_RDWR
| O_CLOEXEC
);
331 if (device
->fd
== -1)
334 device
->context_id
= anv_gem_create_context(device
);
335 if (device
->context_id
== -1)
338 anv_bo_pool_init(&device
->batch_bo_pool
, device
, BATCH_SIZE
);
340 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 2048);
342 anv_state_pool_init(&device
->dynamic_state_pool
,
343 &device
->dynamic_state_block_pool
);
345 anv_block_pool_init(&device
->instruction_block_pool
, device
, 2048);
346 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 2048);
349 /* Binding table pointers are only 16 bits so we have to make sure that
350 * they get allocated at the beginning of the surface state BO. To
351 * handle this, we create a separate block pool that works out of the
352 * first 64 KB of the surface state BO.
354 anv_block_pool_init_slave(&device
->binding_table_block_pool
,
355 &device
->surface_state_block_pool
, 32);
357 anv_state_pool_init(&device
->surface_state_pool
,
358 &device
->surface_state_block_pool
);
360 device
->compiler
= anv_compiler_create(device
->fd
);
361 device
->aub_writer
= NULL
;
363 device
->info
= *physicalDevice
->info
;
365 pthread_mutex_init(&device
->mutex
, NULL
);
367 anv_device_init_meta(device
);
369 *pDevice
= (VkDevice
) device
;
376 anv_device_free(device
, device
);
378 return vk_error(VK_ERROR_UNAVAILABLE
);
381 VkResult
anv_DestroyDevice(
384 struct anv_device
*device
= (struct anv_device
*) _device
;
386 anv_compiler_destroy(device
->compiler
);
389 anv_bo_pool_finish(&device
->batch_bo_pool
);
390 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
391 anv_block_pool_finish(&device
->instruction_block_pool
);
392 anv_block_pool_finish(&device
->surface_state_block_pool
);
396 if (device
->aub_writer
)
397 anv_aub_writer_destroy(device
->aub_writer
);
399 anv_device_free(device
, device
);
404 VkResult
anv_GetGlobalExtensionInfo(
405 VkExtensionInfoType infoType
,
406 uint32_t extensionIndex
,
410 static const VkExtensionProperties extensions
[] = {
412 .extName
= "VK_WSI_LunarG",
416 uint32_t count
= ARRAY_SIZE(extensions
);
419 case VK_EXTENSION_INFO_TYPE_COUNT
:
420 memcpy(pData
, &count
, sizeof(count
));
421 *pDataSize
= sizeof(count
);
424 case VK_EXTENSION_INFO_TYPE_PROPERTIES
:
425 if (extensionIndex
>= count
)
426 return vk_error(VK_ERROR_INVALID_EXTENSION
);
428 memcpy(pData
, &extensions
[extensionIndex
], sizeof(extensions
[0]));
429 *pDataSize
= sizeof(extensions
[0]);
433 return VK_UNSUPPORTED
;
437 VkResult
anv_GetPhysicalDeviceExtensionInfo(
438 VkPhysicalDevice physicalDevice
,
439 VkExtensionInfoType infoType
,
440 uint32_t extensionIndex
,
447 case VK_EXTENSION_INFO_TYPE_COUNT
:
456 case VK_EXTENSION_INFO_TYPE_PROPERTIES
:
457 return vk_error(VK_ERROR_INVALID_EXTENSION
);
460 return VK_UNSUPPORTED
;
464 VkResult
anv_EnumerateLayers(
465 VkPhysicalDevice physicalDevice
,
466 size_t maxStringSize
,
468 char* const* pOutLayers
,
476 VkResult
anv_GetDeviceQueue(
478 uint32_t queueNodeIndex
,
482 struct anv_device
*device
= (struct anv_device
*) _device
;
483 struct anv_queue
*queue
;
485 /* FIXME: Should allocate these at device create time. */
487 queue
= anv_device_alloc(device
, sizeof(*queue
), 8,
488 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
490 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
492 queue
->device
= device
;
493 queue
->pool
= &device
->surface_state_pool
;
495 queue
->completed_serial
= anv_state_pool_alloc(queue
->pool
, 4, 4);
496 *(uint32_t *)queue
->completed_serial
.map
= 0;
497 queue
->next_serial
= 1;
499 *pQueue
= (VkQueue
) queue
;
505 anv_reloc_list_init(struct anv_reloc_list
*list
, struct anv_device
*device
)
507 list
->num_relocs
= 0;
508 list
->array_length
= 256;
510 anv_device_alloc(device
, list
->array_length
* sizeof(*list
->relocs
), 8,
511 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
513 if (list
->relocs
== NULL
)
514 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
517 anv_device_alloc(device
, list
->array_length
* sizeof(*list
->reloc_bos
), 8,
518 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
520 if (list
->relocs
== NULL
) {
521 anv_device_free(device
, list
->relocs
);
522 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
529 anv_reloc_list_finish(struct anv_reloc_list
*list
, struct anv_device
*device
)
531 anv_device_free(device
, list
->relocs
);
532 anv_device_free(device
, list
->reloc_bos
);
536 anv_reloc_list_grow(struct anv_reloc_list
*list
, struct anv_device
*device
,
537 size_t num_additional_relocs
)
539 if (list
->num_relocs
+ num_additional_relocs
<= list
->array_length
)
542 size_t new_length
= list
->array_length
* 2;
543 while (new_length
< list
->num_relocs
+ num_additional_relocs
)
546 struct drm_i915_gem_relocation_entry
*new_relocs
=
547 anv_device_alloc(device
, new_length
* sizeof(*list
->relocs
), 8,
548 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
549 if (new_relocs
== NULL
)
550 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
552 struct anv_bo
**new_reloc_bos
=
553 anv_device_alloc(device
, new_length
* sizeof(*list
->reloc_bos
), 8,
554 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
555 if (new_relocs
== NULL
) {
556 anv_device_free(device
, new_relocs
);
557 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
560 memcpy(new_relocs
, list
->relocs
, list
->num_relocs
* sizeof(*list
->relocs
));
561 memcpy(new_reloc_bos
, list
->reloc_bos
,
562 list
->num_relocs
* sizeof(*list
->reloc_bos
));
564 anv_device_free(device
, list
->relocs
);
565 anv_device_free(device
, list
->reloc_bos
);
567 list
->relocs
= new_relocs
;
568 list
->reloc_bos
= new_reloc_bos
;
574 anv_batch_bo_create(struct anv_device
*device
, struct anv_batch_bo
**bbo_out
)
578 struct anv_batch_bo
*bbo
=
579 anv_device_alloc(device
, sizeof(*bbo
), 8, VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
581 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
584 bbo
->prev_batch_bo
= NULL
;
586 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &bbo
->bo
);
587 if (result
!= VK_SUCCESS
) {
588 anv_device_free(device
, bbo
);
598 anv_batch_bo_start(struct anv_batch_bo
*bbo
, struct anv_batch
*batch
,
599 size_t batch_padding
)
601 batch
->next
= batch
->start
= bbo
->bo
.map
;
602 batch
->end
= bbo
->bo
.map
+ bbo
->bo
.size
- batch_padding
;
603 bbo
->first_reloc
= batch
->relocs
.num_relocs
;
607 anv_batch_bo_finish(struct anv_batch_bo
*bbo
, struct anv_batch
*batch
)
609 assert(batch
->start
== bbo
->bo
.map
);
610 bbo
->length
= batch
->next
- batch
->start
;
611 bbo
->num_relocs
= batch
->relocs
.num_relocs
- bbo
->first_reloc
;
615 anv_batch_bo_destroy(struct anv_batch_bo
*bbo
, struct anv_device
*device
)
617 anv_bo_pool_free(&device
->batch_bo_pool
, &bbo
->bo
);
618 anv_device_free(device
, bbo
);
622 anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
)
624 if (batch
->next
+ num_dwords
* 4 > batch
->end
)
625 batch
->extend_cb(batch
, batch
->user_data
);
627 void *p
= batch
->next
;
629 batch
->next
+= num_dwords
* 4;
630 assert(batch
->next
<= batch
->end
);
636 anv_reloc_list_append(struct anv_reloc_list
*list
, struct anv_device
*device
,
637 struct anv_reloc_list
*other
, uint32_t offset
)
639 anv_reloc_list_grow(list
, device
, other
->num_relocs
);
640 /* TODO: Handle failure */
642 memcpy(&list
->relocs
[list
->num_relocs
], &other
->relocs
[0],
643 other
->num_relocs
* sizeof(other
->relocs
[0]));
644 memcpy(&list
->reloc_bos
[list
->num_relocs
], &other
->reloc_bos
[0],
645 other
->num_relocs
* sizeof(other
->reloc_bos
[0]));
647 for (uint32_t i
= 0; i
< other
->num_relocs
; i
++)
648 list
->relocs
[i
+ list
->num_relocs
].offset
+= offset
;
650 list
->num_relocs
+= other
->num_relocs
;
654 anv_reloc_list_add(struct anv_reloc_list
*list
, struct anv_device
*device
,
655 uint32_t offset
, struct anv_bo
*target_bo
, uint32_t delta
)
657 struct drm_i915_gem_relocation_entry
*entry
;
660 anv_reloc_list_grow(list
, device
, 1);
661 /* TODO: Handle failure */
663 /* XXX: Can we use I915_EXEC_HANDLE_LUT? */
664 index
= list
->num_relocs
++;
665 list
->reloc_bos
[index
] = target_bo
;
666 entry
= &list
->relocs
[index
];
667 entry
->target_handle
= target_bo
->gem_handle
;
668 entry
->delta
= delta
;
669 entry
->offset
= offset
;
670 entry
->presumed_offset
= target_bo
->offset
;
671 entry
->read_domains
= 0;
672 entry
->write_domain
= 0;
674 return target_bo
->offset
+ delta
;
678 anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
)
680 uint32_t size
, offset
;
682 size
= other
->next
- other
->start
;
683 assert(size
% 4 == 0);
685 if (batch
->next
+ size
> batch
->end
)
686 batch
->extend_cb(batch
, batch
->user_data
);
688 assert(batch
->next
+ size
<= batch
->end
);
690 memcpy(batch
->next
, other
->start
, size
);
692 offset
= batch
->next
- batch
->start
;
693 anv_reloc_list_append(&batch
->relocs
, batch
->device
,
694 &other
->relocs
, offset
);
700 anv_batch_emit_reloc(struct anv_batch
*batch
,
701 void *location
, struct anv_bo
*bo
, uint32_t delta
)
703 return anv_reloc_list_add(&batch
->relocs
, batch
->device
,
704 location
- batch
->start
, bo
, delta
);
707 VkResult
anv_QueueSubmit(
709 uint32_t cmdBufferCount
,
710 const VkCmdBuffer
* pCmdBuffers
,
713 struct anv_queue
*queue
= (struct anv_queue
*) _queue
;
714 struct anv_device
*device
= queue
->device
;
715 struct anv_fence
*fence
= (struct anv_fence
*) _fence
;
718 for (uint32_t i
= 0; i
< cmdBufferCount
; i
++) {
719 struct anv_cmd_buffer
*cmd_buffer
=
720 (struct anv_cmd_buffer
*) pCmdBuffers
[i
];
722 if (device
->dump_aub
)
723 anv_cmd_buffer_dump(cmd_buffer
);
725 if (!device
->no_hw
) {
726 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf
);
728 return vk_error(VK_ERROR_UNKNOWN
);
731 ret
= anv_gem_execbuffer(device
, &fence
->execbuf
);
733 return vk_error(VK_ERROR_UNKNOWN
);
736 for (uint32_t i
= 0; i
< cmd_buffer
->bo_count
; i
++)
737 cmd_buffer
->exec2_bos
[i
]->offset
= cmd_buffer
->exec2_objects
[i
].offset
;
739 *(uint32_t *)queue
->completed_serial
.map
= cmd_buffer
->serial
;
746 VkResult
anv_QueueAddMemReferences(
749 const VkDeviceMemory
* pMems
)
754 VkResult
anv_QueueRemoveMemReferences(
757 const VkDeviceMemory
* pMems
)
762 VkResult
anv_QueueWaitIdle(
765 struct anv_queue
*queue
= (struct anv_queue
*) _queue
;
767 return vkDeviceWaitIdle((VkDevice
) queue
->device
);
770 VkResult
anv_DeviceWaitIdle(
773 struct anv_device
*device
= (struct anv_device
*) _device
;
774 struct anv_state state
;
775 struct anv_batch batch
;
776 struct drm_i915_gem_execbuffer2 execbuf
;
777 struct drm_i915_gem_exec_object2 exec2_objects
[1];
778 struct anv_bo
*bo
= NULL
;
783 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, 32, 32);
784 bo
= &device
->dynamic_state_pool
.block_pool
->bo
;
785 batch
.start
= batch
.next
= state
.map
;
786 batch
.end
= state
.map
+ 32;
787 anv_batch_emit(&batch
, GEN8_MI_BATCH_BUFFER_END
);
788 anv_batch_emit(&batch
, GEN8_MI_NOOP
);
790 exec2_objects
[0].handle
= bo
->gem_handle
;
791 exec2_objects
[0].relocation_count
= 0;
792 exec2_objects
[0].relocs_ptr
= 0;
793 exec2_objects
[0].alignment
= 0;
794 exec2_objects
[0].offset
= bo
->offset
;
795 exec2_objects
[0].flags
= 0;
796 exec2_objects
[0].rsvd1
= 0;
797 exec2_objects
[0].rsvd2
= 0;
799 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
800 execbuf
.buffer_count
= 1;
801 execbuf
.batch_start_offset
= state
.offset
;
802 execbuf
.batch_len
= batch
.next
- state
.map
;
803 execbuf
.cliprects_ptr
= 0;
804 execbuf
.num_cliprects
= 0;
809 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
810 execbuf
.rsvd1
= device
->context_id
;
813 if (!device
->no_hw
) {
814 ret
= anv_gem_execbuffer(device
, &execbuf
);
816 result
= vk_error(VK_ERROR_UNKNOWN
);
821 ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
823 result
= vk_error(VK_ERROR_UNKNOWN
);
828 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
833 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
839 anv_device_alloc(struct anv_device
* device
,
842 VkSystemAllocType allocType
)
844 return device
->instance
->pfnAlloc(device
->instance
->pAllocUserData
,
851 anv_device_free(struct anv_device
* device
,
854 return device
->instance
->pfnFree(device
->instance
->pAllocUserData
,
859 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
861 bo
->gem_handle
= anv_gem_create(device
, size
);
863 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
873 VkResult
anv_AllocMemory(
875 const VkMemoryAllocInfo
* pAllocInfo
,
876 VkDeviceMemory
* pMem
)
878 struct anv_device
*device
= (struct anv_device
*) _device
;
879 struct anv_device_memory
*mem
;
882 assert(pAllocInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO
);
884 mem
= anv_device_alloc(device
, sizeof(*mem
), 8,
885 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
887 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
889 result
= anv_bo_init_new(&mem
->bo
, device
, pAllocInfo
->allocationSize
);
890 if (result
!= VK_SUCCESS
)
893 *pMem
= (VkDeviceMemory
) mem
;
898 anv_device_free(device
, mem
);
903 VkResult
anv_FreeMemory(
907 struct anv_device
*device
= (struct anv_device
*) _device
;
908 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
911 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
913 if (mem
->bo
.gem_handle
!= 0)
914 anv_gem_close(device
, mem
->bo
.gem_handle
);
916 anv_device_free(device
, mem
);
921 VkResult
anv_SetMemoryPriority(
924 VkMemoryPriority priority
)
929 VkResult
anv_MapMemory(
934 VkMemoryMapFlags flags
,
937 struct anv_device
*device
= (struct anv_device
*) _device
;
938 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
940 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
941 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
942 * at a time is valid. We could just mmap up front and return an offset
943 * pointer here, but that may exhaust virtual memory on 32 bit
946 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
, offset
, size
);
947 mem
->map_size
= size
;
954 VkResult
anv_UnmapMemory(
958 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
960 anv_gem_munmap(mem
->map
, mem
->map_size
);
965 VkResult
anv_FlushMappedMemory(
971 /* clflush here for !llc platforms */
976 VkResult
anv_PinSystemMemory(
980 VkDeviceMemory
* pMem
)
985 VkResult
anv_GetMultiDeviceCompatibility(
986 VkPhysicalDevice physicalDevice0
,
987 VkPhysicalDevice physicalDevice1
,
988 VkPhysicalDeviceCompatibilityInfo
* pInfo
)
990 return VK_UNSUPPORTED
;
993 VkResult
anv_OpenSharedMemory(
995 const VkMemoryOpenInfo
* pOpenInfo
,
996 VkDeviceMemory
* pMem
)
998 return VK_UNSUPPORTED
;
1001 VkResult
anv_OpenSharedSemaphore(
1003 const VkSemaphoreOpenInfo
* pOpenInfo
,
1004 VkSemaphore
* pSemaphore
)
1006 return VK_UNSUPPORTED
;
1009 VkResult
anv_OpenPeerMemory(
1011 const VkPeerMemoryOpenInfo
* pOpenInfo
,
1012 VkDeviceMemory
* pMem
)
1014 return VK_UNSUPPORTED
;
1017 VkResult
anv_OpenPeerImage(
1019 const VkPeerImageOpenInfo
* pOpenInfo
,
1021 VkDeviceMemory
* pMem
)
1023 return VK_UNSUPPORTED
;
1026 VkResult
anv_DestroyObject(
1028 VkObjectType objType
,
1031 struct anv_device
*device
= (struct anv_device
*) _device
;
1032 struct anv_object
*object
= (struct anv_object
*) _object
;
1035 case VK_OBJECT_TYPE_INSTANCE
:
1036 return anv_DestroyInstance((VkInstance
) _object
);
1038 case VK_OBJECT_TYPE_PHYSICAL_DEVICE
:
1039 /* We don't want to actually destroy physical devices */
1042 case VK_OBJECT_TYPE_DEVICE
:
1043 assert(_device
== (VkDevice
) _object
);
1044 return anv_DestroyDevice((VkDevice
) _object
);
1046 case VK_OBJECT_TYPE_QUEUE
:
1050 case VK_OBJECT_TYPE_DEVICE_MEMORY
:
1051 return anv_FreeMemory(_device
, (VkDeviceMemory
) _object
);
1053 case VK_OBJECT_TYPE_DESCRIPTOR_POOL
:
1054 /* These are just dummys anyway, so we don't need to destroy them */
1057 case VK_OBJECT_TYPE_BUFFER
:
1058 case VK_OBJECT_TYPE_BUFFER_VIEW
:
1059 case VK_OBJECT_TYPE_IMAGE
:
1060 case VK_OBJECT_TYPE_IMAGE_VIEW
:
1061 case VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW
:
1062 case VK_OBJECT_TYPE_DEPTH_STENCIL_VIEW
:
1063 case VK_OBJECT_TYPE_SHADER
:
1064 case VK_OBJECT_TYPE_PIPELINE_LAYOUT
:
1065 case VK_OBJECT_TYPE_SAMPLER
:
1066 case VK_OBJECT_TYPE_DESCRIPTOR_SET
:
1067 case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT
:
1068 case VK_OBJECT_TYPE_DYNAMIC_RS_STATE
:
1069 case VK_OBJECT_TYPE_DYNAMIC_CB_STATE
:
1070 case VK_OBJECT_TYPE_DYNAMIC_DS_STATE
:
1071 case VK_OBJECT_TYPE_RENDER_PASS
:
1072 /* These are trivially destroyable */
1073 anv_device_free(device
, (void *) _object
);
1076 case VK_OBJECT_TYPE_COMMAND_BUFFER
:
1077 case VK_OBJECT_TYPE_PIPELINE
:
1078 case VK_OBJECT_TYPE_DYNAMIC_VP_STATE
:
1079 case VK_OBJECT_TYPE_FENCE
:
1080 case VK_OBJECT_TYPE_QUERY_POOL
:
1081 case VK_OBJECT_TYPE_FRAMEBUFFER
:
1082 (object
->destructor
)(device
, object
, objType
);
1085 case VK_OBJECT_TYPE_SEMAPHORE
:
1086 case VK_OBJECT_TYPE_EVENT
:
1087 stub_return(VK_UNSUPPORTED
);
1090 unreachable("Invalid object type");
1095 fill_memory_requirements(
1096 VkObjectType objType
,
1098 VkMemoryRequirements
* memory_requirements
)
1100 struct anv_buffer
*buffer
;
1101 struct anv_image
*image
;
1103 memory_requirements
->memPropsAllowed
=
1104 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1105 VK_MEMORY_PROPERTY_HOST_DEVICE_COHERENT_BIT
|
1106 /* VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT | */
1107 VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT
|
1108 VK_MEMORY_PROPERTY_PREFER_HOST_LOCAL
|
1109 VK_MEMORY_PROPERTY_SHAREABLE_BIT
;
1111 memory_requirements
->memPropsRequired
= 0;
1114 case VK_OBJECT_TYPE_BUFFER
:
1115 buffer
= (struct anv_buffer
*) object
;
1116 memory_requirements
->size
= buffer
->size
;
1117 memory_requirements
->alignment
= 16;
1119 case VK_OBJECT_TYPE_IMAGE
:
1120 image
= (struct anv_image
*) object
;
1121 memory_requirements
->size
= image
->size
;
1122 memory_requirements
->alignment
= image
->alignment
;
1125 memory_requirements
->size
= 0;
1131 get_allocation_count(VkObjectType objType
)
1134 case VK_OBJECT_TYPE_BUFFER
:
1135 case VK_OBJECT_TYPE_IMAGE
:
1142 VkResult
anv_GetObjectInfo(
1144 VkObjectType objType
,
1146 VkObjectInfoType infoType
,
1150 VkMemoryRequirements memory_requirements
;
1154 case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS
:
1155 *pDataSize
= sizeof(memory_requirements
);
1159 fill_memory_requirements(objType
, object
, pData
);
1162 case VK_OBJECT_INFO_TYPE_MEMORY_ALLOCATION_COUNT
:
1163 *pDataSize
= sizeof(count
);
1168 *count
= get_allocation_count(objType
);
1172 return VK_UNSUPPORTED
;
1177 VkResult
anv_QueueBindObjectMemory(
1179 VkObjectType objType
,
1181 uint32_t allocationIdx
,
1182 VkDeviceMemory _mem
,
1183 VkDeviceSize memOffset
)
1185 struct anv_buffer
*buffer
;
1186 struct anv_image
*image
;
1187 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
1190 case VK_OBJECT_TYPE_BUFFER
:
1191 buffer
= (struct anv_buffer
*) object
;
1192 buffer
->bo
= &mem
->bo
;
1193 buffer
->offset
= memOffset
;
1195 case VK_OBJECT_TYPE_IMAGE
:
1196 image
= (struct anv_image
*) object
;
1197 image
->bo
= &mem
->bo
;
1198 image
->offset
= memOffset
;
1207 VkResult
anv_QueueBindObjectMemoryRange(
1209 VkObjectType objType
,
1211 uint32_t allocationIdx
,
1212 VkDeviceSize rangeOffset
,
1213 VkDeviceSize rangeSize
,
1215 VkDeviceSize memOffset
)
1217 stub_return(VK_UNSUPPORTED
);
1220 VkResult
anv_QueueBindImageMemoryRange(
1223 uint32_t allocationIdx
,
1224 const VkImageMemoryBindInfo
* pBindInfo
,
1226 VkDeviceSize memOffset
)
1228 stub_return(VK_UNSUPPORTED
);
1232 anv_fence_destroy(struct anv_device
*device
,
1233 struct anv_object
*object
,
1234 VkObjectType obj_type
)
1236 struct anv_fence
*fence
= (struct anv_fence
*) object
;
1238 assert(obj_type
== VK_OBJECT_TYPE_FENCE
);
1240 anv_gem_munmap(fence
->bo
.map
, fence
->bo
.size
);
1241 anv_gem_close(device
, fence
->bo
.gem_handle
);
1242 anv_device_free(device
, fence
);
1245 VkResult
anv_CreateFence(
1247 const VkFenceCreateInfo
* pCreateInfo
,
1250 struct anv_device
*device
= (struct anv_device
*) _device
;
1251 struct anv_fence
*fence
;
1252 struct anv_batch batch
;
1255 const uint32_t fence_size
= 128;
1257 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1259 fence
= anv_device_alloc(device
, sizeof(*fence
), 8,
1260 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1262 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1264 result
= anv_bo_init_new(&fence
->bo
, device
, fence_size
);
1265 if (result
!= VK_SUCCESS
)
1268 fence
->base
.destructor
= anv_fence_destroy
;
1271 anv_gem_mmap(device
, fence
->bo
.gem_handle
, 0, fence
->bo
.size
);
1272 batch
.next
= batch
.start
= fence
->bo
.map
;
1273 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1274 anv_batch_emit(&batch
, GEN8_MI_BATCH_BUFFER_END
);
1275 anv_batch_emit(&batch
, GEN8_MI_NOOP
);
1277 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1278 fence
->exec2_objects
[0].relocation_count
= 0;
1279 fence
->exec2_objects
[0].relocs_ptr
= 0;
1280 fence
->exec2_objects
[0].alignment
= 0;
1281 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1282 fence
->exec2_objects
[0].flags
= 0;
1283 fence
->exec2_objects
[0].rsvd1
= 0;
1284 fence
->exec2_objects
[0].rsvd2
= 0;
1286 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1287 fence
->execbuf
.buffer_count
= 1;
1288 fence
->execbuf
.batch_start_offset
= 0;
1289 fence
->execbuf
.batch_len
= batch
.next
- fence
->bo
.map
;
1290 fence
->execbuf
.cliprects_ptr
= 0;
1291 fence
->execbuf
.num_cliprects
= 0;
1292 fence
->execbuf
.DR1
= 0;
1293 fence
->execbuf
.DR4
= 0;
1295 fence
->execbuf
.flags
=
1296 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1297 fence
->execbuf
.rsvd1
= device
->context_id
;
1298 fence
->execbuf
.rsvd2
= 0;
1300 *pFence
= (VkQueryPool
) fence
;
1305 anv_device_free(device
, fence
);
1310 VkResult
anv_ResetFences(
1312 uint32_t fenceCount
,
1315 struct anv_fence
**fences
= (struct anv_fence
**) pFences
;
1317 for (uint32_t i
; i
< fenceCount
; i
++)
1318 fences
[i
]->ready
= false;
1323 VkResult
anv_GetFenceStatus(
1327 struct anv_device
*device
= (struct anv_device
*) _device
;
1328 struct anv_fence
*fence
= (struct anv_fence
*) _fence
;
1335 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1337 fence
->ready
= true;
1341 return VK_NOT_READY
;
1344 VkResult
anv_WaitForFences(
1346 uint32_t fenceCount
,
1347 const VkFence
* pFences
,
1351 struct anv_device
*device
= (struct anv_device
*) _device
;
1352 struct anv_fence
**fences
= (struct anv_fence
**) pFences
;
1353 int64_t t
= timeout
;
1356 /* FIXME: handle !waitAll */
1358 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1359 ret
= anv_gem_wait(device
, fences
[i
]->bo
.gem_handle
, &t
);
1360 if (ret
== -1 && errno
== ETIME
)
1363 return vk_error(VK_ERROR_UNKNOWN
);
1369 // Queue semaphore functions
1371 VkResult
anv_CreateSemaphore(
1373 const VkSemaphoreCreateInfo
* pCreateInfo
,
1374 VkSemaphore
* pSemaphore
)
1376 stub_return(VK_UNSUPPORTED
);
1379 VkResult
anv_QueueSignalSemaphore(
1381 VkSemaphore semaphore
)
1383 stub_return(VK_UNSUPPORTED
);
1386 VkResult
anv_QueueWaitSemaphore(
1388 VkSemaphore semaphore
)
1390 stub_return(VK_UNSUPPORTED
);
1395 VkResult
anv_CreateEvent(
1397 const VkEventCreateInfo
* pCreateInfo
,
1400 stub_return(VK_UNSUPPORTED
);
1403 VkResult
anv_GetEventStatus(
1407 stub_return(VK_UNSUPPORTED
);
1410 VkResult
anv_SetEvent(
1414 stub_return(VK_UNSUPPORTED
);
1417 VkResult
anv_ResetEvent(
1421 stub_return(VK_UNSUPPORTED
);
1427 anv_query_pool_destroy(struct anv_device
*device
,
1428 struct anv_object
*object
,
1429 VkObjectType obj_type
)
1431 struct anv_query_pool
*pool
= (struct anv_query_pool
*) object
;
1433 assert(obj_type
== VK_OBJECT_TYPE_QUERY_POOL
);
1435 anv_gem_munmap(pool
->bo
.map
, pool
->bo
.size
);
1436 anv_gem_close(device
, pool
->bo
.gem_handle
);
1437 anv_device_free(device
, pool
);
1440 VkResult
anv_CreateQueryPool(
1442 const VkQueryPoolCreateInfo
* pCreateInfo
,
1443 VkQueryPool
* pQueryPool
)
1445 struct anv_device
*device
= (struct anv_device
*) _device
;
1446 struct anv_query_pool
*pool
;
1450 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
);
1452 switch (pCreateInfo
->queryType
) {
1453 case VK_QUERY_TYPE_OCCLUSION
:
1455 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
1456 return VK_UNSUPPORTED
;
1461 pool
= anv_device_alloc(device
, sizeof(*pool
), 8,
1462 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1464 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1466 pool
->base
.destructor
= anv_query_pool_destroy
;
1468 pool
->type
= pCreateInfo
->queryType
;
1469 size
= pCreateInfo
->slots
* sizeof(struct anv_query_pool_slot
);
1470 result
= anv_bo_init_new(&pool
->bo
, device
, size
);
1471 if (result
!= VK_SUCCESS
)
1474 pool
->bo
.map
= anv_gem_mmap(device
, pool
->bo
.gem_handle
, 0, size
);
1476 *pQueryPool
= (VkQueryPool
) pool
;
1481 anv_device_free(device
, pool
);
1486 VkResult
anv_GetQueryPoolResults(
1488 VkQueryPool queryPool
,
1489 uint32_t startQuery
,
1490 uint32_t queryCount
,
1493 VkQueryResultFlags flags
)
1495 struct anv_device
*device
= (struct anv_device
*) _device
;
1496 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
1497 struct anv_query_pool_slot
*slot
= pool
->bo
.map
;
1498 int64_t timeout
= INT64_MAX
;
1499 uint32_t *dst32
= pData
;
1500 uint64_t *dst64
= pData
;
1504 if (flags
& VK_QUERY_RESULT_WITH_AVAILABILITY_BIT
) {
1505 /* Where is the availabilty info supposed to go? */
1506 anv_finishme("VK_QUERY_RESULT_WITH_AVAILABILITY_BIT");
1507 return VK_UNSUPPORTED
;
1510 assert(pool
->type
== VK_QUERY_TYPE_OCCLUSION
);
1512 if (flags
& VK_QUERY_RESULT_64_BIT
)
1513 *pDataSize
= queryCount
* sizeof(uint64_t);
1515 *pDataSize
= queryCount
* sizeof(uint32_t);
1520 if (flags
& VK_QUERY_RESULT_WAIT_BIT
) {
1521 ret
= anv_gem_wait(device
, pool
->bo
.gem_handle
, &timeout
);
1523 return vk_error(VK_ERROR_UNKNOWN
);
1526 for (uint32_t i
= 0; i
< queryCount
; i
++) {
1527 result
= slot
[startQuery
+ i
].end
- slot
[startQuery
+ i
].begin
;
1528 if (flags
& VK_QUERY_RESULT_64_BIT
) {
1531 if (result
> UINT32_MAX
)
1532 result
= UINT32_MAX
;
1542 VkResult
anv_CreateBuffer(
1544 const VkBufferCreateInfo
* pCreateInfo
,
1547 struct anv_device
*device
= (struct anv_device
*) _device
;
1548 struct anv_buffer
*buffer
;
1550 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1552 buffer
= anv_device_alloc(device
, sizeof(*buffer
), 8,
1553 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1555 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1557 buffer
->size
= pCreateInfo
->size
;
1561 *pBuffer
= (VkBuffer
) buffer
;
1566 // Buffer view functions
1569 fill_buffer_surface_state(void *state
, VkFormat format
,
1570 uint32_t offset
, uint32_t range
)
1572 const struct anv_format
*info
;
1574 info
= anv_format_for_vk_format(format
);
1575 /* This assumes RGBA float format. */
1576 uint32_t stride
= 4;
1577 uint32_t num_elements
= range
/ stride
;
1579 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
1580 .SurfaceType
= SURFTYPE_BUFFER
,
1581 .SurfaceArray
= false,
1582 .SurfaceFormat
= info
->format
,
1583 .SurfaceVerticalAlignment
= VALIGN4
,
1584 .SurfaceHorizontalAlignment
= HALIGN4
,
1586 .VerticalLineStride
= 0,
1587 .VerticalLineStrideOffset
= 0,
1588 .SamplerL2BypassModeDisable
= true,
1589 .RenderCacheReadWriteMode
= WriteOnlyCache
,
1590 .MemoryObjectControlState
= GEN8_MOCS
,
1593 .Height
= (num_elements
>> 7) & 0x3fff,
1594 .Width
= num_elements
& 0x7f,
1595 .Depth
= (num_elements
>> 21) & 0x3f,
1596 .SurfacePitch
= stride
- 1,
1597 .MinimumArrayElement
= 0,
1598 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
1603 .AuxiliarySurfaceMode
= AUX_NONE
,
1605 .GreenClearColor
= 0,
1606 .BlueClearColor
= 0,
1607 .AlphaClearColor
= 0,
1608 .ShaderChannelSelectRed
= SCS_RED
,
1609 .ShaderChannelSelectGreen
= SCS_GREEN
,
1610 .ShaderChannelSelectBlue
= SCS_BLUE
,
1611 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
1612 .ResourceMinLOD
= 0,
1613 /* FIXME: We assume that the image must be bound at this time. */
1614 .SurfaceBaseAddress
= { NULL
, offset
},
1617 GEN8_RENDER_SURFACE_STATE_pack(NULL
, state
, &surface_state
);
1620 VkResult
anv_CreateBufferView(
1622 const VkBufferViewCreateInfo
* pCreateInfo
,
1623 VkBufferView
* pView
)
1625 struct anv_device
*device
= (struct anv_device
*) _device
;
1626 struct anv_buffer
*buffer
= (struct anv_buffer
*) pCreateInfo
->buffer
;
1627 struct anv_surface_view
*view
;
1629 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO
);
1631 view
= anv_device_alloc(device
, sizeof(*view
), 8,
1632 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1634 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1636 view
->bo
= buffer
->bo
;
1637 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
1638 view
->surface_state
=
1639 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
1640 view
->format
= pCreateInfo
->format
;
1641 view
->range
= pCreateInfo
->range
;
1643 fill_buffer_surface_state(view
->surface_state
.map
,
1644 pCreateInfo
->format
, view
->offset
, pCreateInfo
->range
);
1646 *pView
= (VkImageView
) view
;
1651 // Sampler functions
1653 VkResult
anv_CreateSampler(
1655 const VkSamplerCreateInfo
* pCreateInfo
,
1656 VkSampler
* pSampler
)
1658 struct anv_device
*device
= (struct anv_device
*) _device
;
1659 struct anv_sampler
*sampler
;
1661 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
1663 sampler
= anv_device_alloc(device
, sizeof(*sampler
), 8,
1664 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1666 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1668 static const uint32_t vk_to_gen_tex_filter
[] = {
1669 [VK_TEX_FILTER_NEAREST
] = MAPFILTER_NEAREST
,
1670 [VK_TEX_FILTER_LINEAR
] = MAPFILTER_LINEAR
1673 static const uint32_t vk_to_gen_mipmap_mode
[] = {
1674 [VK_TEX_MIPMAP_MODE_BASE
] = MIPFILTER_NONE
,
1675 [VK_TEX_MIPMAP_MODE_NEAREST
] = MIPFILTER_NEAREST
,
1676 [VK_TEX_MIPMAP_MODE_LINEAR
] = MIPFILTER_LINEAR
1679 static const uint32_t vk_to_gen_tex_address
[] = {
1680 [VK_TEX_ADDRESS_WRAP
] = TCM_WRAP
,
1681 [VK_TEX_ADDRESS_MIRROR
] = TCM_MIRROR
,
1682 [VK_TEX_ADDRESS_CLAMP
] = TCM_CLAMP
,
1683 [VK_TEX_ADDRESS_MIRROR_ONCE
] = TCM_MIRROR_ONCE
,
1684 [VK_TEX_ADDRESS_CLAMP_BORDER
] = TCM_CLAMP_BORDER
,
1687 static const uint32_t vk_to_gen_compare_op
[] = {
1688 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
1689 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
1690 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
1691 [VK_COMPARE_OP_LESS_EQUAL
] = PREFILTEROPLEQUAL
,
1692 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
1693 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
1694 [VK_COMPARE_OP_GREATER_EQUAL
] = PREFILTEROPGEQUAL
,
1695 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,
1698 if (pCreateInfo
->maxAnisotropy
> 0)
1699 anv_finishme("missing support for anisotropic filtering");
1701 struct GEN8_SAMPLER_STATE sampler_state
= {
1702 .SamplerDisable
= false,
1703 .TextureBorderColorMode
= DX10OGL
,
1704 .LODPreClampMode
= 0,
1706 .MipModeFilter
= vk_to_gen_mipmap_mode
[pCreateInfo
->mipMode
],
1707 .MagModeFilter
= vk_to_gen_tex_filter
[pCreateInfo
->magFilter
],
1708 .MinModeFilter
= vk_to_gen_tex_filter
[pCreateInfo
->minFilter
],
1709 .TextureLODBias
= pCreateInfo
->mipLodBias
* 256,
1710 .AnisotropicAlgorithm
= EWAApproximation
,
1711 .MinLOD
= pCreateInfo
->minLod
* 256,
1712 .MaxLOD
= pCreateInfo
->maxLod
* 256,
1713 .ChromaKeyEnable
= 0,
1714 .ChromaKeyIndex
= 0,
1716 .ShadowFunction
= vk_to_gen_compare_op
[pCreateInfo
->compareOp
],
1717 .CubeSurfaceControlMode
= 0,
1718 .IndirectStatePointer
= 0,
1719 .LODClampMagnificationMode
= MIPNONE
,
1720 .MaximumAnisotropy
= 0,
1721 .RAddressMinFilterRoundingEnable
= 0,
1722 .RAddressMagFilterRoundingEnable
= 0,
1723 .VAddressMinFilterRoundingEnable
= 0,
1724 .VAddressMagFilterRoundingEnable
= 0,
1725 .UAddressMinFilterRoundingEnable
= 0,
1726 .UAddressMagFilterRoundingEnable
= 0,
1727 .TrilinearFilterQuality
= 0,
1728 .NonnormalizedCoordinateEnable
= 0,
1729 .TCXAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressU
],
1730 .TCYAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressV
],
1731 .TCZAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressW
],
1734 GEN8_SAMPLER_STATE_pack(NULL
, sampler
->state
, &sampler_state
);
1736 *pSampler
= (VkSampler
) sampler
;
1741 // Descriptor set functions
1743 VkResult
anv_CreateDescriptorSetLayout(
1745 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
1746 VkDescriptorSetLayout
* pSetLayout
)
1748 struct anv_device
*device
= (struct anv_device
*) _device
;
1749 struct anv_descriptor_set_layout
*set_layout
;
1751 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
1753 uint32_t sampler_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1754 uint32_t surface_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1755 uint32_t num_dynamic_buffers
= 0;
1759 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1760 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1761 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1762 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1763 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1764 sampler_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1770 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1771 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1772 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1773 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1774 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1775 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1776 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1777 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1778 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1779 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1780 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1781 surface_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1787 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1788 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1789 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1790 num_dynamic_buffers
+= pCreateInfo
->pBinding
[i
].count
;
1796 count
+= pCreateInfo
->pBinding
[i
].count
;
1799 uint32_t sampler_total
= 0;
1800 uint32_t surface_total
= 0;
1801 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1802 sampler_total
+= sampler_count
[s
];
1803 surface_total
+= surface_count
[s
];
1806 size_t size
= sizeof(*set_layout
) +
1807 (sampler_total
+ surface_total
) * sizeof(set_layout
->entries
[0]);
1808 set_layout
= anv_device_alloc(device
, size
, 8,
1809 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1811 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1813 set_layout
->num_dynamic_buffers
= num_dynamic_buffers
;
1814 set_layout
->count
= count
;
1816 struct anv_descriptor_slot
*p
= set_layout
->entries
;
1817 struct anv_descriptor_slot
*sampler
[VK_NUM_SHADER_STAGE
];
1818 struct anv_descriptor_slot
*surface
[VK_NUM_SHADER_STAGE
];
1819 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1820 set_layout
->stage
[s
].surface_count
= surface_count
[s
];
1821 set_layout
->stage
[s
].surface_start
= surface
[s
] = p
;
1822 p
+= surface_count
[s
];
1823 set_layout
->stage
[s
].sampler_count
= sampler_count
[s
];
1824 set_layout
->stage
[s
].sampler_start
= sampler
[s
] = p
;
1825 p
+= sampler_count
[s
];
1828 uint32_t descriptor
= 0;
1829 int8_t dynamic_slot
= 0;
1831 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1832 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1833 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1834 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1835 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1836 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++) {
1837 sampler
[s
]->index
= descriptor
+ j
;
1838 sampler
[s
]->dynamic_slot
= -1;
1846 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1847 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1848 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1856 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1857 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1858 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1859 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1860 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1861 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1862 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1863 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1864 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1865 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1866 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1867 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++) {
1868 surface
[s
]->index
= descriptor
+ j
;
1870 surface
[s
]->dynamic_slot
= dynamic_slot
+ j
;
1872 surface
[s
]->dynamic_slot
= -1;
1881 dynamic_slot
+= pCreateInfo
->pBinding
[i
].count
;
1883 descriptor
+= pCreateInfo
->pBinding
[i
].count
;
1886 *pSetLayout
= (VkDescriptorSetLayout
) set_layout
;
1891 VkResult
anv_BeginDescriptorPoolUpdate(
1893 VkDescriptorUpdateMode updateMode
)
1898 VkResult
anv_EndDescriptorPoolUpdate(
1905 VkResult
anv_CreateDescriptorPool(
1907 VkDescriptorPoolUsage poolUsage
,
1909 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
1910 VkDescriptorPool
* pDescriptorPool
)
1912 *pDescriptorPool
= 1;
1917 VkResult
anv_ResetDescriptorPool(
1919 VkDescriptorPool descriptorPool
)
1924 VkResult
anv_AllocDescriptorSets(
1926 VkDescriptorPool descriptorPool
,
1927 VkDescriptorSetUsage setUsage
,
1929 const VkDescriptorSetLayout
* pSetLayouts
,
1930 VkDescriptorSet
* pDescriptorSets
,
1933 struct anv_device
*device
= (struct anv_device
*) _device
;
1934 const struct anv_descriptor_set_layout
*layout
;
1935 struct anv_descriptor_set
*set
;
1938 for (uint32_t i
= 0; i
< count
; i
++) {
1939 layout
= (struct anv_descriptor_set_layout
*) pSetLayouts
[i
];
1940 size
= sizeof(*set
) + layout
->count
* sizeof(set
->descriptors
[0]);
1941 set
= anv_device_alloc(device
, size
, 8,
1942 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1945 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1948 /* Descriptor sets may not be 100% filled out so we need to memset to
1949 * ensure that we can properly detect and handle holes.
1951 memset(set
, 0, size
);
1953 pDescriptorSets
[i
] = (VkDescriptorSet
) set
;
1961 void anv_ClearDescriptorSets(
1963 VkDescriptorPool descriptorPool
,
1965 const VkDescriptorSet
* pDescriptorSets
)
1969 void anv_UpdateDescriptors(
1971 VkDescriptorSet descriptorSet
,
1972 uint32_t updateCount
,
1973 const void** ppUpdateArray
)
1975 struct anv_descriptor_set
*set
= (struct anv_descriptor_set
*) descriptorSet
;
1976 VkUpdateSamplers
*update_samplers
;
1977 VkUpdateSamplerTextures
*update_sampler_textures
;
1978 VkUpdateImages
*update_images
;
1979 VkUpdateBuffers
*update_buffers
;
1980 VkUpdateAsCopy
*update_as_copy
;
1982 for (uint32_t i
= 0; i
< updateCount
; i
++) {
1983 const struct anv_common
*common
= ppUpdateArray
[i
];
1985 switch (common
->sType
) {
1986 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS
:
1987 update_samplers
= (VkUpdateSamplers
*) common
;
1989 for (uint32_t j
= 0; j
< update_samplers
->count
; j
++) {
1990 set
->descriptors
[update_samplers
->binding
+ j
].sampler
=
1991 (struct anv_sampler
*) update_samplers
->pSamplers
[j
];
1995 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES
:
1996 /* FIXME: Shouldn't this be *_UPDATE_SAMPLER_IMAGES? */
1997 update_sampler_textures
= (VkUpdateSamplerTextures
*) common
;
1999 for (uint32_t j
= 0; j
< update_sampler_textures
->count
; j
++) {
2000 set
->descriptors
[update_sampler_textures
->binding
+ j
].view
=
2001 (struct anv_surface_view
*)
2002 update_sampler_textures
->pSamplerImageViews
[j
].pImageView
->view
;
2003 set
->descriptors
[update_sampler_textures
->binding
+ j
].sampler
=
2004 (struct anv_sampler
*)
2005 update_sampler_textures
->pSamplerImageViews
[j
].sampler
;
2009 case VK_STRUCTURE_TYPE_UPDATE_IMAGES
:
2010 update_images
= (VkUpdateImages
*) common
;
2012 for (uint32_t j
= 0; j
< update_images
->count
; j
++) {
2013 set
->descriptors
[update_images
->binding
+ j
].view
=
2014 (struct anv_surface_view
*) update_images
->pImageViews
[j
].view
;
2018 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS
:
2019 update_buffers
= (VkUpdateBuffers
*) common
;
2021 for (uint32_t j
= 0; j
< update_buffers
->count
; j
++) {
2022 set
->descriptors
[update_buffers
->binding
+ j
].view
=
2023 (struct anv_surface_view
*) update_buffers
->pBufferViews
[j
].view
;
2025 /* FIXME: descriptor arrays? */
2028 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY
:
2029 update_as_copy
= (VkUpdateAsCopy
*) common
;
2030 (void) update_as_copy
;
2039 // State object functions
2041 static inline int64_t
2042 clamp_int64(int64_t x
, int64_t min
, int64_t max
)
2053 anv_dynamic_vp_state_destroy(struct anv_device
*device
,
2054 struct anv_object
*object
,
2055 VkObjectType obj_type
)
2057 struct anv_dynamic_vp_state
*state
= (void *)object
;
2059 assert(obj_type
== VK_OBJECT_TYPE_DYNAMIC_VP_STATE
);
2061 anv_state_pool_free(&device
->dynamic_state_pool
, state
->sf_clip_vp
);
2062 anv_state_pool_free(&device
->dynamic_state_pool
, state
->cc_vp
);
2063 anv_state_pool_free(&device
->dynamic_state_pool
, state
->scissor
);
2065 anv_device_free(device
, state
);
2068 VkResult
anv_CreateDynamicViewportState(
2070 const VkDynamicVpStateCreateInfo
* pCreateInfo
,
2071 VkDynamicVpState
* pState
)
2073 struct anv_device
*device
= (struct anv_device
*) _device
;
2074 struct anv_dynamic_vp_state
*state
;
2076 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
);
2078 state
= anv_device_alloc(device
, sizeof(*state
), 8,
2079 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2081 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2083 state
->base
.destructor
= anv_dynamic_vp_state_destroy
;
2085 unsigned count
= pCreateInfo
->viewportAndScissorCount
;
2086 state
->sf_clip_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2088 state
->cc_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2090 state
->scissor
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2093 for (uint32_t i
= 0; i
< pCreateInfo
->viewportAndScissorCount
; i
++) {
2094 const VkViewport
*vp
= &pCreateInfo
->pViewports
[i
];
2095 const VkRect
*s
= &pCreateInfo
->pScissors
[i
];
2097 struct GEN8_SF_CLIP_VIEWPORT sf_clip_viewport
= {
2098 .ViewportMatrixElementm00
= vp
->width
/ 2,
2099 .ViewportMatrixElementm11
= vp
->height
/ 2,
2100 .ViewportMatrixElementm22
= (vp
->maxDepth
- vp
->minDepth
) / 2,
2101 .ViewportMatrixElementm30
= vp
->originX
+ vp
->width
/ 2,
2102 .ViewportMatrixElementm31
= vp
->originY
+ vp
->height
/ 2,
2103 .ViewportMatrixElementm32
= (vp
->maxDepth
+ vp
->minDepth
) / 2,
2104 .XMinClipGuardband
= -1.0f
,
2105 .XMaxClipGuardband
= 1.0f
,
2106 .YMinClipGuardband
= -1.0f
,
2107 .YMaxClipGuardband
= 1.0f
,
2108 .XMinViewPort
= vp
->originX
,
2109 .XMaxViewPort
= vp
->originX
+ vp
->width
- 1,
2110 .YMinViewPort
= vp
->originY
,
2111 .YMaxViewPort
= vp
->originY
+ vp
->height
- 1,
2114 struct GEN8_CC_VIEWPORT cc_viewport
= {
2115 .MinimumDepth
= vp
->minDepth
,
2116 .MaximumDepth
= vp
->maxDepth
2119 /* Since xmax and ymax are inclusive, we have to have xmax < xmin or
2120 * ymax < ymin for empty clips. In case clip x, y, width height are all
2121 * 0, the clamps below produce 0 for xmin, ymin, xmax, ymax, which isn't
2122 * what we want. Just special case empty clips and produce a canonical
2124 static const struct GEN8_SCISSOR_RECT empty_scissor
= {
2125 .ScissorRectangleYMin
= 1,
2126 .ScissorRectangleXMin
= 1,
2127 .ScissorRectangleYMax
= 0,
2128 .ScissorRectangleXMax
= 0
2131 const int max
= 0xffff;
2132 struct GEN8_SCISSOR_RECT scissor
= {
2133 /* Do this math using int64_t so overflow gets clamped correctly. */
2134 .ScissorRectangleYMin
= clamp_int64(s
->offset
.y
, 0, max
),
2135 .ScissorRectangleXMin
= clamp_int64(s
->offset
.x
, 0, max
),
2136 .ScissorRectangleYMax
= clamp_int64((uint64_t) s
->offset
.y
+ s
->extent
.height
- 1, 0, max
),
2137 .ScissorRectangleXMax
= clamp_int64((uint64_t) s
->offset
.x
+ s
->extent
.width
- 1, 0, max
)
2140 GEN8_SF_CLIP_VIEWPORT_pack(NULL
, state
->sf_clip_vp
.map
+ i
* 64, &sf_clip_viewport
);
2141 GEN8_CC_VIEWPORT_pack(NULL
, state
->cc_vp
.map
+ i
* 32, &cc_viewport
);
2143 if (s
->extent
.width
<= 0 || s
->extent
.height
<= 0) {
2144 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &empty_scissor
);
2146 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &scissor
);
2150 *pState
= (VkDynamicVpState
) state
;
2155 VkResult
anv_CreateDynamicRasterState(
2157 const VkDynamicRsStateCreateInfo
* pCreateInfo
,
2158 VkDynamicRsState
* pState
)
2160 struct anv_device
*device
= (struct anv_device
*) _device
;
2161 struct anv_dynamic_rs_state
*state
;
2163 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO
);
2165 state
= anv_device_alloc(device
, sizeof(*state
), 8,
2166 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2168 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2171 * float pointFadeThreshold;
2172 * // optional (GL45) - Size of point fade threshold
2175 struct GEN8_3DSTATE_SF sf
= {
2176 GEN8_3DSTATE_SF_header
,
2177 .LineWidth
= pCreateInfo
->lineWidth
,
2178 .PointWidth
= pCreateInfo
->pointSize
,
2181 GEN8_3DSTATE_SF_pack(NULL
, state
->state_sf
, &sf
);
2183 bool enable_bias
= pCreateInfo
->depthBias
!= 0.0f
||
2184 pCreateInfo
->slopeScaledDepthBias
!= 0.0f
;
2185 struct GEN8_3DSTATE_RASTER raster
= {
2186 .GlobalDepthOffsetEnableSolid
= enable_bias
,
2187 .GlobalDepthOffsetEnableWireframe
= enable_bias
,
2188 .GlobalDepthOffsetEnablePoint
= enable_bias
,
2189 .GlobalDepthOffsetConstant
= pCreateInfo
->depthBias
,
2190 .GlobalDepthOffsetScale
= pCreateInfo
->slopeScaledDepthBias
,
2191 .GlobalDepthOffsetClamp
= pCreateInfo
->depthBiasClamp
2194 GEN8_3DSTATE_RASTER_pack(NULL
, state
->state_raster
, &raster
);
2196 *pState
= (VkDynamicRsState
) state
;
2201 VkResult
anv_CreateDynamicColorBlendState(
2203 const VkDynamicCbStateCreateInfo
* pCreateInfo
,
2204 VkDynamicCbState
* pState
)
2206 struct anv_device
*device
= (struct anv_device
*) _device
;
2207 struct anv_dynamic_cb_state
*state
;
2209 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO
);
2211 state
= anv_device_alloc(device
, sizeof(*state
), 8,
2212 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2214 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2216 struct GEN8_COLOR_CALC_STATE color_calc_state
= {
2217 .BlendConstantColorRed
= pCreateInfo
->blendConst
[0],
2218 .BlendConstantColorGreen
= pCreateInfo
->blendConst
[1],
2219 .BlendConstantColorBlue
= pCreateInfo
->blendConst
[2],
2220 .BlendConstantColorAlpha
= pCreateInfo
->blendConst
[3]
2223 GEN8_COLOR_CALC_STATE_pack(NULL
, state
->state_color_calc
, &color_calc_state
);
2225 *pState
= (VkDynamicCbState
) state
;
2230 VkResult
anv_CreateDynamicDepthStencilState(
2232 const VkDynamicDsStateCreateInfo
* pCreateInfo
,
2233 VkDynamicDsState
* pState
)
2235 struct anv_device
*device
= (struct anv_device
*) _device
;
2236 struct anv_dynamic_ds_state
*state
;
2238 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO
);
2240 state
= anv_device_alloc(device
, sizeof(*state
), 8,
2241 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2243 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2245 struct GEN8_3DSTATE_WM_DEPTH_STENCIL wm_depth_stencil
= {
2246 GEN8_3DSTATE_WM_DEPTH_STENCIL_header
,
2248 /* Is this what we need to do? */
2249 .StencilBufferWriteEnable
= pCreateInfo
->stencilWriteMask
!= 0,
2251 .StencilTestMask
= pCreateInfo
->stencilReadMask
,
2252 .StencilWriteMask
= pCreateInfo
->stencilWriteMask
,
2254 .BackfaceStencilTestMask
= pCreateInfo
->stencilReadMask
,
2255 .BackfaceStencilWriteMask
= pCreateInfo
->stencilWriteMask
,
2258 GEN8_3DSTATE_WM_DEPTH_STENCIL_pack(NULL
, state
->state_wm_depth_stencil
,
2261 struct GEN8_COLOR_CALC_STATE color_calc_state
= {
2262 .StencilReferenceValue
= pCreateInfo
->stencilFrontRef
,
2263 .BackFaceStencilReferenceValue
= pCreateInfo
->stencilBackRef
2266 GEN8_COLOR_CALC_STATE_pack(NULL
, state
->state_color_calc
, &color_calc_state
);
2268 *pState
= (VkDynamicDsState
) state
;
2273 // Command buffer functions
2276 anv_cmd_buffer_destroy(struct anv_device
*device
,
2277 struct anv_object
*object
,
2278 VkObjectType obj_type
)
2280 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) object
;
2282 assert(obj_type
== VK_OBJECT_TYPE_COMMAND_BUFFER
);
2284 /* Destroy all of the batch buffers */
2285 struct anv_batch_bo
*bbo
= cmd_buffer
->last_batch_bo
;
2286 while (bbo
->prev_batch_bo
) {
2287 struct anv_batch_bo
*prev
= bbo
->prev_batch_bo
;
2288 anv_batch_bo_destroy(bbo
, device
);
2291 anv_reloc_list_finish(&cmd_buffer
->batch
.relocs
, device
);
2293 /* Destroy all of the surface state buffers */
2294 bbo
= cmd_buffer
->surface_batch_bo
;
2295 while (bbo
->prev_batch_bo
) {
2296 struct anv_batch_bo
*prev
= bbo
->prev_batch_bo
;
2297 anv_batch_bo_destroy(bbo
, device
);
2300 anv_reloc_list_finish(&cmd_buffer
->surface_relocs
, device
);
2302 anv_state_stream_finish(&cmd_buffer
->surface_state_stream
);
2303 anv_state_stream_finish(&cmd_buffer
->dynamic_state_stream
);
2304 anv_state_stream_finish(&cmd_buffer
->binding_table_state_stream
);
2305 anv_device_free(device
, cmd_buffer
->exec2_objects
);
2306 anv_device_free(device
, cmd_buffer
->exec2_bos
);
2307 anv_device_free(device
, cmd_buffer
);
2311 anv_cmd_buffer_chain_batch(struct anv_batch
*batch
, void *_data
)
2313 struct anv_cmd_buffer
*cmd_buffer
= _data
;
2315 struct anv_batch_bo
*new_bbo
, *old_bbo
= cmd_buffer
->last_batch_bo
;
2317 VkResult result
= anv_batch_bo_create(cmd_buffer
->device
, &new_bbo
);
2318 if (result
!= VK_SUCCESS
)
2321 /* We set the end of the batch a little short so we would be sure we
2322 * have room for the chaining command. Since we're about to emit the
2323 * chaining command, let's set it back where it should go.
2325 batch
->end
+= GEN8_MI_BATCH_BUFFER_START_length
* 4;
2326 assert(batch
->end
== old_bbo
->bo
.map
+ old_bbo
->bo
.size
);
2328 anv_batch_emit(batch
, GEN8_MI_BATCH_BUFFER_START
,
2329 GEN8_MI_BATCH_BUFFER_START_header
,
2330 ._2ndLevelBatchBuffer
= _1stlevelbatch
,
2331 .AddressSpaceIndicator
= ASI_PPGTT
,
2332 .BatchBufferStartAddress
= { &new_bbo
->bo
, 0 },
2335 /* Pad out to a 2-dword aligned boundary with zeros */
2336 if ((uintptr_t)batch
->next
% 8 != 0) {
2337 *(uint32_t *)batch
->next
= 0;
2341 anv_batch_bo_finish(cmd_buffer
->last_batch_bo
, batch
);
2343 new_bbo
->prev_batch_bo
= old_bbo
;
2344 cmd_buffer
->last_batch_bo
= new_bbo
;
2346 anv_batch_bo_start(new_bbo
, batch
, GEN8_MI_BATCH_BUFFER_START_length
* 4);
2351 VkResult
anv_CreateCommandBuffer(
2353 const VkCmdBufferCreateInfo
* pCreateInfo
,
2354 VkCmdBuffer
* pCmdBuffer
)
2356 struct anv_device
*device
= (struct anv_device
*) _device
;
2357 struct anv_cmd_buffer
*cmd_buffer
;
2360 cmd_buffer
= anv_device_alloc(device
, sizeof(*cmd_buffer
), 8,
2361 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2362 if (cmd_buffer
== NULL
)
2363 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2365 cmd_buffer
->base
.destructor
= anv_cmd_buffer_destroy
;
2367 cmd_buffer
->device
= device
;
2368 cmd_buffer
->rs_state
= NULL
;
2369 cmd_buffer
->vp_state
= NULL
;
2370 memset(&cmd_buffer
->descriptors
, 0, sizeof(cmd_buffer
->descriptors
));
2372 result
= anv_batch_bo_create(device
, &cmd_buffer
->last_batch_bo
);
2373 if (result
!= VK_SUCCESS
)
2376 result
= anv_reloc_list_init(&cmd_buffer
->batch
.relocs
, device
);
2377 if (result
!= VK_SUCCESS
)
2380 cmd_buffer
->batch
.device
= device
;
2381 cmd_buffer
->batch
.extend_cb
= anv_cmd_buffer_chain_batch
;
2382 cmd_buffer
->batch
.user_data
= cmd_buffer
;
2384 anv_batch_bo_start(cmd_buffer
->last_batch_bo
, &cmd_buffer
->batch
,
2385 GEN8_MI_BATCH_BUFFER_START_length
* 4);
2387 result
= anv_batch_bo_create(device
, &cmd_buffer
->surface_batch_bo
);
2388 if (result
!= VK_SUCCESS
)
2389 goto fail_batch_relocs
;
2390 cmd_buffer
->surface_batch_bo
->first_reloc
= 0;
2392 result
= anv_reloc_list_init(&cmd_buffer
->surface_relocs
, device
);
2393 if (result
!= VK_SUCCESS
)
2394 goto fail_ss_batch_bo
;
2396 /* Start surface_next at 1 so surface offset 0 is invalid. */
2397 cmd_buffer
->surface_next
= 1;
2399 cmd_buffer
->exec2_objects
= NULL
;
2400 cmd_buffer
->exec2_bos
= NULL
;
2401 cmd_buffer
->exec2_array_length
= 0;
2403 anv_state_stream_init(&cmd_buffer
->binding_table_state_stream
,
2404 &device
->binding_table_block_pool
);
2405 anv_state_stream_init(&cmd_buffer
->surface_state_stream
,
2406 &device
->surface_state_block_pool
);
2407 anv_state_stream_init(&cmd_buffer
->dynamic_state_stream
,
2408 &device
->dynamic_state_block_pool
);
2410 cmd_buffer
->dirty
= 0;
2411 cmd_buffer
->vb_dirty
= 0;
2412 cmd_buffer
->pipeline
= NULL
;
2413 cmd_buffer
->vp_state
= NULL
;
2414 cmd_buffer
->rs_state
= NULL
;
2415 cmd_buffer
->ds_state
= NULL
;
2417 *pCmdBuffer
= (VkCmdBuffer
) cmd_buffer
;
2422 anv_batch_bo_destroy(cmd_buffer
->surface_batch_bo
, device
);
2424 anv_reloc_list_finish(&cmd_buffer
->batch
.relocs
, device
);
2426 anv_batch_bo_destroy(cmd_buffer
->last_batch_bo
, device
);
2428 anv_device_free(device
, cmd_buffer
);
2434 anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
)
2436 struct anv_device
*device
= cmd_buffer
->device
;
2438 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_BASE_ADDRESS
,
2439 .GeneralStateBaseAddress
= { NULL
, 0 },
2440 .GeneralStateMemoryObjectControlState
= GEN8_MOCS
,
2441 .GeneralStateBaseAddressModifyEnable
= true,
2442 .GeneralStateBufferSize
= 0xfffff,
2443 .GeneralStateBufferSizeModifyEnable
= true,
2445 .SurfaceStateBaseAddress
= { &cmd_buffer
->surface_batch_bo
->bo
, 0 },
2446 .SurfaceStateMemoryObjectControlState
= GEN8_MOCS
,
2447 .SurfaceStateBaseAddressModifyEnable
= true,
2449 .DynamicStateBaseAddress
= { &device
->dynamic_state_block_pool
.bo
, 0 },
2450 .DynamicStateMemoryObjectControlState
= GEN8_MOCS
,
2451 .DynamicStateBaseAddressModifyEnable
= true,
2452 .DynamicStateBufferSize
= 0xfffff,
2453 .DynamicStateBufferSizeModifyEnable
= true,
2455 .IndirectObjectBaseAddress
= { NULL
, 0 },
2456 .IndirectObjectMemoryObjectControlState
= GEN8_MOCS
,
2457 .IndirectObjectBaseAddressModifyEnable
= true,
2458 .IndirectObjectBufferSize
= 0xfffff,
2459 .IndirectObjectBufferSizeModifyEnable
= true,
2461 .InstructionBaseAddress
= { &device
->instruction_block_pool
.bo
, 0 },
2462 .InstructionMemoryObjectControlState
= GEN8_MOCS
,
2463 .InstructionBaseAddressModifyEnable
= true,
2464 .InstructionBufferSize
= 0xfffff,
2465 .InstructionBuffersizeModifyEnable
= true);
2468 VkResult
anv_BeginCommandBuffer(
2469 VkCmdBuffer cmdBuffer
,
2470 const VkCmdBufferBeginInfo
* pBeginInfo
)
2472 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2474 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPELINE_SELECT
,
2475 .PipelineSelection
= _3D
);
2476 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_SIP
);
2478 anv_cmd_buffer_emit_state_base_address(cmd_buffer
);
2480 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VF_STATISTICS
,
2481 .StatisticsEnable
= true);
2482 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_HS
, .Enable
= false);
2483 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_TE
, .TEEnable
= false);
2484 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DS
, .FunctionEnable
= false);
2485 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_STREAMOUT
, .SOFunctionEnable
= false);
2487 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_VS
,
2488 .ConstantBufferOffset
= 0,
2489 .ConstantBufferSize
= 4);
2490 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_GS
,
2491 .ConstantBufferOffset
= 4,
2492 .ConstantBufferSize
= 4);
2493 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_PS
,
2494 .ConstantBufferOffset
= 8,
2495 .ConstantBufferSize
= 4);
2497 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_WM_CHROMAKEY
,
2498 .ChromaKeyKillEnable
= false);
2499 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SBE_SWIZ
);
2500 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_AA_LINE_PARAMETERS
);
2506 anv_cmd_buffer_add_bo(struct anv_cmd_buffer
*cmd_buffer
,
2508 struct drm_i915_gem_relocation_entry
*relocs
,
2511 struct drm_i915_gem_exec_object2
*obj
;
2513 if (bo
->index
< cmd_buffer
->bo_count
&&
2514 cmd_buffer
->exec2_bos
[bo
->index
] == bo
)
2517 if (cmd_buffer
->bo_count
>= cmd_buffer
->exec2_array_length
) {
2518 uint32_t new_len
= cmd_buffer
->exec2_objects
?
2519 cmd_buffer
->exec2_array_length
* 2 : 64;
2521 struct drm_i915_gem_exec_object2
*new_objects
=
2522 anv_device_alloc(cmd_buffer
->device
, new_len
* sizeof(*new_objects
),
2523 8, VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
2524 if (new_objects
== NULL
)
2525 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2527 struct anv_bo
**new_bos
=
2528 anv_device_alloc(cmd_buffer
->device
, new_len
* sizeof(*new_bos
),
2529 8, VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
2530 if (new_objects
== NULL
) {
2531 anv_device_free(cmd_buffer
->device
, new_objects
);
2532 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2535 if (cmd_buffer
->exec2_objects
) {
2536 memcpy(new_objects
, cmd_buffer
->exec2_objects
,
2537 cmd_buffer
->bo_count
* sizeof(*new_objects
));
2538 memcpy(new_bos
, cmd_buffer
->exec2_bos
,
2539 cmd_buffer
->bo_count
* sizeof(*new_bos
));
2542 cmd_buffer
->exec2_objects
= new_objects
;
2543 cmd_buffer
->exec2_bos
= new_bos
;
2544 cmd_buffer
->exec2_array_length
= new_len
;
2547 assert(cmd_buffer
->bo_count
< cmd_buffer
->exec2_array_length
);
2549 bo
->index
= cmd_buffer
->bo_count
++;
2550 obj
= &cmd_buffer
->exec2_objects
[bo
->index
];
2551 cmd_buffer
->exec2_bos
[bo
->index
] = bo
;
2553 obj
->handle
= bo
->gem_handle
;
2554 obj
->relocation_count
= 0;
2555 obj
->relocs_ptr
= 0;
2557 obj
->offset
= bo
->offset
;
2563 obj
->relocation_count
= num_relocs
;
2564 obj
->relocs_ptr
= (uintptr_t) relocs
;
2571 anv_cmd_buffer_add_validate_bos(struct anv_cmd_buffer
*cmd_buffer
,
2572 struct anv_reloc_list
*list
)
2574 for (size_t i
= 0; i
< list
->num_relocs
; i
++)
2575 anv_cmd_buffer_add_bo(cmd_buffer
, list
->reloc_bos
[i
], NULL
, 0);
2579 anv_cmd_buffer_process_relocs(struct anv_cmd_buffer
*cmd_buffer
,
2580 struct anv_reloc_list
*list
)
2584 /* If the kernel supports I915_EXEC_NO_RELOC, it will compare offset in
2585 * struct drm_i915_gem_exec_object2 against the bos current offset and if
2586 * all bos haven't moved it will skip relocation processing alltogether.
2587 * If I915_EXEC_NO_RELOC is not supported, the kernel ignores the incoming
2588 * value of offset so we can set it either way. For that to work we need
2589 * to make sure all relocs use the same presumed offset.
2592 for (size_t i
= 0; i
< list
->num_relocs
; i
++) {
2593 bo
= list
->reloc_bos
[i
];
2594 if (bo
->offset
!= list
->relocs
[i
].presumed_offset
)
2595 cmd_buffer
->need_reloc
= true;
2597 list
->relocs
[i
].target_handle
= bo
->index
;
2601 VkResult
anv_EndCommandBuffer(
2602 VkCmdBuffer cmdBuffer
)
2604 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2605 struct anv_device
*device
= cmd_buffer
->device
;
2606 struct anv_batch
*batch
= &cmd_buffer
->batch
;
2608 anv_batch_emit(batch
, GEN8_MI_BATCH_BUFFER_END
);
2610 /* Round batch up to an even number of dwords. */
2611 if ((batch
->next
- batch
->start
) & 4)
2612 anv_batch_emit(batch
, GEN8_MI_NOOP
);
2614 anv_batch_bo_finish(cmd_buffer
->last_batch_bo
, &cmd_buffer
->batch
);
2615 cmd_buffer
->surface_batch_bo
->num_relocs
=
2616 cmd_buffer
->surface_relocs
.num_relocs
- cmd_buffer
->surface_batch_bo
->first_reloc
;
2617 cmd_buffer
->surface_batch_bo
->length
= cmd_buffer
->surface_next
;
2619 cmd_buffer
->bo_count
= 0;
2620 cmd_buffer
->need_reloc
= false;
2622 /* Lock for access to bo->index. */
2623 pthread_mutex_lock(&device
->mutex
);
2625 /* Add surface state bos first so we can add them with their relocs. */
2626 for (struct anv_batch_bo
*bbo
= cmd_buffer
->surface_batch_bo
;
2627 bbo
!= NULL
; bbo
= bbo
->prev_batch_bo
) {
2628 anv_cmd_buffer_add_bo(cmd_buffer
, &bbo
->bo
,
2629 &cmd_buffer
->surface_relocs
.relocs
[bbo
->first_reloc
],
2633 /* Add all of the BOs referenced by surface state */
2634 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &cmd_buffer
->surface_relocs
);
2636 /* Add all but the first batch BO */
2637 struct anv_batch_bo
*batch_bo
= cmd_buffer
->last_batch_bo
;
2638 while (batch_bo
->prev_batch_bo
) {
2639 anv_cmd_buffer_add_bo(cmd_buffer
, &batch_bo
->bo
,
2640 &batch
->relocs
.relocs
[batch_bo
->first_reloc
],
2641 batch_bo
->num_relocs
);
2642 batch_bo
= batch_bo
->prev_batch_bo
;
2645 /* Add everything referenced by the batches */
2646 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &batch
->relocs
);
2648 /* Add the first batch bo last */
2649 assert(batch_bo
->prev_batch_bo
== NULL
&& batch_bo
->first_reloc
== 0);
2650 anv_cmd_buffer_add_bo(cmd_buffer
, &batch_bo
->bo
,
2651 &batch
->relocs
.relocs
[batch_bo
->first_reloc
],
2652 batch_bo
->num_relocs
);
2653 assert(batch_bo
->bo
.index
== cmd_buffer
->bo_count
- 1);
2655 anv_cmd_buffer_process_relocs(cmd_buffer
, &cmd_buffer
->surface_relocs
);
2656 anv_cmd_buffer_process_relocs(cmd_buffer
, &batch
->relocs
);
2658 cmd_buffer
->execbuf
.buffers_ptr
= (uintptr_t) cmd_buffer
->exec2_objects
;
2659 cmd_buffer
->execbuf
.buffer_count
= cmd_buffer
->bo_count
;
2660 cmd_buffer
->execbuf
.batch_start_offset
= 0;
2661 cmd_buffer
->execbuf
.batch_len
= batch
->next
- batch
->start
;
2662 cmd_buffer
->execbuf
.cliprects_ptr
= 0;
2663 cmd_buffer
->execbuf
.num_cliprects
= 0;
2664 cmd_buffer
->execbuf
.DR1
= 0;
2665 cmd_buffer
->execbuf
.DR4
= 0;
2667 cmd_buffer
->execbuf
.flags
= I915_EXEC_HANDLE_LUT
;
2668 if (!cmd_buffer
->need_reloc
)
2669 cmd_buffer
->execbuf
.flags
|= I915_EXEC_NO_RELOC
;
2670 cmd_buffer
->execbuf
.flags
|= I915_EXEC_RENDER
;
2671 cmd_buffer
->execbuf
.rsvd1
= device
->context_id
;
2672 cmd_buffer
->execbuf
.rsvd2
= 0;
2674 pthread_mutex_unlock(&device
->mutex
);
2679 VkResult
anv_ResetCommandBuffer(
2680 VkCmdBuffer cmdBuffer
)
2682 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2684 /* Delete all but the first batch bo */
2685 while (cmd_buffer
->last_batch_bo
->prev_batch_bo
) {
2686 struct anv_batch_bo
*prev
= cmd_buffer
->last_batch_bo
->prev_batch_bo
;
2687 anv_batch_bo_destroy(cmd_buffer
->last_batch_bo
, cmd_buffer
->device
);
2688 cmd_buffer
->last_batch_bo
= prev
;
2690 assert(cmd_buffer
->last_batch_bo
->prev_batch_bo
== NULL
);
2692 cmd_buffer
->batch
.relocs
.num_relocs
= 0;
2693 anv_batch_bo_start(cmd_buffer
->last_batch_bo
, &cmd_buffer
->batch
,
2694 GEN8_MI_BATCH_BUFFER_START_length
* 4);
2696 /* Delete all but the first batch bo */
2697 while (cmd_buffer
->surface_batch_bo
->prev_batch_bo
) {
2698 struct anv_batch_bo
*prev
= cmd_buffer
->surface_batch_bo
->prev_batch_bo
;
2699 anv_batch_bo_destroy(cmd_buffer
->surface_batch_bo
, cmd_buffer
->device
);
2700 cmd_buffer
->surface_batch_bo
= prev
;
2702 assert(cmd_buffer
->surface_batch_bo
->prev_batch_bo
== NULL
);
2704 cmd_buffer
->surface_next
= 1;
2705 cmd_buffer
->surface_relocs
.num_relocs
= 0;
2710 // Command buffer building functions
2712 void anv_CmdBindPipeline(
2713 VkCmdBuffer cmdBuffer
,
2714 VkPipelineBindPoint pipelineBindPoint
,
2715 VkPipeline _pipeline
)
2717 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2718 struct anv_pipeline
*pipeline
= (struct anv_pipeline
*) _pipeline
;
2720 cmd_buffer
->pipeline
= pipeline
;
2721 cmd_buffer
->vb_dirty
|= pipeline
->vb_used
;
2722 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
;
2725 void anv_CmdBindDynamicStateObject(
2726 VkCmdBuffer cmdBuffer
,
2727 VkStateBindPoint stateBindPoint
,
2728 VkDynamicStateObject dynamicState
)
2730 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2731 struct anv_dynamic_vp_state
*vp_state
;
2733 switch (stateBindPoint
) {
2734 case VK_STATE_BIND_POINT_VIEWPORT
:
2735 vp_state
= (struct anv_dynamic_vp_state
*) dynamicState
;
2736 /* We emit state immediately, but set cmd_buffer->vp_state to indicate
2737 * that vp state has been set in this command buffer. */
2738 cmd_buffer
->vp_state
= vp_state
;
2739 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SCISSOR_STATE_POINTERS
,
2740 .ScissorRectPointer
= vp_state
->scissor
.offset
);
2741 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_CC
,
2742 .CCViewportPointer
= vp_state
->cc_vp
.offset
);
2743 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
,
2744 .SFClipViewportPointer
= vp_state
->sf_clip_vp
.offset
);
2746 case VK_STATE_BIND_POINT_RASTER
:
2747 cmd_buffer
->rs_state
= (struct anv_dynamic_rs_state
*) dynamicState
;
2748 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_RS_DIRTY
;
2750 case VK_STATE_BIND_POINT_COLOR_BLEND
:
2751 cmd_buffer
->cb_state
= (struct anv_dynamic_cb_state
*) dynamicState
;
2752 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_CB_DIRTY
;
2754 case VK_STATE_BIND_POINT_DEPTH_STENCIL
:
2755 cmd_buffer
->ds_state
= (struct anv_dynamic_ds_state
*) dynamicState
;
2756 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DS_DIRTY
;
2763 static struct anv_state
2764 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
,
2765 uint32_t size
, uint32_t alignment
)
2767 struct anv_state state
;
2769 state
.offset
= ALIGN_U32(cmd_buffer
->surface_next
, alignment
);
2770 if (state
.offset
+ size
> cmd_buffer
->surface_batch_bo
->bo
.size
)
2771 return (struct anv_state
) { 0 };
2773 state
.map
= cmd_buffer
->surface_batch_bo
->bo
.map
+ state
.offset
;
2774 state
.alloc_size
= size
;
2775 cmd_buffer
->surface_next
= state
.offset
+ size
;
2777 assert(state
.offset
+ size
<= cmd_buffer
->surface_batch_bo
->bo
.size
);
2783 anv_cmd_buffer_new_surface_state_bo(struct anv_cmd_buffer
*cmd_buffer
)
2785 struct anv_batch_bo
*new_bbo
, *old_bbo
= cmd_buffer
->surface_batch_bo
;
2787 /* Finish off the old buffer */
2788 old_bbo
->num_relocs
=
2789 cmd_buffer
->surface_relocs
.num_relocs
- old_bbo
->first_reloc
;
2790 old_bbo
->length
= cmd_buffer
->surface_next
;
2792 VkResult result
= anv_batch_bo_create(cmd_buffer
->device
, &new_bbo
);
2793 if (result
!= VK_SUCCESS
)
2796 new_bbo
->first_reloc
= cmd_buffer
->surface_relocs
.num_relocs
;
2797 cmd_buffer
->surface_next
= 1;
2799 new_bbo
->prev_batch_bo
= old_bbo
;
2800 cmd_buffer
->surface_batch_bo
= new_bbo
;
2802 /* Re-emit state base addresses so we get the new surface state base
2803 * address before we start emitting binding tables etc.
2805 anv_cmd_buffer_emit_state_base_address(cmd_buffer
);
2810 void anv_CmdBindDescriptorSets(
2811 VkCmdBuffer cmdBuffer
,
2812 VkPipelineBindPoint pipelineBindPoint
,
2815 const VkDescriptorSet
* pDescriptorSets
,
2816 uint32_t dynamicOffsetCount
,
2817 const uint32_t* pDynamicOffsets
)
2819 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2820 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
2821 struct anv_descriptor_set
*set
;
2822 struct anv_descriptor_set_layout
*set_layout
;
2824 assert(firstSet
+ setCount
< MAX_SETS
);
2826 uint32_t dynamic_slot
= 0;
2827 for (uint32_t i
= 0; i
< setCount
; i
++) {
2828 set
= (struct anv_descriptor_set
*) pDescriptorSets
[i
];
2829 set_layout
= layout
->set
[firstSet
+ i
].layout
;
2831 cmd_buffer
->descriptors
[firstSet
+ i
].set
= set
;
2833 assert(set_layout
->num_dynamic_buffers
<
2834 ARRAY_SIZE(cmd_buffer
->descriptors
[0].dynamic_offsets
));
2835 memcpy(cmd_buffer
->descriptors
[firstSet
+ i
].dynamic_offsets
,
2836 pDynamicOffsets
+ dynamic_slot
,
2837 set_layout
->num_dynamic_buffers
* sizeof(*pDynamicOffsets
));
2839 dynamic_slot
+= set_layout
->num_dynamic_buffers
;
2842 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
2845 void anv_CmdBindIndexBuffer(
2846 VkCmdBuffer cmdBuffer
,
2848 VkDeviceSize offset
,
2849 VkIndexType indexType
)
2851 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2852 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2854 static const uint32_t vk_to_gen_index_type
[] = {
2855 [VK_INDEX_TYPE_UINT8
] = INDEX_BYTE
,
2856 [VK_INDEX_TYPE_UINT16
] = INDEX_WORD
,
2857 [VK_INDEX_TYPE_UINT32
] = INDEX_DWORD
,
2860 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_INDEX_BUFFER
,
2861 .IndexFormat
= vk_to_gen_index_type
[indexType
],
2862 .MemoryObjectControlState
= GEN8_MOCS
,
2863 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
2864 .BufferSize
= buffer
->size
- offset
);
2867 void anv_CmdBindVertexBuffers(
2868 VkCmdBuffer cmdBuffer
,
2869 uint32_t startBinding
,
2870 uint32_t bindingCount
,
2871 const VkBuffer
* pBuffers
,
2872 const VkDeviceSize
* pOffsets
)
2874 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2875 struct anv_vertex_binding
*vb
= cmd_buffer
->vertex_bindings
;
2877 /* We have to defer setting up vertex buffer since we need the buffer
2878 * stride from the pipeline. */
2880 assert(startBinding
+ bindingCount
< MAX_VBS
);
2881 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
2882 vb
[startBinding
+ i
].buffer
= (struct anv_buffer
*) pBuffers
[i
];
2883 vb
[startBinding
+ i
].offset
= pOffsets
[i
];
2884 cmd_buffer
->vb_dirty
|= 1 << (startBinding
+ i
);
2889 cmd_buffer_emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
2892 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
2893 uint32_t color_attachments
, bias
, size
;
2894 struct anv_state bt_state
;
2896 if (stage
== VK_SHADER_STAGE_FRAGMENT
) {
2898 color_attachments
= cmd_buffer
->framebuffer
->color_attachment_count
;
2901 color_attachments
= 0;
2904 /* This is a little awkward: layout can be NULL but we still have to
2905 * allocate and set a binding table for the PS stage for render
2907 uint32_t surface_count
= layout
? layout
->stage
[stage
].surface_count
: 0;
2909 if (color_attachments
+ surface_count
== 0)
2912 size
= (bias
+ surface_count
) * sizeof(uint32_t);
2913 bt_state
= anv_cmd_buffer_alloc_surface_state(cmd_buffer
, size
, 32);
2914 uint32_t *bt_map
= bt_state
.map
;
2916 if (bt_state
.map
== NULL
)
2917 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2919 static const uint32_t binding_table_opcodes
[] = {
2920 [VK_SHADER_STAGE_VERTEX
] = 38,
2921 [VK_SHADER_STAGE_TESS_CONTROL
] = 39,
2922 [VK_SHADER_STAGE_TESS_EVALUATION
] = 40,
2923 [VK_SHADER_STAGE_GEOMETRY
] = 41,
2924 [VK_SHADER_STAGE_FRAGMENT
] = 42,
2925 [VK_SHADER_STAGE_COMPUTE
] = 0,
2928 anv_batch_emit(&cmd_buffer
->batch
,
2929 GEN8_3DSTATE_BINDING_TABLE_POINTERS_VS
,
2930 ._3DCommandSubOpcode
= binding_table_opcodes
[stage
],
2931 .PointertoVSBindingTable
= bt_state
.offset
);
2933 for (uint32_t ca
= 0; ca
< color_attachments
; ca
++) {
2934 const struct anv_surface_view
*view
=
2935 cmd_buffer
->framebuffer
->color_attachments
[ca
];
2937 struct anv_state state
=
2938 anv_cmd_buffer_alloc_surface_state(cmd_buffer
, 64, 64);
2940 if (state
.map
== NULL
)
2941 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2943 memcpy(state
.map
, view
->surface_state
.map
, 64);
2945 /* The address goes in dwords 8 and 9 of the SURFACE_STATE */
2946 *(uint64_t *)(state
.map
+ 8 * 4) =
2947 anv_reloc_list_add(&cmd_buffer
->surface_relocs
,
2949 state
.offset
+ 8 * 4,
2950 view
->bo
, view
->offset
);
2952 bt_map
[ca
] = state
.offset
;
2958 for (uint32_t set
= 0; set
< layout
->num_sets
; set
++) {
2959 struct anv_descriptor_set_binding
*d
= &cmd_buffer
->descriptors
[set
];
2960 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[set
].layout
;
2961 struct anv_descriptor_slot
*surface_slots
=
2962 set_layout
->stage
[stage
].surface_start
;
2964 uint32_t start
= bias
+ layout
->set
[set
].surface_start
[stage
];
2966 for (uint32_t b
= 0; b
< set_layout
->stage
[stage
].surface_count
; b
++) {
2967 struct anv_surface_view
*view
=
2968 d
->set
->descriptors
[surface_slots
[b
].index
].view
;
2973 struct anv_state state
=
2974 anv_cmd_buffer_alloc_surface_state(cmd_buffer
, 64, 64);
2976 if (state
.map
== NULL
)
2977 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2980 if (surface_slots
[b
].dynamic_slot
>= 0) {
2981 uint32_t dynamic_offset
=
2982 d
->dynamic_offsets
[surface_slots
[b
].dynamic_slot
];
2984 offset
= view
->offset
+ dynamic_offset
;
2985 fill_buffer_surface_state(state
.map
, view
->format
, offset
,
2986 view
->range
- dynamic_offset
);
2988 offset
= view
->offset
;
2989 memcpy(state
.map
, view
->surface_state
.map
, 64);
2992 /* The address goes in dwords 8 and 9 of the SURFACE_STATE */
2993 *(uint64_t *)(state
.map
+ 8 * 4) =
2994 anv_reloc_list_add(&cmd_buffer
->surface_relocs
,
2996 state
.offset
+ 8 * 4,
2999 bt_map
[start
+ b
] = state
.offset
;
3007 cmd_buffer_emit_samplers(struct anv_cmd_buffer
*cmd_buffer
, unsigned stage
)
3009 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
3010 struct anv_state state
;
3015 uint32_t sampler_count
= layout
->stage
[stage
].sampler_count
;
3017 if (sampler_count
== 0)
3020 uint32_t size
= sampler_count
* 16;
3021 state
= anv_state_stream_alloc(&cmd_buffer
->dynamic_state_stream
, size
, 32);
3023 if (state
.map
== NULL
)
3024 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3026 static const uint32_t sampler_state_opcodes
[] = {
3027 [VK_SHADER_STAGE_VERTEX
] = 43,
3028 [VK_SHADER_STAGE_TESS_CONTROL
] = 44, /* HS */
3029 [VK_SHADER_STAGE_TESS_EVALUATION
] = 45, /* DS */
3030 [VK_SHADER_STAGE_GEOMETRY
] = 46,
3031 [VK_SHADER_STAGE_FRAGMENT
] = 47,
3032 [VK_SHADER_STAGE_COMPUTE
] = 0,
3035 anv_batch_emit(&cmd_buffer
->batch
,
3036 GEN8_3DSTATE_SAMPLER_STATE_POINTERS_VS
,
3037 ._3DCommandSubOpcode
= sampler_state_opcodes
[stage
],
3038 .PointertoVSSamplerState
= state
.offset
);
3040 for (uint32_t set
= 0; set
< layout
->num_sets
; set
++) {
3041 struct anv_descriptor_set_binding
*d
= &cmd_buffer
->descriptors
[set
];
3042 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[set
].layout
;
3043 struct anv_descriptor_slot
*sampler_slots
=
3044 set_layout
->stage
[stage
].sampler_start
;
3046 uint32_t start
= layout
->set
[set
].sampler_start
[stage
];
3048 for (uint32_t b
= 0; b
< set_layout
->stage
[stage
].sampler_count
; b
++) {
3049 struct anv_sampler
*sampler
=
3050 d
->set
->descriptors
[sampler_slots
[b
].index
].sampler
;
3055 memcpy(state
.map
+ (start
+ b
) * 16,
3056 sampler
->state
, sizeof(sampler
->state
));
3064 flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
)
3067 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
3068 result
= cmd_buffer_emit_binding_table(cmd_buffer
, s
);
3069 if (result
!= VK_SUCCESS
)
3072 result
= cmd_buffer_emit_samplers(cmd_buffer
, s
);
3073 if (result
!= VK_SUCCESS
)
3077 if (result
!= VK_SUCCESS
) {
3078 assert(result
== VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3080 result
= anv_cmd_buffer_new_surface_state_bo(cmd_buffer
);
3081 assert(result
== VK_SUCCESS
);
3083 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
3084 result
= cmd_buffer_emit_binding_table(cmd_buffer
, s
);
3085 result
= cmd_buffer_emit_samplers(cmd_buffer
, s
);
3088 /* It had better succeed this time */
3089 assert(result
== VK_SUCCESS
);
3092 cmd_buffer
->dirty
&= ~ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
3095 static struct anv_state
3096 anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
3097 uint32_t *a
, uint32_t dwords
, uint32_t alignment
)
3099 struct anv_device
*device
= cmd_buffer
->device
;
3100 struct anv_state state
;
3102 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, dwords
* 4, alignment
);
3103 memcpy(state
.map
, a
, dwords
* 4);
3108 static struct anv_state
3109 anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
3110 uint32_t *a
, uint32_t *b
, uint32_t dwords
, uint32_t alignment
)
3112 struct anv_device
*device
= cmd_buffer
->device
;
3113 struct anv_state state
;
3116 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, dwords
* 4, alignment
);
3118 for (uint32_t i
= 0; i
< dwords
; i
++)
3125 anv_cmd_buffer_flush_state(struct anv_cmd_buffer
*cmd_buffer
)
3127 struct anv_pipeline
*pipeline
= cmd_buffer
->pipeline
;
3130 uint32_t vb_emit
= cmd_buffer
->vb_dirty
& pipeline
->vb_used
;
3133 const uint32_t num_buffers
= __builtin_popcount(vb_emit
);
3134 const uint32_t num_dwords
= 1 + num_buffers
* 4;
3136 p
= anv_batch_emitn(&cmd_buffer
->batch
, num_dwords
,
3137 GEN8_3DSTATE_VERTEX_BUFFERS
);
3139 for_each_bit(vb
, vb_emit
) {
3140 struct anv_buffer
*buffer
= cmd_buffer
->vertex_bindings
[vb
].buffer
;
3141 uint32_t offset
= cmd_buffer
->vertex_bindings
[vb
].offset
;
3143 struct GEN8_VERTEX_BUFFER_STATE state
= {
3144 .VertexBufferIndex
= vb
,
3145 .MemoryObjectControlState
= GEN8_MOCS
,
3146 .AddressModifyEnable
= true,
3147 .BufferPitch
= pipeline
->binding_stride
[vb
],
3148 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
3149 .BufferSize
= buffer
->size
- offset
3152 GEN8_VERTEX_BUFFER_STATE_pack(&cmd_buffer
->batch
, &p
[1 + i
* 4], &state
);
3157 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_PIPELINE_DIRTY
)
3158 anv_batch_emit_batch(&cmd_buffer
->batch
, &pipeline
->batch
);
3160 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
)
3161 flush_descriptor_sets(cmd_buffer
);
3163 if (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_PIPELINE_DIRTY
| ANV_CMD_BUFFER_RS_DIRTY
)) {
3164 anv_batch_emit_merge(&cmd_buffer
->batch
,
3165 cmd_buffer
->rs_state
->state_sf
, pipeline
->state_sf
);
3166 anv_batch_emit_merge(&cmd_buffer
->batch
,
3167 cmd_buffer
->rs_state
->state_raster
, pipeline
->state_raster
);
3170 if (cmd_buffer
->ds_state
&&
3171 (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_PIPELINE_DIRTY
| ANV_CMD_BUFFER_DS_DIRTY
)))
3172 anv_batch_emit_merge(&cmd_buffer
->batch
,
3173 cmd_buffer
->ds_state
->state_wm_depth_stencil
,
3174 pipeline
->state_wm_depth_stencil
);
3176 if (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_CB_DIRTY
| ANV_CMD_BUFFER_DS_DIRTY
)) {
3177 struct anv_state state
;
3178 if (cmd_buffer
->ds_state
== NULL
)
3179 state
= anv_cmd_buffer_emit_dynamic(cmd_buffer
,
3180 cmd_buffer
->cb_state
->state_color_calc
,
3181 GEN8_COLOR_CALC_STATE_length
, 32);
3182 else if (cmd_buffer
->cb_state
== NULL
)
3183 state
= anv_cmd_buffer_emit_dynamic(cmd_buffer
,
3184 cmd_buffer
->ds_state
->state_color_calc
,
3185 GEN8_COLOR_CALC_STATE_length
, 32);
3187 state
= anv_cmd_buffer_merge_dynamic(cmd_buffer
,
3188 cmd_buffer
->ds_state
->state_color_calc
,
3189 cmd_buffer
->cb_state
->state_color_calc
,
3190 GEN8_COLOR_CALC_STATE_length
, 32);
3192 anv_batch_emit(&cmd_buffer
->batch
,
3193 GEN8_3DSTATE_CC_STATE_POINTERS
,
3194 .ColorCalcStatePointer
= state
.offset
,
3195 .ColorCalcStatePointerValid
= true);
3198 cmd_buffer
->vb_dirty
&= ~vb_emit
;
3199 cmd_buffer
->dirty
= 0;
3203 VkCmdBuffer cmdBuffer
,
3204 uint32_t firstVertex
,
3205 uint32_t vertexCount
,
3206 uint32_t firstInstance
,
3207 uint32_t instanceCount
)
3209 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3211 anv_cmd_buffer_flush_state(cmd_buffer
);
3213 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
3214 .VertexAccessType
= SEQUENTIAL
,
3215 .VertexCountPerInstance
= vertexCount
,
3216 .StartVertexLocation
= firstVertex
,
3217 .InstanceCount
= instanceCount
,
3218 .StartInstanceLocation
= firstInstance
,
3219 .BaseVertexLocation
= 0);
3222 void anv_CmdDrawIndexed(
3223 VkCmdBuffer cmdBuffer
,
3224 uint32_t firstIndex
,
3225 uint32_t indexCount
,
3226 int32_t vertexOffset
,
3227 uint32_t firstInstance
,
3228 uint32_t instanceCount
)
3230 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3232 anv_cmd_buffer_flush_state(cmd_buffer
);
3234 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
3235 .VertexAccessType
= RANDOM
,
3236 .VertexCountPerInstance
= indexCount
,
3237 .StartVertexLocation
= firstIndex
,
3238 .InstanceCount
= instanceCount
,
3239 .StartInstanceLocation
= firstInstance
,
3240 .BaseVertexLocation
= 0);
3244 anv_batch_lrm(struct anv_batch
*batch
,
3245 uint32_t reg
, struct anv_bo
*bo
, uint32_t offset
)
3247 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_MEM
,
3248 .RegisterAddress
= reg
,
3249 .MemoryAddress
= { bo
, offset
});
3253 anv_batch_lri(struct anv_batch
*batch
, uint32_t reg
, uint32_t imm
)
3255 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_IMM
,
3256 .RegisterOffset
= reg
,
3260 /* Auto-Draw / Indirect Registers */
3261 #define GEN7_3DPRIM_END_OFFSET 0x2420
3262 #define GEN7_3DPRIM_START_VERTEX 0x2430
3263 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
3264 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
3265 #define GEN7_3DPRIM_START_INSTANCE 0x243C
3266 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
3268 void anv_CmdDrawIndirect(
3269 VkCmdBuffer cmdBuffer
,
3271 VkDeviceSize offset
,
3275 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3276 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
3277 struct anv_bo
*bo
= buffer
->bo
;
3278 uint32_t bo_offset
= buffer
->offset
+ offset
;
3280 anv_cmd_buffer_flush_state(cmd_buffer
);
3282 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
3283 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
3284 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
3285 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 12);
3286 anv_batch_lri(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, 0);
3288 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
3289 .IndirectParameterEnable
= true,
3290 .VertexAccessType
= SEQUENTIAL
);
3293 void anv_CmdDrawIndexedIndirect(
3294 VkCmdBuffer cmdBuffer
,
3296 VkDeviceSize offset
,
3300 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3301 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
3302 struct anv_bo
*bo
= buffer
->bo
;
3303 uint32_t bo_offset
= buffer
->offset
+ offset
;
3305 anv_cmd_buffer_flush_state(cmd_buffer
);
3307 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
3308 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
3309 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
3310 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, bo
, bo_offset
+ 12);
3311 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 16);
3313 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
3314 .IndirectParameterEnable
= true,
3315 .VertexAccessType
= RANDOM
);
3318 void anv_CmdDispatch(
3319 VkCmdBuffer cmdBuffer
,
3327 void anv_CmdDispatchIndirect(
3328 VkCmdBuffer cmdBuffer
,
3330 VkDeviceSize offset
)
3335 void anv_CmdSetEvent(
3336 VkCmdBuffer cmdBuffer
,
3338 VkPipeEvent pipeEvent
)
3343 void anv_CmdResetEvent(
3344 VkCmdBuffer cmdBuffer
,
3346 VkPipeEvent pipeEvent
)
3351 void anv_CmdWaitEvents(
3352 VkCmdBuffer cmdBuffer
,
3353 VkWaitEvent waitEvent
,
3354 uint32_t eventCount
,
3355 const VkEvent
* pEvents
,
3356 uint32_t memBarrierCount
,
3357 const void** ppMemBarriers
)
3362 void anv_CmdPipelineBarrier(
3363 VkCmdBuffer cmdBuffer
,
3364 VkWaitEvent waitEvent
,
3365 uint32_t pipeEventCount
,
3366 const VkPipeEvent
* pPipeEvents
,
3367 uint32_t memBarrierCount
,
3368 const void** ppMemBarriers
)
3374 anv_batch_emit_ps_depth_count(struct anv_batch
*batch
,
3375 struct anv_bo
*bo
, uint32_t offset
)
3377 anv_batch_emit(batch
, GEN8_PIPE_CONTROL
,
3378 .DestinationAddressType
= DAT_PPGTT
,
3379 .PostSyncOperation
= WritePSDepthCount
,
3380 .Address
= { bo
, offset
}); /* FIXME: This is only lower 32 bits */
3383 void anv_CmdBeginQuery(
3384 VkCmdBuffer cmdBuffer
,
3385 VkQueryPool queryPool
,
3387 VkQueryControlFlags flags
)
3389 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3390 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
3392 switch (pool
->type
) {
3393 case VK_QUERY_TYPE_OCCLUSION
:
3394 anv_batch_emit_ps_depth_count(&cmd_buffer
->batch
, &pool
->bo
,
3395 slot
* sizeof(struct anv_query_pool_slot
));
3398 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
3404 void anv_CmdEndQuery(
3405 VkCmdBuffer cmdBuffer
,
3406 VkQueryPool queryPool
,
3409 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3410 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
3412 switch (pool
->type
) {
3413 case VK_QUERY_TYPE_OCCLUSION
:
3414 anv_batch_emit_ps_depth_count(&cmd_buffer
->batch
, &pool
->bo
,
3415 slot
* sizeof(struct anv_query_pool_slot
) + 8);
3418 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
3424 void anv_CmdResetQueryPool(
3425 VkCmdBuffer cmdBuffer
,
3426 VkQueryPool queryPool
,
3427 uint32_t startQuery
,
3428 uint32_t queryCount
)
3433 #define TIMESTAMP 0x2358
3435 void anv_CmdWriteTimestamp(
3436 VkCmdBuffer cmdBuffer
,
3437 VkTimestampType timestampType
,
3438 VkBuffer destBuffer
,
3439 VkDeviceSize destOffset
)
3441 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3442 struct anv_buffer
*buffer
= (struct anv_buffer
*) destBuffer
;
3443 struct anv_bo
*bo
= buffer
->bo
;
3445 switch (timestampType
) {
3446 case VK_TIMESTAMP_TYPE_TOP
:
3447 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MI_STORE_REGISTER_MEM
,
3448 .RegisterAddress
= TIMESTAMP
,
3449 .MemoryAddress
= { bo
, buffer
->offset
+ destOffset
});
3450 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MI_STORE_REGISTER_MEM
,
3451 .RegisterAddress
= TIMESTAMP
+ 4,
3452 .MemoryAddress
= { bo
, buffer
->offset
+ destOffset
+ 4 });
3455 case VK_TIMESTAMP_TYPE_BOTTOM
:
3456 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
3457 .DestinationAddressType
= DAT_PPGTT
,
3458 .PostSyncOperation
= WriteTimestamp
,
3459 .Address
= /* FIXME: This is only lower 32 bits */
3460 { bo
, buffer
->offset
+ destOffset
});
3468 #define alu_opcode(v) __gen_field((v), 20, 31)
3469 #define alu_operand1(v) __gen_field((v), 10, 19)
3470 #define alu_operand2(v) __gen_field((v), 0, 9)
3471 #define alu(opcode, operand1, operand2) \
3472 alu_opcode(opcode) | alu_operand1(operand1) | alu_operand2(operand2)
3474 #define OPCODE_NOOP 0x000
3475 #define OPCODE_LOAD 0x080
3476 #define OPCODE_LOADINV 0x480
3477 #define OPCODE_LOAD0 0x081
3478 #define OPCODE_LOAD1 0x481
3479 #define OPCODE_ADD 0x100
3480 #define OPCODE_SUB 0x101
3481 #define OPCODE_AND 0x102
3482 #define OPCODE_OR 0x103
3483 #define OPCODE_XOR 0x104
3484 #define OPCODE_STORE 0x180
3485 #define OPCODE_STOREINV 0x580
3487 #define OPERAND_R0 0x00
3488 #define OPERAND_R1 0x01
3489 #define OPERAND_R2 0x02
3490 #define OPERAND_R3 0x03
3491 #define OPERAND_R4 0x04
3492 #define OPERAND_SRCA 0x20
3493 #define OPERAND_SRCB 0x21
3494 #define OPERAND_ACCU 0x31
3495 #define OPERAND_ZF 0x32
3496 #define OPERAND_CF 0x33
3498 #define CS_GPR(n) (0x2600 + (n) * 8)
3501 emit_load_alu_reg_u64(struct anv_batch
*batch
, uint32_t reg
,
3502 struct anv_bo
*bo
, uint32_t offset
)
3504 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_MEM
,
3505 .RegisterAddress
= reg
,
3506 .MemoryAddress
= { bo
, offset
});
3507 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_MEM
,
3508 .RegisterAddress
= reg
+ 4,
3509 .MemoryAddress
= { bo
, offset
+ 4 });
3512 void anv_CmdCopyQueryPoolResults(
3513 VkCmdBuffer cmdBuffer
,
3514 VkQueryPool queryPool
,
3515 uint32_t startQuery
,
3516 uint32_t queryCount
,
3517 VkBuffer destBuffer
,
3518 VkDeviceSize destOffset
,
3519 VkDeviceSize destStride
,
3520 VkQueryResultFlags flags
)
3522 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3523 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
3524 struct anv_buffer
*buffer
= (struct anv_buffer
*) destBuffer
;
3525 uint32_t slot_offset
, dst_offset
;
3527 if (flags
& VK_QUERY_RESULT_WITH_AVAILABILITY_BIT
) {
3528 /* Where is the availabilty info supposed to go? */
3529 anv_finishme("VK_QUERY_RESULT_WITH_AVAILABILITY_BIT");
3533 assert(pool
->type
== VK_QUERY_TYPE_OCCLUSION
);
3535 /* FIXME: If we're not waiting, should we just do this on the CPU? */
3536 if (flags
& VK_QUERY_RESULT_WAIT_BIT
)
3537 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
3538 .CommandStreamerStallEnable
= true,
3539 .StallAtPixelScoreboard
= true);
3541 dst_offset
= buffer
->offset
+ destOffset
;
3542 for (uint32_t i
= 0; i
< queryCount
; i
++) {
3544 slot_offset
= (startQuery
+ i
) * sizeof(struct anv_query_pool_slot
);
3546 emit_load_alu_reg_u64(&cmd_buffer
->batch
, CS_GPR(0), &pool
->bo
, slot_offset
);
3547 emit_load_alu_reg_u64(&cmd_buffer
->batch
, CS_GPR(1), &pool
->bo
, slot_offset
+ 8);
3549 /* FIXME: We need to clamp the result for 32 bit. */
3551 uint32_t *dw
= anv_batch_emitn(&cmd_buffer
->batch
, 5, GEN8_MI_MATH
);
3552 dw
[1] = alu(OPCODE_LOAD
, OPERAND_SRCA
, OPERAND_R1
);
3553 dw
[2] = alu(OPCODE_LOAD
, OPERAND_SRCB
, OPERAND_R0
);
3554 dw
[3] = alu(OPCODE_SUB
, 0, 0);
3555 dw
[4] = alu(OPCODE_STORE
, OPERAND_R2
, OPERAND_ACCU
);
3557 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MI_STORE_REGISTER_MEM
,
3558 .RegisterAddress
= CS_GPR(2),
3559 /* FIXME: This is only lower 32 bits */
3560 .MemoryAddress
= { buffer
->bo
, dst_offset
});
3562 if (flags
& VK_QUERY_RESULT_64_BIT
)
3563 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MI_STORE_REGISTER_MEM
,
3564 .RegisterAddress
= CS_GPR(2) + 4,
3565 /* FIXME: This is only lower 32 bits */
3566 .MemoryAddress
= { buffer
->bo
, dst_offset
+ 4 });
3568 dst_offset
+= destStride
;
3572 void anv_CmdInitAtomicCounters(
3573 VkCmdBuffer cmdBuffer
,
3574 VkPipelineBindPoint pipelineBindPoint
,
3575 uint32_t startCounter
,
3576 uint32_t counterCount
,
3577 const uint32_t* pData
)
3582 void anv_CmdLoadAtomicCounters(
3583 VkCmdBuffer cmdBuffer
,
3584 VkPipelineBindPoint pipelineBindPoint
,
3585 uint32_t startCounter
,
3586 uint32_t counterCount
,
3588 VkDeviceSize srcOffset
)
3593 void anv_CmdSaveAtomicCounters(
3594 VkCmdBuffer cmdBuffer
,
3595 VkPipelineBindPoint pipelineBindPoint
,
3596 uint32_t startCounter
,
3597 uint32_t counterCount
,
3598 VkBuffer destBuffer
,
3599 VkDeviceSize destOffset
)
3605 anv_framebuffer_destroy(struct anv_device
*device
,
3606 struct anv_object
*object
,
3607 VkObjectType obj_type
)
3609 struct anv_framebuffer
*fb
= (struct anv_framebuffer
*)object
;
3611 assert(obj_type
== VK_OBJECT_TYPE_FRAMEBUFFER
);
3613 anv_DestroyObject((VkDevice
) device
,
3614 VK_OBJECT_TYPE_DYNAMIC_VP_STATE
,
3617 anv_device_free(device
, fb
);
3620 VkResult
anv_CreateFramebuffer(
3622 const VkFramebufferCreateInfo
* pCreateInfo
,
3623 VkFramebuffer
* pFramebuffer
)
3625 struct anv_device
*device
= (struct anv_device
*) _device
;
3626 struct anv_framebuffer
*framebuffer
;
3628 static const struct anv_depth_stencil_view null_view
=
3629 { .depth_format
= D16_UNORM
, .depth_stride
= 0, .stencil_stride
= 0 };
3631 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3633 framebuffer
= anv_device_alloc(device
, sizeof(*framebuffer
), 8,
3634 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
3635 if (framebuffer
== NULL
)
3636 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3638 framebuffer
->base
.destructor
= anv_framebuffer_destroy
;
3640 framebuffer
->color_attachment_count
= pCreateInfo
->colorAttachmentCount
;
3641 for (uint32_t i
= 0; i
< pCreateInfo
->colorAttachmentCount
; i
++) {
3642 framebuffer
->color_attachments
[i
] =
3643 (struct anv_surface_view
*) pCreateInfo
->pColorAttachments
[i
].view
;
3646 if (pCreateInfo
->pDepthStencilAttachment
) {
3647 framebuffer
->depth_stencil
=
3648 (struct anv_depth_stencil_view
*) pCreateInfo
->pDepthStencilAttachment
->view
;
3650 framebuffer
->depth_stencil
= &null_view
;
3653 framebuffer
->sample_count
= pCreateInfo
->sampleCount
;
3654 framebuffer
->width
= pCreateInfo
->width
;
3655 framebuffer
->height
= pCreateInfo
->height
;
3656 framebuffer
->layers
= pCreateInfo
->layers
;
3658 vkCreateDynamicViewportState((VkDevice
) device
,
3659 &(VkDynamicVpStateCreateInfo
) {
3660 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
,
3661 .viewportAndScissorCount
= 1,
3662 .pViewports
= (VkViewport
[]) {
3666 .width
= pCreateInfo
->width
,
3667 .height
= pCreateInfo
->height
,
3672 .pScissors
= (VkRect
[]) {
3674 { pCreateInfo
->width
, pCreateInfo
->height
} },
3677 &framebuffer
->vp_state
);
3679 *pFramebuffer
= (VkFramebuffer
) framebuffer
;
3684 VkResult
anv_CreateRenderPass(
3686 const VkRenderPassCreateInfo
* pCreateInfo
,
3687 VkRenderPass
* pRenderPass
)
3689 struct anv_device
*device
= (struct anv_device
*) _device
;
3690 struct anv_render_pass
*pass
;
3693 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
3695 size
= sizeof(*pass
) +
3696 pCreateInfo
->layers
* sizeof(struct anv_render_pass_layer
);
3697 pass
= anv_device_alloc(device
, size
, 8,
3698 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
3700 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3702 pass
->render_area
= pCreateInfo
->renderArea
;
3704 pass
->num_layers
= pCreateInfo
->layers
;
3706 pass
->num_clear_layers
= 0;
3707 for (uint32_t i
= 0; i
< pCreateInfo
->layers
; i
++) {
3708 pass
->layers
[i
].color_load_op
= pCreateInfo
->pColorLoadOps
[i
];
3709 pass
->layers
[i
].clear_color
= pCreateInfo
->pColorLoadClearValues
[i
];
3710 if (pass
->layers
[i
].color_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
)
3711 pass
->num_clear_layers
++;
3714 *pRenderPass
= (VkRenderPass
) pass
;
3720 anv_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
,
3721 struct anv_render_pass
*pass
)
3723 const struct anv_depth_stencil_view
*view
=
3724 cmd_buffer
->framebuffer
->depth_stencil
;
3726 /* FIXME: Implement the PMA stall W/A */
3728 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DEPTH_BUFFER
,
3729 .SurfaceType
= SURFTYPE_2D
,
3730 .DepthWriteEnable
= view
->depth_stride
> 0,
3731 .StencilWriteEnable
= view
->stencil_stride
> 0,
3732 .HierarchicalDepthBufferEnable
= false,
3733 .SurfaceFormat
= view
->depth_format
,
3734 .SurfacePitch
= view
->depth_stride
> 0 ? view
->depth_stride
- 1 : 0,
3735 .SurfaceBaseAddress
= { view
->bo
, view
->depth_offset
},
3736 .Height
= pass
->render_area
.extent
.height
- 1,
3737 .Width
= pass
->render_area
.extent
.width
- 1,
3740 .MinimumArrayElement
= 0,
3741 .DepthBufferObjectControlState
= GEN8_MOCS
,
3742 .RenderTargetViewExtent
= 1 - 1,
3743 .SurfaceQPitch
= 0);
3745 /* Disable hierarchial depth buffers. */
3746 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_HIER_DEPTH_BUFFER
);
3748 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_STENCIL_BUFFER
,
3749 .StencilBufferEnable
= view
->stencil_stride
> 0,
3750 .StencilBufferObjectControlState
= GEN8_MOCS
,
3751 .SurfacePitch
= view
->stencil_stride
> 0 ? view
->stencil_stride
- 1 : 0,
3752 .SurfaceBaseAddress
= { view
->bo
, view
->stencil_offset
},
3753 .SurfaceQPitch
= 0);
3755 /* Clear the clear params. */
3756 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_CLEAR_PARAMS
);
3759 void anv_CmdBeginRenderPass(
3760 VkCmdBuffer cmdBuffer
,
3761 const VkRenderPassBegin
* pRenderPassBegin
)
3763 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3764 struct anv_render_pass
*pass
= (struct anv_render_pass
*) pRenderPassBegin
->renderPass
;
3765 struct anv_framebuffer
*framebuffer
=
3766 (struct anv_framebuffer
*) pRenderPassBegin
->framebuffer
;
3768 cmd_buffer
->framebuffer
= framebuffer
;
3770 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
3772 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DRAWING_RECTANGLE
,
3773 .ClippedDrawingRectangleYMin
= pass
->render_area
.offset
.y
,
3774 .ClippedDrawingRectangleXMin
= pass
->render_area
.offset
.x
,
3775 .ClippedDrawingRectangleYMax
=
3776 pass
->render_area
.offset
.y
+ pass
->render_area
.extent
.height
- 1,
3777 .ClippedDrawingRectangleXMax
=
3778 pass
->render_area
.offset
.x
+ pass
->render_area
.extent
.width
- 1,
3779 .DrawingRectangleOriginY
= 0,
3780 .DrawingRectangleOriginX
= 0);
3782 anv_cmd_buffer_emit_depth_stencil(cmd_buffer
, pass
);
3784 anv_cmd_buffer_clear(cmd_buffer
, pass
);
3787 void anv_CmdEndRenderPass(
3788 VkCmdBuffer cmdBuffer
,
3789 VkRenderPass renderPass
)
3791 /* Emit a flushing pipe control at the end of a pass. This is kind of a
3792 * hack but it ensures that render targets always actually get written.
3793 * Eventually, we should do flushing based on image format transitions
3794 * or something of that nature.
3796 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
3797 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
3798 .PostSyncOperation
= NoWrite
,
3799 .RenderTargetCacheFlushEnable
= true,
3800 .InstructionCacheInvalidateEnable
= true,
3801 .DepthCacheFlushEnable
= true,
3802 .VFCacheInvalidationEnable
= true,
3803 .TextureCacheInvalidationEnable
= true,
3804 .CommandStreamerStallEnable
= true);
3807 void vkCmdDbgMarkerBegin(
3808 VkCmdBuffer cmdBuffer
,
3809 const char* pMarker
)
3810 __attribute__ ((visibility ("default")));
3812 void vkCmdDbgMarkerEnd(
3813 VkCmdBuffer cmdBuffer
)
3814 __attribute__ ((visibility ("default")));
3816 VkResult
vkDbgSetObjectTag(
3821 __attribute__ ((visibility ("default")));
3824 void vkCmdDbgMarkerBegin(
3825 VkCmdBuffer cmdBuffer
,
3826 const char* pMarker
)
3830 void vkCmdDbgMarkerEnd(
3831 VkCmdBuffer cmdBuffer
)
3835 VkResult
vkDbgSetObjectTag(