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");
145 if (result
== VK_SUCCESS
)
146 instance
->physicalDeviceCount
++;
148 *pInstance
= (VkInstance
) instance
;
153 VkResult
anv_DestroyInstance(
154 VkInstance _instance
)
156 struct anv_instance
*instance
= (struct anv_instance
*) _instance
;
158 instance
->pfnFree(instance
->pAllocUserData
, instance
);
163 VkResult
anv_EnumeratePhysicalDevices(
164 VkInstance _instance
,
165 uint32_t* pPhysicalDeviceCount
,
166 VkPhysicalDevice
* pPhysicalDevices
)
168 struct anv_instance
*instance
= (struct anv_instance
*) _instance
;
170 if (*pPhysicalDeviceCount
>= 1)
171 pPhysicalDevices
[0] = (VkPhysicalDevice
) &instance
->physicalDevice
;
172 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
177 VkResult
anv_GetPhysicalDeviceInfo(
178 VkPhysicalDevice physicalDevice
,
179 VkPhysicalDeviceInfoType infoType
,
183 struct anv_physical_device
*device
= (struct anv_physical_device
*) physicalDevice
;
184 VkPhysicalDeviceProperties
*properties
;
185 VkPhysicalDevicePerformance
*performance
;
186 VkPhysicalDeviceQueueProperties
*queue_properties
;
187 VkPhysicalDeviceMemoryProperties
*memory_properties
;
188 uint64_t ns_per_tick
= 80;
191 case VK_PHYSICAL_DEVICE_INFO_TYPE_PROPERTIES
:
194 *pDataSize
= sizeof(*properties
);
198 properties
->apiVersion
= 1;
199 properties
->driverVersion
= 1;
200 properties
->vendorId
= 0x8086;
201 properties
->deviceId
= device
->chipset_id
;
202 properties
->deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
;
203 strcpy(properties
->deviceName
, device
->name
);
204 properties
->maxInlineMemoryUpdateSize
= 0;
205 properties
->maxBoundDescriptorSets
= 0;
206 properties
->maxThreadGroupSize
= 0;
207 properties
->timestampFrequency
= 1000 * 1000 * 1000 / ns_per_tick
;
208 properties
->multiColorAttachmentClears
= 0;
209 properties
->maxDescriptorSets
= 2;
210 properties
->maxViewports
= 16;
211 properties
->maxColorAttachments
= 8;
214 case VK_PHYSICAL_DEVICE_INFO_TYPE_PERFORMANCE
:
217 *pDataSize
= sizeof(*performance
);
221 performance
->maxDeviceClock
= 1.0;
222 performance
->aluPerClock
= 1.0;
223 performance
->texPerClock
= 1.0;
224 performance
->primsPerClock
= 1.0;
225 performance
->pixelsPerClock
= 1.0;
228 case VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES
:
229 queue_properties
= pData
;
231 *pDataSize
= sizeof(*queue_properties
);
235 queue_properties
->queueFlags
= 0;
236 queue_properties
->queueCount
= 1;
237 queue_properties
->maxAtomicCounters
= 0;
238 queue_properties
->supportsTimestamps
= 0;
239 queue_properties
->maxMemReferences
= 0;
242 case VK_PHYSICAL_DEVICE_INFO_TYPE_MEMORY_PROPERTIES
:
243 memory_properties
= pData
;
245 *pDataSize
= sizeof(*memory_properties
);
249 memory_properties
->supportsMigration
= false;
250 memory_properties
->supportsPinning
= false;
254 return VK_UNSUPPORTED
;
259 void * vkGetProcAddr(
260 VkPhysicalDevice physicalDevice
,
263 return anv_lookup_entrypoint(pName
);
267 parse_debug_flags(struct anv_device
*device
)
269 const char *debug
, *p
, *end
;
271 debug
= getenv("INTEL_DEBUG");
272 device
->dump_aub
= false;
274 for (p
= debug
; *p
; p
= end
+ 1) {
275 end
= strchrnul(p
, ',');
276 if (end
- p
== 3 && memcmp(p
, "aub", 3) == 0)
277 device
->dump_aub
= true;
278 if (end
- p
== 5 && memcmp(p
, "no_hw", 5) == 0)
279 device
->no_hw
= true;
286 VkResult
anv_CreateDevice(
287 VkPhysicalDevice _physicalDevice
,
288 const VkDeviceCreateInfo
* pCreateInfo
,
291 struct anv_physical_device
*physicalDevice
=
292 (struct anv_physical_device
*) _physicalDevice
;
293 struct anv_instance
*instance
= physicalDevice
->instance
;
294 struct anv_device
*device
;
296 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
298 device
= instance
->pfnAlloc(instance
->pAllocUserData
,
300 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
302 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
304 device
->no_hw
= physicalDevice
->no_hw
;
305 parse_debug_flags(device
);
307 device
->instance
= physicalDevice
->instance
;
308 device
->fd
= open("/dev/dri/renderD128", O_RDWR
| O_CLOEXEC
);
309 if (device
->fd
== -1)
312 device
->context_id
= anv_gem_create_context(device
);
313 if (device
->context_id
== -1)
316 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 2048);
318 anv_state_pool_init(&device
->dynamic_state_pool
,
319 &device
->dynamic_state_block_pool
);
321 anv_block_pool_init(&device
->instruction_block_pool
, device
, 2048);
322 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 2048);
324 anv_state_pool_init(&device
->surface_state_pool
,
325 &device
->surface_state_block_pool
);
327 device
->compiler
= anv_compiler_create(device
->fd
);
328 device
->aub_writer
= NULL
;
330 device
->info
= *physicalDevice
->info
;
332 pthread_mutex_init(&device
->mutex
, NULL
);
334 anv_device_init_meta(device
);
336 *pDevice
= (VkDevice
) device
;
343 anv_device_free(device
, device
);
345 return vk_error(VK_ERROR_UNAVAILABLE
);
348 VkResult
anv_DestroyDevice(
351 struct anv_device
*device
= (struct anv_device
*) _device
;
353 anv_compiler_destroy(device
->compiler
);
355 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
356 anv_block_pool_finish(&device
->instruction_block_pool
);
357 anv_block_pool_finish(&device
->surface_state_block_pool
);
361 if (device
->aub_writer
)
362 anv_aub_writer_destroy(device
->aub_writer
);
364 anv_device_free(device
, device
);
369 VkResult
anv_GetGlobalExtensionInfo(
370 VkExtensionInfoType infoType
,
371 uint32_t extensionIndex
,
378 case VK_EXTENSION_INFO_TYPE_COUNT
:
380 assert(*pDataSize
== 4);
384 case VK_EXTENSION_INFO_TYPE_PROPERTIES
:
385 return vk_error(VK_ERROR_INVALID_EXTENSION
);
388 return VK_UNSUPPORTED
;
392 VkResult
anv_GetPhysicalDeviceExtensionInfo(
393 VkPhysicalDevice physicalDevice
,
394 VkExtensionInfoType infoType
,
395 uint32_t extensionIndex
,
402 case VK_EXTENSION_INFO_TYPE_COUNT
:
411 case VK_EXTENSION_INFO_TYPE_PROPERTIES
:
412 return vk_error(VK_ERROR_INVALID_EXTENSION
);
415 return VK_UNSUPPORTED
;
419 VkResult
anv_EnumerateLayers(
420 VkPhysicalDevice physicalDevice
,
421 size_t maxStringSize
,
423 char* const* pOutLayers
,
431 VkResult
anv_GetDeviceQueue(
433 uint32_t queueNodeIndex
,
437 struct anv_device
*device
= (struct anv_device
*) _device
;
438 struct anv_queue
*queue
;
440 /* FIXME: Should allocate these at device create time. */
442 queue
= anv_device_alloc(device
, sizeof(*queue
), 8,
443 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
445 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
447 queue
->device
= device
;
448 queue
->pool
= &device
->surface_state_pool
;
450 queue
->completed_serial
= anv_state_pool_alloc(queue
->pool
, 4, 4);
451 *(uint32_t *)queue
->completed_serial
.map
= 0;
452 queue
->next_serial
= 1;
454 *pQueue
= (VkQueue
) queue
;
459 static const uint32_t BATCH_SIZE
= 8192;
462 anv_batch_init(struct anv_batch
*batch
, struct anv_device
*device
)
466 result
= anv_bo_init_new(&batch
->bo
, device
, BATCH_SIZE
);
467 if (result
!= VK_SUCCESS
)
471 anv_gem_mmap(device
, batch
->bo
.gem_handle
, 0, BATCH_SIZE
);
472 if (batch
->bo
.map
== NULL
) {
473 anv_gem_close(device
, batch
->bo
.gem_handle
);
474 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
477 batch
->cmd_relocs
.num_relocs
= 0;
478 batch
->surf_relocs
.num_relocs
= 0;
479 batch
->next
= batch
->bo
.map
;
485 anv_batch_finish(struct anv_batch
*batch
, struct anv_device
*device
)
487 anv_gem_munmap(batch
->bo
.map
, BATCH_SIZE
);
488 anv_gem_close(device
, batch
->bo
.gem_handle
);
492 anv_batch_reset(struct anv_batch
*batch
)
494 batch
->next
= batch
->bo
.map
;
495 batch
->cmd_relocs
.num_relocs
= 0;
496 batch
->surf_relocs
.num_relocs
= 0;
500 anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
)
502 void *p
= batch
->next
;
504 batch
->next
+= num_dwords
* 4;
510 anv_reloc_list_append(struct anv_reloc_list
*list
,
511 struct anv_reloc_list
*other
, uint32_t offset
)
515 count
= list
->num_relocs
;
516 memcpy(&list
->relocs
[count
], &other
->relocs
[0],
517 other
->num_relocs
* sizeof(other
->relocs
[0]));
518 memcpy(&list
->reloc_bos
[count
], &other
->reloc_bos
[0],
519 other
->num_relocs
* sizeof(other
->reloc_bos
[0]));
520 for (i
= 0; i
< other
->num_relocs
; i
++)
521 list
->relocs
[i
+ count
].offset
+= offset
;
523 count
+= other
->num_relocs
;
527 anv_reloc_list_add(struct anv_reloc_list
*list
,
529 struct anv_bo
*target_bo
, uint32_t delta
)
531 struct drm_i915_gem_relocation_entry
*entry
;
534 assert(list
->num_relocs
< ANV_BATCH_MAX_RELOCS
);
536 /* XXX: Can we use I915_EXEC_HANDLE_LUT? */
537 index
= list
->num_relocs
++;
538 list
->reloc_bos
[index
] = target_bo
;
539 entry
= &list
->relocs
[index
];
540 entry
->target_handle
= target_bo
->gem_handle
;
541 entry
->delta
= delta
;
542 entry
->offset
= offset
;
543 entry
->presumed_offset
= target_bo
->offset
;
544 entry
->read_domains
= 0;
545 entry
->write_domain
= 0;
547 return target_bo
->offset
+ delta
;
551 anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
)
553 uint32_t size
, offset
;
555 size
= other
->next
- other
->bo
.map
;
556 memcpy(batch
->next
, other
->bo
.map
, size
);
558 offset
= batch
->next
- batch
->bo
.map
;
559 anv_reloc_list_append(&batch
->cmd_relocs
, &other
->cmd_relocs
, offset
);
560 anv_reloc_list_append(&batch
->surf_relocs
, &other
->surf_relocs
, offset
);
566 anv_batch_emit_reloc(struct anv_batch
*batch
,
567 void *location
, struct anv_bo
*bo
, uint32_t delta
)
569 return anv_reloc_list_add(&batch
->cmd_relocs
,
570 location
- batch
->bo
.map
, bo
, delta
);
573 VkResult
anv_QueueSubmit(
575 uint32_t cmdBufferCount
,
576 const VkCmdBuffer
* pCmdBuffers
,
579 struct anv_queue
*queue
= (struct anv_queue
*) _queue
;
580 struct anv_device
*device
= queue
->device
;
581 struct anv_fence
*fence
= (struct anv_fence
*) _fence
;
584 for (uint32_t i
= 0; i
< cmdBufferCount
; i
++) {
585 struct anv_cmd_buffer
*cmd_buffer
=
586 (struct anv_cmd_buffer
*) pCmdBuffers
[i
];
588 if (device
->dump_aub
)
589 anv_cmd_buffer_dump(cmd_buffer
);
591 if (!device
->no_hw
) {
592 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf
);
594 return vk_error(VK_ERROR_UNKNOWN
);
597 ret
= anv_gem_execbuffer(device
, &fence
->execbuf
);
599 return vk_error(VK_ERROR_UNKNOWN
);
602 for (uint32_t i
= 0; i
< cmd_buffer
->bo_count
; i
++)
603 cmd_buffer
->exec2_bos
[i
]->offset
= cmd_buffer
->exec2_objects
[i
].offset
;
605 *(uint32_t *)queue
->completed_serial
.map
= cmd_buffer
->serial
;
612 VkResult
anv_QueueAddMemReferences(
615 const VkDeviceMemory
* pMems
)
620 VkResult
anv_QueueRemoveMemReferences(
623 const VkDeviceMemory
* pMems
)
628 VkResult
anv_QueueWaitIdle(
631 struct anv_queue
*queue
= (struct anv_queue
*) _queue
;
633 return vkDeviceWaitIdle((VkDevice
) queue
->device
);
636 VkResult
anv_DeviceWaitIdle(
639 struct anv_device
*device
= (struct anv_device
*) _device
;
640 struct anv_state state
;
641 struct anv_batch batch
;
642 struct drm_i915_gem_execbuffer2 execbuf
;
643 struct drm_i915_gem_exec_object2 exec2_objects
[1];
644 struct anv_bo
*bo
= NULL
;
649 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, 32, 32);
650 bo
= &device
->dynamic_state_pool
.block_pool
->bo
;
651 batch
.next
= state
.map
;
652 anv_batch_emit(&batch
, GEN8_MI_BATCH_BUFFER_END
);
653 anv_batch_emit(&batch
, GEN8_MI_NOOP
);
655 exec2_objects
[0].handle
= bo
->gem_handle
;
656 exec2_objects
[0].relocation_count
= 0;
657 exec2_objects
[0].relocs_ptr
= 0;
658 exec2_objects
[0].alignment
= 0;
659 exec2_objects
[0].offset
= bo
->offset
;
660 exec2_objects
[0].flags
= 0;
661 exec2_objects
[0].rsvd1
= 0;
662 exec2_objects
[0].rsvd2
= 0;
664 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
665 execbuf
.buffer_count
= 1;
666 execbuf
.batch_start_offset
= state
.offset
;
667 execbuf
.batch_len
= batch
.next
- state
.map
;
668 execbuf
.cliprects_ptr
= 0;
669 execbuf
.num_cliprects
= 0;
674 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
675 execbuf
.rsvd1
= device
->context_id
;
678 if (!device
->no_hw
) {
679 ret
= anv_gem_execbuffer(device
, &execbuf
);
681 result
= vk_error(VK_ERROR_UNKNOWN
);
686 ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
688 result
= vk_error(VK_ERROR_UNKNOWN
);
693 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
698 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
704 anv_device_alloc(struct anv_device
* device
,
707 VkSystemAllocType allocType
)
709 return device
->instance
->pfnAlloc(device
->instance
->pAllocUserData
,
716 anv_device_free(struct anv_device
* device
,
719 return device
->instance
->pfnFree(device
->instance
->pAllocUserData
,
724 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
726 bo
->gem_handle
= anv_gem_create(device
, size
);
728 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
738 VkResult
anv_AllocMemory(
740 const VkMemoryAllocInfo
* pAllocInfo
,
741 VkDeviceMemory
* pMem
)
743 struct anv_device
*device
= (struct anv_device
*) _device
;
744 struct anv_device_memory
*mem
;
747 assert(pAllocInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO
);
749 mem
= anv_device_alloc(device
, sizeof(*mem
), 8,
750 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
752 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
754 result
= anv_bo_init_new(&mem
->bo
, device
, pAllocInfo
->allocationSize
);
755 if (result
!= VK_SUCCESS
)
758 *pMem
= (VkDeviceMemory
) mem
;
763 anv_device_free(device
, mem
);
768 VkResult
anv_FreeMemory(
772 struct anv_device
*device
= (struct anv_device
*) _device
;
773 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
776 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
778 if (mem
->bo
.gem_handle
!= 0)
779 anv_gem_close(device
, mem
->bo
.gem_handle
);
781 anv_device_free(device
, mem
);
786 VkResult
anv_SetMemoryPriority(
789 VkMemoryPriority priority
)
794 VkResult
anv_MapMemory(
799 VkMemoryMapFlags flags
,
802 struct anv_device
*device
= (struct anv_device
*) _device
;
803 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
805 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
806 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
807 * at a time is valid. We could just mmap up front and return an offset
808 * pointer here, but that may exhaust virtual memory on 32 bit
811 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
, offset
, size
);
812 mem
->map_size
= size
;
819 VkResult
anv_UnmapMemory(
823 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
825 anv_gem_munmap(mem
->map
, mem
->map_size
);
830 VkResult
anv_FlushMappedMemory(
836 /* clflush here for !llc platforms */
841 VkResult
anv_PinSystemMemory(
845 VkDeviceMemory
* pMem
)
850 VkResult
anv_GetMultiDeviceCompatibility(
851 VkPhysicalDevice physicalDevice0
,
852 VkPhysicalDevice physicalDevice1
,
853 VkPhysicalDeviceCompatibilityInfo
* pInfo
)
855 return VK_UNSUPPORTED
;
858 VkResult
anv_OpenSharedMemory(
860 const VkMemoryOpenInfo
* pOpenInfo
,
861 VkDeviceMemory
* pMem
)
863 return VK_UNSUPPORTED
;
866 VkResult
anv_OpenSharedSemaphore(
868 const VkSemaphoreOpenInfo
* pOpenInfo
,
869 VkSemaphore
* pSemaphore
)
871 return VK_UNSUPPORTED
;
874 VkResult
anv_OpenPeerMemory(
876 const VkPeerMemoryOpenInfo
* pOpenInfo
,
877 VkDeviceMemory
* pMem
)
879 return VK_UNSUPPORTED
;
882 VkResult
anv_OpenPeerImage(
884 const VkPeerImageOpenInfo
* pOpenInfo
,
886 VkDeviceMemory
* pMem
)
888 return VK_UNSUPPORTED
;
892 anv_instance_destructor(struct anv_device
* device
,
895 return vkDestroyInstance(object
);
899 anv_noop_destructor(struct anv_device
* device
,
906 anv_device_destructor(struct anv_device
* device
,
909 return vkDestroyDevice(object
);
913 anv_cmd_buffer_destructor(struct anv_device
* device
,
916 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) object
;
918 anv_state_stream_finish(&cmd_buffer
->surface_state_stream
);
919 anv_state_stream_finish(&cmd_buffer
->dynamic_state_stream
);
920 anv_batch_finish(&cmd_buffer
->batch
, device
);
921 anv_device_free(device
, cmd_buffer
->exec2_objects
);
922 anv_device_free(device
, cmd_buffer
->exec2_bos
);
923 anv_device_free(device
, cmd_buffer
);
929 anv_pipeline_destructor(struct anv_device
* device
,
932 struct anv_pipeline
*pipeline
= (struct anv_pipeline
*) object
;
934 return anv_pipeline_destroy(pipeline
);
938 anv_free_destructor(struct anv_device
* device
,
941 anv_device_free(device
, (void *) object
);
947 anv_fence_destructor(struct anv_device
* device
,
950 struct anv_fence
*fence
= (struct anv_fence
*) object
;
952 anv_gem_munmap(fence
->bo
.map
, fence
->bo
.size
);
953 anv_gem_close(device
, fence
->bo
.gem_handle
);
954 anv_device_free(device
, fence
);
959 static VkResult (*anv_object_destructors
[])(struct anv_device
*device
,
961 [VK_OBJECT_TYPE_INSTANCE
] = anv_instance_destructor
,
962 [VK_OBJECT_TYPE_PHYSICAL_DEVICE
] = anv_noop_destructor
,
963 [VK_OBJECT_TYPE_DEVICE
] = anv_device_destructor
,
964 [VK_OBJECT_TYPE_QUEUE
] = anv_noop_destructor
,
965 [VK_OBJECT_TYPE_COMMAND_BUFFER
] = anv_cmd_buffer_destructor
,
966 [VK_OBJECT_TYPE_PIPELINE
] = anv_pipeline_destructor
,
967 [VK_OBJECT_TYPE_SHADER
] = anv_free_destructor
,
968 [VK_OBJECT_TYPE_BUFFER
] = anv_free_destructor
,
969 [VK_OBJECT_TYPE_IMAGE
] = anv_free_destructor
,
970 [VK_OBJECT_TYPE_RENDER_PASS
] = anv_free_destructor
,
971 [VK_OBJECT_TYPE_FENCE
] = anv_fence_destructor
974 VkResult
anv_DestroyObject(
976 VkObjectType objType
,
979 struct anv_device
*device
= (struct anv_device
*) _device
;
981 assert(objType
< ARRAY_SIZE(anv_object_destructors
) &&
982 anv_object_destructors
[objType
] != NULL
);
984 return anv_object_destructors
[objType
](device
, object
);
988 fill_memory_requirements(
989 VkObjectType objType
,
991 VkMemoryRequirements
* memory_requirements
)
993 struct anv_buffer
*buffer
;
994 struct anv_image
*image
;
996 memory_requirements
->memPropsAllowed
=
997 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
998 VK_MEMORY_PROPERTY_HOST_DEVICE_COHERENT_BIT
|
999 /* VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT | */
1000 VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT
|
1001 VK_MEMORY_PROPERTY_PREFER_HOST_LOCAL
|
1002 VK_MEMORY_PROPERTY_SHAREABLE_BIT
;
1004 memory_requirements
->memPropsRequired
= 0;
1007 case VK_OBJECT_TYPE_BUFFER
:
1008 buffer
= (struct anv_buffer
*) object
;
1009 memory_requirements
->size
= buffer
->size
;
1010 memory_requirements
->alignment
= 16;
1012 case VK_OBJECT_TYPE_IMAGE
:
1013 image
= (struct anv_image
*) object
;
1014 memory_requirements
->size
= image
->size
;
1015 memory_requirements
->alignment
= image
->alignment
;
1018 memory_requirements
->size
= 0;
1024 get_allocation_count(VkObjectType objType
)
1027 case VK_OBJECT_TYPE_BUFFER
:
1028 case VK_OBJECT_TYPE_IMAGE
:
1035 VkResult
anv_GetObjectInfo(
1037 VkObjectType objType
,
1039 VkObjectInfoType infoType
,
1043 VkMemoryRequirements memory_requirements
;
1047 case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS
:
1048 *pDataSize
= sizeof(memory_requirements
);
1052 fill_memory_requirements(objType
, object
, &memory_requirements
);
1053 memcpy(pData
, &memory_requirements
,
1054 MIN2(*pDataSize
, sizeof(memory_requirements
)));
1057 case VK_OBJECT_INFO_TYPE_MEMORY_ALLOCATION_COUNT
:
1058 *pDataSize
= sizeof(count
);
1062 count
= get_allocation_count(objType
);
1066 return VK_UNSUPPORTED
;
1071 VkResult
anv_QueueBindObjectMemory(
1073 VkObjectType objType
,
1075 uint32_t allocationIdx
,
1076 VkDeviceMemory _mem
,
1077 VkDeviceSize memOffset
)
1079 struct anv_buffer
*buffer
;
1080 struct anv_image
*image
;
1081 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
1084 case VK_OBJECT_TYPE_BUFFER
:
1085 buffer
= (struct anv_buffer
*) object
;
1086 buffer
->bo
= &mem
->bo
;
1087 buffer
->offset
= memOffset
;
1089 case VK_OBJECT_TYPE_IMAGE
:
1090 image
= (struct anv_image
*) object
;
1091 image
->bo
= &mem
->bo
;
1092 image
->offset
= memOffset
;
1101 VkResult
anv_QueueBindObjectMemoryRange(
1103 VkObjectType objType
,
1105 uint32_t allocationIdx
,
1106 VkDeviceSize rangeOffset
,
1107 VkDeviceSize rangeSize
,
1109 VkDeviceSize memOffset
)
1111 stub_return(VK_UNSUPPORTED
);
1114 VkResult
anv_QueueBindImageMemoryRange(
1117 uint32_t allocationIdx
,
1118 const VkImageMemoryBindInfo
* pBindInfo
,
1120 VkDeviceSize memOffset
)
1122 stub_return(VK_UNSUPPORTED
);
1125 VkResult
anv_CreateFence(
1127 const VkFenceCreateInfo
* pCreateInfo
,
1130 struct anv_device
*device
= (struct anv_device
*) _device
;
1131 struct anv_fence
*fence
;
1132 struct anv_batch batch
;
1135 const uint32_t fence_size
= 128;
1137 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1139 fence
= anv_device_alloc(device
, sizeof(*fence
), 8,
1140 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1142 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1144 result
= anv_bo_init_new(&fence
->bo
, device
, fence_size
);
1145 if (result
!= VK_SUCCESS
)
1149 anv_gem_mmap(device
, fence
->bo
.gem_handle
, 0, fence
->bo
.size
);
1150 batch
.next
= fence
->bo
.map
;
1151 anv_batch_emit(&batch
, GEN8_MI_BATCH_BUFFER_END
);
1152 anv_batch_emit(&batch
, GEN8_MI_NOOP
);
1154 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1155 fence
->exec2_objects
[0].relocation_count
= 0;
1156 fence
->exec2_objects
[0].relocs_ptr
= 0;
1157 fence
->exec2_objects
[0].alignment
= 0;
1158 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1159 fence
->exec2_objects
[0].flags
= 0;
1160 fence
->exec2_objects
[0].rsvd1
= 0;
1161 fence
->exec2_objects
[0].rsvd2
= 0;
1163 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1164 fence
->execbuf
.buffer_count
= 1;
1165 fence
->execbuf
.batch_start_offset
= 0;
1166 fence
->execbuf
.batch_len
= batch
.next
- fence
->bo
.map
;
1167 fence
->execbuf
.cliprects_ptr
= 0;
1168 fence
->execbuf
.num_cliprects
= 0;
1169 fence
->execbuf
.DR1
= 0;
1170 fence
->execbuf
.DR4
= 0;
1172 fence
->execbuf
.flags
=
1173 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1174 fence
->execbuf
.rsvd1
= device
->context_id
;
1175 fence
->execbuf
.rsvd2
= 0;
1177 *pFence
= (VkQueryPool
) fence
;
1182 anv_device_free(device
, fence
);
1187 VkResult
anv_ResetFences(
1189 uint32_t fenceCount
,
1192 struct anv_fence
**fences
= (struct anv_fence
**) pFences
;
1194 for (uint32_t i
; i
< fenceCount
; i
++)
1195 fences
[i
]->ready
= false;
1200 VkResult
anv_GetFenceStatus(
1204 struct anv_device
*device
= (struct anv_device
*) _device
;
1205 struct anv_fence
*fence
= (struct anv_fence
*) _fence
;
1212 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1214 fence
->ready
= true;
1218 return VK_NOT_READY
;
1221 VkResult
anv_WaitForFences(
1223 uint32_t fenceCount
,
1224 const VkFence
* pFences
,
1228 struct anv_device
*device
= (struct anv_device
*) _device
;
1229 struct anv_fence
**fences
= (struct anv_fence
**) pFences
;
1230 int64_t t
= timeout
;
1233 /* FIXME: handle !waitAll */
1235 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1236 ret
= anv_gem_wait(device
, fences
[i
]->bo
.gem_handle
, &t
);
1237 if (ret
== -1 && errno
== ETIME
)
1240 return vk_error(VK_ERROR_UNKNOWN
);
1246 // Queue semaphore functions
1248 VkResult
anv_CreateSemaphore(
1250 const VkSemaphoreCreateInfo
* pCreateInfo
,
1251 VkSemaphore
* pSemaphore
)
1253 stub_return(VK_UNSUPPORTED
);
1256 VkResult
anv_QueueSignalSemaphore(
1258 VkSemaphore semaphore
)
1260 stub_return(VK_UNSUPPORTED
);
1263 VkResult
anv_QueueWaitSemaphore(
1265 VkSemaphore semaphore
)
1267 stub_return(VK_UNSUPPORTED
);
1272 VkResult
anv_CreateEvent(
1274 const VkEventCreateInfo
* pCreateInfo
,
1277 stub_return(VK_UNSUPPORTED
);
1280 VkResult
anv_GetEventStatus(
1284 stub_return(VK_UNSUPPORTED
);
1287 VkResult
anv_SetEvent(
1291 stub_return(VK_UNSUPPORTED
);
1294 VkResult
anv_ResetEvent(
1298 stub_return(VK_UNSUPPORTED
);
1303 struct anv_query_pool
{
1309 VkResult
anv_CreateQueryPool(
1311 const VkQueryPoolCreateInfo
* pCreateInfo
,
1312 VkQueryPool
* pQueryPool
)
1314 struct anv_device
*device
= (struct anv_device
*) _device
;
1315 struct anv_query_pool
*pool
;
1318 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
);
1320 pool
= anv_device_alloc(device
, sizeof(*pool
), 8,
1321 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1323 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1325 pool
->type
= pCreateInfo
->queryType
;
1326 result
= anv_bo_init_new(&pool
->bo
, device
, pCreateInfo
->slots
* 16);
1327 if (result
!= VK_SUCCESS
)
1330 *pQueryPool
= (VkQueryPool
) pool
;
1335 anv_device_free(device
, pool
);
1340 VkResult
anv_GetQueryPoolResults(
1342 VkQueryPool queryPool
,
1343 uint32_t startQuery
,
1344 uint32_t queryCount
,
1347 VkQueryResultFlags flags
)
1349 stub_return(VK_UNSUPPORTED
);
1354 VkResult
anv_CreateBuffer(
1356 const VkBufferCreateInfo
* pCreateInfo
,
1359 struct anv_device
*device
= (struct anv_device
*) _device
;
1360 struct anv_buffer
*buffer
;
1362 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1364 buffer
= anv_device_alloc(device
, sizeof(*buffer
), 8,
1365 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1367 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1369 buffer
->size
= pCreateInfo
->size
;
1373 *pBuffer
= (VkBuffer
) buffer
;
1378 // Buffer view functions
1380 VkResult
anv_CreateBufferView(
1382 const VkBufferViewCreateInfo
* pCreateInfo
,
1383 VkBufferView
* pView
)
1385 struct anv_device
*device
= (struct anv_device
*) _device
;
1386 struct anv_buffer
*buffer
= (struct anv_buffer
*) pCreateInfo
->buffer
;
1387 struct anv_surface_view
*view
;
1388 const struct anv_format
*format
;
1390 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO
);
1392 view
= anv_device_alloc(device
, sizeof(*view
), 8,
1393 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1395 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1397 view
->bo
= buffer
->bo
;
1398 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
1399 view
->surface_state
=
1400 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
1401 view
->format
= pCreateInfo
->format
;
1403 format
= anv_format_for_vk_format(pCreateInfo
->format
);
1404 /* This assumes RGBA float format. */
1405 uint32_t stride
= 4;
1406 uint32_t num_elements
= pCreateInfo
->range
/ stride
;
1407 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
1408 .SurfaceType
= SURFTYPE_BUFFER
,
1409 .SurfaceArray
= false,
1410 .SurfaceFormat
= format
->format
,
1411 .SurfaceVerticalAlignment
= VALIGN4
,
1412 .SurfaceHorizontalAlignment
= HALIGN4
,
1414 .VerticalLineStride
= 0,
1415 .VerticalLineStrideOffset
= 0,
1416 .SamplerL2BypassModeDisable
= true,
1417 .RenderCacheReadWriteMode
= WriteOnlyCache
,
1418 .MemoryObjectControlState
= 0, /* FIXME: MOCS */
1421 .Height
= (num_elements
>> 7) & 0x3fff,
1422 .Width
= num_elements
& 0x7f,
1423 .Depth
= (num_elements
>> 21) & 0x3f,
1424 .SurfacePitch
= stride
- 1,
1425 .MinimumArrayElement
= 0,
1426 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
1431 .AuxiliarySurfaceMode
= AUX_NONE
,
1433 .GreenClearColor
= 0,
1434 .BlueClearColor
= 0,
1435 .AlphaClearColor
= 0,
1436 .ShaderChannelSelectRed
= SCS_RED
,
1437 .ShaderChannelSelectGreen
= SCS_GREEN
,
1438 .ShaderChannelSelectBlue
= SCS_BLUE
,
1439 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
1440 .ResourceMinLOD
= 0,
1441 /* FIXME: We assume that the image must be bound at this time. */
1442 .SurfaceBaseAddress
= { NULL
, view
->offset
},
1445 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
1447 *pView
= (VkImageView
) view
;
1452 // Sampler functions
1454 VkResult
anv_CreateSampler(
1456 const VkSamplerCreateInfo
* pCreateInfo
,
1457 VkSampler
* pSampler
)
1459 struct anv_device
*device
= (struct anv_device
*) _device
;
1460 struct anv_sampler
*sampler
;
1462 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
1464 sampler
= anv_device_alloc(device
, sizeof(*sampler
), 8,
1465 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1467 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1469 static const uint32_t vk_to_gen_tex_filter
[] = {
1470 [VK_TEX_FILTER_NEAREST
] = MAPFILTER_NEAREST
,
1471 [VK_TEX_FILTER_LINEAR
] = MAPFILTER_LINEAR
1474 static const uint32_t vk_to_gen_mipmap_mode
[] = {
1475 [VK_TEX_MIPMAP_MODE_BASE
] = MIPFILTER_NONE
,
1476 [VK_TEX_MIPMAP_MODE_NEAREST
] = MIPFILTER_NEAREST
,
1477 [VK_TEX_MIPMAP_MODE_LINEAR
] = MIPFILTER_LINEAR
1480 static const uint32_t vk_to_gen_tex_address
[] = {
1481 [VK_TEX_ADDRESS_WRAP
] = TCM_WRAP
,
1482 [VK_TEX_ADDRESS_MIRROR
] = TCM_MIRROR
,
1483 [VK_TEX_ADDRESS_CLAMP
] = TCM_CLAMP
,
1484 [VK_TEX_ADDRESS_MIRROR_ONCE
] = TCM_MIRROR_ONCE
,
1485 [VK_TEX_ADDRESS_CLAMP_BORDER
] = TCM_CLAMP_BORDER
,
1488 static const uint32_t vk_to_gen_compare_op
[] = {
1489 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
1490 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
1491 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
1492 [VK_COMPARE_OP_LESS_EQUAL
] = PREFILTEROPLEQUAL
,
1493 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
1494 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
1495 [VK_COMPARE_OP_GREATER_EQUAL
] = PREFILTEROPGEQUAL
,
1496 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,
1499 if (pCreateInfo
->maxAnisotropy
> 0)
1500 anv_finishme("missing support for anisotropic filtering");
1502 struct GEN8_SAMPLER_STATE sampler_state
= {
1503 .SamplerDisable
= false,
1504 .TextureBorderColorMode
= DX10OGL
,
1505 .LODPreClampMode
= 0,
1507 .MipModeFilter
= vk_to_gen_mipmap_mode
[pCreateInfo
->mipMode
],
1508 .MagModeFilter
= vk_to_gen_tex_filter
[pCreateInfo
->magFilter
],
1509 .MinModeFilter
= vk_to_gen_tex_filter
[pCreateInfo
->minFilter
],
1510 .TextureLODBias
= pCreateInfo
->mipLodBias
* 256,
1511 .AnisotropicAlgorithm
= EWAApproximation
,
1512 .MinLOD
= pCreateInfo
->minLod
* 256,
1513 .MaxLOD
= pCreateInfo
->maxLod
* 256,
1514 .ChromaKeyEnable
= 0,
1515 .ChromaKeyIndex
= 0,
1517 .ShadowFunction
= vk_to_gen_compare_op
[pCreateInfo
->compareOp
],
1518 .CubeSurfaceControlMode
= 0,
1519 .IndirectStatePointer
= 0,
1520 .LODClampMagnificationMode
= MIPNONE
,
1521 .MaximumAnisotropy
= 0,
1522 .RAddressMinFilterRoundingEnable
= 0,
1523 .RAddressMagFilterRoundingEnable
= 0,
1524 .VAddressMinFilterRoundingEnable
= 0,
1525 .VAddressMagFilterRoundingEnable
= 0,
1526 .UAddressMinFilterRoundingEnable
= 0,
1527 .UAddressMagFilterRoundingEnable
= 0,
1528 .TrilinearFilterQuality
= 0,
1529 .NonnormalizedCoordinateEnable
= 0,
1530 .TCXAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressU
],
1531 .TCYAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressV
],
1532 .TCZAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressW
],
1535 GEN8_SAMPLER_STATE_pack(NULL
, sampler
->state
, &sampler_state
);
1537 *pSampler
= (VkSampler
) sampler
;
1542 // Descriptor set functions
1544 VkResult
anv_CreateDescriptorSetLayout(
1546 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
1547 VkDescriptorSetLayout
* pSetLayout
)
1549 struct anv_device
*device
= (struct anv_device
*) _device
;
1550 struct anv_descriptor_set_layout
*set_layout
;
1552 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
1554 uint32_t sampler_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1555 uint32_t surface_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1556 uint32_t num_dynamic_buffers
= 0;
1560 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1561 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1562 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1563 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1564 sampler_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1567 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1568 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1569 sampler_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1573 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1574 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1575 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1576 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1577 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1578 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1579 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1580 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1581 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1582 surface_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1588 count
+= pCreateInfo
->pBinding
[i
].count
;
1591 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1592 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1593 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1594 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1595 num_dynamic_buffers
++;
1602 uint32_t sampler_total
= 0;
1603 uint32_t surface_total
= 0;
1604 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1605 sampler_total
+= sampler_count
[s
];
1606 surface_total
+= surface_count
[s
];
1609 size_t size
= sizeof(*set_layout
) +
1610 (sampler_total
+ surface_total
) * sizeof(uint32_t);
1611 set_layout
= anv_device_alloc(device
, size
, 8,
1612 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1614 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1616 set_layout
->num_dynamic_buffers
= num_dynamic_buffers
;
1617 set_layout
->count
= count
;
1619 uint32_t *p
= set_layout
->entries
;
1620 uint32_t *sampler
[VK_NUM_SHADER_STAGE
];
1621 uint32_t *surface
[VK_NUM_SHADER_STAGE
];
1622 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1623 set_layout
->stage
[s
].surface_count
= surface_count
[s
];
1624 set_layout
->stage
[s
].surface_start
= surface
[s
] = p
;
1625 p
+= surface_count
[s
];
1626 set_layout
->stage
[s
].sampler_count
= sampler_count
[s
];
1627 set_layout
->stage
[s
].sampler_start
= sampler
[s
] = p
;
1628 p
+= sampler_count
[s
];
1631 uint32_t descriptor
= 0;
1632 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1633 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1634 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1635 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1636 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++)
1637 *(sampler
[s
])++ = descriptor
+ j
;
1640 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1641 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1642 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++)
1643 *(sampler
[s
])++ = descriptor
+ j
;
1647 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1648 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1649 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1650 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1651 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1652 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1653 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1654 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1655 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1656 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++) {
1657 *(surface
[s
])++ = descriptor
+ j
;
1663 descriptor
+= pCreateInfo
->pBinding
[i
].count
;
1666 *pSetLayout
= (VkDescriptorSetLayout
) set_layout
;
1671 VkResult
anv_BeginDescriptorPoolUpdate(
1673 VkDescriptorUpdateMode updateMode
)
1678 VkResult
anv_EndDescriptorPoolUpdate(
1685 VkResult
anv_CreateDescriptorPool(
1687 VkDescriptorPoolUsage poolUsage
,
1689 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
1690 VkDescriptorPool
* pDescriptorPool
)
1692 *pDescriptorPool
= 1;
1697 VkResult
anv_ResetDescriptorPool(
1699 VkDescriptorPool descriptorPool
)
1704 VkResult
anv_AllocDescriptorSets(
1706 VkDescriptorPool descriptorPool
,
1707 VkDescriptorSetUsage setUsage
,
1709 const VkDescriptorSetLayout
* pSetLayouts
,
1710 VkDescriptorSet
* pDescriptorSets
,
1713 struct anv_device
*device
= (struct anv_device
*) _device
;
1714 const struct anv_descriptor_set_layout
*layout
;
1715 struct anv_descriptor_set
*set
;
1718 for (uint32_t i
= 0; i
< count
; i
++) {
1719 layout
= (struct anv_descriptor_set_layout
*) pSetLayouts
[i
];
1720 size
= sizeof(*set
) + layout
->count
* sizeof(set
->descriptors
[0]);
1721 set
= anv_device_alloc(device
, size
, 8,
1722 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1725 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1728 pDescriptorSets
[i
] = (VkDescriptorSet
) set
;
1736 void anv_ClearDescriptorSets(
1738 VkDescriptorPool descriptorPool
,
1740 const VkDescriptorSet
* pDescriptorSets
)
1744 void anv_UpdateDescriptors(
1746 VkDescriptorSet descriptorSet
,
1747 uint32_t updateCount
,
1748 const void** ppUpdateArray
)
1750 struct anv_descriptor_set
*set
= (struct anv_descriptor_set
*) descriptorSet
;
1751 VkUpdateSamplers
*update_samplers
;
1752 VkUpdateSamplerTextures
*update_sampler_textures
;
1753 VkUpdateImages
*update_images
;
1754 VkUpdateBuffers
*update_buffers
;
1755 VkUpdateAsCopy
*update_as_copy
;
1757 for (uint32_t i
= 0; i
< updateCount
; i
++) {
1758 const struct anv_common
*common
= ppUpdateArray
[i
];
1760 switch (common
->sType
) {
1761 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS
:
1762 update_samplers
= (VkUpdateSamplers
*) common
;
1764 for (uint32_t j
= 0; j
< update_samplers
->count
; j
++) {
1765 set
->descriptors
[update_samplers
->binding
+ j
].sampler
=
1766 (struct anv_sampler
*) update_samplers
->pSamplers
[j
];
1770 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES
:
1771 /* FIXME: Shouldn't this be *_UPDATE_SAMPLER_IMAGES? */
1772 update_sampler_textures
= (VkUpdateSamplerTextures
*) common
;
1774 for (uint32_t j
= 0; j
< update_sampler_textures
->count
; j
++) {
1775 set
->descriptors
[update_sampler_textures
->binding
+ j
].view
=
1776 (struct anv_surface_view
*)
1777 update_sampler_textures
->pSamplerImageViews
[j
].pImageView
->view
;
1778 set
->descriptors
[update_sampler_textures
->binding
+ j
].sampler
=
1779 (struct anv_sampler
*)
1780 update_sampler_textures
->pSamplerImageViews
[j
].sampler
;
1784 case VK_STRUCTURE_TYPE_UPDATE_IMAGES
:
1785 update_images
= (VkUpdateImages
*) common
;
1787 for (uint32_t j
= 0; j
< update_images
->count
; j
++) {
1788 set
->descriptors
[update_images
->binding
+ j
].view
=
1789 (struct anv_surface_view
*) update_images
->pImageViews
[j
].view
;
1793 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS
:
1794 update_buffers
= (VkUpdateBuffers
*) common
;
1796 for (uint32_t j
= 0; j
< update_buffers
->count
; j
++) {
1797 set
->descriptors
[update_buffers
->binding
+ j
].view
=
1798 (struct anv_surface_view
*) update_buffers
->pBufferViews
[j
].view
;
1800 /* FIXME: descriptor arrays? */
1803 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY
:
1804 update_as_copy
= (VkUpdateAsCopy
*) common
;
1805 (void) update_as_copy
;
1814 // State object functions
1816 static inline int64_t
1817 clamp_int64(int64_t x
, int64_t min
, int64_t max
)
1827 VkResult
anv_CreateDynamicViewportState(
1829 const VkDynamicVpStateCreateInfo
* pCreateInfo
,
1830 VkDynamicVpState
* pState
)
1832 struct anv_device
*device
= (struct anv_device
*) _device
;
1833 struct anv_dynamic_vp_state
*state
;
1835 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
);
1837 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1838 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1840 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1842 unsigned count
= pCreateInfo
->viewportAndScissorCount
;
1843 state
->sf_clip_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1845 state
->cc_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1847 state
->scissor
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1850 for (uint32_t i
= 0; i
< pCreateInfo
->viewportAndScissorCount
; i
++) {
1851 const VkViewport
*vp
= &pCreateInfo
->pViewports
[i
];
1852 const VkRect
*s
= &pCreateInfo
->pScissors
[i
];
1854 struct GEN8_SF_CLIP_VIEWPORT sf_clip_viewport
= {
1855 .ViewportMatrixElementm00
= vp
->width
/ 2,
1856 .ViewportMatrixElementm11
= vp
->height
/ 2,
1857 .ViewportMatrixElementm22
= (vp
->maxDepth
- vp
->minDepth
) / 2,
1858 .ViewportMatrixElementm30
= vp
->originX
+ vp
->width
/ 2,
1859 .ViewportMatrixElementm31
= vp
->originY
+ vp
->height
/ 2,
1860 .ViewportMatrixElementm32
= (vp
->maxDepth
+ vp
->minDepth
) / 2,
1861 .XMinClipGuardband
= -1.0f
,
1862 .XMaxClipGuardband
= 1.0f
,
1863 .YMinClipGuardband
= -1.0f
,
1864 .YMaxClipGuardband
= 1.0f
,
1865 .XMinViewPort
= vp
->originX
,
1866 .XMaxViewPort
= vp
->originX
+ vp
->width
- 1,
1867 .YMinViewPort
= vp
->originY
,
1868 .YMaxViewPort
= vp
->originY
+ vp
->height
- 1,
1871 struct GEN8_CC_VIEWPORT cc_viewport
= {
1872 .MinimumDepth
= vp
->minDepth
,
1873 .MaximumDepth
= vp
->maxDepth
1876 /* Since xmax and ymax are inclusive, we have to have xmax < xmin or
1877 * ymax < ymin for empty clips. In case clip x, y, width height are all
1878 * 0, the clamps below produce 0 for xmin, ymin, xmax, ymax, which isn't
1879 * what we want. Just special case empty clips and produce a canonical
1881 static const struct GEN8_SCISSOR_RECT empty_scissor
= {
1882 .ScissorRectangleYMin
= 1,
1883 .ScissorRectangleXMin
= 1,
1884 .ScissorRectangleYMax
= 0,
1885 .ScissorRectangleXMax
= 0
1888 const int max
= 0xffff;
1889 struct GEN8_SCISSOR_RECT scissor
= {
1890 /* Do this math using int64_t so overflow gets clamped correctly. */
1891 .ScissorRectangleYMin
= clamp_int64(s
->offset
.y
, 0, max
),
1892 .ScissorRectangleXMin
= clamp_int64(s
->offset
.x
, 0, max
),
1893 .ScissorRectangleYMax
= clamp_int64((uint64_t) s
->offset
.y
+ s
->extent
.height
- 1, 0, max
),
1894 .ScissorRectangleXMax
= clamp_int64((uint64_t) s
->offset
.x
+ s
->extent
.width
- 1, 0, max
)
1897 GEN8_SF_CLIP_VIEWPORT_pack(NULL
, state
->sf_clip_vp
.map
+ i
* 64, &sf_clip_viewport
);
1898 GEN8_CC_VIEWPORT_pack(NULL
, state
->cc_vp
.map
+ i
* 32, &cc_viewport
);
1900 if (s
->extent
.width
<= 0 || s
->extent
.height
<= 0) {
1901 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &empty_scissor
);
1903 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &scissor
);
1907 *pState
= (VkDynamicVpState
) state
;
1912 VkResult
anv_CreateDynamicRasterState(
1914 const VkDynamicRsStateCreateInfo
* pCreateInfo
,
1915 VkDynamicRsState
* pState
)
1917 struct anv_device
*device
= (struct anv_device
*) _device
;
1918 struct anv_dynamic_rs_state
*state
;
1920 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO
);
1922 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1923 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1925 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1929 * float depthBiasClamp;
1930 * float slopeScaledDepthBias;
1931 * float pointFadeThreshold;
1932 * // optional (GL45) - Size of point fade threshold
1935 struct GEN8_3DSTATE_SF sf
= {
1936 GEN8_3DSTATE_SF_header
,
1937 .LineWidth
= pCreateInfo
->lineWidth
,
1938 .PointWidth
= pCreateInfo
->pointSize
,
1941 GEN8_3DSTATE_SF_pack(NULL
, state
->state_sf
, &sf
);
1943 *pState
= (VkDynamicRsState
) state
;
1948 VkResult
anv_CreateDynamicColorBlendState(
1950 const VkDynamicCbStateCreateInfo
* pCreateInfo
,
1951 VkDynamicCbState
* pState
)
1953 struct anv_device
*device
= (struct anv_device
*) _device
;
1954 struct anv_dynamic_cb_state
*state
;
1956 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO
);
1958 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1959 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1961 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1963 *pState
= (VkDynamicCbState
) state
;
1968 VkResult
anv_CreateDynamicDepthStencilState(
1970 const VkDynamicDsStateCreateInfo
* pCreateInfo
,
1971 VkDynamicDsState
* pState
)
1973 stub_return(VK_UNSUPPORTED
);
1976 // Command buffer functions
1978 VkResult
anv_CreateCommandBuffer(
1980 const VkCmdBufferCreateInfo
* pCreateInfo
,
1981 VkCmdBuffer
* pCmdBuffer
)
1983 struct anv_device
*device
= (struct anv_device
*) _device
;
1984 struct anv_cmd_buffer
*cmd_buffer
;
1987 cmd_buffer
= anv_device_alloc(device
, sizeof(*cmd_buffer
), 8,
1988 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1989 if (cmd_buffer
== NULL
)
1990 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1992 cmd_buffer
->device
= device
;
1993 cmd_buffer
->rs_state
= NULL
;
1994 cmd_buffer
->vp_state
= NULL
;
1995 memset(&cmd_buffer
->default_bindings
, 0, sizeof(cmd_buffer
->default_bindings
));
1996 cmd_buffer
->bindings
= &cmd_buffer
->default_bindings
;
1998 result
= anv_batch_init(&cmd_buffer
->batch
, device
);
1999 if (result
!= VK_SUCCESS
)
2002 cmd_buffer
->exec2_objects
=
2003 anv_device_alloc(device
, 8192 * sizeof(cmd_buffer
->exec2_objects
[0]), 8,
2004 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2005 if (cmd_buffer
->exec2_objects
== NULL
) {
2006 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2010 cmd_buffer
->exec2_bos
=
2011 anv_device_alloc(device
, 8192 * sizeof(cmd_buffer
->exec2_bos
[0]), 8,
2012 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2013 if (cmd_buffer
->exec2_bos
== NULL
) {
2014 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2015 goto fail_exec2_objects
;
2018 anv_state_stream_init(&cmd_buffer
->surface_state_stream
,
2019 &device
->surface_state_block_pool
);
2020 anv_state_stream_init(&cmd_buffer
->dynamic_state_stream
,
2021 &device
->dynamic_state_block_pool
);
2023 cmd_buffer
->dirty
= 0;
2024 cmd_buffer
->vb_dirty
= 0;
2026 *pCmdBuffer
= (VkCmdBuffer
) cmd_buffer
;
2031 anv_device_free(device
, cmd_buffer
->exec2_objects
);
2033 anv_batch_finish(&cmd_buffer
->batch
, device
);
2035 anv_device_free(device
, cmd_buffer
);
2040 VkResult
anv_BeginCommandBuffer(
2041 VkCmdBuffer cmdBuffer
,
2042 const VkCmdBufferBeginInfo
* pBeginInfo
)
2044 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2045 struct anv_device
*device
= cmd_buffer
->device
;
2047 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPELINE_SELECT
,
2048 .PipelineSelection
= _3D
);
2049 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_SIP
);
2051 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_BASE_ADDRESS
,
2052 .GeneralStateBaseAddress
= { NULL
, 0 },
2053 .GeneralStateBaseAddressModifyEnable
= true,
2054 .GeneralStateBufferSize
= 0xfffff,
2055 .GeneralStateBufferSizeModifyEnable
= true,
2057 .SurfaceStateBaseAddress
= { &device
->surface_state_block_pool
.bo
, 0 },
2058 .SurfaceStateMemoryObjectControlState
= 0, /* FIXME: MOCS */
2059 .SurfaceStateBaseAddressModifyEnable
= true,
2061 .DynamicStateBaseAddress
= { &device
->dynamic_state_block_pool
.bo
, 0 },
2062 .DynamicStateBaseAddressModifyEnable
= true,
2063 .DynamicStateBufferSize
= 0xfffff,
2064 .DynamicStateBufferSizeModifyEnable
= true,
2066 .IndirectObjectBaseAddress
= { NULL
, 0 },
2067 .IndirectObjectBaseAddressModifyEnable
= true,
2068 .IndirectObjectBufferSize
= 0xfffff,
2069 .IndirectObjectBufferSizeModifyEnable
= true,
2071 .InstructionBaseAddress
= { &device
->instruction_block_pool
.bo
, 0 },
2072 .InstructionBaseAddressModifyEnable
= true,
2073 .InstructionBufferSize
= 0xfffff,
2074 .InstructionBuffersizeModifyEnable
= true);
2076 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VF_STATISTICS
,
2077 .StatisticsEnable
= true);
2078 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_HS
, .Enable
= false);
2079 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_TE
, .TEEnable
= false);
2080 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DS
, .FunctionEnable
= false);
2081 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_STREAMOUT
, .SOFunctionEnable
= false);
2083 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_VS
,
2084 .ConstantBufferOffset
= 0,
2085 .ConstantBufferSize
= 4);
2086 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_GS
,
2087 .ConstantBufferOffset
= 4,
2088 .ConstantBufferSize
= 4);
2089 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_PS
,
2090 .ConstantBufferOffset
= 8,
2091 .ConstantBufferSize
= 4);
2093 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_WM_CHROMAKEY
,
2094 .ChromaKeyKillEnable
= false);
2095 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SBE_SWIZ
);
2096 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_AA_LINE_PARAMETERS
);
2098 /* Hardcoded state: */
2099 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DEPTH_BUFFER
,
2100 .SurfaceType
= SURFTYPE_2D
,
2103 .SurfaceFormat
= D16_UNORM
,
2104 .SurfaceBaseAddress
= { NULL
, 0 },
2105 .HierarchicalDepthBufferEnable
= 0);
2107 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_WM_DEPTH_STENCIL
,
2108 .DepthTestEnable
= false,
2109 .DepthBufferWriteEnable
= false);
2115 anv_cmd_buffer_add_bo(struct anv_cmd_buffer
*cmd_buffer
,
2116 struct anv_bo
*bo
, struct anv_reloc_list
*list
)
2118 struct drm_i915_gem_exec_object2
*obj
;
2120 bo
->index
= cmd_buffer
->bo_count
;
2121 obj
= &cmd_buffer
->exec2_objects
[bo
->index
];
2122 cmd_buffer
->exec2_bos
[bo
->index
] = bo
;
2123 cmd_buffer
->bo_count
++;
2125 obj
->handle
= bo
->gem_handle
;
2126 obj
->relocation_count
= 0;
2127 obj
->relocs_ptr
= 0;
2129 obj
->offset
= bo
->offset
;
2135 obj
->relocation_count
= list
->num_relocs
;
2136 obj
->relocs_ptr
= (uintptr_t) list
->relocs
;
2141 anv_cmd_buffer_add_validate_bos(struct anv_cmd_buffer
*cmd_buffer
,
2142 struct anv_reloc_list
*list
)
2144 struct anv_bo
*bo
, *batch_bo
;
2146 batch_bo
= &cmd_buffer
->batch
.bo
;
2147 for (size_t i
= 0; i
< list
->num_relocs
; i
++) {
2148 bo
= list
->reloc_bos
[i
];
2149 /* Skip any relocations targeting the batch bo. We need to make sure
2150 * it's the last in the list so we'll add it manually later.
2154 if (bo
->index
< cmd_buffer
->bo_count
&& cmd_buffer
->exec2_bos
[bo
->index
] == bo
)
2157 anv_cmd_buffer_add_bo(cmd_buffer
, bo
, NULL
);
2162 anv_cmd_buffer_process_relocs(struct anv_cmd_buffer
*cmd_buffer
,
2163 struct anv_reloc_list
*list
)
2167 /* If the kernel supports I915_EXEC_NO_RELOC, it will compare offset in
2168 * struct drm_i915_gem_exec_object2 against the bos current offset and if
2169 * all bos haven't moved it will skip relocation processing alltogether.
2170 * If I915_EXEC_NO_RELOC is not supported, the kernel ignores the incoming
2171 * value of offset so we can set it either way. For that to work we need
2172 * to make sure all relocs use the same presumed offset.
2175 for (size_t i
= 0; i
< list
->num_relocs
; i
++) {
2176 bo
= list
->reloc_bos
[i
];
2177 if (bo
->offset
!= list
->relocs
[i
].presumed_offset
)
2178 cmd_buffer
->need_reloc
= true;
2180 list
->relocs
[i
].target_handle
= bo
->index
;
2184 VkResult
anv_EndCommandBuffer(
2185 VkCmdBuffer cmdBuffer
)
2187 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2188 struct anv_device
*device
= cmd_buffer
->device
;
2189 struct anv_batch
*batch
= &cmd_buffer
->batch
;
2191 anv_batch_emit(batch
, GEN8_MI_BATCH_BUFFER_END
);
2193 /* Round batch up to an even number of dwords. */
2194 if ((batch
->next
- batch
->bo
.map
) & 4)
2195 anv_batch_emit(batch
, GEN8_MI_NOOP
);
2197 cmd_buffer
->bo_count
= 0;
2198 cmd_buffer
->need_reloc
= false;
2200 /* Lock for access to bo->index. */
2201 pthread_mutex_lock(&device
->mutex
);
2203 /* Add block pool bos first so we can add them with their relocs. */
2204 anv_cmd_buffer_add_bo(cmd_buffer
, &device
->surface_state_block_pool
.bo
,
2205 &batch
->surf_relocs
);
2207 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &batch
->surf_relocs
);
2208 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &batch
->cmd_relocs
);
2209 anv_cmd_buffer_add_bo(cmd_buffer
, &batch
->bo
, &batch
->cmd_relocs
);
2210 anv_cmd_buffer_process_relocs(cmd_buffer
, &batch
->surf_relocs
);
2211 anv_cmd_buffer_process_relocs(cmd_buffer
, &batch
->cmd_relocs
);
2213 cmd_buffer
->execbuf
.buffers_ptr
= (uintptr_t) cmd_buffer
->exec2_objects
;
2214 cmd_buffer
->execbuf
.buffer_count
= cmd_buffer
->bo_count
;
2215 cmd_buffer
->execbuf
.batch_start_offset
= 0;
2216 cmd_buffer
->execbuf
.batch_len
= batch
->next
- batch
->bo
.map
;
2217 cmd_buffer
->execbuf
.cliprects_ptr
= 0;
2218 cmd_buffer
->execbuf
.num_cliprects
= 0;
2219 cmd_buffer
->execbuf
.DR1
= 0;
2220 cmd_buffer
->execbuf
.DR4
= 0;
2222 cmd_buffer
->execbuf
.flags
= I915_EXEC_HANDLE_LUT
;
2223 if (!cmd_buffer
->need_reloc
)
2224 cmd_buffer
->execbuf
.flags
|= I915_EXEC_NO_RELOC
;
2225 cmd_buffer
->execbuf
.flags
|= I915_EXEC_RENDER
;
2226 cmd_buffer
->execbuf
.rsvd1
= device
->context_id
;
2227 cmd_buffer
->execbuf
.rsvd2
= 0;
2229 pthread_mutex_unlock(&device
->mutex
);
2234 VkResult
anv_ResetCommandBuffer(
2235 VkCmdBuffer cmdBuffer
)
2237 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2239 anv_batch_reset(&cmd_buffer
->batch
);
2244 // Command buffer building functions
2246 void anv_CmdBindPipeline(
2247 VkCmdBuffer cmdBuffer
,
2248 VkPipelineBindPoint pipelineBindPoint
,
2249 VkPipeline _pipeline
)
2251 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2253 cmd_buffer
->pipeline
= (struct anv_pipeline
*) _pipeline
;
2254 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
;
2257 void anv_CmdBindDynamicStateObject(
2258 VkCmdBuffer cmdBuffer
,
2259 VkStateBindPoint stateBindPoint
,
2260 VkDynamicStateObject dynamicState
)
2262 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2263 struct anv_dynamic_vp_state
*vp_state
;
2265 switch (stateBindPoint
) {
2266 case VK_STATE_BIND_POINT_VIEWPORT
:
2267 vp_state
= (struct anv_dynamic_vp_state
*) dynamicState
;
2268 /* We emit state immediately, but set cmd_buffer->vp_state to indicate
2269 * that vp state has been set in this command buffer. */
2270 cmd_buffer
->vp_state
= vp_state
;
2271 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SCISSOR_STATE_POINTERS
,
2272 .ScissorRectPointer
= vp_state
->scissor
.offset
);
2273 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_CC
,
2274 .CCViewportPointer
= vp_state
->cc_vp
.offset
);
2275 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
,
2276 .SFClipViewportPointer
= vp_state
->sf_clip_vp
.offset
);
2278 case VK_STATE_BIND_POINT_RASTER
:
2279 cmd_buffer
->rs_state
= (struct anv_dynamic_rs_state
*) dynamicState
;
2280 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_RS_DIRTY
;
2282 case VK_STATE_BIND_POINT_COLOR_BLEND
:
2283 case VK_STATE_BIND_POINT_DEPTH_STENCIL
:
2290 void anv_CmdBindDescriptorSets(
2291 VkCmdBuffer cmdBuffer
,
2292 VkPipelineBindPoint pipelineBindPoint
,
2295 const VkDescriptorSet
* pDescriptorSets
,
2296 uint32_t dynamicOffsetCount
,
2297 const uint32_t* pDynamicOffsets
)
2299 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2300 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
2301 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2303 uint32_t offset
= 0;
2304 for (uint32_t i
= 0; i
< setCount
; i
++) {
2305 struct anv_descriptor_set
*set
=
2306 (struct anv_descriptor_set
*) pDescriptorSets
[i
];
2307 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[firstSet
+ i
].layout
;
2309 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
2310 uint32_t *surface_to_desc
= set_layout
->stage
[s
].surface_start
;
2311 uint32_t *sampler_to_desc
= set_layout
->stage
[s
].sampler_start
;
2312 uint32_t bias
= s
== VK_SHADER_STAGE_FRAGMENT
? MAX_RTS
: 0;
2315 start
= bias
+ layout
->set
[firstSet
+ i
].surface_start
[s
];
2316 for (uint32_t b
= 0; b
< set_layout
->stage
[s
].surface_count
; b
++) {
2317 struct anv_surface_view
*view
= set
->descriptors
[surface_to_desc
[b
]].view
;
2319 bindings
->descriptors
[s
].surfaces
[start
+ b
] =
2320 view
->surface_state
.offset
;
2321 bindings
->descriptors
[s
].relocs
[start
+ b
].bo
= view
->bo
;
2322 bindings
->descriptors
[s
].relocs
[start
+ b
].offset
= view
->offset
;
2325 start
= layout
->set
[firstSet
+ i
].sampler_start
[s
];
2326 for (uint32_t b
= 0; b
< set_layout
->stage
[s
].sampler_count
; b
++) {
2327 struct anv_sampler
*sampler
= set
->descriptors
[sampler_to_desc
[b
]].sampler
;
2329 memcpy(&bindings
->descriptors
[s
].samplers
[start
+ b
],
2330 sampler
->state
, sizeof(sampler
->state
));
2334 offset
+= layout
->set
[firstSet
+ i
].layout
->num_dynamic_buffers
;
2337 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
2340 void anv_CmdBindIndexBuffer(
2341 VkCmdBuffer cmdBuffer
,
2343 VkDeviceSize offset
,
2344 VkIndexType indexType
)
2346 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2347 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2349 static const uint32_t vk_to_gen_index_type
[] = {
2350 [VK_INDEX_TYPE_UINT8
] = INDEX_BYTE
,
2351 [VK_INDEX_TYPE_UINT16
] = INDEX_WORD
,
2352 [VK_INDEX_TYPE_UINT32
] = INDEX_DWORD
,
2355 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_INDEX_BUFFER
,
2356 .IndexFormat
= vk_to_gen_index_type
[indexType
],
2357 .MemoryObjectControlState
= 0,
2358 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
2359 .BufferSize
= buffer
->size
- offset
);
2362 void anv_CmdBindVertexBuffers(
2363 VkCmdBuffer cmdBuffer
,
2364 uint32_t startBinding
,
2365 uint32_t bindingCount
,
2366 const VkBuffer
* pBuffers
,
2367 const VkDeviceSize
* pOffsets
)
2369 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2370 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2372 /* We have to defer setting up vertex buffer since we need the buffer
2373 * stride from the pipeline. */
2375 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
2376 bindings
->vb
[startBinding
+ i
].buffer
= (struct anv_buffer
*) pBuffers
[i
];
2377 bindings
->vb
[startBinding
+ i
].offset
= pOffsets
[i
];
2378 cmd_buffer
->vb_dirty
|= 1 << (startBinding
+ i
);
2383 flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
)
2385 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
2386 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2387 uint32_t layers
= cmd_buffer
->framebuffer
->layers
;
2389 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
2392 if (s
== VK_SHADER_STAGE_FRAGMENT
) {
2394 layers
= cmd_buffer
->framebuffer
->layers
;
2400 /* This is a little awkward: layout can be NULL but we still have to
2401 * allocate and set a binding table for the PS stage for render
2403 uint32_t surface_count
= layout
? layout
->stage
[s
].surface_count
: 0;
2405 if (layers
+ surface_count
> 0) {
2406 struct anv_state state
;
2409 size
= (bias
+ surface_count
) * sizeof(uint32_t);
2410 state
= anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, size
, 32);
2411 memcpy(state
.map
, bindings
->descriptors
[s
].surfaces
, size
);
2413 for (uint32_t i
= 0; i
< layers
; i
++)
2414 anv_reloc_list_add(&cmd_buffer
->batch
.surf_relocs
,
2415 bindings
->descriptors
[s
].surfaces
[i
] + 8 * sizeof(int32_t),
2416 bindings
->descriptors
[s
].relocs
[i
].bo
,
2417 bindings
->descriptors
[s
].relocs
[i
].offset
);
2419 for (uint32_t i
= 0; i
< surface_count
; i
++)
2420 anv_reloc_list_add(&cmd_buffer
->batch
.surf_relocs
,
2421 bindings
->descriptors
[s
].surfaces
[bias
+ i
] + 8 * sizeof(int32_t),
2422 bindings
->descriptors
[s
].relocs
[bias
+ i
].bo
,
2423 bindings
->descriptors
[s
].relocs
[bias
+ i
].offset
);
2425 static const uint32_t binding_table_opcodes
[] = {
2426 [VK_SHADER_STAGE_VERTEX
] = 38,
2427 [VK_SHADER_STAGE_TESS_CONTROL
] = 39,
2428 [VK_SHADER_STAGE_TESS_EVALUATION
] = 40,
2429 [VK_SHADER_STAGE_GEOMETRY
] = 41,
2430 [VK_SHADER_STAGE_FRAGMENT
] = 42,
2431 [VK_SHADER_STAGE_COMPUTE
] = 0,
2434 anv_batch_emit(&cmd_buffer
->batch
,
2435 GEN8_3DSTATE_BINDING_TABLE_POINTERS_VS
,
2436 ._3DCommandSubOpcode
= binding_table_opcodes
[s
],
2437 .PointertoVSBindingTable
= state
.offset
);
2440 if (layout
&& layout
->stage
[s
].sampler_count
> 0) {
2441 struct anv_state state
;
2444 size
= layout
->stage
[s
].sampler_count
* 16;
2445 state
= anv_state_stream_alloc(&cmd_buffer
->dynamic_state_stream
, size
, 32);
2446 memcpy(state
.map
, bindings
->descriptors
[s
].samplers
, size
);
2448 static const uint32_t sampler_state_opcodes
[] = {
2449 [VK_SHADER_STAGE_VERTEX
] = 43,
2450 [VK_SHADER_STAGE_TESS_CONTROL
] = 44, /* HS */
2451 [VK_SHADER_STAGE_TESS_EVALUATION
] = 45, /* DS */
2452 [VK_SHADER_STAGE_GEOMETRY
] = 46,
2453 [VK_SHADER_STAGE_FRAGMENT
] = 47,
2454 [VK_SHADER_STAGE_COMPUTE
] = 0,
2457 anv_batch_emit(&cmd_buffer
->batch
,
2458 GEN8_3DSTATE_SAMPLER_STATE_POINTERS_VS
,
2459 ._3DCommandSubOpcode
= sampler_state_opcodes
[s
],
2460 .PointertoVSSamplerState
= state
.offset
);
2466 anv_cmd_buffer_flush_state(struct anv_cmd_buffer
*cmd_buffer
)
2468 struct anv_pipeline
*pipeline
= cmd_buffer
->pipeline
;
2469 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2470 const uint32_t num_buffers
= __builtin_popcount(cmd_buffer
->vb_dirty
);
2471 const uint32_t num_dwords
= 1 + num_buffers
* 4;
2474 if (cmd_buffer
->vb_dirty
) {
2475 p
= anv_batch_emitn(&cmd_buffer
->batch
, num_dwords
,
2476 GEN8_3DSTATE_VERTEX_BUFFERS
);
2478 for_each_bit(vb
, cmd_buffer
->vb_dirty
) {
2479 struct anv_buffer
*buffer
= bindings
->vb
[vb
].buffer
;
2480 uint32_t offset
= bindings
->vb
[vb
].offset
;
2482 struct GEN8_VERTEX_BUFFER_STATE state
= {
2483 .VertexBufferIndex
= vb
,
2484 .MemoryObjectControlState
= 0,
2485 .AddressModifyEnable
= true,
2486 .BufferPitch
= pipeline
->binding_stride
[vb
],
2487 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
2488 .BufferSize
= buffer
->size
- offset
2491 GEN8_VERTEX_BUFFER_STATE_pack(&cmd_buffer
->batch
, &p
[1 + i
* 4], &state
);
2496 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_PIPELINE_DIRTY
)
2497 anv_batch_emit_batch(&cmd_buffer
->batch
, &pipeline
->batch
);
2499 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
)
2500 flush_descriptor_sets(cmd_buffer
);
2502 if (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_PIPELINE_DIRTY
| ANV_CMD_BUFFER_RS_DIRTY
))
2503 anv_batch_emit_merge(&cmd_buffer
->batch
,
2504 cmd_buffer
->rs_state
->state_sf
, pipeline
->state_sf
);
2506 cmd_buffer
->vb_dirty
= 0;
2507 cmd_buffer
->dirty
= 0;
2511 VkCmdBuffer cmdBuffer
,
2512 uint32_t firstVertex
,
2513 uint32_t vertexCount
,
2514 uint32_t firstInstance
,
2515 uint32_t instanceCount
)
2517 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2519 anv_cmd_buffer_flush_state(cmd_buffer
);
2521 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2522 .VertexAccessType
= SEQUENTIAL
,
2523 .VertexCountPerInstance
= vertexCount
,
2524 .StartVertexLocation
= firstVertex
,
2525 .InstanceCount
= instanceCount
,
2526 .StartInstanceLocation
= firstInstance
,
2527 .BaseVertexLocation
= 0);
2530 void anv_CmdDrawIndexed(
2531 VkCmdBuffer cmdBuffer
,
2532 uint32_t firstIndex
,
2533 uint32_t indexCount
,
2534 int32_t vertexOffset
,
2535 uint32_t firstInstance
,
2536 uint32_t instanceCount
)
2538 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2540 anv_cmd_buffer_flush_state(cmd_buffer
);
2542 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2543 .VertexAccessType
= RANDOM
,
2544 .VertexCountPerInstance
= indexCount
,
2545 .StartVertexLocation
= firstIndex
,
2546 .InstanceCount
= instanceCount
,
2547 .StartInstanceLocation
= firstInstance
,
2548 .BaseVertexLocation
= 0);
2552 anv_batch_lrm(struct anv_batch
*batch
,
2553 uint32_t reg
, struct anv_bo
*bo
, uint32_t offset
)
2555 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_MEM
,
2556 .RegisterAddress
= reg
,
2557 .MemoryAddress
= { bo
, offset
});
2561 anv_batch_lri(struct anv_batch
*batch
, uint32_t reg
, uint32_t imm
)
2563 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_IMM
,
2564 .RegisterOffset
= reg
,
2568 /* Auto-Draw / Indirect Registers */
2569 #define GEN7_3DPRIM_END_OFFSET 0x2420
2570 #define GEN7_3DPRIM_START_VERTEX 0x2430
2571 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
2572 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
2573 #define GEN7_3DPRIM_START_INSTANCE 0x243C
2574 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
2576 void anv_CmdDrawIndirect(
2577 VkCmdBuffer cmdBuffer
,
2579 VkDeviceSize offset
,
2583 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2584 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2585 struct anv_bo
*bo
= buffer
->bo
;
2586 uint32_t bo_offset
= buffer
->offset
+ offset
;
2588 anv_cmd_buffer_flush_state(cmd_buffer
);
2590 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
2591 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
2592 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
2593 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 12);
2594 anv_batch_lri(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, 0);
2596 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2597 .IndirectParameterEnable
= true,
2598 .VertexAccessType
= SEQUENTIAL
);
2601 void anv_CmdDrawIndexedIndirect(
2602 VkCmdBuffer cmdBuffer
,
2604 VkDeviceSize offset
,
2608 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2609 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2610 struct anv_bo
*bo
= buffer
->bo
;
2611 uint32_t bo_offset
= buffer
->offset
+ offset
;
2613 anv_cmd_buffer_flush_state(cmd_buffer
);
2615 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
2616 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
2617 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
2618 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, bo
, bo_offset
+ 12);
2619 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 16);
2621 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2622 .IndirectParameterEnable
= true,
2623 .VertexAccessType
= RANDOM
);
2626 void anv_CmdDispatch(
2627 VkCmdBuffer cmdBuffer
,
2635 void anv_CmdDispatchIndirect(
2636 VkCmdBuffer cmdBuffer
,
2638 VkDeviceSize offset
)
2643 void anv_CmdSetEvent(
2644 VkCmdBuffer cmdBuffer
,
2646 VkPipeEvent pipeEvent
)
2651 void anv_CmdResetEvent(
2652 VkCmdBuffer cmdBuffer
,
2654 VkPipeEvent pipeEvent
)
2659 void anv_CmdWaitEvents(
2660 VkCmdBuffer cmdBuffer
,
2661 VkWaitEvent waitEvent
,
2662 uint32_t eventCount
,
2663 const VkEvent
* pEvents
,
2664 uint32_t memBarrierCount
,
2665 const void** ppMemBarriers
)
2670 void anv_CmdPipelineBarrier(
2671 VkCmdBuffer cmdBuffer
,
2672 VkWaitEvent waitEvent
,
2673 uint32_t pipeEventCount
,
2674 const VkPipeEvent
* pPipeEvents
,
2675 uint32_t memBarrierCount
,
2676 const void** ppMemBarriers
)
2682 anv_batch_emit_ps_depth_count(struct anv_batch
*batch
,
2683 struct anv_bo
*bo
, uint32_t offset
)
2685 anv_batch_emit(batch
, GEN8_PIPE_CONTROL
,
2686 .DestinationAddressType
= DAT_PPGTT
,
2687 .PostSyncOperation
= WritePSDepthCount
,
2688 .Address
= { bo
, offset
}); /* FIXME: This is only lower 32 bits */
2691 void anv_CmdBeginQuery(
2692 VkCmdBuffer cmdBuffer
,
2693 VkQueryPool queryPool
,
2695 VkQueryControlFlags flags
)
2697 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2698 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
2700 switch (pool
->type
) {
2701 case VK_QUERY_TYPE_OCCLUSION
:
2702 anv_batch_emit_ps_depth_count(&cmd_buffer
->batch
, &pool
->bo
, slot
* 16);
2705 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
2713 void anv_CmdEndQuery(
2714 VkCmdBuffer cmdBuffer
,
2715 VkQueryPool queryPool
,
2718 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2719 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
2721 switch (pool
->type
) {
2722 case VK_QUERY_TYPE_OCCLUSION
:
2723 anv_batch_emit_ps_depth_count(&cmd_buffer
->batch
, &pool
->bo
, slot
* 16 + 8);
2726 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
2734 void anv_CmdResetQueryPool(
2735 VkCmdBuffer cmdBuffer
,
2736 VkQueryPool queryPool
,
2737 uint32_t startQuery
,
2738 uint32_t queryCount
)
2743 #define TIMESTAMP 0x44070
2745 void anv_CmdWriteTimestamp(
2746 VkCmdBuffer cmdBuffer
,
2747 VkTimestampType timestampType
,
2748 VkBuffer destBuffer
,
2749 VkDeviceSize destOffset
)
2751 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2752 struct anv_buffer
*buffer
= (struct anv_buffer
*) destBuffer
;
2753 struct anv_bo
*bo
= buffer
->bo
;
2755 switch (timestampType
) {
2756 case VK_TIMESTAMP_TYPE_TOP
:
2757 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MI_STORE_REGISTER_MEM
,
2758 .RegisterAddress
= TIMESTAMP
,
2759 .MemoryAddress
= { bo
, buffer
->offset
+ destOffset
});
2762 case VK_TIMESTAMP_TYPE_BOTTOM
:
2763 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
2764 .DestinationAddressType
= DAT_PPGTT
,
2765 .PostSyncOperation
= WriteTimestamp
,
2766 .Address
= /* FIXME: This is only lower 32 bits */
2767 { bo
, buffer
->offset
+ destOffset
});
2775 void anv_CmdCopyQueryPoolResults(
2776 VkCmdBuffer cmdBuffer
,
2777 VkQueryPool queryPool
,
2778 uint32_t startQuery
,
2779 uint32_t queryCount
,
2780 VkBuffer destBuffer
,
2781 VkDeviceSize destOffset
,
2782 VkDeviceSize destStride
,
2783 VkQueryResultFlags flags
)
2788 void anv_CmdInitAtomicCounters(
2789 VkCmdBuffer cmdBuffer
,
2790 VkPipelineBindPoint pipelineBindPoint
,
2791 uint32_t startCounter
,
2792 uint32_t counterCount
,
2793 const uint32_t* pData
)
2798 void anv_CmdLoadAtomicCounters(
2799 VkCmdBuffer cmdBuffer
,
2800 VkPipelineBindPoint pipelineBindPoint
,
2801 uint32_t startCounter
,
2802 uint32_t counterCount
,
2804 VkDeviceSize srcOffset
)
2809 void anv_CmdSaveAtomicCounters(
2810 VkCmdBuffer cmdBuffer
,
2811 VkPipelineBindPoint pipelineBindPoint
,
2812 uint32_t startCounter
,
2813 uint32_t counterCount
,
2814 VkBuffer destBuffer
,
2815 VkDeviceSize destOffset
)
2820 VkResult
anv_CreateFramebuffer(
2822 const VkFramebufferCreateInfo
* pCreateInfo
,
2823 VkFramebuffer
* pFramebuffer
)
2825 struct anv_device
*device
= (struct anv_device
*) _device
;
2826 struct anv_framebuffer
*framebuffer
;
2828 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2830 framebuffer
= anv_device_alloc(device
, sizeof(*framebuffer
), 8,
2831 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2832 if (framebuffer
== NULL
)
2833 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2835 framebuffer
->color_attachment_count
= pCreateInfo
->colorAttachmentCount
;
2836 for (uint32_t i
= 0; i
< pCreateInfo
->colorAttachmentCount
; i
++) {
2837 framebuffer
->color_attachments
[i
] =
2838 (struct anv_surface_view
*) pCreateInfo
->pColorAttachments
[i
].view
;
2841 if (pCreateInfo
->pDepthStencilAttachment
) {
2842 framebuffer
->depth_stencil
=
2843 (struct anv_depth_stencil_view
*) pCreateInfo
->pDepthStencilAttachment
->view
;
2846 framebuffer
->sample_count
= pCreateInfo
->sampleCount
;
2847 framebuffer
->width
= pCreateInfo
->width
;
2848 framebuffer
->height
= pCreateInfo
->height
;
2849 framebuffer
->layers
= pCreateInfo
->layers
;
2851 vkCreateDynamicViewportState((VkDevice
) device
,
2852 &(VkDynamicVpStateCreateInfo
) {
2853 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
,
2854 .viewportAndScissorCount
= 2,
2855 .pViewports
= (VkViewport
[]) {
2859 .width
= pCreateInfo
->width
,
2860 .height
= pCreateInfo
->height
,
2865 .pScissors
= (VkRect
[]) {
2867 { pCreateInfo
->width
, pCreateInfo
->height
} },
2870 &framebuffer
->vp_state
);
2872 *pFramebuffer
= (VkFramebuffer
) framebuffer
;
2877 VkResult
anv_CreateRenderPass(
2879 const VkRenderPassCreateInfo
* pCreateInfo
,
2880 VkRenderPass
* pRenderPass
)
2882 struct anv_device
*device
= (struct anv_device
*) _device
;
2883 struct anv_render_pass
*pass
;
2886 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
2888 size
= sizeof(*pass
) +
2889 pCreateInfo
->layers
* sizeof(struct anv_render_pass_layer
);
2890 pass
= anv_device_alloc(device
, size
, 8,
2891 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2893 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2895 pass
->render_area
= pCreateInfo
->renderArea
;
2897 pass
->num_layers
= pCreateInfo
->layers
;
2899 pass
->num_clear_layers
= 0;
2900 for (uint32_t i
= 0; i
< pCreateInfo
->layers
; i
++) {
2901 pass
->layers
[i
].color_load_op
= pCreateInfo
->pColorLoadOps
[i
];
2902 pass
->layers
[i
].clear_color
= pCreateInfo
->pColorLoadClearValues
[i
];
2903 if (pass
->layers
[i
].color_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
)
2904 pass
->num_clear_layers
++;
2907 *pRenderPass
= (VkRenderPass
) pass
;
2913 anv_cmd_buffer_fill_render_targets(struct anv_cmd_buffer
*cmd_buffer
)
2915 struct anv_framebuffer
*framebuffer
= cmd_buffer
->framebuffer
;
2916 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2918 for (uint32_t i
= 0; i
< framebuffer
->color_attachment_count
; i
++) {
2919 struct anv_surface_view
*view
= framebuffer
->color_attachments
[i
];
2921 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].surfaces
[i
] = view
->surface_state
.offset
;
2922 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].relocs
[i
].bo
= view
->bo
;
2923 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].relocs
[i
].offset
= view
->offset
;
2925 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
2928 void anv_CmdBeginRenderPass(
2929 VkCmdBuffer cmdBuffer
,
2930 const VkRenderPassBegin
* pRenderPassBegin
)
2932 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2933 struct anv_render_pass
*pass
= (struct anv_render_pass
*) pRenderPassBegin
->renderPass
;
2934 struct anv_framebuffer
*framebuffer
=
2935 (struct anv_framebuffer
*) pRenderPassBegin
->framebuffer
;
2937 cmd_buffer
->framebuffer
= framebuffer
;
2939 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DRAWING_RECTANGLE
,
2940 .ClippedDrawingRectangleYMin
= pass
->render_area
.offset
.y
,
2941 .ClippedDrawingRectangleXMin
= pass
->render_area
.offset
.x
,
2942 .ClippedDrawingRectangleYMax
=
2943 pass
->render_area
.offset
.y
+ pass
->render_area
.extent
.height
- 1,
2944 .ClippedDrawingRectangleXMax
=
2945 pass
->render_area
.offset
.x
+ pass
->render_area
.extent
.width
- 1,
2946 .DrawingRectangleOriginY
= 0,
2947 .DrawingRectangleOriginX
= 0);
2949 anv_cmd_buffer_fill_render_targets(cmd_buffer
);
2951 anv_cmd_buffer_clear(cmd_buffer
, pass
);
2954 void anv_CmdEndRenderPass(
2955 VkCmdBuffer cmdBuffer
,
2956 VkRenderPass renderPass
)
2958 /* Emit a flushing pipe control at the end of a pass. This is kind of a
2959 * hack but it ensures that render targets always actually get written.
2960 * Eventually, we should do flushing based on image format transitions
2961 * or something of that nature.
2963 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
2964 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
2965 .PostSyncOperation
= NoWrite
,
2966 .RenderTargetCacheFlushEnable
= true,
2967 .InstructionCacheInvalidateEnable
= true,
2968 .DepthCacheFlushEnable
= true,
2969 .VFCacheInvalidationEnable
= true,
2970 .TextureCacheInvalidationEnable
= true,
2971 .CommandStreamerStallEnable
= true);