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
:
193 assert(*pDataSize
>= sizeof(*properties
));
194 *pDataSize
= sizeof(*properties
); /* Assuming we have to return the size of our struct. */
196 properties
->apiVersion
= 1;
197 properties
->driverVersion
= 1;
198 properties
->vendorId
= 0x8086;
199 properties
->deviceId
= device
->chipset_id
;
200 properties
->deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
;
201 strcpy(properties
->deviceName
, device
->name
);
202 properties
->maxInlineMemoryUpdateSize
= 0;
203 properties
->maxBoundDescriptorSets
= 0;
204 properties
->maxThreadGroupSize
= 0;
205 properties
->timestampFrequency
= 1000 * 1000 * 1000 / ns_per_tick
;
206 properties
->multiColorAttachmentClears
= 0;
207 properties
->maxDescriptorSets
= 2;
208 properties
->maxViewports
= 16;
209 properties
->maxColorAttachments
= 8;
212 case VK_PHYSICAL_DEVICE_INFO_TYPE_PERFORMANCE
:
214 assert(*pDataSize
>= sizeof(*performance
));
215 *pDataSize
= sizeof(*performance
); /* Assuming we have to return the size of our struct. */
217 performance
->maxDeviceClock
= 1.0;
218 performance
->aluPerClock
= 1.0;
219 performance
->texPerClock
= 1.0;
220 performance
->primsPerClock
= 1.0;
221 performance
->pixelsPerClock
= 1.0;
224 case VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES
:
225 queue_properties
= pData
;
226 assert(*pDataSize
>= sizeof(*queue_properties
));
227 *pDataSize
= sizeof(*queue_properties
);
229 queue_properties
->queueFlags
= 0;
230 queue_properties
->queueCount
= 1;
231 queue_properties
->maxAtomicCounters
= 0;
232 queue_properties
->supportsTimestamps
= 0;
233 queue_properties
->maxMemReferences
= 0;
236 case VK_PHYSICAL_DEVICE_INFO_TYPE_MEMORY_PROPERTIES
:
237 memory_properties
= pData
;
238 assert(*pDataSize
>= sizeof(*memory_properties
));
239 *pDataSize
= sizeof(*memory_properties
);
241 memory_properties
->supportsMigration
= false;
242 memory_properties
->supportsPinning
= false;
246 return VK_UNSUPPORTED
;
251 void * vkGetProcAddr(
252 VkPhysicalDevice physicalDevice
,
255 return anv_lookup_entrypoint(pName
);
259 parse_debug_flags(struct anv_device
*device
)
261 const char *debug
, *p
, *end
;
263 debug
= getenv("INTEL_DEBUG");
264 device
->dump_aub
= false;
266 for (p
= debug
; *p
; p
= end
+ 1) {
267 end
= strchrnul(p
, ',');
268 if (end
- p
== 3 && memcmp(p
, "aub", 3) == 0)
269 device
->dump_aub
= true;
270 if (end
- p
== 5 && memcmp(p
, "no_hw", 5) == 0)
271 device
->no_hw
= true;
278 VkResult
anv_CreateDevice(
279 VkPhysicalDevice _physicalDevice
,
280 const VkDeviceCreateInfo
* pCreateInfo
,
283 struct anv_physical_device
*physicalDevice
=
284 (struct anv_physical_device
*) _physicalDevice
;
285 struct anv_instance
*instance
= physicalDevice
->instance
;
286 struct anv_device
*device
;
288 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
290 device
= instance
->pfnAlloc(instance
->pAllocUserData
,
292 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
294 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
296 device
->no_hw
= physicalDevice
->no_hw
;
297 parse_debug_flags(device
);
299 device
->instance
= physicalDevice
->instance
;
300 device
->fd
= open("/dev/dri/renderD128", O_RDWR
| O_CLOEXEC
);
301 if (device
->fd
== -1)
304 device
->context_id
= anv_gem_create_context(device
);
305 if (device
->context_id
== -1)
308 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 2048);
310 anv_state_pool_init(&device
->dynamic_state_pool
,
311 &device
->dynamic_state_block_pool
);
313 anv_block_pool_init(&device
->instruction_block_pool
, device
, 2048);
314 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 2048);
316 anv_state_pool_init(&device
->surface_state_pool
,
317 &device
->surface_state_block_pool
);
319 device
->compiler
= anv_compiler_create(device
->fd
);
320 device
->aub_writer
= NULL
;
322 device
->info
= *physicalDevice
->info
;
324 pthread_mutex_init(&device
->mutex
, NULL
);
326 anv_device_init_meta(device
);
328 *pDevice
= (VkDevice
) device
;
335 anv_device_free(device
, device
);
337 return vk_error(VK_ERROR_UNAVAILABLE
);
340 VkResult
anv_DestroyDevice(
343 struct anv_device
*device
= (struct anv_device
*) _device
;
345 anv_compiler_destroy(device
->compiler
);
347 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
348 anv_block_pool_finish(&device
->instruction_block_pool
);
349 anv_block_pool_finish(&device
->surface_state_block_pool
);
353 if (device
->aub_writer
)
354 anv_aub_writer_destroy(device
->aub_writer
);
356 anv_device_free(device
, device
);
361 VkResult
anv_GetGlobalExtensionInfo(
362 VkExtensionInfoType infoType
,
363 uint32_t extensionIndex
,
370 case VK_EXTENSION_INFO_TYPE_COUNT
:
372 assert(*pDataSize
== 4);
376 case VK_EXTENSION_INFO_TYPE_PROPERTIES
:
377 return vk_error(VK_ERROR_INVALID_EXTENSION
);
380 return VK_UNSUPPORTED
;
384 VkResult
anv_GetPhysicalDeviceExtensionInfo(
385 VkPhysicalDevice physicalDevice
,
386 VkExtensionInfoType infoType
,
387 uint32_t extensionIndex
,
394 case VK_EXTENSION_INFO_TYPE_COUNT
:
396 assert(*pDataSize
== 4);
400 case VK_EXTENSION_INFO_TYPE_PROPERTIES
:
401 return vk_error(VK_ERROR_INVALID_EXTENSION
);
404 return VK_UNSUPPORTED
;
408 VkResult
anv_EnumerateLayers(
409 VkPhysicalDevice physicalDevice
,
410 size_t maxStringSize
,
412 char* const* pOutLayers
,
420 VkResult
anv_GetDeviceQueue(
422 uint32_t queueNodeIndex
,
426 struct anv_device
*device
= (struct anv_device
*) _device
;
427 struct anv_queue
*queue
;
429 /* FIXME: Should allocate these at device create time. */
431 queue
= anv_device_alloc(device
, sizeof(*queue
), 8,
432 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
434 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
436 queue
->device
= device
;
437 queue
->pool
= &device
->surface_state_pool
;
439 queue
->completed_serial
= anv_state_pool_alloc(queue
->pool
, 4, 4);
440 *(uint32_t *)queue
->completed_serial
.map
= 0;
441 queue
->next_serial
= 1;
443 *pQueue
= (VkQueue
) queue
;
448 static const uint32_t BATCH_SIZE
= 8192;
451 anv_batch_init(struct anv_batch
*batch
, struct anv_device
*device
)
455 result
= anv_bo_init_new(&batch
->bo
, device
, BATCH_SIZE
);
456 if (result
!= VK_SUCCESS
)
460 anv_gem_mmap(device
, batch
->bo
.gem_handle
, 0, BATCH_SIZE
);
461 if (batch
->bo
.map
== NULL
) {
462 anv_gem_close(device
, batch
->bo
.gem_handle
);
463 return vk_error(VK_ERROR_MEMORY_MAP_FAILED
);
466 batch
->cmd_relocs
.num_relocs
= 0;
467 batch
->surf_relocs
.num_relocs
= 0;
468 batch
->next
= batch
->bo
.map
;
474 anv_batch_finish(struct anv_batch
*batch
, struct anv_device
*device
)
476 anv_gem_munmap(batch
->bo
.map
, BATCH_SIZE
);
477 anv_gem_close(device
, batch
->bo
.gem_handle
);
481 anv_batch_reset(struct anv_batch
*batch
)
483 batch
->next
= batch
->bo
.map
;
484 batch
->cmd_relocs
.num_relocs
= 0;
485 batch
->surf_relocs
.num_relocs
= 0;
489 anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
)
491 void *p
= batch
->next
;
493 batch
->next
+= num_dwords
* 4;
499 anv_reloc_list_append(struct anv_reloc_list
*list
,
500 struct anv_reloc_list
*other
, uint32_t offset
)
504 count
= list
->num_relocs
;
505 memcpy(&list
->relocs
[count
], &other
->relocs
[0],
506 other
->num_relocs
* sizeof(other
->relocs
[0]));
507 memcpy(&list
->reloc_bos
[count
], &other
->reloc_bos
[0],
508 other
->num_relocs
* sizeof(other
->reloc_bos
[0]));
509 for (i
= 0; i
< other
->num_relocs
; i
++)
510 list
->relocs
[i
+ count
].offset
+= offset
;
512 count
+= other
->num_relocs
;
516 anv_reloc_list_add(struct anv_reloc_list
*list
,
518 struct anv_bo
*target_bo
, uint32_t delta
)
520 struct drm_i915_gem_relocation_entry
*entry
;
523 assert(list
->num_relocs
< ANV_BATCH_MAX_RELOCS
);
525 /* XXX: Can we use I915_EXEC_HANDLE_LUT? */
526 index
= list
->num_relocs
++;
527 list
->reloc_bos
[index
] = target_bo
;
528 entry
= &list
->relocs
[index
];
529 entry
->target_handle
= target_bo
->gem_handle
;
530 entry
->delta
= delta
;
531 entry
->offset
= offset
;
532 entry
->presumed_offset
= target_bo
->offset
;
533 entry
->read_domains
= 0;
534 entry
->write_domain
= 0;
536 return target_bo
->offset
+ delta
;
540 anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
)
542 uint32_t size
, offset
;
544 size
= other
->next
- other
->bo
.map
;
545 memcpy(batch
->next
, other
->bo
.map
, size
);
547 offset
= batch
->next
- batch
->bo
.map
;
548 anv_reloc_list_append(&batch
->cmd_relocs
, &other
->cmd_relocs
, offset
);
549 anv_reloc_list_append(&batch
->surf_relocs
, &other
->surf_relocs
, offset
);
555 anv_batch_emit_reloc(struct anv_batch
*batch
,
556 void *location
, struct anv_bo
*bo
, uint32_t delta
)
558 return anv_reloc_list_add(&batch
->cmd_relocs
,
559 location
- batch
->bo
.map
, bo
, delta
);
562 VkResult
anv_QueueSubmit(
564 uint32_t cmdBufferCount
,
565 const VkCmdBuffer
* pCmdBuffers
,
568 struct anv_queue
*queue
= (struct anv_queue
*) _queue
;
569 struct anv_device
*device
= queue
->device
;
572 for (uint32_t i
= 0; i
< cmdBufferCount
; i
++) {
573 struct anv_cmd_buffer
*cmd_buffer
=
574 (struct anv_cmd_buffer
*) pCmdBuffers
[i
];
576 if (device
->dump_aub
)
577 anv_cmd_buffer_dump(cmd_buffer
);
579 if (!device
->no_hw
) {
580 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf
);
582 return vk_error(VK_ERROR_UNKNOWN
);
584 for (uint32_t i
= 0; i
< cmd_buffer
->bo_count
; i
++)
585 cmd_buffer
->exec2_bos
[i
]->offset
= cmd_buffer
->exec2_objects
[i
].offset
;
587 *(uint32_t *)queue
->completed_serial
.map
= cmd_buffer
->serial
;
594 VkResult
anv_QueueAddMemReferences(
597 const VkDeviceMemory
* pMems
)
602 VkResult
anv_QueueRemoveMemReferences(
605 const VkDeviceMemory
* pMems
)
610 VkResult
anv_QueueWaitIdle(
613 struct anv_queue
*queue
= (struct anv_queue
*) _queue
;
615 return vkDeviceWaitIdle((VkDevice
) queue
->device
);
618 VkResult
anv_DeviceWaitIdle(
621 struct anv_device
*device
= (struct anv_device
*) _device
;
622 struct anv_state state
;
623 struct anv_batch batch
;
624 struct drm_i915_gem_execbuffer2 execbuf
;
625 struct drm_i915_gem_exec_object2 exec2_objects
[1];
626 struct anv_bo
*bo
= NULL
;
631 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, 32, 32);
632 bo
= &device
->dynamic_state_pool
.block_pool
->bo
;
633 batch
.next
= state
.map
;
634 anv_batch_emit(&batch
, GEN8_MI_BATCH_BUFFER_END
);
635 anv_batch_emit(&batch
, GEN8_MI_NOOP
);
637 exec2_objects
[0].handle
= bo
->gem_handle
;
638 exec2_objects
[0].relocation_count
= 0;
639 exec2_objects
[0].relocs_ptr
= 0;
640 exec2_objects
[0].alignment
= 0;
641 exec2_objects
[0].offset
= bo
->offset
;
642 exec2_objects
[0].flags
= 0;
643 exec2_objects
[0].rsvd1
= 0;
644 exec2_objects
[0].rsvd2
= 0;
646 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
647 execbuf
.buffer_count
= 1;
648 execbuf
.batch_start_offset
= state
.offset
;
649 execbuf
.batch_len
= batch
.next
- state
.map
;
650 execbuf
.cliprects_ptr
= 0;
651 execbuf
.num_cliprects
= 0;
656 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
657 execbuf
.rsvd1
= device
->context_id
;
660 if (!device
->no_hw
) {
661 ret
= anv_gem_execbuffer(device
, &execbuf
);
663 result
= vk_error(VK_ERROR_UNKNOWN
);
668 ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
670 result
= vk_error(VK_ERROR_UNKNOWN
);
675 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
680 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
686 anv_device_alloc(struct anv_device
* device
,
689 VkSystemAllocType allocType
)
691 return device
->instance
->pfnAlloc(device
->instance
->pAllocUserData
,
698 anv_device_free(struct anv_device
* device
,
701 return device
->instance
->pfnFree(device
->instance
->pAllocUserData
,
706 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
708 bo
->gem_handle
= anv_gem_create(device
, size
);
710 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
720 VkResult
anv_AllocMemory(
722 const VkMemoryAllocInfo
* pAllocInfo
,
723 VkDeviceMemory
* pMem
)
725 struct anv_device
*device
= (struct anv_device
*) _device
;
726 struct anv_device_memory
*mem
;
729 assert(pAllocInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO
);
731 mem
= anv_device_alloc(device
, sizeof(*mem
), 8,
732 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
734 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
736 result
= anv_bo_init_new(&mem
->bo
, device
, pAllocInfo
->allocationSize
);
737 if (result
!= VK_SUCCESS
)
740 *pMem
= (VkDeviceMemory
) mem
;
745 anv_device_free(device
, mem
);
750 VkResult
anv_FreeMemory(
754 struct anv_device
*device
= (struct anv_device
*) _device
;
755 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
758 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
760 if (mem
->bo
.gem_handle
!= 0)
761 anv_gem_close(device
, mem
->bo
.gem_handle
);
763 anv_device_free(device
, mem
);
768 VkResult
anv_SetMemoryPriority(
771 VkMemoryPriority priority
)
776 VkResult
anv_MapMemory(
781 VkMemoryMapFlags flags
,
784 struct anv_device
*device
= (struct anv_device
*) _device
;
785 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
787 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
788 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
789 * at a time is valid. We could just mmap up front and return an offset
790 * pointer here, but that may exhaust virtual memory on 32 bit
793 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
, offset
, size
);
794 mem
->map_size
= size
;
801 VkResult
anv_UnmapMemory(
805 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
807 anv_gem_munmap(mem
->map
, mem
->map_size
);
812 VkResult
anv_FlushMappedMemory(
818 /* clflush here for !llc platforms */
823 VkResult
anv_PinSystemMemory(
827 VkDeviceMemory
* pMem
)
832 VkResult
anv_GetMultiDeviceCompatibility(
833 VkPhysicalDevice physicalDevice0
,
834 VkPhysicalDevice physicalDevice1
,
835 VkPhysicalDeviceCompatibilityInfo
* pInfo
)
837 return VK_UNSUPPORTED
;
840 VkResult
anv_OpenSharedMemory(
842 const VkMemoryOpenInfo
* pOpenInfo
,
843 VkDeviceMemory
* pMem
)
845 return VK_UNSUPPORTED
;
848 VkResult
anv_OpenSharedSemaphore(
850 const VkSemaphoreOpenInfo
* pOpenInfo
,
851 VkSemaphore
* pSemaphore
)
853 return VK_UNSUPPORTED
;
856 VkResult
anv_OpenPeerMemory(
858 const VkPeerMemoryOpenInfo
* pOpenInfo
,
859 VkDeviceMemory
* pMem
)
861 return VK_UNSUPPORTED
;
864 VkResult
anv_OpenPeerImage(
866 const VkPeerImageOpenInfo
* pOpenInfo
,
868 VkDeviceMemory
* pMem
)
870 return VK_UNSUPPORTED
;
874 anv_instance_destructor(struct anv_device
* device
,
877 return vkDestroyInstance(object
);
881 anv_noop_destructor(struct anv_device
* device
,
888 anv_device_destructor(struct anv_device
* device
,
891 return vkDestroyDevice(object
);
895 anv_cmd_buffer_destructor(struct anv_device
* device
,
898 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) object
;
900 anv_state_stream_finish(&cmd_buffer
->surface_state_stream
);
901 anv_state_stream_finish(&cmd_buffer
->dynamic_state_stream
);
902 anv_batch_finish(&cmd_buffer
->batch
, device
);
903 anv_device_free(device
, cmd_buffer
->exec2_objects
);
904 anv_device_free(device
, cmd_buffer
->exec2_bos
);
905 anv_device_free(device
, cmd_buffer
);
911 anv_pipeline_destructor(struct anv_device
* device
,
914 struct anv_pipeline
*pipeline
= (struct anv_pipeline
*) object
;
916 return anv_pipeline_destroy(pipeline
);
920 anv_free_destructor(struct anv_device
* device
,
923 anv_device_free(device
, (void *) object
);
928 static VkResult (*anv_object_destructors
[])(struct anv_device
*device
,
930 [VK_OBJECT_TYPE_INSTANCE
] = anv_instance_destructor
,
931 [VK_OBJECT_TYPE_PHYSICAL_DEVICE
] = anv_noop_destructor
,
932 [VK_OBJECT_TYPE_DEVICE
] = anv_device_destructor
,
933 [VK_OBJECT_TYPE_QUEUE
] = anv_noop_destructor
,
934 [VK_OBJECT_TYPE_COMMAND_BUFFER
] = anv_cmd_buffer_destructor
,
935 [VK_OBJECT_TYPE_PIPELINE
] = anv_pipeline_destructor
,
936 [VK_OBJECT_TYPE_SHADER
] = anv_free_destructor
,
937 [VK_OBJECT_TYPE_BUFFER
] = anv_free_destructor
,
938 [VK_OBJECT_TYPE_IMAGE
] = anv_free_destructor
,
939 [VK_OBJECT_TYPE_RENDER_PASS
] = anv_free_destructor
942 VkResult
anv_DestroyObject(
944 VkObjectType objType
,
947 struct anv_device
*device
= (struct anv_device
*) _device
;
949 assert(objType
< ARRAY_SIZE(anv_object_destructors
) &&
950 anv_object_destructors
[objType
] != NULL
);
952 return anv_object_destructors
[objType
](device
, object
);
956 fill_memory_requirements(
957 VkObjectType objType
,
959 VkMemoryRequirements
* memory_requirements
)
961 struct anv_buffer
*buffer
;
962 struct anv_image
*image
;
964 memory_requirements
->memPropsAllowed
=
965 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
966 VK_MEMORY_PROPERTY_HOST_DEVICE_COHERENT_BIT
|
967 /* VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT | */
968 VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT
|
969 VK_MEMORY_PROPERTY_PREFER_HOST_LOCAL
|
970 VK_MEMORY_PROPERTY_SHAREABLE_BIT
;
972 memory_requirements
->memPropsRequired
= 0;
975 case VK_OBJECT_TYPE_BUFFER
:
976 buffer
= (struct anv_buffer
*) object
;
977 memory_requirements
->size
= buffer
->size
;
978 memory_requirements
->alignment
= 16;
980 case VK_OBJECT_TYPE_IMAGE
:
981 image
= (struct anv_image
*) object
;
982 memory_requirements
->size
= image
->size
;
983 memory_requirements
->alignment
= image
->alignment
;
986 memory_requirements
->size
= 0;
991 VkResult
anv_GetObjectInfo(
993 VkObjectType objType
,
995 VkObjectInfoType infoType
,
999 VkMemoryRequirements memory_requirements
;
1002 case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS
:
1003 fill_memory_requirements(objType
, object
, &memory_requirements
);
1004 memcpy(pData
, &memory_requirements
,
1005 MIN2(*pDataSize
, sizeof(memory_requirements
)));
1006 *pDataSize
= sizeof(memory_requirements
);
1009 case VK_OBJECT_INFO_TYPE_MEMORY_ALLOCATION_COUNT
:
1011 return VK_UNSUPPORTED
;
1016 VkResult
anv_QueueBindObjectMemory(
1018 VkObjectType objType
,
1020 uint32_t allocationIdx
,
1021 VkDeviceMemory _mem
,
1022 VkDeviceSize memOffset
)
1024 struct anv_buffer
*buffer
;
1025 struct anv_image
*image
;
1026 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
1029 case VK_OBJECT_TYPE_BUFFER
:
1030 buffer
= (struct anv_buffer
*) object
;
1031 buffer
->bo
= &mem
->bo
;
1032 buffer
->offset
= memOffset
;
1034 case VK_OBJECT_TYPE_IMAGE
:
1035 image
= (struct anv_image
*) object
;
1036 image
->bo
= &mem
->bo
;
1037 image
->offset
= memOffset
;
1046 VkResult
anv_QueueBindObjectMemoryRange(
1048 VkObjectType objType
,
1050 uint32_t allocationIdx
,
1051 VkDeviceSize rangeOffset
,
1052 VkDeviceSize rangeSize
,
1054 VkDeviceSize memOffset
)
1056 stub_return(VK_UNSUPPORTED
);
1059 VkResult
anv_QueueBindImageMemoryRange(
1062 uint32_t allocationIdx
,
1063 const VkImageMemoryBindInfo
* pBindInfo
,
1065 VkDeviceSize memOffset
)
1067 stub_return(VK_UNSUPPORTED
);
1070 VkResult
anv_CreateFence(
1072 const VkFenceCreateInfo
* pCreateInfo
,
1075 stub_return(VK_UNSUPPORTED
);
1078 VkResult
anv_ResetFences(
1080 uint32_t fenceCount
,
1083 stub_return(VK_UNSUPPORTED
);
1086 VkResult
anv_GetFenceStatus(
1090 stub_return(VK_UNSUPPORTED
);
1093 VkResult
anv_WaitForFences(
1095 uint32_t fenceCount
,
1096 const VkFence
* pFences
,
1100 stub_return(VK_UNSUPPORTED
);
1103 // Queue semaphore functions
1105 VkResult
anv_CreateSemaphore(
1107 const VkSemaphoreCreateInfo
* pCreateInfo
,
1108 VkSemaphore
* pSemaphore
)
1110 stub_return(VK_UNSUPPORTED
);
1113 VkResult
anv_QueueSignalSemaphore(
1115 VkSemaphore semaphore
)
1117 stub_return(VK_UNSUPPORTED
);
1120 VkResult
anv_QueueWaitSemaphore(
1122 VkSemaphore semaphore
)
1124 stub_return(VK_UNSUPPORTED
);
1129 VkResult
anv_CreateEvent(
1131 const VkEventCreateInfo
* pCreateInfo
,
1134 stub_return(VK_UNSUPPORTED
);
1137 VkResult
anv_GetEventStatus(
1141 stub_return(VK_UNSUPPORTED
);
1144 VkResult
anv_SetEvent(
1148 stub_return(VK_UNSUPPORTED
);
1151 VkResult
anv_ResetEvent(
1155 stub_return(VK_UNSUPPORTED
);
1160 struct anv_query_pool
{
1166 VkResult
anv_CreateQueryPool(
1168 const VkQueryPoolCreateInfo
* pCreateInfo
,
1169 VkQueryPool
* pQueryPool
)
1171 struct anv_device
*device
= (struct anv_device
*) _device
;
1172 struct anv_query_pool
*pool
;
1175 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO
);
1177 pool
= anv_device_alloc(device
, sizeof(*pool
), 8,
1178 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1180 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1182 pool
->type
= pCreateInfo
->queryType
;
1183 result
= anv_bo_init_new(&pool
->bo
, device
, pCreateInfo
->slots
* 16);
1184 if (result
!= VK_SUCCESS
)
1187 *pQueryPool
= (VkQueryPool
) pool
;
1192 anv_device_free(device
, pool
);
1197 VkResult
anv_GetQueryPoolResults(
1199 VkQueryPool queryPool
,
1200 uint32_t startQuery
,
1201 uint32_t queryCount
,
1204 VkQueryResultFlags flags
)
1206 stub_return(VK_UNSUPPORTED
);
1211 VkResult
anv_CreateBuffer(
1213 const VkBufferCreateInfo
* pCreateInfo
,
1216 struct anv_device
*device
= (struct anv_device
*) _device
;
1217 struct anv_buffer
*buffer
;
1219 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1221 buffer
= anv_device_alloc(device
, sizeof(*buffer
), 8,
1222 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1224 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1226 buffer
->size
= pCreateInfo
->size
;
1230 *pBuffer
= (VkBuffer
) buffer
;
1235 // Buffer view functions
1237 VkResult
anv_CreateBufferView(
1239 const VkBufferViewCreateInfo
* pCreateInfo
,
1240 VkBufferView
* pView
)
1242 struct anv_device
*device
= (struct anv_device
*) _device
;
1243 struct anv_buffer
*buffer
= (struct anv_buffer
*) pCreateInfo
->buffer
;
1244 struct anv_surface_view
*view
;
1245 const struct anv_format
*format
;
1247 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO
);
1249 view
= anv_device_alloc(device
, sizeof(*view
), 8,
1250 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1252 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1254 view
->bo
= buffer
->bo
;
1255 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
1256 view
->surface_state
=
1257 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
1258 view
->format
= pCreateInfo
->format
;
1260 format
= anv_format_for_vk_format(pCreateInfo
->format
);
1261 /* This assumes RGBA float format. */
1262 uint32_t stride
= 4;
1263 uint32_t num_elements
= pCreateInfo
->range
/ stride
;
1264 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
1265 .SurfaceType
= SURFTYPE_BUFFER
,
1266 .SurfaceArray
= false,
1267 .SurfaceFormat
= format
->format
,
1268 .SurfaceVerticalAlignment
= VALIGN4
,
1269 .SurfaceHorizontalAlignment
= HALIGN4
,
1271 .VerticalLineStride
= 0,
1272 .VerticalLineStrideOffset
= 0,
1273 .SamplerL2BypassModeDisable
= true,
1274 .RenderCacheReadWriteMode
= WriteOnlyCache
,
1275 .MemoryObjectControlState
= 0, /* FIXME: MOCS */
1278 .Height
= (num_elements
>> 7) & 0x3fff,
1279 .Width
= num_elements
& 0x7f,
1280 .Depth
= (num_elements
>> 21) & 0x3f,
1281 .SurfacePitch
= stride
- 1,
1282 .MinimumArrayElement
= 0,
1283 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
1288 .AuxiliarySurfaceMode
= AUX_NONE
,
1290 .GreenClearColor
= 0,
1291 .BlueClearColor
= 0,
1292 .AlphaClearColor
= 0,
1293 .ShaderChannelSelectRed
= SCS_RED
,
1294 .ShaderChannelSelectGreen
= SCS_GREEN
,
1295 .ShaderChannelSelectBlue
= SCS_BLUE
,
1296 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
1297 .ResourceMinLOD
= 0,
1298 /* FIXME: We assume that the image must be bound at this time. */
1299 .SurfaceBaseAddress
= { NULL
, view
->offset
},
1302 GEN8_RENDER_SURFACE_STATE_pack(NULL
, view
->surface_state
.map
, &surface_state
);
1304 *pView
= (VkImageView
) view
;
1309 // Sampler functions
1311 VkResult
anv_CreateSampler(
1313 const VkSamplerCreateInfo
* pCreateInfo
,
1314 VkSampler
* pSampler
)
1316 struct anv_device
*device
= (struct anv_device
*) _device
;
1317 struct anv_sampler
*sampler
;
1319 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
1321 sampler
= anv_device_alloc(device
, sizeof(*sampler
), 8,
1322 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1324 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1326 static const uint32_t vk_to_gen_tex_filter
[] = {
1327 [VK_TEX_FILTER_NEAREST
] = MAPFILTER_NEAREST
,
1328 [VK_TEX_FILTER_LINEAR
] = MAPFILTER_LINEAR
1331 static const uint32_t vk_to_gen_mipmap_mode
[] = {
1332 [VK_TEX_MIPMAP_MODE_BASE
] = MIPFILTER_NONE
,
1333 [VK_TEX_MIPMAP_MODE_NEAREST
] = MIPFILTER_NEAREST
,
1334 [VK_TEX_MIPMAP_MODE_LINEAR
] = MIPFILTER_LINEAR
1337 static const uint32_t vk_to_gen_tex_address
[] = {
1338 [VK_TEX_ADDRESS_WRAP
] = TCM_WRAP
,
1339 [VK_TEX_ADDRESS_MIRROR
] = TCM_MIRROR
,
1340 [VK_TEX_ADDRESS_CLAMP
] = TCM_CLAMP
,
1341 [VK_TEX_ADDRESS_MIRROR_ONCE
] = TCM_MIRROR_ONCE
,
1342 [VK_TEX_ADDRESS_CLAMP_BORDER
] = TCM_CLAMP_BORDER
,
1345 static const uint32_t vk_to_gen_compare_op
[] = {
1346 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
1347 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
1348 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
1349 [VK_COMPARE_OP_LESS_EQUAL
] = PREFILTEROPLEQUAL
,
1350 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
1351 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
1352 [VK_COMPARE_OP_GREATER_EQUAL
] = PREFILTEROPGEQUAL
,
1353 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,
1356 if (pCreateInfo
->maxAnisotropy
> 0)
1357 anv_finishme("missing support for anisotropic filtering");
1359 struct GEN8_SAMPLER_STATE sampler_state
= {
1360 .SamplerDisable
= false,
1361 .TextureBorderColorMode
= DX10OGL
,
1362 .LODPreClampMode
= 0,
1364 .MipModeFilter
= vk_to_gen_mipmap_mode
[pCreateInfo
->mipMode
],
1365 .MagModeFilter
= vk_to_gen_tex_filter
[pCreateInfo
->magFilter
],
1366 .MinModeFilter
= vk_to_gen_tex_filter
[pCreateInfo
->minFilter
],
1367 .TextureLODBias
= pCreateInfo
->mipLodBias
* 256,
1368 .AnisotropicAlgorithm
= EWAApproximation
,
1369 .MinLOD
= pCreateInfo
->minLod
* 256,
1370 .MaxLOD
= pCreateInfo
->maxLod
* 256,
1371 .ChromaKeyEnable
= 0,
1372 .ChromaKeyIndex
= 0,
1374 .ShadowFunction
= vk_to_gen_compare_op
[pCreateInfo
->compareOp
],
1375 .CubeSurfaceControlMode
= 0,
1376 .IndirectStatePointer
= 0,
1377 .LODClampMagnificationMode
= MIPNONE
,
1378 .MaximumAnisotropy
= 0,
1379 .RAddressMinFilterRoundingEnable
= 0,
1380 .RAddressMagFilterRoundingEnable
= 0,
1381 .VAddressMinFilterRoundingEnable
= 0,
1382 .VAddressMagFilterRoundingEnable
= 0,
1383 .UAddressMinFilterRoundingEnable
= 0,
1384 .UAddressMagFilterRoundingEnable
= 0,
1385 .TrilinearFilterQuality
= 0,
1386 .NonnormalizedCoordinateEnable
= 0,
1387 .TCXAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressU
],
1388 .TCYAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressV
],
1389 .TCZAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressW
],
1392 GEN8_SAMPLER_STATE_pack(NULL
, sampler
->state
, &sampler_state
);
1394 *pSampler
= (VkSampler
) sampler
;
1399 // Descriptor set functions
1401 VkResult
anv_CreateDescriptorSetLayout(
1403 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
1404 VkDescriptorSetLayout
* pSetLayout
)
1406 struct anv_device
*device
= (struct anv_device
*) _device
;
1407 struct anv_descriptor_set_layout
*set_layout
;
1409 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
1411 uint32_t sampler_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1412 uint32_t surface_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1413 uint32_t num_dynamic_buffers
= 0;
1417 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1418 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1419 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1420 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1421 sampler_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1424 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1425 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1426 sampler_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1430 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1431 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1432 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1433 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1434 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1435 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1436 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1437 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1438 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1439 surface_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1445 count
+= pCreateInfo
->pBinding
[i
].count
;
1448 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1449 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1450 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1451 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1452 num_dynamic_buffers
++;
1459 uint32_t sampler_total
= 0;
1460 uint32_t surface_total
= 0;
1461 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1462 sampler_total
+= sampler_count
[s
];
1463 surface_total
+= surface_count
[s
];
1466 size_t size
= sizeof(*set_layout
) +
1467 (sampler_total
+ surface_total
) * sizeof(uint32_t);
1468 set_layout
= anv_device_alloc(device
, size
, 8,
1469 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1471 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1473 set_layout
->num_dynamic_buffers
= num_dynamic_buffers
;
1474 set_layout
->count
= count
;
1476 uint32_t *p
= set_layout
->entries
;
1477 uint32_t *sampler
[VK_NUM_SHADER_STAGE
];
1478 uint32_t *surface
[VK_NUM_SHADER_STAGE
];
1479 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1480 set_layout
->stage
[s
].surface_count
= surface_count
[s
];
1481 set_layout
->stage
[s
].surface_start
= surface
[s
] = p
;
1482 p
+= surface_count
[s
];
1483 set_layout
->stage
[s
].sampler_count
= sampler_count
[s
];
1484 set_layout
->stage
[s
].sampler_start
= sampler
[s
] = p
;
1485 p
+= sampler_count
[s
];
1488 uint32_t descriptor
= 0;
1489 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1490 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1491 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1492 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1493 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++)
1494 *(sampler
[s
])++ = descriptor
+ j
;
1497 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1498 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1499 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++)
1500 *(sampler
[s
])++ = descriptor
+ j
;
1504 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1505 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1506 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1507 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1508 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1509 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1510 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1511 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1512 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1513 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++) {
1514 *(surface
[s
])++ = descriptor
+ j
;
1520 descriptor
+= pCreateInfo
->pBinding
[i
].count
;
1523 *pSetLayout
= (VkDescriptorSetLayout
) set_layout
;
1528 VkResult
anv_BeginDescriptorPoolUpdate(
1530 VkDescriptorUpdateMode updateMode
)
1532 stub_return(VK_UNSUPPORTED
);
1535 VkResult
anv_EndDescriptorPoolUpdate(
1539 stub_return(VK_UNSUPPORTED
);
1542 VkResult
anv_CreateDescriptorPool(
1544 VkDescriptorPoolUsage poolUsage
,
1546 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
1547 VkDescriptorPool
* pDescriptorPool
)
1549 stub_return(VK_UNSUPPORTED
);
1552 VkResult
anv_ResetDescriptorPool(
1554 VkDescriptorPool descriptorPool
)
1556 stub_return(VK_UNSUPPORTED
);
1559 VkResult
anv_AllocDescriptorSets(
1561 VkDescriptorPool descriptorPool
,
1562 VkDescriptorSetUsage setUsage
,
1564 const VkDescriptorSetLayout
* pSetLayouts
,
1565 VkDescriptorSet
* pDescriptorSets
,
1568 struct anv_device
*device
= (struct anv_device
*) _device
;
1569 const struct anv_descriptor_set_layout
*layout
;
1570 struct anv_descriptor_set
*set
;
1573 for (uint32_t i
= 0; i
< count
; i
++) {
1574 layout
= (struct anv_descriptor_set_layout
*) pSetLayouts
[i
];
1575 size
= sizeof(*set
) + layout
->count
* sizeof(set
->descriptors
[0]);
1576 set
= anv_device_alloc(device
, size
, 8,
1577 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1580 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1583 pDescriptorSets
[i
] = (VkDescriptorSet
) set
;
1588 return VK_UNSUPPORTED
;
1591 void anv_ClearDescriptorSets(
1593 VkDescriptorPool descriptorPool
,
1595 const VkDescriptorSet
* pDescriptorSets
)
1600 void anv_UpdateDescriptors(
1602 VkDescriptorSet descriptorSet
,
1603 uint32_t updateCount
,
1604 const void** ppUpdateArray
)
1606 struct anv_descriptor_set
*set
= (struct anv_descriptor_set
*) descriptorSet
;
1607 VkUpdateSamplers
*update_samplers
;
1608 VkUpdateSamplerTextures
*update_sampler_textures
;
1609 VkUpdateImages
*update_images
;
1610 VkUpdateBuffers
*update_buffers
;
1611 VkUpdateAsCopy
*update_as_copy
;
1613 for (uint32_t i
= 0; i
< updateCount
; i
++) {
1614 const struct anv_common
*common
= ppUpdateArray
[i
];
1616 switch (common
->sType
) {
1617 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS
:
1618 update_samplers
= (VkUpdateSamplers
*) common
;
1620 for (uint32_t j
= 0; j
< update_samplers
->count
; j
++) {
1621 set
->descriptors
[update_samplers
->binding
+ j
].sampler
=
1622 (struct anv_sampler
*) update_samplers
->pSamplers
[j
];
1626 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES
:
1627 /* FIXME: Shouldn't this be *_UPDATE_SAMPLER_IMAGES? */
1628 update_sampler_textures
= (VkUpdateSamplerTextures
*) common
;
1630 for (uint32_t j
= 0; j
< update_sampler_textures
->count
; j
++) {
1631 set
->descriptors
[update_sampler_textures
->binding
+ j
].view
=
1632 (struct anv_surface_view
*)
1633 update_sampler_textures
->pSamplerImageViews
[j
].pImageView
->view
;
1634 set
->descriptors
[update_sampler_textures
->binding
+ j
].sampler
=
1635 (struct anv_sampler
*)
1636 update_sampler_textures
->pSamplerImageViews
[j
].sampler
;
1640 case VK_STRUCTURE_TYPE_UPDATE_IMAGES
:
1641 update_images
= (VkUpdateImages
*) common
;
1643 for (uint32_t j
= 0; j
< update_images
->count
; j
++) {
1644 set
->descriptors
[update_images
->binding
+ j
].view
=
1645 (struct anv_surface_view
*) update_images
->pImageViews
[j
].view
;
1649 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS
:
1650 update_buffers
= (VkUpdateBuffers
*) common
;
1652 for (uint32_t j
= 0; j
< update_buffers
->count
; j
++) {
1653 set
->descriptors
[update_buffers
->binding
+ j
].view
=
1654 (struct anv_surface_view
*) update_buffers
->pBufferViews
[j
].view
;
1656 /* FIXME: descriptor arrays? */
1659 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY
:
1660 update_as_copy
= (VkUpdateAsCopy
*) common
;
1661 (void) update_as_copy
;
1670 // State object functions
1672 static inline int64_t
1673 clamp_int64(int64_t x
, int64_t min
, int64_t max
)
1683 VkResult
anv_CreateDynamicViewportState(
1685 const VkDynamicVpStateCreateInfo
* pCreateInfo
,
1686 VkDynamicVpState
* pState
)
1688 struct anv_device
*device
= (struct anv_device
*) _device
;
1689 struct anv_dynamic_vp_state
*state
;
1691 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
);
1693 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1694 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1696 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1698 unsigned count
= pCreateInfo
->viewportAndScissorCount
;
1699 state
->sf_clip_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1701 state
->cc_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1703 state
->scissor
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
1706 for (uint32_t i
= 0; i
< pCreateInfo
->viewportAndScissorCount
; i
++) {
1707 const VkViewport
*vp
= &pCreateInfo
->pViewports
[i
];
1708 const VkRect
*s
= &pCreateInfo
->pScissors
[i
];
1710 struct GEN8_SF_CLIP_VIEWPORT sf_clip_viewport
= {
1711 .ViewportMatrixElementm00
= vp
->width
/ 2,
1712 .ViewportMatrixElementm11
= vp
->height
/ 2,
1713 .ViewportMatrixElementm22
= (vp
->maxDepth
- vp
->minDepth
) / 2,
1714 .ViewportMatrixElementm30
= vp
->originX
+ vp
->width
/ 2,
1715 .ViewportMatrixElementm31
= vp
->originY
+ vp
->height
/ 2,
1716 .ViewportMatrixElementm32
= (vp
->maxDepth
+ vp
->minDepth
) / 2,
1717 .XMinClipGuardband
= -1.0f
,
1718 .XMaxClipGuardband
= 1.0f
,
1719 .YMinClipGuardband
= -1.0f
,
1720 .YMaxClipGuardband
= 1.0f
,
1721 .XMinViewPort
= vp
->originX
,
1722 .XMaxViewPort
= vp
->originX
+ vp
->width
- 1,
1723 .YMinViewPort
= vp
->originY
,
1724 .YMaxViewPort
= vp
->originY
+ vp
->height
- 1,
1727 struct GEN8_CC_VIEWPORT cc_viewport
= {
1728 .MinimumDepth
= vp
->minDepth
,
1729 .MaximumDepth
= vp
->maxDepth
1732 /* Since xmax and ymax are inclusive, we have to have xmax < xmin or
1733 * ymax < ymin for empty clips. In case clip x, y, width height are all
1734 * 0, the clamps below produce 0 for xmin, ymin, xmax, ymax, which isn't
1735 * what we want. Just special case empty clips and produce a canonical
1737 static const struct GEN8_SCISSOR_RECT empty_scissor
= {
1738 .ScissorRectangleYMin
= 1,
1739 .ScissorRectangleXMin
= 1,
1740 .ScissorRectangleYMax
= 0,
1741 .ScissorRectangleXMax
= 0
1744 const int max
= 0xffff;
1745 struct GEN8_SCISSOR_RECT scissor
= {
1746 /* Do this math using int64_t so overflow gets clamped correctly. */
1747 .ScissorRectangleYMin
= clamp_int64(s
->offset
.y
, 0, max
),
1748 .ScissorRectangleXMin
= clamp_int64(s
->offset
.x
, 0, max
),
1749 .ScissorRectangleYMax
= clamp_int64((uint64_t) s
->offset
.y
+ s
->extent
.height
- 1, 0, max
),
1750 .ScissorRectangleXMax
= clamp_int64((uint64_t) s
->offset
.x
+ s
->extent
.width
- 1, 0, max
)
1753 GEN8_SF_CLIP_VIEWPORT_pack(NULL
, state
->sf_clip_vp
.map
+ i
* 64, &sf_clip_viewport
);
1754 GEN8_CC_VIEWPORT_pack(NULL
, state
->cc_vp
.map
+ i
* 32, &cc_viewport
);
1756 if (s
->extent
.width
<= 0 || s
->extent
.height
<= 0) {
1757 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &empty_scissor
);
1759 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &scissor
);
1763 *pState
= (VkDynamicVpState
) state
;
1768 VkResult
anv_CreateDynamicRasterState(
1770 const VkDynamicRsStateCreateInfo
* pCreateInfo
,
1771 VkDynamicRsState
* pState
)
1773 struct anv_device
*device
= (struct anv_device
*) _device
;
1774 struct anv_dynamic_rs_state
*state
;
1776 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO
);
1778 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1779 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1781 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1785 * float depthBiasClamp;
1786 * float slopeScaledDepthBias;
1787 * float pointFadeThreshold;
1788 * // optional (GL45) - Size of point fade threshold
1791 struct GEN8_3DSTATE_SF sf
= {
1792 GEN8_3DSTATE_SF_header
,
1793 .LineWidth
= pCreateInfo
->lineWidth
,
1794 .PointWidth
= pCreateInfo
->pointSize
,
1797 GEN8_3DSTATE_SF_pack(NULL
, state
->state_sf
, &sf
);
1799 *pState
= (VkDynamicRsState
) state
;
1804 VkResult
anv_CreateDynamicColorBlendState(
1806 const VkDynamicCbStateCreateInfo
* pCreateInfo
,
1807 VkDynamicCbState
* pState
)
1809 struct anv_device
*device
= (struct anv_device
*) _device
;
1810 struct anv_dynamic_cb_state
*state
;
1812 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO
);
1814 state
= anv_device_alloc(device
, sizeof(*state
), 8,
1815 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1817 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1819 *pState
= (VkDynamicCbState
) state
;
1824 VkResult
anv_CreateDynamicDepthStencilState(
1826 const VkDynamicDsStateCreateInfo
* pCreateInfo
,
1827 VkDynamicDsState
* pState
)
1829 stub_return(VK_UNSUPPORTED
);
1832 // Command buffer functions
1834 VkResult
anv_CreateCommandBuffer(
1836 const VkCmdBufferCreateInfo
* pCreateInfo
,
1837 VkCmdBuffer
* pCmdBuffer
)
1839 struct anv_device
*device
= (struct anv_device
*) _device
;
1840 struct anv_cmd_buffer
*cmd_buffer
;
1843 cmd_buffer
= anv_device_alloc(device
, sizeof(*cmd_buffer
), 8,
1844 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1845 if (cmd_buffer
== NULL
)
1846 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1848 cmd_buffer
->device
= device
;
1849 cmd_buffer
->rs_state
= NULL
;
1850 cmd_buffer
->vp_state
= NULL
;
1851 memset(&cmd_buffer
->default_bindings
, 0, sizeof(cmd_buffer
->default_bindings
));
1852 cmd_buffer
->bindings
= &cmd_buffer
->default_bindings
;
1854 result
= anv_batch_init(&cmd_buffer
->batch
, device
);
1855 if (result
!= VK_SUCCESS
)
1858 cmd_buffer
->exec2_objects
=
1859 anv_device_alloc(device
, 8192 * sizeof(cmd_buffer
->exec2_objects
[0]), 8,
1860 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1861 if (cmd_buffer
->exec2_objects
== NULL
) {
1862 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1866 cmd_buffer
->exec2_bos
=
1867 anv_device_alloc(device
, 8192 * sizeof(cmd_buffer
->exec2_bos
[0]), 8,
1868 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1869 if (cmd_buffer
->exec2_bos
== NULL
) {
1870 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1871 goto fail_exec2_objects
;
1874 anv_state_stream_init(&cmd_buffer
->surface_state_stream
,
1875 &device
->surface_state_block_pool
);
1876 anv_state_stream_init(&cmd_buffer
->dynamic_state_stream
,
1877 &device
->dynamic_state_block_pool
);
1879 cmd_buffer
->dirty
= 0;
1880 cmd_buffer
->vb_dirty
= 0;
1882 *pCmdBuffer
= (VkCmdBuffer
) cmd_buffer
;
1887 anv_device_free(device
, cmd_buffer
->exec2_objects
);
1889 anv_batch_finish(&cmd_buffer
->batch
, device
);
1891 anv_device_free(device
, cmd_buffer
);
1896 VkResult
anv_BeginCommandBuffer(
1897 VkCmdBuffer cmdBuffer
,
1898 const VkCmdBufferBeginInfo
* pBeginInfo
)
1900 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
1901 struct anv_device
*device
= cmd_buffer
->device
;
1903 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPELINE_SELECT
,
1904 .PipelineSelection
= _3D
);
1905 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_SIP
);
1907 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_BASE_ADDRESS
,
1908 .GeneralStateBaseAddress
= { NULL
, 0 },
1909 .GeneralStateBaseAddressModifyEnable
= true,
1910 .GeneralStateBufferSize
= 0xfffff,
1911 .GeneralStateBufferSizeModifyEnable
= true,
1913 .SurfaceStateBaseAddress
= { &device
->surface_state_block_pool
.bo
, 0 },
1914 .SurfaceStateMemoryObjectControlState
= 0, /* FIXME: MOCS */
1915 .SurfaceStateBaseAddressModifyEnable
= true,
1917 .DynamicStateBaseAddress
= { &device
->dynamic_state_block_pool
.bo
, 0 },
1918 .DynamicStateBaseAddressModifyEnable
= true,
1919 .DynamicStateBufferSize
= 0xfffff,
1920 .DynamicStateBufferSizeModifyEnable
= true,
1922 .IndirectObjectBaseAddress
= { NULL
, 0 },
1923 .IndirectObjectBaseAddressModifyEnable
= true,
1924 .IndirectObjectBufferSize
= 0xfffff,
1925 .IndirectObjectBufferSizeModifyEnable
= true,
1927 .InstructionBaseAddress
= { &device
->instruction_block_pool
.bo
, 0 },
1928 .InstructionBaseAddressModifyEnable
= true,
1929 .InstructionBufferSize
= 0xfffff,
1930 .InstructionBuffersizeModifyEnable
= true);
1932 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VF_STATISTICS
,
1933 .StatisticsEnable
= true);
1934 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_HS
, .Enable
= false);
1935 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_TE
, .TEEnable
= false);
1936 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DS
, .FunctionEnable
= false);
1937 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_STREAMOUT
, .SOFunctionEnable
= false);
1939 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_VS
,
1940 .ConstantBufferOffset
= 0,
1941 .ConstantBufferSize
= 4);
1942 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_GS
,
1943 .ConstantBufferOffset
= 4,
1944 .ConstantBufferSize
= 4);
1945 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_PUSH_CONSTANT_ALLOC_PS
,
1946 .ConstantBufferOffset
= 8,
1947 .ConstantBufferSize
= 4);
1949 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_WM_CHROMAKEY
,
1950 .ChromaKeyKillEnable
= false);
1951 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SBE_SWIZ
);
1952 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_AA_LINE_PARAMETERS
);
1954 /* Hardcoded state: */
1955 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DEPTH_BUFFER
,
1956 .SurfaceType
= SURFTYPE_2D
,
1959 .SurfaceFormat
= D16_UNORM
,
1960 .SurfaceBaseAddress
= { NULL
, 0 },
1961 .HierarchicalDepthBufferEnable
= 0);
1963 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_WM_DEPTH_STENCIL
,
1964 .DepthTestEnable
= false,
1965 .DepthBufferWriteEnable
= false);
1971 anv_cmd_buffer_add_bo(struct anv_cmd_buffer
*cmd_buffer
,
1972 struct anv_bo
*bo
, struct anv_reloc_list
*list
)
1974 struct drm_i915_gem_exec_object2
*obj
;
1976 bo
->index
= cmd_buffer
->bo_count
;
1977 obj
= &cmd_buffer
->exec2_objects
[bo
->index
];
1978 cmd_buffer
->exec2_bos
[bo
->index
] = bo
;
1979 cmd_buffer
->bo_count
++;
1981 obj
->handle
= bo
->gem_handle
;
1982 obj
->relocation_count
= 0;
1983 obj
->relocs_ptr
= 0;
1985 obj
->offset
= bo
->offset
;
1991 obj
->relocation_count
= list
->num_relocs
;
1992 obj
->relocs_ptr
= (uintptr_t) list
->relocs
;
1997 anv_cmd_buffer_add_validate_bos(struct anv_cmd_buffer
*cmd_buffer
,
1998 struct anv_reloc_list
*list
)
2000 struct anv_bo
*bo
, *batch_bo
;
2002 batch_bo
= &cmd_buffer
->batch
.bo
;
2003 for (size_t i
= 0; i
< list
->num_relocs
; i
++) {
2004 bo
= list
->reloc_bos
[i
];
2005 /* Skip any relocations targeting the batch bo. We need to make sure
2006 * it's the last in the list so we'll add it manually later.
2010 if (bo
->index
< cmd_buffer
->bo_count
&& cmd_buffer
->exec2_bos
[bo
->index
] == bo
)
2013 anv_cmd_buffer_add_bo(cmd_buffer
, bo
, NULL
);
2018 anv_cmd_buffer_process_relocs(struct anv_cmd_buffer
*cmd_buffer
,
2019 struct anv_reloc_list
*list
)
2023 /* If the kernel supports I915_EXEC_NO_RELOC, it will compare offset in
2024 * struct drm_i915_gem_exec_object2 against the bos current offset and if
2025 * all bos haven't moved it will skip relocation processing alltogether.
2026 * If I915_EXEC_NO_RELOC is not supported, the kernel ignores the incoming
2027 * value of offset so we can set it either way. For that to work we need
2028 * to make sure all relocs use the same presumed offset.
2031 for (size_t i
= 0; i
< list
->num_relocs
; i
++) {
2032 bo
= list
->reloc_bos
[i
];
2033 if (bo
->offset
!= list
->relocs
[i
].presumed_offset
)
2034 cmd_buffer
->need_reloc
= true;
2036 list
->relocs
[i
].target_handle
= bo
->index
;
2040 VkResult
anv_EndCommandBuffer(
2041 VkCmdBuffer cmdBuffer
)
2043 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2044 struct anv_device
*device
= cmd_buffer
->device
;
2045 struct anv_batch
*batch
= &cmd_buffer
->batch
;
2047 anv_batch_emit(batch
, GEN8_MI_BATCH_BUFFER_END
);
2049 /* Round batch up to an even number of dwords. */
2050 if ((batch
->next
- batch
->bo
.map
) & 4)
2051 anv_batch_emit(batch
, GEN8_MI_NOOP
);
2053 cmd_buffer
->bo_count
= 0;
2054 cmd_buffer
->need_reloc
= false;
2056 /* Lock for access to bo->index. */
2057 pthread_mutex_lock(&device
->mutex
);
2059 /* Add block pool bos first so we can add them with their relocs. */
2060 anv_cmd_buffer_add_bo(cmd_buffer
, &device
->surface_state_block_pool
.bo
,
2061 &batch
->surf_relocs
);
2063 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &batch
->surf_relocs
);
2064 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &batch
->cmd_relocs
);
2065 anv_cmd_buffer_add_bo(cmd_buffer
, &batch
->bo
, &batch
->cmd_relocs
);
2066 anv_cmd_buffer_process_relocs(cmd_buffer
, &batch
->surf_relocs
);
2067 anv_cmd_buffer_process_relocs(cmd_buffer
, &batch
->cmd_relocs
);
2069 cmd_buffer
->execbuf
.buffers_ptr
= (uintptr_t) cmd_buffer
->exec2_objects
;
2070 cmd_buffer
->execbuf
.buffer_count
= cmd_buffer
->bo_count
;
2071 cmd_buffer
->execbuf
.batch_start_offset
= 0;
2072 cmd_buffer
->execbuf
.batch_len
= batch
->next
- batch
->bo
.map
;
2073 cmd_buffer
->execbuf
.cliprects_ptr
= 0;
2074 cmd_buffer
->execbuf
.num_cliprects
= 0;
2075 cmd_buffer
->execbuf
.DR1
= 0;
2076 cmd_buffer
->execbuf
.DR4
= 0;
2078 cmd_buffer
->execbuf
.flags
= I915_EXEC_HANDLE_LUT
;
2079 if (!cmd_buffer
->need_reloc
)
2080 cmd_buffer
->execbuf
.flags
|= I915_EXEC_NO_RELOC
;
2081 cmd_buffer
->execbuf
.flags
|= I915_EXEC_RENDER
;
2082 cmd_buffer
->execbuf
.rsvd1
= device
->context_id
;
2083 cmd_buffer
->execbuf
.rsvd2
= 0;
2085 pthread_mutex_unlock(&device
->mutex
);
2090 VkResult
anv_ResetCommandBuffer(
2091 VkCmdBuffer cmdBuffer
)
2093 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2095 anv_batch_reset(&cmd_buffer
->batch
);
2100 // Command buffer building functions
2102 void anv_CmdBindPipeline(
2103 VkCmdBuffer cmdBuffer
,
2104 VkPipelineBindPoint pipelineBindPoint
,
2105 VkPipeline _pipeline
)
2107 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2109 cmd_buffer
->pipeline
= (struct anv_pipeline
*) _pipeline
;
2110 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
;
2113 void anv_CmdBindDynamicStateObject(
2114 VkCmdBuffer cmdBuffer
,
2115 VkStateBindPoint stateBindPoint
,
2116 VkDynamicStateObject dynamicState
)
2118 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2119 struct anv_dynamic_vp_state
*vp_state
;
2121 switch (stateBindPoint
) {
2122 case VK_STATE_BIND_POINT_VIEWPORT
:
2123 vp_state
= (struct anv_dynamic_vp_state
*) dynamicState
;
2124 /* We emit state immediately, but set cmd_buffer->vp_state to indicate
2125 * that vp state has been set in this command buffer. */
2126 cmd_buffer
->vp_state
= vp_state
;
2127 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SCISSOR_STATE_POINTERS
,
2128 .ScissorRectPointer
= vp_state
->scissor
.offset
);
2129 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_CC
,
2130 .CCViewportPointer
= vp_state
->cc_vp
.offset
);
2131 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
,
2132 .SFClipViewportPointer
= vp_state
->sf_clip_vp
.offset
);
2134 case VK_STATE_BIND_POINT_RASTER
:
2135 cmd_buffer
->rs_state
= (struct anv_dynamic_rs_state
*) dynamicState
;
2136 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_RS_DIRTY
;
2138 case VK_STATE_BIND_POINT_COLOR_BLEND
:
2139 case VK_STATE_BIND_POINT_DEPTH_STENCIL
:
2146 void anv_CmdBindDescriptorSets(
2147 VkCmdBuffer cmdBuffer
,
2148 VkPipelineBindPoint pipelineBindPoint
,
2151 const VkDescriptorSet
* pDescriptorSets
,
2152 uint32_t dynamicOffsetCount
,
2153 const uint32_t* pDynamicOffsets
)
2155 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2156 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
2157 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2159 uint32_t offset
= 0;
2160 for (uint32_t i
= 0; i
< setCount
; i
++) {
2161 struct anv_descriptor_set
*set
=
2162 (struct anv_descriptor_set
*) pDescriptorSets
[i
];
2163 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[firstSet
+ i
].layout
;
2165 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
2166 uint32_t *surface_to_desc
= set_layout
->stage
[s
].surface_start
;
2167 uint32_t *sampler_to_desc
= set_layout
->stage
[s
].sampler_start
;
2168 uint32_t bias
= s
== VK_SHADER_STAGE_FRAGMENT
? MAX_RTS
: 0;
2171 start
= bias
+ layout
->set
[firstSet
+ i
].surface_start
[s
];
2172 for (uint32_t b
= 0; b
< set_layout
->stage
[s
].surface_count
; b
++) {
2173 struct anv_surface_view
*view
= set
->descriptors
[surface_to_desc
[b
]].view
;
2175 bindings
->descriptors
[s
].surfaces
[start
+ b
] =
2176 view
->surface_state
.offset
;
2177 bindings
->descriptors
[s
].relocs
[start
+ b
].bo
= view
->bo
;
2178 bindings
->descriptors
[s
].relocs
[start
+ b
].offset
= view
->offset
;
2181 start
= layout
->set
[firstSet
+ i
].sampler_start
[s
];
2182 for (uint32_t b
= 0; b
< set_layout
->stage
[s
].sampler_count
; b
++) {
2183 struct anv_sampler
*sampler
= set
->descriptors
[sampler_to_desc
[b
]].sampler
;
2185 memcpy(&bindings
->descriptors
[s
].samplers
[start
+ b
],
2186 sampler
->state
, sizeof(sampler
->state
));
2190 offset
+= layout
->set
[firstSet
+ i
].layout
->num_dynamic_buffers
;
2193 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
2196 void anv_CmdBindIndexBuffer(
2197 VkCmdBuffer cmdBuffer
,
2199 VkDeviceSize offset
,
2200 VkIndexType indexType
)
2202 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2203 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2205 static const uint32_t vk_to_gen_index_type
[] = {
2206 [VK_INDEX_TYPE_UINT8
] = INDEX_BYTE
,
2207 [VK_INDEX_TYPE_UINT16
] = INDEX_WORD
,
2208 [VK_INDEX_TYPE_UINT32
] = INDEX_DWORD
,
2211 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_INDEX_BUFFER
,
2212 .IndexFormat
= vk_to_gen_index_type
[indexType
],
2213 .MemoryObjectControlState
= 0,
2214 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
2215 .BufferSize
= buffer
->size
- offset
);
2218 void anv_CmdBindVertexBuffers(
2219 VkCmdBuffer cmdBuffer
,
2220 uint32_t startBinding
,
2221 uint32_t bindingCount
,
2222 const VkBuffer
* pBuffers
,
2223 const VkDeviceSize
* pOffsets
)
2225 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2226 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2228 /* We have to defer setting up vertex buffer since we need the buffer
2229 * stride from the pipeline. */
2231 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
2232 bindings
->vb
[startBinding
+ i
].buffer
= (struct anv_buffer
*) pBuffers
[i
];
2233 bindings
->vb
[startBinding
+ i
].offset
= pOffsets
[i
];
2234 cmd_buffer
->vb_dirty
|= 1 << (startBinding
+ i
);
2239 flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
)
2241 struct anv_pipeline_layout
*layout
= cmd_buffer
->pipeline
->layout
;
2242 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2243 uint32_t layers
= cmd_buffer
->framebuffer
->layers
;
2245 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
2248 if (s
== VK_SHADER_STAGE_FRAGMENT
) {
2250 layers
= cmd_buffer
->framebuffer
->layers
;
2256 /* This is a little awkward: layout can be NULL but we still have to
2257 * allocate and set a binding table for the PS stage for render
2259 uint32_t surface_count
= layout
? layout
->stage
[s
].surface_count
: 0;
2261 if (layers
+ surface_count
> 0) {
2262 struct anv_state state
;
2265 size
= (bias
+ surface_count
) * sizeof(uint32_t);
2266 state
= anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, size
, 32);
2267 memcpy(state
.map
, bindings
->descriptors
[s
].surfaces
, size
);
2269 for (uint32_t i
= 0; i
< layers
; i
++)
2270 anv_reloc_list_add(&cmd_buffer
->batch
.surf_relocs
,
2271 bindings
->descriptors
[s
].surfaces
[i
] + 8 * sizeof(int32_t),
2272 bindings
->descriptors
[s
].relocs
[i
].bo
,
2273 bindings
->descriptors
[s
].relocs
[i
].offset
);
2275 for (uint32_t i
= 0; i
< surface_count
; i
++)
2276 anv_reloc_list_add(&cmd_buffer
->batch
.surf_relocs
,
2277 bindings
->descriptors
[s
].surfaces
[bias
+ i
] + 8 * sizeof(int32_t),
2278 bindings
->descriptors
[s
].relocs
[bias
+ i
].bo
,
2279 bindings
->descriptors
[s
].relocs
[bias
+ i
].offset
);
2281 static const uint32_t binding_table_opcodes
[] = {
2282 [VK_SHADER_STAGE_VERTEX
] = 38,
2283 [VK_SHADER_STAGE_TESS_CONTROL
] = 39,
2284 [VK_SHADER_STAGE_TESS_EVALUATION
] = 40,
2285 [VK_SHADER_STAGE_GEOMETRY
] = 41,
2286 [VK_SHADER_STAGE_FRAGMENT
] = 42,
2287 [VK_SHADER_STAGE_COMPUTE
] = 0,
2290 anv_batch_emit(&cmd_buffer
->batch
,
2291 GEN8_3DSTATE_BINDING_TABLE_POINTERS_VS
,
2292 ._3DCommandSubOpcode
= binding_table_opcodes
[s
],
2293 .PointertoVSBindingTable
= state
.offset
);
2296 if (layout
&& layout
->stage
[s
].sampler_count
> 0) {
2297 struct anv_state state
;
2300 size
= layout
->stage
[s
].sampler_count
* 16;
2301 state
= anv_state_stream_alloc(&cmd_buffer
->dynamic_state_stream
, size
, 32);
2302 memcpy(state
.map
, bindings
->descriptors
[s
].samplers
, size
);
2304 static const uint32_t sampler_state_opcodes
[] = {
2305 [VK_SHADER_STAGE_VERTEX
] = 43,
2306 [VK_SHADER_STAGE_TESS_CONTROL
] = 44, /* HS */
2307 [VK_SHADER_STAGE_TESS_EVALUATION
] = 45, /* DS */
2308 [VK_SHADER_STAGE_GEOMETRY
] = 46,
2309 [VK_SHADER_STAGE_FRAGMENT
] = 47,
2310 [VK_SHADER_STAGE_COMPUTE
] = 0,
2313 anv_batch_emit(&cmd_buffer
->batch
,
2314 GEN8_3DSTATE_SAMPLER_STATE_POINTERS_VS
,
2315 ._3DCommandSubOpcode
= sampler_state_opcodes
[s
],
2316 .PointertoVSSamplerState
= state
.offset
);
2322 anv_cmd_buffer_flush_state(struct anv_cmd_buffer
*cmd_buffer
)
2324 struct anv_pipeline
*pipeline
= cmd_buffer
->pipeline
;
2325 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2326 const uint32_t num_buffers
= __builtin_popcount(cmd_buffer
->vb_dirty
);
2327 const uint32_t num_dwords
= 1 + num_buffers
* 4;
2330 if (cmd_buffer
->vb_dirty
) {
2331 p
= anv_batch_emitn(&cmd_buffer
->batch
, num_dwords
,
2332 GEN8_3DSTATE_VERTEX_BUFFERS
);
2334 for_each_bit(vb
, cmd_buffer
->vb_dirty
) {
2335 struct anv_buffer
*buffer
= bindings
->vb
[vb
].buffer
;
2336 uint32_t offset
= bindings
->vb
[vb
].offset
;
2338 struct GEN8_VERTEX_BUFFER_STATE state
= {
2339 .VertexBufferIndex
= vb
,
2340 .MemoryObjectControlState
= 0,
2341 .AddressModifyEnable
= true,
2342 .BufferPitch
= pipeline
->binding_stride
[vb
],
2343 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
2344 .BufferSize
= buffer
->size
- offset
2347 GEN8_VERTEX_BUFFER_STATE_pack(&cmd_buffer
->batch
, &p
[1 + i
* 4], &state
);
2352 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_PIPELINE_DIRTY
)
2353 anv_batch_emit_batch(&cmd_buffer
->batch
, &pipeline
->batch
);
2355 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
)
2356 flush_descriptor_sets(cmd_buffer
);
2358 if (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_PIPELINE_DIRTY
| ANV_CMD_BUFFER_RS_DIRTY
))
2359 anv_batch_emit_merge(&cmd_buffer
->batch
,
2360 cmd_buffer
->rs_state
->state_sf
, pipeline
->state_sf
);
2362 cmd_buffer
->vb_dirty
= 0;
2363 cmd_buffer
->dirty
= 0;
2367 VkCmdBuffer cmdBuffer
,
2368 uint32_t firstVertex
,
2369 uint32_t vertexCount
,
2370 uint32_t firstInstance
,
2371 uint32_t instanceCount
)
2373 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2375 anv_cmd_buffer_flush_state(cmd_buffer
);
2377 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2378 .VertexAccessType
= SEQUENTIAL
,
2379 .VertexCountPerInstance
= vertexCount
,
2380 .StartVertexLocation
= firstVertex
,
2381 .InstanceCount
= instanceCount
,
2382 .StartInstanceLocation
= firstInstance
,
2383 .BaseVertexLocation
= 0);
2386 void anv_CmdDrawIndexed(
2387 VkCmdBuffer cmdBuffer
,
2388 uint32_t firstIndex
,
2389 uint32_t indexCount
,
2390 int32_t vertexOffset
,
2391 uint32_t firstInstance
,
2392 uint32_t instanceCount
)
2394 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2396 anv_cmd_buffer_flush_state(cmd_buffer
);
2398 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2399 .VertexAccessType
= RANDOM
,
2400 .VertexCountPerInstance
= indexCount
,
2401 .StartVertexLocation
= firstIndex
,
2402 .InstanceCount
= instanceCount
,
2403 .StartInstanceLocation
= firstInstance
,
2404 .BaseVertexLocation
= 0);
2408 anv_batch_lrm(struct anv_batch
*batch
,
2409 uint32_t reg
, struct anv_bo
*bo
, uint32_t offset
)
2411 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_MEM
,
2412 .RegisterAddress
= reg
,
2413 .MemoryAddress
= { bo
, offset
});
2417 anv_batch_lri(struct anv_batch
*batch
, uint32_t reg
, uint32_t imm
)
2419 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_IMM
,
2420 .RegisterOffset
= reg
,
2424 /* Auto-Draw / Indirect Registers */
2425 #define GEN7_3DPRIM_END_OFFSET 0x2420
2426 #define GEN7_3DPRIM_START_VERTEX 0x2430
2427 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
2428 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
2429 #define GEN7_3DPRIM_START_INSTANCE 0x243C
2430 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
2432 void anv_CmdDrawIndirect(
2433 VkCmdBuffer cmdBuffer
,
2435 VkDeviceSize offset
,
2439 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2440 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2441 struct anv_bo
*bo
= buffer
->bo
;
2442 uint32_t bo_offset
= buffer
->offset
+ offset
;
2444 anv_cmd_buffer_flush_state(cmd_buffer
);
2446 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
2447 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
2448 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
2449 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 12);
2450 anv_batch_lri(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, 0);
2452 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2453 .IndirectParameterEnable
= true,
2454 .VertexAccessType
= SEQUENTIAL
);
2457 void anv_CmdDrawIndexedIndirect(
2458 VkCmdBuffer cmdBuffer
,
2460 VkDeviceSize offset
,
2464 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2465 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2466 struct anv_bo
*bo
= buffer
->bo
;
2467 uint32_t bo_offset
= buffer
->offset
+ offset
;
2469 anv_cmd_buffer_flush_state(cmd_buffer
);
2471 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
2472 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
2473 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
2474 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, bo
, bo_offset
+ 12);
2475 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 16);
2477 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
2478 .IndirectParameterEnable
= true,
2479 .VertexAccessType
= RANDOM
);
2482 void anv_CmdDispatch(
2483 VkCmdBuffer cmdBuffer
,
2491 void anv_CmdDispatchIndirect(
2492 VkCmdBuffer cmdBuffer
,
2494 VkDeviceSize offset
)
2499 void anv_CmdSetEvent(
2500 VkCmdBuffer cmdBuffer
,
2502 VkPipeEvent pipeEvent
)
2507 void anv_CmdResetEvent(
2508 VkCmdBuffer cmdBuffer
,
2510 VkPipeEvent pipeEvent
)
2515 void anv_CmdWaitEvents(
2516 VkCmdBuffer cmdBuffer
,
2517 VkWaitEvent waitEvent
,
2518 uint32_t eventCount
,
2519 const VkEvent
* pEvents
,
2520 uint32_t memBarrierCount
,
2521 const void** ppMemBarriers
)
2526 void anv_CmdPipelineBarrier(
2527 VkCmdBuffer cmdBuffer
,
2528 VkWaitEvent waitEvent
,
2529 uint32_t pipeEventCount
,
2530 const VkPipeEvent
* pPipeEvents
,
2531 uint32_t memBarrierCount
,
2532 const void** ppMemBarriers
)
2538 anv_batch_emit_ps_depth_count(struct anv_batch
*batch
,
2539 struct anv_bo
*bo
, uint32_t offset
)
2541 anv_batch_emit(batch
, GEN8_PIPE_CONTROL
,
2542 .DestinationAddressType
= DAT_PPGTT
,
2543 .PostSyncOperation
= WritePSDepthCount
,
2544 .Address
= { bo
, offset
}); /* FIXME: This is only lower 32 bits */
2547 void anv_CmdBeginQuery(
2548 VkCmdBuffer cmdBuffer
,
2549 VkQueryPool queryPool
,
2551 VkQueryControlFlags flags
)
2553 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2554 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
2556 switch (pool
->type
) {
2557 case VK_QUERY_TYPE_OCCLUSION
:
2558 anv_batch_emit_ps_depth_count(&cmd_buffer
->batch
, &pool
->bo
, slot
* 16);
2561 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
2569 void anv_CmdEndQuery(
2570 VkCmdBuffer cmdBuffer
,
2571 VkQueryPool queryPool
,
2574 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2575 struct anv_query_pool
*pool
= (struct anv_query_pool
*) queryPool
;
2577 switch (pool
->type
) {
2578 case VK_QUERY_TYPE_OCCLUSION
:
2579 anv_batch_emit_ps_depth_count(&cmd_buffer
->batch
, &pool
->bo
, slot
* 16 + 8);
2582 case VK_QUERY_TYPE_PIPELINE_STATISTICS
:
2590 void anv_CmdResetQueryPool(
2591 VkCmdBuffer cmdBuffer
,
2592 VkQueryPool queryPool
,
2593 uint32_t startQuery
,
2594 uint32_t queryCount
)
2599 #define TIMESTAMP 0x44070
2601 void anv_CmdWriteTimestamp(
2602 VkCmdBuffer cmdBuffer
,
2603 VkTimestampType timestampType
,
2604 VkBuffer destBuffer
,
2605 VkDeviceSize destOffset
)
2607 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2608 struct anv_buffer
*buffer
= (struct anv_buffer
*) destBuffer
;
2609 struct anv_bo
*bo
= buffer
->bo
;
2611 switch (timestampType
) {
2612 case VK_TIMESTAMP_TYPE_TOP
:
2613 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MI_STORE_REGISTER_MEM
,
2614 .RegisterAddress
= TIMESTAMP
,
2615 .MemoryAddress
= { bo
, buffer
->offset
+ destOffset
});
2618 case VK_TIMESTAMP_TYPE_BOTTOM
:
2619 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
2620 .DestinationAddressType
= DAT_PPGTT
,
2621 .PostSyncOperation
= WriteTimestamp
,
2622 .Address
= /* FIXME: This is only lower 32 bits */
2623 { bo
, buffer
->offset
+ destOffset
});
2631 void anv_CmdCopyQueryPoolResults(
2632 VkCmdBuffer cmdBuffer
,
2633 VkQueryPool queryPool
,
2634 uint32_t startQuery
,
2635 uint32_t queryCount
,
2636 VkBuffer destBuffer
,
2637 VkDeviceSize destOffset
,
2638 VkDeviceSize destStride
,
2639 VkQueryResultFlags flags
)
2644 void anv_CmdInitAtomicCounters(
2645 VkCmdBuffer cmdBuffer
,
2646 VkPipelineBindPoint pipelineBindPoint
,
2647 uint32_t startCounter
,
2648 uint32_t counterCount
,
2649 const uint32_t* pData
)
2654 void anv_CmdLoadAtomicCounters(
2655 VkCmdBuffer cmdBuffer
,
2656 VkPipelineBindPoint pipelineBindPoint
,
2657 uint32_t startCounter
,
2658 uint32_t counterCount
,
2660 VkDeviceSize srcOffset
)
2665 void anv_CmdSaveAtomicCounters(
2666 VkCmdBuffer cmdBuffer
,
2667 VkPipelineBindPoint pipelineBindPoint
,
2668 uint32_t startCounter
,
2669 uint32_t counterCount
,
2670 VkBuffer destBuffer
,
2671 VkDeviceSize destOffset
)
2676 VkResult
anv_CreateFramebuffer(
2678 const VkFramebufferCreateInfo
* pCreateInfo
,
2679 VkFramebuffer
* pFramebuffer
)
2681 struct anv_device
*device
= (struct anv_device
*) _device
;
2682 struct anv_framebuffer
*framebuffer
;
2684 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2686 framebuffer
= anv_device_alloc(device
, sizeof(*framebuffer
), 8,
2687 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2688 if (framebuffer
== NULL
)
2689 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2691 framebuffer
->color_attachment_count
= pCreateInfo
->colorAttachmentCount
;
2692 for (uint32_t i
= 0; i
< pCreateInfo
->colorAttachmentCount
; i
++) {
2693 framebuffer
->color_attachments
[i
] =
2694 (struct anv_surface_view
*) pCreateInfo
->pColorAttachments
[i
].view
;
2697 if (pCreateInfo
->pDepthStencilAttachment
) {
2698 framebuffer
->depth_stencil
=
2699 (struct anv_depth_stencil_view
*) pCreateInfo
->pDepthStencilAttachment
->view
;
2702 framebuffer
->sample_count
= pCreateInfo
->sampleCount
;
2703 framebuffer
->width
= pCreateInfo
->width
;
2704 framebuffer
->height
= pCreateInfo
->height
;
2705 framebuffer
->layers
= pCreateInfo
->layers
;
2707 vkCreateDynamicViewportState((VkDevice
) device
,
2708 &(VkDynamicVpStateCreateInfo
) {
2709 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
,
2710 .viewportAndScissorCount
= 2,
2711 .pViewports
= (VkViewport
[]) {
2715 .width
= pCreateInfo
->width
,
2716 .height
= pCreateInfo
->height
,
2721 .pScissors
= (VkRect
[]) {
2723 { pCreateInfo
->width
, pCreateInfo
->height
} },
2726 &framebuffer
->vp_state
);
2728 *pFramebuffer
= (VkFramebuffer
) framebuffer
;
2733 VkResult
anv_CreateRenderPass(
2735 const VkRenderPassCreateInfo
* pCreateInfo
,
2736 VkRenderPass
* pRenderPass
)
2738 struct anv_device
*device
= (struct anv_device
*) _device
;
2739 struct anv_render_pass
*pass
;
2742 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
2744 size
= sizeof(*pass
) +
2745 pCreateInfo
->layers
* sizeof(struct anv_render_pass_layer
);
2746 pass
= anv_device_alloc(device
, size
, 8,
2747 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2749 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2751 pass
->render_area
= pCreateInfo
->renderArea
;
2753 pass
->num_layers
= pCreateInfo
->layers
;
2755 pass
->num_clear_layers
= 0;
2756 for (uint32_t i
= 0; i
< pCreateInfo
->layers
; i
++) {
2757 pass
->layers
[i
].color_load_op
= pCreateInfo
->pColorLoadOps
[i
];
2758 pass
->layers
[i
].clear_color
= pCreateInfo
->pColorLoadClearValues
[i
];
2759 if (pass
->layers
[i
].color_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
)
2760 pass
->num_clear_layers
++;
2763 *pRenderPass
= (VkRenderPass
) pass
;
2769 anv_cmd_buffer_fill_render_targets(struct anv_cmd_buffer
*cmd_buffer
)
2771 struct anv_framebuffer
*framebuffer
= cmd_buffer
->framebuffer
;
2772 struct anv_bindings
*bindings
= cmd_buffer
->bindings
;
2774 for (uint32_t i
= 0; i
< framebuffer
->color_attachment_count
; i
++) {
2775 struct anv_surface_view
*view
= framebuffer
->color_attachments
[i
];
2777 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].surfaces
[i
] = view
->surface_state
.offset
;
2778 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].relocs
[i
].bo
= view
->bo
;
2779 bindings
->descriptors
[VK_SHADER_STAGE_FRAGMENT
].relocs
[i
].offset
= view
->offset
;
2781 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
2784 void anv_CmdBeginRenderPass(
2785 VkCmdBuffer cmdBuffer
,
2786 const VkRenderPassBegin
* pRenderPassBegin
)
2788 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2789 struct anv_render_pass
*pass
= (struct anv_render_pass
*) pRenderPassBegin
->renderPass
;
2790 struct anv_framebuffer
*framebuffer
=
2791 (struct anv_framebuffer
*) pRenderPassBegin
->framebuffer
;
2793 cmd_buffer
->framebuffer
= framebuffer
;
2795 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DRAWING_RECTANGLE
,
2796 .ClippedDrawingRectangleYMin
= pass
->render_area
.offset
.y
,
2797 .ClippedDrawingRectangleXMin
= pass
->render_area
.offset
.x
,
2798 .ClippedDrawingRectangleYMax
=
2799 pass
->render_area
.offset
.y
+ pass
->render_area
.extent
.height
- 1,
2800 .ClippedDrawingRectangleXMax
=
2801 pass
->render_area
.offset
.x
+ pass
->render_area
.extent
.width
- 1,
2802 .DrawingRectangleOriginY
= 0,
2803 .DrawingRectangleOriginX
= 0);
2805 anv_cmd_buffer_fill_render_targets(cmd_buffer
);
2807 anv_cmd_buffer_clear(cmd_buffer
, pass
);
2810 void anv_CmdEndRenderPass(
2811 VkCmdBuffer cmdBuffer
,
2812 VkRenderPass renderPass
)
2814 /* Emit a flushing pipe control at the end of a pass. This is kind of a
2815 * hack but it ensures that render targets always actually get written.
2816 * Eventually, we should do flushing based on image format transitions
2817 * or something of that nature.
2819 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
2820 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
2821 .PostSyncOperation
= NoWrite
,
2822 .RenderTargetCacheFlushEnable
= true,
2823 .InstructionCacheInvalidateEnable
= true,
2824 .DepthCacheFlushEnable
= true,
2825 .VFCacheInvalidationEnable
= true,
2826 .TextureCacheInvalidationEnable
= true,
2827 .CommandStreamerStallEnable
= true);