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
, pData
);
1055 case VK_OBJECT_INFO_TYPE_MEMORY_ALLOCATION_COUNT
:
1056 *pDataSize
= sizeof(count
);
1061 *count
= get_allocation_count(objType
);
1065 return VK_UNSUPPORTED
;
1070 VkResult
anv_QueueBindObjectMemory(
1072 VkObjectType objType
,
1074 uint32_t allocationIdx
,
1075 VkDeviceMemory _mem
,
1076 VkDeviceSize memOffset
)
1078 struct anv_buffer
*buffer
;
1079 struct anv_image
*image
;
1080 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
1083 case VK_OBJECT_TYPE_BUFFER
:
1084 buffer
= (struct anv_buffer
*) object
;
1085 buffer
->bo
= &mem
->bo
;
1086 buffer
->offset
= memOffset
;
1088 case VK_OBJECT_TYPE_IMAGE
:
1089 image
= (struct anv_image
*) object
;
1090 image
->bo
= &mem
->bo
;
1091 image
->offset
= memOffset
;
1100 VkResult
anv_QueueBindObjectMemoryRange(
1102 VkObjectType objType
,
1104 uint32_t allocationIdx
,
1105 VkDeviceSize rangeOffset
,
1106 VkDeviceSize rangeSize
,
1108 VkDeviceSize memOffset
)
1110 stub_return(VK_UNSUPPORTED
);
1113 VkResult
anv_QueueBindImageMemoryRange(
1116 uint32_t allocationIdx
,
1117 const VkImageMemoryBindInfo
* pBindInfo
,
1119 VkDeviceSize memOffset
)
1121 stub_return(VK_UNSUPPORTED
);
1124 VkResult
anv_CreateFence(
1126 const VkFenceCreateInfo
* pCreateInfo
,
1129 struct anv_device
*device
= (struct anv_device
*) _device
;
1130 struct anv_fence
*fence
;
1131 struct anv_batch batch
;
1134 const uint32_t fence_size
= 128;
1136 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1138 fence
= anv_device_alloc(device
, sizeof(*fence
), 8,
1139 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1141 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1143 result
= anv_bo_init_new(&fence
->bo
, device
, fence_size
);
1144 if (result
!= VK_SUCCESS
)
1148 anv_gem_mmap(device
, fence
->bo
.gem_handle
, 0, fence
->bo
.size
);
1149 batch
.next
= fence
->bo
.map
;
1150 anv_batch_emit(&batch
, GEN8_MI_BATCH_BUFFER_END
);
1151 anv_batch_emit(&batch
, GEN8_MI_NOOP
);
1153 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1154 fence
->exec2_objects
[0].relocation_count
= 0;
1155 fence
->exec2_objects
[0].relocs_ptr
= 0;
1156 fence
->exec2_objects
[0].alignment
= 0;
1157 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1158 fence
->exec2_objects
[0].flags
= 0;
1159 fence
->exec2_objects
[0].rsvd1
= 0;
1160 fence
->exec2_objects
[0].rsvd2
= 0;
1162 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1163 fence
->execbuf
.buffer_count
= 1;
1164 fence
->execbuf
.batch_start_offset
= 0;
1165 fence
->execbuf
.batch_len
= batch
.next
- fence
->bo
.map
;
1166 fence
->execbuf
.cliprects_ptr
= 0;
1167 fence
->execbuf
.num_cliprects
= 0;
1168 fence
->execbuf
.DR1
= 0;
1169 fence
->execbuf
.DR4
= 0;
1171 fence
->execbuf
.flags
=
1172 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1173 fence
->execbuf
.rsvd1
= device
->context_id
;
1174 fence
->execbuf
.rsvd2
= 0;
1176 *pFence
= (VkQueryPool
) fence
;
1181 anv_device_free(device
, fence
);
1186 VkResult
anv_ResetFences(
1188 uint32_t fenceCount
,
1191 struct anv_fence
**fences
= (struct anv_fence
**) pFences
;
1193 for (uint32_t i
; i
< fenceCount
; i
++)
1194 fences
[i
]->ready
= false;
1199 VkResult
anv_GetFenceStatus(
1203 struct anv_device
*device
= (struct anv_device
*) _device
;
1204 struct anv_fence
*fence
= (struct anv_fence
*) _fence
;
1211 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1213 fence
->ready
= true;
1217 return VK_NOT_READY
;
1220 VkResult
anv_WaitForFences(
1222 uint32_t fenceCount
,
1223 const VkFence
* pFences
,
1227 struct anv_device
*device
= (struct anv_device
*) _device
;
1228 struct anv_fence
**fences
= (struct anv_fence
**) pFences
;
1229 int64_t t
= timeout
;
1232 /* FIXME: handle !waitAll */
1234 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1235 ret
= anv_gem_wait(device
, fences
[i
]->bo
.gem_handle
, &t
);
1236 if (ret
== -1 && errno
== ETIME
)
1239 return vk_error(VK_ERROR_UNKNOWN
);
1245 // Queue semaphore functions
1247 VkResult
anv_CreateSemaphore(
1249 const VkSemaphoreCreateInfo
* pCreateInfo
,
1250 VkSemaphore
* pSemaphore
)
1252 stub_return(VK_UNSUPPORTED
);
1255 VkResult
anv_QueueSignalSemaphore(
1257 VkSemaphore semaphore
)
1259 stub_return(VK_UNSUPPORTED
);
1262 VkResult
anv_QueueWaitSemaphore(
1264 VkSemaphore semaphore
)
1266 stub_return(VK_UNSUPPORTED
);
1271 VkResult
anv_CreateEvent(
1273 const VkEventCreateInfo
* pCreateInfo
,
1276 stub_return(VK_UNSUPPORTED
);
1279 VkResult
anv_GetEventStatus(
1283 stub_return(VK_UNSUPPORTED
);
1286 VkResult
anv_SetEvent(
1290 stub_return(VK_UNSUPPORTED
);
1293 VkResult
anv_ResetEvent(
1297 stub_return(VK_UNSUPPORTED
);
1302 struct anv_query_pool
{
1308 VkResult
anv_CreateQueryPool(
1310 const VkQueryPoolCreateInfo
* pCreateInfo
,
1311 VkQueryPool
* pQueryPool
)
1313 struct anv_device
*device
= (struct anv_device
*) _device
;
1314 struct anv_query_pool
*pool
;
1317 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
);
1319 pool
= anv_device_alloc(device
, sizeof(*pool
), 8,
1320 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1322 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1324 pool
->type
= pCreateInfo
->queryType
;
1325 result
= anv_bo_init_new(&pool
->bo
, device
, pCreateInfo
->slots
* 16);
1326 if (result
!= VK_SUCCESS
)
1329 *pQueryPool
= (VkQueryPool
) pool
;
1334 anv_device_free(device
, pool
);
1339 VkResult
anv_GetQueryPoolResults(
1341 VkQueryPool queryPool
,
1342 uint32_t startQuery
,
1343 uint32_t queryCount
,
1346 VkQueryResultFlags flags
)
1348 stub_return(VK_UNSUPPORTED
);
1353 VkResult
anv_CreateBuffer(
1355 const VkBufferCreateInfo
* pCreateInfo
,
1358 struct anv_device
*device
= (struct anv_device
*) _device
;
1359 struct anv_buffer
*buffer
;
1361 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1363 buffer
= anv_device_alloc(device
, sizeof(*buffer
), 8,
1364 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1366 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1368 buffer
->size
= pCreateInfo
->size
;
1372 *pBuffer
= (VkBuffer
) buffer
;
1377 // Buffer view functions
1379 VkResult
anv_CreateBufferView(
1381 const VkBufferViewCreateInfo
* pCreateInfo
,
1382 VkBufferView
* pView
)
1384 struct anv_device
*device
= (struct anv_device
*) _device
;
1385 struct anv_buffer
*buffer
= (struct anv_buffer
*) pCreateInfo
->buffer
;
1386 struct anv_surface_view
*view
;
1387 const struct anv_format
*format
;
1389 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO
);
1391 view
= anv_device_alloc(device
, sizeof(*view
), 8,
1392 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1394 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1396 view
->bo
= buffer
->bo
;
1397 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
1398 view
->surface_state
=
1399 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
1400 view
->format
= pCreateInfo
->format
;
1402 format
= anv_format_for_vk_format(pCreateInfo
->format
);
1403 /* This assumes RGBA float format. */
1404 uint32_t stride
= 4;
1405 uint32_t num_elements
= pCreateInfo
->range
/ stride
;
1406 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
1407 .SurfaceType
= SURFTYPE_BUFFER
,
1408 .SurfaceArray
= false,
1409 .SurfaceFormat
= format
->format
,
1410 .SurfaceVerticalAlignment
= VALIGN4
,
1411 .SurfaceHorizontalAlignment
= HALIGN4
,
1413 .VerticalLineStride
= 0,
1414 .VerticalLineStrideOffset
= 0,
1415 .SamplerL2BypassModeDisable
= true,
1416 .RenderCacheReadWriteMode
= WriteOnlyCache
,
1417 .MemoryObjectControlState
= 0, /* FIXME: MOCS */
1420 .Height
= (num_elements
>> 7) & 0x3fff,
1421 .Width
= num_elements
& 0x7f,
1422 .Depth
= (num_elements
>> 21) & 0x3f,
1423 .SurfacePitch
= stride
- 1,
1424 .MinimumArrayElement
= 0,
1425 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
1430 .AuxiliarySurfaceMode
= AUX_NONE
,
1432 .GreenClearColor
= 0,
1433 .BlueClearColor
= 0,
1434 .AlphaClearColor
= 0,
1435 .ShaderChannelSelectRed
= SCS_RED
,
1436 .ShaderChannelSelectGreen
= SCS_GREEN
,
1437 .ShaderChannelSelectBlue
= SCS_BLUE
,
1438 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
1439 .ResourceMinLOD
= 0,
1440 /* FIXME: We assume that the image must be bound at this time. */
1441 .SurfaceBaseAddress
= { NULL
, view
->offset
},
1444 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
1446 *pView
= (VkImageView
) view
;
1451 // Sampler functions
1453 VkResult
anv_CreateSampler(
1455 const VkSamplerCreateInfo
* pCreateInfo
,
1456 VkSampler
* pSampler
)
1458 struct anv_device
*device
= (struct anv_device
*) _device
;
1459 struct anv_sampler
*sampler
;
1461 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
1463 sampler
= anv_device_alloc(device
, sizeof(*sampler
), 8,
1464 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1466 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1468 static const uint32_t vk_to_gen_tex_filter
[] = {
1469 [VK_TEX_FILTER_NEAREST
] = MAPFILTER_NEAREST
,
1470 [VK_TEX_FILTER_LINEAR
] = MAPFILTER_LINEAR
1473 static const uint32_t vk_to_gen_mipmap_mode
[] = {
1474 [VK_TEX_MIPMAP_MODE_BASE
] = MIPFILTER_NONE
,
1475 [VK_TEX_MIPMAP_MODE_NEAREST
] = MIPFILTER_NEAREST
,
1476 [VK_TEX_MIPMAP_MODE_LINEAR
] = MIPFILTER_LINEAR
1479 static const uint32_t vk_to_gen_tex_address
[] = {
1480 [VK_TEX_ADDRESS_WRAP
] = TCM_WRAP
,
1481 [VK_TEX_ADDRESS_MIRROR
] = TCM_MIRROR
,
1482 [VK_TEX_ADDRESS_CLAMP
] = TCM_CLAMP
,
1483 [VK_TEX_ADDRESS_MIRROR_ONCE
] = TCM_MIRROR_ONCE
,
1484 [VK_TEX_ADDRESS_CLAMP_BORDER
] = TCM_CLAMP_BORDER
,
1487 static const uint32_t vk_to_gen_compare_op
[] = {
1488 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
1489 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
1490 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
1491 [VK_COMPARE_OP_LESS_EQUAL
] = PREFILTEROPLEQUAL
,
1492 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
1493 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
1494 [VK_COMPARE_OP_GREATER_EQUAL
] = PREFILTEROPGEQUAL
,
1495 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,
1498 if (pCreateInfo
->maxAnisotropy
> 0)
1499 anv_finishme("missing support for anisotropic filtering");
1501 struct GEN8_SAMPLER_STATE sampler_state
= {
1502 .SamplerDisable
= false,
1503 .TextureBorderColorMode
= DX10OGL
,
1504 .LODPreClampMode
= 0,
1506 .MipModeFilter
= vk_to_gen_mipmap_mode
[pCreateInfo
->mipMode
],
1507 .MagModeFilter
= vk_to_gen_tex_filter
[pCreateInfo
->magFilter
],
1508 .MinModeFilter
= vk_to_gen_tex_filter
[pCreateInfo
->minFilter
],
1509 .TextureLODBias
= pCreateInfo
->mipLodBias
* 256,
1510 .AnisotropicAlgorithm
= EWAApproximation
,
1511 .MinLOD
= pCreateInfo
->minLod
* 256,
1512 .MaxLOD
= pCreateInfo
->maxLod
* 256,
1513 .ChromaKeyEnable
= 0,
1514 .ChromaKeyIndex
= 0,
1516 .ShadowFunction
= vk_to_gen_compare_op
[pCreateInfo
->compareOp
],
1517 .CubeSurfaceControlMode
= 0,
1518 .IndirectStatePointer
= 0,
1519 .LODClampMagnificationMode
= MIPNONE
,
1520 .MaximumAnisotropy
= 0,
1521 .RAddressMinFilterRoundingEnable
= 0,
1522 .RAddressMagFilterRoundingEnable
= 0,
1523 .VAddressMinFilterRoundingEnable
= 0,
1524 .VAddressMagFilterRoundingEnable
= 0,
1525 .UAddressMinFilterRoundingEnable
= 0,
1526 .UAddressMagFilterRoundingEnable
= 0,
1527 .TrilinearFilterQuality
= 0,
1528 .NonnormalizedCoordinateEnable
= 0,
1529 .TCXAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressU
],
1530 .TCYAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressV
],
1531 .TCZAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressW
],
1534 GEN8_SAMPLER_STATE_pack(NULL
, sampler
->state
, &sampler_state
);
1536 *pSampler
= (VkSampler
) sampler
;
1541 // Descriptor set functions
1543 VkResult
anv_CreateDescriptorSetLayout(
1545 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
1546 VkDescriptorSetLayout
* pSetLayout
)
1548 struct anv_device
*device
= (struct anv_device
*) _device
;
1549 struct anv_descriptor_set_layout
*set_layout
;
1551 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
1553 uint32_t sampler_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1554 uint32_t surface_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1555 uint32_t num_dynamic_buffers
= 0;
1559 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1560 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1561 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1562 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1563 sampler_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1566 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1567 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1568 sampler_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1572 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1573 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1574 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1575 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1576 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1577 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1578 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1579 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1580 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1581 surface_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1587 count
+= pCreateInfo
->pBinding
[i
].count
;
1590 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1591 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1592 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1593 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1594 num_dynamic_buffers
++;
1601 uint32_t sampler_total
= 0;
1602 uint32_t surface_total
= 0;
1603 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1604 sampler_total
+= sampler_count
[s
];
1605 surface_total
+= surface_count
[s
];
1608 size_t size
= sizeof(*set_layout
) +
1609 (sampler_total
+ surface_total
) * sizeof(uint32_t);
1610 set_layout
= anv_device_alloc(device
, size
, 8,
1611 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1613 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1615 set_layout
->num_dynamic_buffers
= num_dynamic_buffers
;
1616 set_layout
->count
= count
;
1618 uint32_t *p
= set_layout
->entries
;
1619 uint32_t *sampler
[VK_NUM_SHADER_STAGE
];
1620 uint32_t *surface
[VK_NUM_SHADER_STAGE
];
1621 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1622 set_layout
->stage
[s
].surface_count
= surface_count
[s
];
1623 set_layout
->stage
[s
].surface_start
= surface
[s
] = p
;
1624 p
+= surface_count
[s
];
1625 set_layout
->stage
[s
].sampler_count
= sampler_count
[s
];
1626 set_layout
->stage
[s
].sampler_start
= sampler
[s
] = p
;
1627 p
+= sampler_count
[s
];
1630 uint32_t descriptor
= 0;
1631 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1632 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1633 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1634 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1635 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++)
1636 *(sampler
[s
])++ = descriptor
+ j
;
1639 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1640 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1641 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++)
1642 *(sampler
[s
])++ = descriptor
+ j
;
1646 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1647 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1648 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1649 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1650 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1651 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1652 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1653 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1654 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1655 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++) {
1656 *(surface
[s
])++ = descriptor
+ j
;
1662 descriptor
+= pCreateInfo
->pBinding
[i
].count
;
1665 *pSetLayout
= (VkDescriptorSetLayout
) set_layout
;
1670 VkResult
anv_BeginDescriptorPoolUpdate(
1672 VkDescriptorUpdateMode updateMode
)
1677 VkResult
anv_EndDescriptorPoolUpdate(
1684 VkResult
anv_CreateDescriptorPool(
1686 VkDescriptorPoolUsage poolUsage
,
1688 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
1689 VkDescriptorPool
* pDescriptorPool
)
1691 *pDescriptorPool
= 1;
1696 VkResult
anv_ResetDescriptorPool(
1698 VkDescriptorPool descriptorPool
)
1703 VkResult
anv_AllocDescriptorSets(
1705 VkDescriptorPool descriptorPool
,
1706 VkDescriptorSetUsage setUsage
,
1708 const VkDescriptorSetLayout
* pSetLayouts
,
1709 VkDescriptorSet
* pDescriptorSets
,
1712 struct anv_device
*device
= (struct anv_device
*) _device
;
1713 const struct anv_descriptor_set_layout
*layout
;
1714 struct anv_descriptor_set
*set
;
1717 for (uint32_t i
= 0; i
< count
; i
++) {
1718 layout
= (struct anv_descriptor_set_layout
*) pSetLayouts
[i
];
1719 size
= sizeof(*set
) + layout
->count
* sizeof(set
->descriptors
[0]);
1720 set
= anv_device_alloc(device
, size
, 8,
1721 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1724 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1727 pDescriptorSets
[i
] = (VkDescriptorSet
) set
;
1735 void anv_ClearDescriptorSets(
1737 VkDescriptorPool descriptorPool
,
1739 const VkDescriptorSet
* pDescriptorSets
)
1743 void anv_UpdateDescriptors(
1745 VkDescriptorSet descriptorSet
,
1746 uint32_t updateCount
,
1747 const void** ppUpdateArray
)
1749 struct anv_descriptor_set
*set
= (struct anv_descriptor_set
*) descriptorSet
;
1750 VkUpdateSamplers
*update_samplers
;
1751 VkUpdateSamplerTextures
*update_sampler_textures
;
1752 VkUpdateImages
*update_images
;
1753 VkUpdateBuffers
*update_buffers
;
1754 VkUpdateAsCopy
*update_as_copy
;
1756 for (uint32_t i
= 0; i
< updateCount
; i
++) {
1757 const struct anv_common
*common
= ppUpdateArray
[i
];
1759 switch (common
->sType
) {
1760 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS
:
1761 update_samplers
= (VkUpdateSamplers
*) common
;
1763 for (uint32_t j
= 0; j
< update_samplers
->count
; j
++) {
1764 set
->descriptors
[update_samplers
->binding
+ j
].sampler
=
1765 (struct anv_sampler
*) update_samplers
->pSamplers
[j
];
1769 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES
:
1770 /* FIXME: Shouldn't this be *_UPDATE_SAMPLER_IMAGES? */
1771 update_sampler_textures
= (VkUpdateSamplerTextures
*) common
;
1773 for (uint32_t j
= 0; j
< update_sampler_textures
->count
; j
++) {
1774 set
->descriptors
[update_sampler_textures
->binding
+ j
].view
=
1775 (struct anv_surface_view
*)
1776 update_sampler_textures
->pSamplerImageViews
[j
].pImageView
->view
;
1777 set
->descriptors
[update_sampler_textures
->binding
+ j
].sampler
=
1778 (struct anv_sampler
*)
1779 update_sampler_textures
->pSamplerImageViews
[j
].sampler
;
1783 case VK_STRUCTURE_TYPE_UPDATE_IMAGES
:
1784 update_images
= (VkUpdateImages
*) common
;
1786 for (uint32_t j
= 0; j
< update_images
->count
; j
++) {
1787 set
->descriptors
[update_images
->binding
+ j
].view
=
1788 (struct anv_surface_view
*) update_images
->pImageViews
[j
].view
;
1792 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS
:
1793 update_buffers
= (VkUpdateBuffers
*) common
;
1795 for (uint32_t j
= 0; j
< update_buffers
->count
; j
++) {
1796 set
->descriptors
[update_buffers
->binding
+ j
].view
=
1797 (struct anv_surface_view
*) update_buffers
->pBufferViews
[j
].view
;
1799 /* FIXME: descriptor arrays? */
1802 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY
:
1803 update_as_copy
= (VkUpdateAsCopy
*) common
;
1804 (void) update_as_copy
;
1813 // State object functions
1815 static inline int64_t
1816 clamp_int64(int64_t x
, int64_t min
, int64_t max
)
1826 VkResult
anv_CreateDynamicViewportState(
1828 const VkDynamicVpStateCreateInfo
* pCreateInfo
,
1829 VkDynamicVpState
* pState
)
1831 struct anv_device
*device
= (struct anv_device
*) _device
;
1832 struct anv_dynamic_vp_state
*state
;
1834 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
);
1836 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1837 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1839 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1841 unsigned count
= pCreateInfo
->viewportAndScissorCount
;
1842 state
->sf_clip_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1844 state
->cc_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1846 state
->scissor
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1849 for (uint32_t i
= 0; i
< pCreateInfo
->viewportAndScissorCount
; i
++) {
1850 const VkViewport
*vp
= &pCreateInfo
->pViewports
[i
];
1851 const VkRect
*s
= &pCreateInfo
->pScissors
[i
];
1853 struct GEN8_SF_CLIP_VIEWPORT sf_clip_viewport
= {
1854 .ViewportMatrixElementm00
= vp
->width
/ 2,
1855 .ViewportMatrixElementm11
= vp
->height
/ 2,
1856 .ViewportMatrixElementm22
= (vp
->maxDepth
- vp
->minDepth
) / 2,
1857 .ViewportMatrixElementm30
= vp
->originX
+ vp
->width
/ 2,
1858 .ViewportMatrixElementm31
= vp
->originY
+ vp
->height
/ 2,
1859 .ViewportMatrixElementm32
= (vp
->maxDepth
+ vp
->minDepth
) / 2,
1860 .XMinClipGuardband
= -1.0f
,
1861 .XMaxClipGuardband
= 1.0f
,
1862 .YMinClipGuardband
= -1.0f
,
1863 .YMaxClipGuardband
= 1.0f
,
1864 .XMinViewPort
= vp
->originX
,
1865 .XMaxViewPort
= vp
->originX
+ vp
->width
- 1,
1866 .YMinViewPort
= vp
->originY
,
1867 .YMaxViewPort
= vp
->originY
+ vp
->height
- 1,
1870 struct GEN8_CC_VIEWPORT cc_viewport
= {
1871 .MinimumDepth
= vp
->minDepth
,
1872 .MaximumDepth
= vp
->maxDepth
1875 /* Since xmax and ymax are inclusive, we have to have xmax < xmin or
1876 * ymax < ymin for empty clips. In case clip x, y, width height are all
1877 * 0, the clamps below produce 0 for xmin, ymin, xmax, ymax, which isn't
1878 * what we want. Just special case empty clips and produce a canonical
1880 static const struct GEN8_SCISSOR_RECT empty_scissor
= {
1881 .ScissorRectangleYMin
= 1,
1882 .ScissorRectangleXMin
= 1,
1883 .ScissorRectangleYMax
= 0,
1884 .ScissorRectangleXMax
= 0
1887 const int max
= 0xffff;
1888 struct GEN8_SCISSOR_RECT scissor
= {
1889 /* Do this math using int64_t so overflow gets clamped correctly. */
1890 .ScissorRectangleYMin
= clamp_int64(s
->offset
.y
, 0, max
),
1891 .ScissorRectangleXMin
= clamp_int64(s
->offset
.x
, 0, max
),
1892 .ScissorRectangleYMax
= clamp_int64((uint64_t) s
->offset
.y
+ s
->extent
.height
- 1, 0, max
),
1893 .ScissorRectangleXMax
= clamp_int64((uint64_t) s
->offset
.x
+ s
->extent
.width
- 1, 0, max
)
1896 GEN8_SF_CLIP_VIEWPORT_pack(NULL
, state
->sf_clip_vp
.map
+ i
* 64, &sf_clip_viewport
);
1897 GEN8_CC_VIEWPORT_pack(NULL
, state
->cc_vp
.map
+ i
* 32, &cc_viewport
);
1899 if (s
->extent
.width
<= 0 || s
->extent
.height
<= 0) {
1900 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &empty_scissor
);
1902 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &scissor
);
1906 *pState
= (VkDynamicVpState
) state
;
1911 VkResult
anv_CreateDynamicRasterState(
1913 const VkDynamicRsStateCreateInfo
* pCreateInfo
,
1914 VkDynamicRsState
* pState
)
1916 struct anv_device
*device
= (struct anv_device
*) _device
;
1917 struct anv_dynamic_rs_state
*state
;
1919 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO
);
1921 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1922 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1924 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1928 * float depthBiasClamp;
1929 * float slopeScaledDepthBias;
1930 * float pointFadeThreshold;
1931 * // optional (GL45) - Size of point fade threshold
1934 struct GEN8_3DSTATE_SF sf
= {
1935 GEN8_3DSTATE_SF_header
,
1936 .LineWidth
= pCreateInfo
->lineWidth
,
1937 .PointWidth
= pCreateInfo
->pointSize
,
1940 GEN8_3DSTATE_SF_pack(NULL
, state
->state_sf
, &sf
);
1942 *pState
= (VkDynamicRsState
) state
;
1947 VkResult
anv_CreateDynamicColorBlendState(
1949 const VkDynamicCbStateCreateInfo
* pCreateInfo
,
1950 VkDynamicCbState
* pState
)
1952 struct anv_device
*device
= (struct anv_device
*) _device
;
1953 struct anv_dynamic_cb_state
*state
;
1955 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO
);
1957 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1958 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1960 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1962 *pState
= (VkDynamicCbState
) state
;
1967 VkResult
anv_CreateDynamicDepthStencilState(
1969 const VkDynamicDsStateCreateInfo
* pCreateInfo
,
1970 VkDynamicDsState
* pState
)
1972 stub_return(VK_UNSUPPORTED
);
1975 // Command buffer functions
1977 VkResult
anv_CreateCommandBuffer(
1979 const VkCmdBufferCreateInfo
* pCreateInfo
,
1980 VkCmdBuffer
* pCmdBuffer
)
1982 struct anv_device
*device
= (struct anv_device
*) _device
;
1983 struct anv_cmd_buffer
*cmd_buffer
;
1986 cmd_buffer
= anv_device_alloc(device
, sizeof(*cmd_buffer
), 8,
1987 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1988 if (cmd_buffer
== NULL
)
1989 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1991 cmd_buffer
->device
= device
;
1992 cmd_buffer
->rs_state
= NULL
;
1993 cmd_buffer
->vp_state
= NULL
;
1994 memset(&cmd_buffer
->default_bindings
, 0, sizeof(cmd_buffer
->default_bindings
));
1995 cmd_buffer
->bindings
= &cmd_buffer
->default_bindings
;
1997 result
= anv_batch_init(&cmd_buffer
->batch
, device
);
1998 if (result
!= VK_SUCCESS
)
2001 cmd_buffer
->exec2_objects
=
2002 anv_device_alloc(device
, 8192 * sizeof(cmd_buffer
->exec2_objects
[0]), 8,
2003 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2004 if (cmd_buffer
->exec2_objects
== NULL
) {
2005 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2009 cmd_buffer
->exec2_bos
=
2010 anv_device_alloc(device
, 8192 * sizeof(cmd_buffer
->exec2_bos
[0]), 8,
2011 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2012 if (cmd_buffer
->exec2_bos
== NULL
) {
2013 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2014 goto fail_exec2_objects
;
2017 anv_state_stream_init(&cmd_buffer
->surface_state_stream
,
2018 &device
->surface_state_block_pool
);
2019 anv_state_stream_init(&cmd_buffer
->dynamic_state_stream
,
2020 &device
->dynamic_state_block_pool
);
2022 cmd_buffer
->dirty
= 0;
2023 cmd_buffer
->vb_dirty
= 0;
2025 *pCmdBuffer
= (VkCmdBuffer
) cmd_buffer
;
2030 anv_device_free(device
, cmd_buffer
->exec2_objects
);
2032 anv_batch_finish(&cmd_buffer
->batch
, device
);
2034 anv_device_free(device
, cmd_buffer
);
2039 VkResult
anv_BeginCommandBuffer(
2040 VkCmdBuffer cmdBuffer
,
2041 const VkCmdBufferBeginInfo
* pBeginInfo
)
2043 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2044 struct anv_device
*device
= cmd_buffer
->device
;
2046 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPELINE_SELECT
,
2047 .PipelineSelection
= _3D
);
2048 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_SIP
);
2050 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_BASE_ADDRESS
,
2051 .GeneralStateBaseAddress
= { NULL
, 0 },
2052 .GeneralStateBaseAddressModifyEnable
= true,
2053 .GeneralStateBufferSize
= 0xfffff,
2054 .GeneralStateBufferSizeModifyEnable
= true,
2056 .SurfaceStateBaseAddress
= { &device
->surface_state_block_pool
.bo
, 0 },
2057 .SurfaceStateMemoryObjectControlState
= 0, /* FIXME: MOCS */
2058 .SurfaceStateBaseAddressModifyEnable
= true,
2060 .DynamicStateBaseAddress
= { &device
->dynamic_state_block_pool
.bo
, 0 },
2061 .DynamicStateBaseAddressModifyEnable
= true,
2062 .DynamicStateBufferSize
= 0xfffff,
2063 .DynamicStateBufferSizeModifyEnable
= true,
2065 .IndirectObjectBaseAddress
= { NULL
, 0 },
2066 .IndirectObjectBaseAddressModifyEnable
= true,
2067 .IndirectObjectBufferSize
= 0xfffff,
2068 .IndirectObjectBufferSizeModifyEnable
= true,
2070 .InstructionBaseAddress
= { &device
->instruction_block_pool
.bo
, 0 },
2071 .InstructionBaseAddressModifyEnable
= true,
2072 .InstructionBufferSize
= 0xfffff,
2073 .InstructionBuffersizeModifyEnable
= true);
2075 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VF_STATISTICS
,
2076 .StatisticsEnable
= true);
2077 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_HS
, .Enable
= false);
2078 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_TE
, .TEEnable
= false);
2079 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DS
, .FunctionEnable
= false);
2080 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_STREAMOUT
, .SOFunctionEnable
= false);
2082 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_VS
,
2083 .ConstantBufferOffset
= 0,
2084 .ConstantBufferSize
= 4);
2085 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_GS
,
2086 .ConstantBufferOffset
= 4,
2087 .ConstantBufferSize
= 4);
2088 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_PS
,
2089 .ConstantBufferOffset
= 8,
2090 .ConstantBufferSize
= 4);
2092 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_WM_CHROMAKEY
,
2093 .ChromaKeyKillEnable
= false);
2094 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SBE_SWIZ
);
2095 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_AA_LINE_PARAMETERS
);
2097 /* Hardcoded state: */
2098 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DEPTH_BUFFER
,
2099 .SurfaceType
= SURFTYPE_2D
,
2102 .SurfaceFormat
= D16_UNORM
,
2103 .SurfaceBaseAddress
= { NULL
, 0 },
2104 .HierarchicalDepthBufferEnable
= 0);
2106 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_WM_DEPTH_STENCIL
,
2107 .DepthTestEnable
= false,
2108 .DepthBufferWriteEnable
= false);
2114 anv_cmd_buffer_add_bo(struct anv_cmd_buffer
*cmd_buffer
,
2115 struct anv_bo
*bo
, struct anv_reloc_list
*list
)
2117 struct drm_i915_gem_exec_object2
*obj
;
2119 bo
->index
= cmd_buffer
->bo_count
;
2120 obj
= &cmd_buffer
->exec2_objects
[bo
->index
];
2121 cmd_buffer
->exec2_bos
[bo
->index
] = bo
;
2122 cmd_buffer
->bo_count
++;
2124 obj
->handle
= bo
->gem_handle
;
2125 obj
->relocation_count
= 0;
2126 obj
->relocs_ptr
= 0;
2128 obj
->offset
= bo
->offset
;
2134 obj
->relocation_count
= list
->num_relocs
;
2135 obj
->relocs_ptr
= (uintptr_t) list
->relocs
;
2140 anv_cmd_buffer_add_validate_bos(struct anv_cmd_buffer
*cmd_buffer
,
2141 struct anv_reloc_list
*list
)
2143 struct anv_bo
*bo
, *batch_bo
;
2145 batch_bo
= &cmd_buffer
->batch
.bo
;
2146 for (size_t i
= 0; i
< list
->num_relocs
; i
++) {
2147 bo
= list
->reloc_bos
[i
];
2148 /* Skip any relocations targeting the batch bo. We need to make sure
2149 * it's the last in the list so we'll add it manually later.
2153 if (bo
->index
< cmd_buffer
->bo_count
&& cmd_buffer
->exec2_bos
[bo
->index
] == bo
)
2156 anv_cmd_buffer_add_bo(cmd_buffer
, bo
, NULL
);
2161 anv_cmd_buffer_process_relocs(struct anv_cmd_buffer
*cmd_buffer
,
2162 struct anv_reloc_list
*list
)
2166 /* If the kernel supports I915_EXEC_NO_RELOC, it will compare offset in
2167 * struct drm_i915_gem_exec_object2 against the bos current offset and if
2168 * all bos haven't moved it will skip relocation processing alltogether.
2169 * If I915_EXEC_NO_RELOC is not supported, the kernel ignores the incoming
2170 * value of offset so we can set it either way. For that to work we need
2171 * to make sure all relocs use the same presumed offset.
2174 for (size_t i
= 0; i
< list
->num_relocs
; i
++) {
2175 bo
= list
->reloc_bos
[i
];
2176 if (bo
->offset
!= list
->relocs
[i
].presumed_offset
)
2177 cmd_buffer
->need_reloc
= true;
2179 list
->relocs
[i
].target_handle
= bo
->index
;
2183 VkResult
anv_EndCommandBuffer(
2184 VkCmdBuffer cmdBuffer
)
2186 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2187 struct anv_device
*device
= cmd_buffer
->device
;
2188 struct anv_batch
*batch
= &cmd_buffer
->batch
;
2190 anv_batch_emit(batch
, GEN8_MI_BATCH_BUFFER_END
);
2192 /* Round batch up to an even number of dwords. */
2193 if ((batch
->next
- batch
->bo
.map
) & 4)
2194 anv_batch_emit(batch
, GEN8_MI_NOOP
);
2196 cmd_buffer
->bo_count
= 0;
2197 cmd_buffer
->need_reloc
= false;
2199 /* Lock for access to bo->index. */
2200 pthread_mutex_lock(&device
->mutex
);
2202 /* Add block pool bos first so we can add them with their relocs. */
2203 anv_cmd_buffer_add_bo(cmd_buffer
, &device
->surface_state_block_pool
.bo
,
2204 &batch
->surf_relocs
);
2206 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &batch
->surf_relocs
);
2207 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &batch
->cmd_relocs
);
2208 anv_cmd_buffer_add_bo(cmd_buffer
, &batch
->bo
, &batch
->cmd_relocs
);
2209 anv_cmd_buffer_process_relocs(cmd_buffer
, &batch
->surf_relocs
);
2210 anv_cmd_buffer_process_relocs(cmd_buffer
, &batch
->cmd_relocs
);
2212 cmd_buffer
->execbuf
.buffers_ptr
= (uintptr_t) cmd_buffer
->exec2_objects
;
2213 cmd_buffer
->execbuf
.buffer_count
= cmd_buffer
->bo_count
;
2214 cmd_buffer
->execbuf
.batch_start_offset
= 0;
2215 cmd_buffer
->execbuf
.batch_len
= batch
->next
- batch
->bo
.map
;
2216 cmd_buffer
->execbuf
.cliprects_ptr
= 0;
2217 cmd_buffer
->execbuf
.num_cliprects
= 0;
2218 cmd_buffer
->execbuf
.DR1
= 0;
2219 cmd_buffer
->execbuf
.DR4
= 0;
2221 cmd_buffer
->execbuf
.flags
= I915_EXEC_HANDLE_LUT
;
2222 if (!cmd_buffer
->need_reloc
)
2223 cmd_buffer
->execbuf
.flags
|= I915_EXEC_NO_RELOC
;
2224 cmd_buffer
->execbuf
.flags
|= I915_EXEC_RENDER
;
2225 cmd_buffer
->execbuf
.rsvd1
= device
->context_id
;
2226 cmd_buffer
->execbuf
.rsvd2
= 0;
2228 pthread_mutex_unlock(&device
->mutex
);
2233 VkResult
anv_ResetCommandBuffer(
2234 VkCmdBuffer cmdBuffer
)
2236 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2238 anv_batch_reset(&cmd_buffer
->batch
);
2243 // Command buffer building functions
2245 void anv_CmdBindPipeline(
2246 VkCmdBuffer cmdBuffer
,
2247 VkPipelineBindPoint pipelineBindPoint
,
2248 VkPipeline _pipeline
)
2250 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2252 cmd_buffer
->pipeline
= (struct anv_pipeline
*) _pipeline
;
2253 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
;
2256 void anv_CmdBindDynamicStateObject(
2257 VkCmdBuffer cmdBuffer
,
2258 VkStateBindPoint stateBindPoint
,
2259 VkDynamicStateObject dynamicState
)
2261 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2262 struct anv_dynamic_vp_state
*vp_state
;
2264 switch (stateBindPoint
) {
2265 case VK_STATE_BIND_POINT_VIEWPORT
:
2266 vp_state
= (struct anv_dynamic_vp_state
*) dynamicState
;
2267 /* We emit state immediately, but set cmd_buffer->vp_state to indicate
2268 * that vp state has been set in this command buffer. */
2269 cmd_buffer
->vp_state
= vp_state
;
2270 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SCISSOR_STATE_POINTERS
,
2271 .ScissorRectPointer
= vp_state
->scissor
.offset
);
2272 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_CC
,
2273 .CCViewportPointer
= vp_state
->cc_vp
.offset
);
2274 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
,
2275 .SFClipViewportPointer
= vp_state
->sf_clip_vp
.offset
);
2277 case VK_STATE_BIND_POINT_RASTER
:
2278 cmd_buffer
->rs_state
= (struct anv_dynamic_rs_state
*) dynamicState
;
2279 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_RS_DIRTY
;
2281 case VK_STATE_BIND_POINT_COLOR_BLEND
:
2282 case VK_STATE_BIND_POINT_DEPTH_STENCIL
:
2289 void anv_CmdBindDescriptorSets(
2290 VkCmdBuffer cmdBuffer
,
2291 VkPipelineBindPoint pipelineBindPoint
,
2294 const VkDescriptorSet
* pDescriptorSets
,
2295 uint32_t dynamicOffsetCount
,
2296 const uint32_t* pDynamicOffsets
)
2298 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2299 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
2300 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2302 uint32_t offset
= 0;
2303 for (uint32_t i
= 0; i
< setCount
; i
++) {
2304 struct anv_descriptor_set
*set
=
2305 (struct anv_descriptor_set
*) pDescriptorSets
[i
];
2306 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[firstSet
+ i
].layout
;
2308 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
2309 uint32_t *surface_to_desc
= set_layout
->stage
[s
].surface_start
;
2310 uint32_t *sampler_to_desc
= set_layout
->stage
[s
].sampler_start
;
2311 uint32_t bias
= s
== VK_SHADER_STAGE_FRAGMENT
? MAX_RTS
: 0;
2314 start
= bias
+ layout
->set
[firstSet
+ i
].surface_start
[s
];
2315 for (uint32_t b
= 0; b
< set_layout
->stage
[s
].surface_count
; b
++) {
2316 struct anv_surface_view
*view
= set
->descriptors
[surface_to_desc
[b
]].view
;
2318 bindings
->descriptors
[s
].surfaces
[start
+ b
] =
2319 view
->surface_state
.offset
;
2320 bindings
->descriptors
[s
].relocs
[start
+ b
].bo
= view
->bo
;
2321 bindings
->descriptors
[s
].relocs
[start
+ b
].offset
= view
->offset
;
2324 start
= layout
->set
[firstSet
+ i
].sampler_start
[s
];
2325 for (uint32_t b
= 0; b
< set_layout
->stage
[s
].sampler_count
; b
++) {
2326 struct anv_sampler
*sampler
= set
->descriptors
[sampler_to_desc
[b
]].sampler
;
2328 memcpy(&bindings
->descriptors
[s
].samplers
[start
+ b
],
2329 sampler
->state
, sizeof(sampler
->state
));
2333 offset
+= layout
->set
[firstSet
+ i
].layout
->num_dynamic_buffers
;
2336 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
2339 void anv_CmdBindIndexBuffer(
2340 VkCmdBuffer cmdBuffer
,
2342 VkDeviceSize offset
,
2343 VkIndexType indexType
)
2345 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2346 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2348 static const uint32_t vk_to_gen_index_type
[] = {
2349 [VK_INDEX_TYPE_UINT8
] = INDEX_BYTE
,
2350 [VK_INDEX_TYPE_UINT16
] = INDEX_WORD
,
2351 [VK_INDEX_TYPE_UINT32
] = INDEX_DWORD
,
2354 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_INDEX_BUFFER
,
2355 .IndexFormat
= vk_to_gen_index_type
[indexType
],
2356 .MemoryObjectControlState
= 0,
2357 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
2358 .BufferSize
= buffer
->size
- offset
);
2361 void anv_CmdBindVertexBuffers(
2362 VkCmdBuffer cmdBuffer
,
2363 uint32_t startBinding
,
2364 uint32_t bindingCount
,
2365 const VkBuffer
* pBuffers
,
2366 const VkDeviceSize
* pOffsets
)
2368 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2369 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2371 /* We have to defer setting up vertex buffer since we need the buffer
2372 * stride from the pipeline. */
2374 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
2375 bindings
->vb
[startBinding
+ i
].buffer
= (struct anv_buffer
*) pBuffers
[i
];
2376 bindings
->vb
[startBinding
+ i
].offset
= pOffsets
[i
];
2377 cmd_buffer
->vb_dirty
|= 1 << (startBinding
+ i
);
2382 flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
)
2384 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
2385 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2386 uint32_t layers
= cmd_buffer
->framebuffer
->layers
;
2388 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
2391 if (s
== VK_SHADER_STAGE_FRAGMENT
) {
2393 layers
= cmd_buffer
->framebuffer
->layers
;
2399 /* This is a little awkward: layout can be NULL but we still have to
2400 * allocate and set a binding table for the PS stage for render
2402 uint32_t surface_count
= layout
? layout
->stage
[s
].surface_count
: 0;
2404 if (layers
+ surface_count
> 0) {
2405 struct anv_state state
;
2408 size
= (bias
+ surface_count
) * sizeof(uint32_t);
2409 state
= anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, size
, 32);
2410 memcpy(state
.map
, bindings
->descriptors
[s
].surfaces
, size
);
2412 for (uint32_t i
= 0; i
< layers
; i
++)
2413 anv_reloc_list_add(&cmd_buffer
->batch
.surf_relocs
,
2414 bindings
->descriptors
[s
].surfaces
[i
] + 8 * sizeof(int32_t),
2415 bindings
->descriptors
[s
].relocs
[i
].bo
,
2416 bindings
->descriptors
[s
].relocs
[i
].offset
);
2418 for (uint32_t i
= 0; i
< surface_count
; i
++)
2419 anv_reloc_list_add(&cmd_buffer
->batch
.surf_relocs
,
2420 bindings
->descriptors
[s
].surfaces
[bias
+ i
] + 8 * sizeof(int32_t),
2421 bindings
->descriptors
[s
].relocs
[bias
+ i
].bo
,
2422 bindings
->descriptors
[s
].relocs
[bias
+ i
].offset
);
2424 static const uint32_t binding_table_opcodes
[] = {
2425 [VK_SHADER_STAGE_VERTEX
] = 38,
2426 [VK_SHADER_STAGE_TESS_CONTROL
] = 39,
2427 [VK_SHADER_STAGE_TESS_EVALUATION
] = 40,
2428 [VK_SHADER_STAGE_GEOMETRY
] = 41,
2429 [VK_SHADER_STAGE_FRAGMENT
] = 42,
2430 [VK_SHADER_STAGE_COMPUTE
] = 0,
2433 anv_batch_emit(&cmd_buffer
->batch
,
2434 GEN8_3DSTATE_BINDING_TABLE_POINTERS_VS
,
2435 ._3DCommandSubOpcode
= binding_table_opcodes
[s
],
2436 .PointertoVSBindingTable
= state
.offset
);
2439 if (layout
&& layout
->stage
[s
].sampler_count
> 0) {
2440 struct anv_state state
;
2443 size
= layout
->stage
[s
].sampler_count
* 16;
2444 state
= anv_state_stream_alloc(&cmd_buffer
->dynamic_state_stream
, size
, 32);
2445 memcpy(state
.map
, bindings
->descriptors
[s
].samplers
, size
);
2447 static const uint32_t sampler_state_opcodes
[] = {
2448 [VK_SHADER_STAGE_VERTEX
] = 43,
2449 [VK_SHADER_STAGE_TESS_CONTROL
] = 44, /* HS */
2450 [VK_SHADER_STAGE_TESS_EVALUATION
] = 45, /* DS */
2451 [VK_SHADER_STAGE_GEOMETRY
] = 46,
2452 [VK_SHADER_STAGE_FRAGMENT
] = 47,
2453 [VK_SHADER_STAGE_COMPUTE
] = 0,
2456 anv_batch_emit(&cmd_buffer
->batch
,
2457 GEN8_3DSTATE_SAMPLER_STATE_POINTERS_VS
,
2458 ._3DCommandSubOpcode
= sampler_state_opcodes
[s
],
2459 .PointertoVSSamplerState
= state
.offset
);
2465 anv_cmd_buffer_flush_state(struct anv_cmd_buffer
*cmd_buffer
)
2467 struct anv_pipeline
*pipeline
= cmd_buffer
->pipeline
;
2468 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2469 const uint32_t num_buffers
= __builtin_popcount(cmd_buffer
->vb_dirty
);
2470 const uint32_t num_dwords
= 1 + num_buffers
* 4;
2473 if (cmd_buffer
->vb_dirty
) {
2474 p
= anv_batch_emitn(&cmd_buffer
->batch
, num_dwords
,
2475 GEN8_3DSTATE_VERTEX_BUFFERS
);
2477 for_each_bit(vb
, cmd_buffer
->vb_dirty
) {
2478 struct anv_buffer
*buffer
= bindings
->vb
[vb
].buffer
;
2479 uint32_t offset
= bindings
->vb
[vb
].offset
;
2481 struct GEN8_VERTEX_BUFFER_STATE state
= {
2482 .VertexBufferIndex
= vb
,
2483 .MemoryObjectControlState
= 0,
2484 .AddressModifyEnable
= true,
2485 .BufferPitch
= pipeline
->binding_stride
[vb
],
2486 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
2487 .BufferSize
= buffer
->size
- offset
2490 GEN8_VERTEX_BUFFER_STATE_pack(&cmd_buffer
->batch
, &p
[1 + i
* 4], &state
);
2495 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_PIPELINE_DIRTY
)
2496 anv_batch_emit_batch(&cmd_buffer
->batch
, &pipeline
->batch
);
2498 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
)
2499 flush_descriptor_sets(cmd_buffer
);
2501 if (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_PIPELINE_DIRTY
| ANV_CMD_BUFFER_RS_DIRTY
))
2502 anv_batch_emit_merge(&cmd_buffer
->batch
,
2503 cmd_buffer
->rs_state
->state_sf
, pipeline
->state_sf
);
2505 cmd_buffer
->vb_dirty
= 0;
2506 cmd_buffer
->dirty
= 0;
2510 VkCmdBuffer cmdBuffer
,
2511 uint32_t firstVertex
,
2512 uint32_t vertexCount
,
2513 uint32_t firstInstance
,
2514 uint32_t instanceCount
)
2516 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2518 anv_cmd_buffer_flush_state(cmd_buffer
);
2520 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2521 .VertexAccessType
= SEQUENTIAL
,
2522 .VertexCountPerInstance
= vertexCount
,
2523 .StartVertexLocation
= firstVertex
,
2524 .InstanceCount
= instanceCount
,
2525 .StartInstanceLocation
= firstInstance
,
2526 .BaseVertexLocation
= 0);
2529 void anv_CmdDrawIndexed(
2530 VkCmdBuffer cmdBuffer
,
2531 uint32_t firstIndex
,
2532 uint32_t indexCount
,
2533 int32_t vertexOffset
,
2534 uint32_t firstInstance
,
2535 uint32_t instanceCount
)
2537 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2539 anv_cmd_buffer_flush_state(cmd_buffer
);
2541 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2542 .VertexAccessType
= RANDOM
,
2543 .VertexCountPerInstance
= indexCount
,
2544 .StartVertexLocation
= firstIndex
,
2545 .InstanceCount
= instanceCount
,
2546 .StartInstanceLocation
= firstInstance
,
2547 .BaseVertexLocation
= 0);
2551 anv_batch_lrm(struct anv_batch
*batch
,
2552 uint32_t reg
, struct anv_bo
*bo
, uint32_t offset
)
2554 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_MEM
,
2555 .RegisterAddress
= reg
,
2556 .MemoryAddress
= { bo
, offset
});
2560 anv_batch_lri(struct anv_batch
*batch
, uint32_t reg
, uint32_t imm
)
2562 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_IMM
,
2563 .RegisterOffset
= reg
,
2567 /* Auto-Draw / Indirect Registers */
2568 #define GEN7_3DPRIM_END_OFFSET 0x2420
2569 #define GEN7_3DPRIM_START_VERTEX 0x2430
2570 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
2571 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
2572 #define GEN7_3DPRIM_START_INSTANCE 0x243C
2573 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
2575 void anv_CmdDrawIndirect(
2576 VkCmdBuffer cmdBuffer
,
2578 VkDeviceSize offset
,
2582 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2583 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2584 struct anv_bo
*bo
= buffer
->bo
;
2585 uint32_t bo_offset
= buffer
->offset
+ offset
;
2587 anv_cmd_buffer_flush_state(cmd_buffer
);
2589 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
2590 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
2591 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
2592 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 12);
2593 anv_batch_lri(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, 0);
2595 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2596 .IndirectParameterEnable
= true,
2597 .VertexAccessType
= SEQUENTIAL
);
2600 void anv_CmdDrawIndexedIndirect(
2601 VkCmdBuffer cmdBuffer
,
2603 VkDeviceSize offset
,
2607 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2608 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2609 struct anv_bo
*bo
= buffer
->bo
;
2610 uint32_t bo_offset
= buffer
->offset
+ offset
;
2612 anv_cmd_buffer_flush_state(cmd_buffer
);
2614 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
2615 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
2616 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
2617 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, bo
, bo_offset
+ 12);
2618 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 16);
2620 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2621 .IndirectParameterEnable
= true,
2622 .VertexAccessType
= RANDOM
);
2625 void anv_CmdDispatch(
2626 VkCmdBuffer cmdBuffer
,
2634 void anv_CmdDispatchIndirect(
2635 VkCmdBuffer cmdBuffer
,
2637 VkDeviceSize offset
)
2642 void anv_CmdSetEvent(
2643 VkCmdBuffer cmdBuffer
,
2645 VkPipeEvent pipeEvent
)
2650 void anv_CmdResetEvent(
2651 VkCmdBuffer cmdBuffer
,
2653 VkPipeEvent pipeEvent
)
2658 void anv_CmdWaitEvents(
2659 VkCmdBuffer cmdBuffer
,
2660 VkWaitEvent waitEvent
,
2661 uint32_t eventCount
,
2662 const VkEvent
* pEvents
,
2663 uint32_t memBarrierCount
,
2664 const void** ppMemBarriers
)
2669 void anv_CmdPipelineBarrier(
2670 VkCmdBuffer cmdBuffer
,
2671 VkWaitEvent waitEvent
,
2672 uint32_t pipeEventCount
,
2673 const VkPipeEvent
* pPipeEvents
,
2674 uint32_t memBarrierCount
,
2675 const void** ppMemBarriers
)
2681 anv_batch_emit_ps_depth_count(struct anv_batch
*batch
,
2682 struct anv_bo
*bo
, uint32_t offset
)
2684 anv_batch_emit(batch
, GEN8_PIPE_CONTROL
,
2685 .DestinationAddressType
= DAT_PPGTT
,
2686 .PostSyncOperation
= WritePSDepthCount
,
2687 .Address
= { bo
, offset
}); /* FIXME: This is only lower 32 bits */
2690 void anv_CmdBeginQuery(
2691 VkCmdBuffer cmdBuffer
,
2692 VkQueryPool queryPool
,
2694 VkQueryControlFlags flags
)
2696 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2697 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
2699 switch (pool
->type
) {
2700 case VK_QUERY_TYPE_OCCLUSION
:
2701 anv_batch_emit_ps_depth_count(&cmd_buffer
->batch
, &pool
->bo
, slot
* 16);
2704 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
2712 void anv_CmdEndQuery(
2713 VkCmdBuffer cmdBuffer
,
2714 VkQueryPool queryPool
,
2717 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2718 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
2720 switch (pool
->type
) {
2721 case VK_QUERY_TYPE_OCCLUSION
:
2722 anv_batch_emit_ps_depth_count(&cmd_buffer
->batch
, &pool
->bo
, slot
* 16 + 8);
2725 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
2733 void anv_CmdResetQueryPool(
2734 VkCmdBuffer cmdBuffer
,
2735 VkQueryPool queryPool
,
2736 uint32_t startQuery
,
2737 uint32_t queryCount
)
2742 #define TIMESTAMP 0x44070
2744 void anv_CmdWriteTimestamp(
2745 VkCmdBuffer cmdBuffer
,
2746 VkTimestampType timestampType
,
2747 VkBuffer destBuffer
,
2748 VkDeviceSize destOffset
)
2750 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2751 struct anv_buffer
*buffer
= (struct anv_buffer
*) destBuffer
;
2752 struct anv_bo
*bo
= buffer
->bo
;
2754 switch (timestampType
) {
2755 case VK_TIMESTAMP_TYPE_TOP
:
2756 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MI_STORE_REGISTER_MEM
,
2757 .RegisterAddress
= TIMESTAMP
,
2758 .MemoryAddress
= { bo
, buffer
->offset
+ destOffset
});
2761 case VK_TIMESTAMP_TYPE_BOTTOM
:
2762 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
2763 .DestinationAddressType
= DAT_PPGTT
,
2764 .PostSyncOperation
= WriteTimestamp
,
2765 .Address
= /* FIXME: This is only lower 32 bits */
2766 { bo
, buffer
->offset
+ destOffset
});
2774 void anv_CmdCopyQueryPoolResults(
2775 VkCmdBuffer cmdBuffer
,
2776 VkQueryPool queryPool
,
2777 uint32_t startQuery
,
2778 uint32_t queryCount
,
2779 VkBuffer destBuffer
,
2780 VkDeviceSize destOffset
,
2781 VkDeviceSize destStride
,
2782 VkQueryResultFlags flags
)
2787 void anv_CmdInitAtomicCounters(
2788 VkCmdBuffer cmdBuffer
,
2789 VkPipelineBindPoint pipelineBindPoint
,
2790 uint32_t startCounter
,
2791 uint32_t counterCount
,
2792 const uint32_t* pData
)
2797 void anv_CmdLoadAtomicCounters(
2798 VkCmdBuffer cmdBuffer
,
2799 VkPipelineBindPoint pipelineBindPoint
,
2800 uint32_t startCounter
,
2801 uint32_t counterCount
,
2803 VkDeviceSize srcOffset
)
2808 void anv_CmdSaveAtomicCounters(
2809 VkCmdBuffer cmdBuffer
,
2810 VkPipelineBindPoint pipelineBindPoint
,
2811 uint32_t startCounter
,
2812 uint32_t counterCount
,
2813 VkBuffer destBuffer
,
2814 VkDeviceSize destOffset
)
2819 VkResult
anv_CreateFramebuffer(
2821 const VkFramebufferCreateInfo
* pCreateInfo
,
2822 VkFramebuffer
* pFramebuffer
)
2824 struct anv_device
*device
= (struct anv_device
*) _device
;
2825 struct anv_framebuffer
*framebuffer
;
2827 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2829 framebuffer
= anv_device_alloc(device
, sizeof(*framebuffer
), 8,
2830 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2831 if (framebuffer
== NULL
)
2832 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2834 framebuffer
->color_attachment_count
= pCreateInfo
->colorAttachmentCount
;
2835 for (uint32_t i
= 0; i
< pCreateInfo
->colorAttachmentCount
; i
++) {
2836 framebuffer
->color_attachments
[i
] =
2837 (struct anv_surface_view
*) pCreateInfo
->pColorAttachments
[i
].view
;
2840 if (pCreateInfo
->pDepthStencilAttachment
) {
2841 framebuffer
->depth_stencil
=
2842 (struct anv_depth_stencil_view
*) pCreateInfo
->pDepthStencilAttachment
->view
;
2845 framebuffer
->sample_count
= pCreateInfo
->sampleCount
;
2846 framebuffer
->width
= pCreateInfo
->width
;
2847 framebuffer
->height
= pCreateInfo
->height
;
2848 framebuffer
->layers
= pCreateInfo
->layers
;
2850 vkCreateDynamicViewportState((VkDevice
) device
,
2851 &(VkDynamicVpStateCreateInfo
) {
2852 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
,
2853 .viewportAndScissorCount
= 2,
2854 .pViewports
= (VkViewport
[]) {
2858 .width
= pCreateInfo
->width
,
2859 .height
= pCreateInfo
->height
,
2864 .pScissors
= (VkRect
[]) {
2866 { pCreateInfo
->width
, pCreateInfo
->height
} },
2869 &framebuffer
->vp_state
);
2871 *pFramebuffer
= (VkFramebuffer
) framebuffer
;
2876 VkResult
anv_CreateRenderPass(
2878 const VkRenderPassCreateInfo
* pCreateInfo
,
2879 VkRenderPass
* pRenderPass
)
2881 struct anv_device
*device
= (struct anv_device
*) _device
;
2882 struct anv_render_pass
*pass
;
2885 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
2887 size
= sizeof(*pass
) +
2888 pCreateInfo
->layers
* sizeof(struct anv_render_pass_layer
);
2889 pass
= anv_device_alloc(device
, size
, 8,
2890 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2892 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2894 pass
->render_area
= pCreateInfo
->renderArea
;
2896 pass
->num_layers
= pCreateInfo
->layers
;
2898 pass
->num_clear_layers
= 0;
2899 for (uint32_t i
= 0; i
< pCreateInfo
->layers
; i
++) {
2900 pass
->layers
[i
].color_load_op
= pCreateInfo
->pColorLoadOps
[i
];
2901 pass
->layers
[i
].clear_color
= pCreateInfo
->pColorLoadClearValues
[i
];
2902 if (pass
->layers
[i
].color_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
)
2903 pass
->num_clear_layers
++;
2906 *pRenderPass
= (VkRenderPass
) pass
;
2912 anv_cmd_buffer_fill_render_targets(struct anv_cmd_buffer
*cmd_buffer
)
2914 struct anv_framebuffer
*framebuffer
= cmd_buffer
->framebuffer
;
2915 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2917 for (uint32_t i
= 0; i
< framebuffer
->color_attachment_count
; i
++) {
2918 struct anv_surface_view
*view
= framebuffer
->color_attachments
[i
];
2920 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].surfaces
[i
] = view
->surface_state
.offset
;
2921 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].relocs
[i
].bo
= view
->bo
;
2922 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].relocs
[i
].offset
= view
->offset
;
2924 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
2927 void anv_CmdBeginRenderPass(
2928 VkCmdBuffer cmdBuffer
,
2929 const VkRenderPassBegin
* pRenderPassBegin
)
2931 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2932 struct anv_render_pass
*pass
= (struct anv_render_pass
*) pRenderPassBegin
->renderPass
;
2933 struct anv_framebuffer
*framebuffer
=
2934 (struct anv_framebuffer
*) pRenderPassBegin
->framebuffer
;
2936 cmd_buffer
->framebuffer
= framebuffer
;
2938 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DRAWING_RECTANGLE
,
2939 .ClippedDrawingRectangleYMin
= pass
->render_area
.offset
.y
,
2940 .ClippedDrawingRectangleXMin
= pass
->render_area
.offset
.x
,
2941 .ClippedDrawingRectangleYMax
=
2942 pass
->render_area
.offset
.y
+ pass
->render_area
.extent
.height
- 1,
2943 .ClippedDrawingRectangleXMax
=
2944 pass
->render_area
.offset
.x
+ pass
->render_area
.extent
.width
- 1,
2945 .DrawingRectangleOriginY
= 0,
2946 .DrawingRectangleOriginX
= 0);
2948 anv_cmd_buffer_fill_render_targets(cmd_buffer
);
2950 anv_cmd_buffer_clear(cmd_buffer
, pass
);
2953 void anv_CmdEndRenderPass(
2954 VkCmdBuffer cmdBuffer
,
2955 VkRenderPass renderPass
)
2957 /* Emit a flushing pipe control at the end of a pass. This is kind of a
2958 * hack but it ensures that render targets always actually get written.
2959 * Eventually, we should do flushing based on image format transitions
2960 * or something of that nature.
2962 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
2963 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
2964 .PostSyncOperation
= NoWrite
,
2965 .RenderTargetCacheFlushEnable
= true,
2966 .InstructionCacheInvalidateEnable
= true,
2967 .DepthCacheFlushEnable
= true,
2968 .VFCacheInvalidationEnable
= true,
2969 .TextureCacheInvalidationEnable
= true,
2970 .CommandStreamerStallEnable
= true);