2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33 anv_env_get_int(const char *name
)
35 const char *val
= getenv(name
);
40 return strtol(val
, NULL
, 0);
44 fill_physical_device(struct anv_physical_device
*device
,
45 struct anv_instance
*instance
,
50 fd
= open("/dev/dri/renderD128", O_RDWR
| O_CLOEXEC
);
52 return vk_error(VK_ERROR_UNAVAILABLE
);
54 device
->instance
= instance
;
57 device
->chipset_id
= anv_env_get_int("INTEL_DEVID_OVERRIDE");
58 device
->no_hw
= false;
59 if (device
->chipset_id
) {
60 /* INTEL_DEVID_OVERRIDE implies INTEL_NO_HW. */
63 device
->chipset_id
= anv_gem_get_param(fd
, I915_PARAM_CHIPSET_ID
);
65 if (!device
->chipset_id
)
68 device
->name
= brw_get_device_name(device
->chipset_id
);
69 device
->info
= brw_get_device_info(device
->chipset_id
, -1);
73 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_WAIT_TIMEOUT
))
76 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXECBUF2
))
79 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_LLC
))
82 if (!anv_gem_get_param(fd
, I915_PARAM_HAS_EXEC_CONSTANTS
))
92 return vk_error(VK_ERROR_UNAVAILABLE
);
95 static void *default_alloc(
99 VkSystemAllocType allocType
)
104 static void default_free(
111 static const VkAllocCallbacks default_alloc_callbacks
= {
113 .pfnAlloc
= default_alloc
,
114 .pfnFree
= default_free
117 VkResult
anv_CreateInstance(
118 const VkInstanceCreateInfo
* pCreateInfo
,
119 VkInstance
* pInstance
)
121 struct anv_instance
*instance
;
122 const VkAllocCallbacks
*alloc_callbacks
= &default_alloc_callbacks
;
123 void *user_data
= NULL
;
126 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
128 if (pCreateInfo
->pAllocCb
) {
129 alloc_callbacks
= pCreateInfo
->pAllocCb
;
130 user_data
= pCreateInfo
->pAllocCb
->pUserData
;
132 instance
= alloc_callbacks
->pfnAlloc(user_data
, sizeof(*instance
), 8,
133 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
135 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
137 instance
->pAllocUserData
= alloc_callbacks
->pUserData
;
138 instance
->pfnAlloc
= alloc_callbacks
->pfnAlloc
;
139 instance
->pfnFree
= alloc_callbacks
->pfnFree
;
140 instance
->apiVersion
= pCreateInfo
->pAppInfo
->apiVersion
;
142 instance
->physicalDeviceCount
= 0;
143 result
= fill_physical_device(&instance
->physicalDevice
,
144 instance
, "/dev/dri/renderD128");
146 if (result
!= VK_SUCCESS
)
149 instance
->physicalDeviceCount
++;
150 *pInstance
= (VkInstance
) instance
;
155 VkResult
anv_DestroyInstance(
156 VkInstance _instance
)
158 struct anv_instance
*instance
= (struct anv_instance
*) _instance
;
160 instance
->pfnFree(instance
->pAllocUserData
, instance
);
165 VkResult
anv_EnumeratePhysicalDevices(
166 VkInstance _instance
,
167 uint32_t* pPhysicalDeviceCount
,
168 VkPhysicalDevice
* pPhysicalDevices
)
170 struct anv_instance
*instance
= (struct anv_instance
*) _instance
;
172 if (*pPhysicalDeviceCount
>= 1)
173 pPhysicalDevices
[0] = (VkPhysicalDevice
) &instance
->physicalDevice
;
174 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
179 VkResult
anv_GetPhysicalDeviceInfo(
180 VkPhysicalDevice physicalDevice
,
181 VkPhysicalDeviceInfoType infoType
,
185 struct anv_physical_device
*device
= (struct anv_physical_device
*) physicalDevice
;
186 VkPhysicalDeviceProperties
*properties
;
187 VkPhysicalDevicePerformance
*performance
;
188 VkPhysicalDeviceQueueProperties
*queue_properties
;
189 VkPhysicalDeviceMemoryProperties
*memory_properties
;
190 VkDisplayPropertiesWSI
*display_properties
;
191 uint64_t ns_per_tick
= 80;
193 switch ((uint32_t) infoType
) {
194 case VK_PHYSICAL_DEVICE_INFO_TYPE_PROPERTIES
:
197 *pDataSize
= sizeof(*properties
);
201 properties
->apiVersion
= 1;
202 properties
->driverVersion
= 1;
203 properties
->vendorId
= 0x8086;
204 properties
->deviceId
= device
->chipset_id
;
205 properties
->deviceType
= VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
;
206 strcpy(properties
->deviceName
, device
->name
);
207 properties
->maxInlineMemoryUpdateSize
= 0;
208 properties
->maxBoundDescriptorSets
= MAX_SETS
;
209 properties
->maxThreadGroupSize
= 512;
210 properties
->timestampFrequency
= 1000 * 1000 * 1000 / ns_per_tick
;
211 properties
->multiColorAttachmentClears
= true;
212 properties
->maxDescriptorSets
= 8;
213 properties
->maxViewports
= 16;
214 properties
->maxColorAttachments
= 8;
217 case VK_PHYSICAL_DEVICE_INFO_TYPE_PERFORMANCE
:
220 *pDataSize
= sizeof(*performance
);
224 performance
->maxDeviceClock
= 1.0;
225 performance
->aluPerClock
= 1.0;
226 performance
->texPerClock
= 1.0;
227 performance
->primsPerClock
= 1.0;
228 performance
->pixelsPerClock
= 1.0;
231 case VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES
:
232 queue_properties
= pData
;
234 *pDataSize
= sizeof(*queue_properties
);
238 queue_properties
->queueFlags
= 0;
239 queue_properties
->queueCount
= 1;
240 queue_properties
->maxAtomicCounters
= 0;
241 queue_properties
->supportsTimestamps
= true;
242 queue_properties
->maxMemReferences
= 256;
245 case VK_PHYSICAL_DEVICE_INFO_TYPE_MEMORY_PROPERTIES
:
246 memory_properties
= pData
;
248 *pDataSize
= sizeof(*memory_properties
);
252 memory_properties
->supportsMigration
= false;
253 memory_properties
->supportsPinning
= false;
256 case VK_PHYSICAL_DEVICE_INFO_TYPE_DISPLAY_PROPERTIES_WSI
:
257 anv_finishme("VK_PHYSICAL_DEVICE_INFO_TYPE_DISPLAY_PROPERTIES_WSI");
259 *pDataSize
= sizeof(*display_properties
);
263 display_properties
= pData
;
264 display_properties
->display
= 0;
265 display_properties
->physicalResolution
= (VkExtent2D
) { 0, 0 };
268 case VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PRESENT_PROPERTIES_WSI
:
269 anv_finishme("VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PRESENT_PROPERTIES_WSI");
274 return VK_UNSUPPORTED
;
279 void * vkGetProcAddr(
280 VkPhysicalDevice physicalDevice
,
283 return anv_lookup_entrypoint(pName
);
287 parse_debug_flags(struct anv_device
*device
)
289 const char *debug
, *p
, *end
;
291 debug
= getenv("INTEL_DEBUG");
292 device
->dump_aub
= false;
294 for (p
= debug
; *p
; p
= end
+ 1) {
295 end
= strchrnul(p
, ',');
296 if (end
- p
== 3 && memcmp(p
, "aub", 3) == 0)
297 device
->dump_aub
= true;
298 if (end
- p
== 5 && memcmp(p
, "no_hw", 5) == 0)
299 device
->no_hw
= true;
307 anv_queue_init(struct anv_device
*device
, struct anv_queue
*queue
)
309 queue
->device
= device
;
310 queue
->pool
= &device
->surface_state_pool
;
312 queue
->completed_serial
= anv_state_pool_alloc(queue
->pool
, 4, 4);
313 if (queue
->completed_serial
.map
== NULL
)
314 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
316 *(uint32_t *)queue
->completed_serial
.map
= 0;
317 queue
->next_serial
= 1;
323 anv_queue_finish(struct anv_queue
*queue
)
326 /* This gets torn down with the device so we only need to do this if
327 * valgrind is present.
329 anv_state_pool_free(queue
->pool
, queue
->completed_serial
);
334 anv_device_init_border_colors(struct anv_device
*device
)
336 float float_border_colors
[][4] = {
337 [VK_BORDER_COLOR_OPAQUE_WHITE
] = { 1.0, 1.0, 1.0, 1.0 },
338 [VK_BORDER_COLOR_TRANSPARENT_BLACK
] = { 0.0, 0.0, 0.0, 0.0 },
339 [VK_BORDER_COLOR_OPAQUE_BLACK
] = { 0.0, 0.0, 0.0, 1.0 }
342 uint32_t uint32_border_colors
[][4] = {
343 [VK_BORDER_COLOR_OPAQUE_WHITE
] = { 1, 1, 1, 1 },
344 [VK_BORDER_COLOR_TRANSPARENT_BLACK
] = { 0, 0, 0, 0 },
345 [VK_BORDER_COLOR_OPAQUE_BLACK
] = { 0, 0, 0, 1 }
348 device
->float_border_colors
=
349 anv_state_pool_alloc(&device
->dynamic_state_pool
,
350 sizeof(float_border_colors
), 32);
351 memcpy(device
->float_border_colors
.map
,
352 float_border_colors
, sizeof(float_border_colors
));
354 device
->uint32_border_colors
=
355 anv_state_pool_alloc(&device
->dynamic_state_pool
,
356 sizeof(uint32_border_colors
), 32);
357 memcpy(device
->uint32_border_colors
.map
,
358 uint32_border_colors
, sizeof(uint32_border_colors
));
362 static const uint32_t BATCH_SIZE
= 8192;
364 VkResult
anv_CreateDevice(
365 VkPhysicalDevice _physicalDevice
,
366 const VkDeviceCreateInfo
* pCreateInfo
,
369 struct anv_physical_device
*physicalDevice
=
370 (struct anv_physical_device
*) _physicalDevice
;
371 struct anv_instance
*instance
= physicalDevice
->instance
;
372 struct anv_device
*device
;
374 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
);
376 device
= instance
->pfnAlloc(instance
->pAllocUserData
,
378 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
380 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
382 device
->no_hw
= physicalDevice
->no_hw
;
383 parse_debug_flags(device
);
385 device
->instance
= physicalDevice
->instance
;
386 device
->fd
= open("/dev/dri/renderD128", O_RDWR
| O_CLOEXEC
);
387 if (device
->fd
== -1)
390 device
->context_id
= anv_gem_create_context(device
);
391 if (device
->context_id
== -1)
394 anv_bo_pool_init(&device
->batch_bo_pool
, device
, BATCH_SIZE
);
396 anv_block_pool_init(&device
->dynamic_state_block_pool
, device
, 2048);
398 anv_state_pool_init(&device
->dynamic_state_pool
,
399 &device
->dynamic_state_block_pool
);
401 anv_block_pool_init(&device
->instruction_block_pool
, device
, 2048);
402 anv_block_pool_init(&device
->surface_state_block_pool
, device
, 2048);
404 anv_state_pool_init(&device
->surface_state_pool
,
405 &device
->surface_state_block_pool
);
407 device
->info
= *physicalDevice
->info
;
409 device
->compiler
= anv_compiler_create(device
);
410 device
->aub_writer
= NULL
;
412 pthread_mutex_init(&device
->mutex
, NULL
);
414 anv_queue_init(device
, &device
->queue
);
416 anv_device_init_meta(device
);
418 anv_device_init_border_colors(device
);
420 *pDevice
= (VkDevice
) device
;
427 anv_device_free(device
, device
);
429 return vk_error(VK_ERROR_UNAVAILABLE
);
432 VkResult
anv_DestroyDevice(
435 struct anv_device
*device
= (struct anv_device
*) _device
;
437 anv_compiler_destroy(device
->compiler
);
439 anv_queue_finish(&device
->queue
);
441 anv_device_finish_meta(device
);
444 /* We only need to free these to prevent valgrind errors. The backing
445 * BO will go away in a couple of lines so we don't actually leak.
447 anv_state_pool_free(&device
->dynamic_state_pool
,
448 device
->float_border_colors
);
449 anv_state_pool_free(&device
->dynamic_state_pool
,
450 device
->uint32_border_colors
);
453 anv_bo_pool_finish(&device
->batch_bo_pool
);
454 anv_block_pool_finish(&device
->dynamic_state_block_pool
);
455 anv_block_pool_finish(&device
->instruction_block_pool
);
456 anv_block_pool_finish(&device
->surface_state_block_pool
);
460 if (device
->aub_writer
)
461 anv_aub_writer_destroy(device
->aub_writer
);
463 anv_device_free(device
, device
);
468 VkResult
anv_GetGlobalExtensionInfo(
469 VkExtensionInfoType infoType
,
470 uint32_t extensionIndex
,
474 static const VkExtensionProperties extensions
[] = {
476 .extName
= "VK_WSI_LunarG",
480 uint32_t count
= ARRAY_SIZE(extensions
);
483 case VK_EXTENSION_INFO_TYPE_COUNT
:
484 memcpy(pData
, &count
, sizeof(count
));
485 *pDataSize
= sizeof(count
);
488 case VK_EXTENSION_INFO_TYPE_PROPERTIES
:
489 if (extensionIndex
>= count
)
490 return vk_error(VK_ERROR_INVALID_EXTENSION
);
492 memcpy(pData
, &extensions
[extensionIndex
], sizeof(extensions
[0]));
493 *pDataSize
= sizeof(extensions
[0]);
497 return VK_UNSUPPORTED
;
501 VkResult
anv_GetPhysicalDeviceExtensionInfo(
502 VkPhysicalDevice physicalDevice
,
503 VkExtensionInfoType infoType
,
504 uint32_t extensionIndex
,
511 case VK_EXTENSION_INFO_TYPE_COUNT
:
520 case VK_EXTENSION_INFO_TYPE_PROPERTIES
:
521 return vk_error(VK_ERROR_INVALID_EXTENSION
);
524 return VK_UNSUPPORTED
;
528 VkResult
anv_EnumerateLayers(
529 VkPhysicalDevice physicalDevice
,
530 size_t maxStringSize
,
532 char* const* pOutLayers
,
540 VkResult
anv_GetDeviceQueue(
542 uint32_t queueNodeIndex
,
546 struct anv_device
*device
= (struct anv_device
*) _device
;
548 assert(queueIndex
== 0);
550 *pQueue
= (VkQueue
) &device
->queue
;
556 anv_reloc_list_init(struct anv_reloc_list
*list
, struct anv_device
*device
)
558 list
->num_relocs
= 0;
559 list
->array_length
= 256;
561 anv_device_alloc(device
, list
->array_length
* sizeof(*list
->relocs
), 8,
562 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
564 if (list
->relocs
== NULL
)
565 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
568 anv_device_alloc(device
, list
->array_length
* sizeof(*list
->reloc_bos
), 8,
569 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
571 if (list
->relocs
== NULL
) {
572 anv_device_free(device
, list
->relocs
);
573 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
580 anv_reloc_list_finish(struct anv_reloc_list
*list
, struct anv_device
*device
)
582 anv_device_free(device
, list
->relocs
);
583 anv_device_free(device
, list
->reloc_bos
);
587 anv_reloc_list_grow(struct anv_reloc_list
*list
, struct anv_device
*device
,
588 size_t num_additional_relocs
)
590 if (list
->num_relocs
+ num_additional_relocs
<= list
->array_length
)
593 size_t new_length
= list
->array_length
* 2;
594 while (new_length
< list
->num_relocs
+ num_additional_relocs
)
597 struct drm_i915_gem_relocation_entry
*new_relocs
=
598 anv_device_alloc(device
, new_length
* sizeof(*list
->relocs
), 8,
599 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
600 if (new_relocs
== NULL
)
601 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
603 struct anv_bo
**new_reloc_bos
=
604 anv_device_alloc(device
, new_length
* sizeof(*list
->reloc_bos
), 8,
605 VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
606 if (new_relocs
== NULL
) {
607 anv_device_free(device
, new_relocs
);
608 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
611 memcpy(new_relocs
, list
->relocs
, list
->num_relocs
* sizeof(*list
->relocs
));
612 memcpy(new_reloc_bos
, list
->reloc_bos
,
613 list
->num_relocs
* sizeof(*list
->reloc_bos
));
615 anv_device_free(device
, list
->relocs
);
616 anv_device_free(device
, list
->reloc_bos
);
618 list
->relocs
= new_relocs
;
619 list
->reloc_bos
= new_reloc_bos
;
625 anv_batch_bo_create(struct anv_device
*device
, struct anv_batch_bo
**bbo_out
)
629 struct anv_batch_bo
*bbo
=
630 anv_device_alloc(device
, sizeof(*bbo
), 8, VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
632 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
635 bbo
->prev_batch_bo
= NULL
;
637 result
= anv_bo_pool_alloc(&device
->batch_bo_pool
, &bbo
->bo
);
638 if (result
!= VK_SUCCESS
) {
639 anv_device_free(device
, bbo
);
649 anv_batch_bo_start(struct anv_batch_bo
*bbo
, struct anv_batch
*batch
,
650 size_t batch_padding
)
652 batch
->next
= batch
->start
= bbo
->bo
.map
;
653 batch
->end
= bbo
->bo
.map
+ bbo
->bo
.size
- batch_padding
;
654 bbo
->first_reloc
= batch
->relocs
.num_relocs
;
658 anv_batch_bo_finish(struct anv_batch_bo
*bbo
, struct anv_batch
*batch
)
660 assert(batch
->start
== bbo
->bo
.map
);
661 bbo
->length
= batch
->next
- batch
->start
;
662 VG(VALGRIND_CHECK_MEM_IS_DEFINED(batch
->start
, bbo
->length
));
663 bbo
->num_relocs
= batch
->relocs
.num_relocs
- bbo
->first_reloc
;
667 anv_batch_bo_destroy(struct anv_batch_bo
*bbo
, struct anv_device
*device
)
669 anv_bo_pool_free(&device
->batch_bo_pool
, &bbo
->bo
);
670 anv_device_free(device
, bbo
);
674 anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
)
676 if (batch
->next
+ num_dwords
* 4 > batch
->end
)
677 batch
->extend_cb(batch
, batch
->user_data
);
679 void *p
= batch
->next
;
681 batch
->next
+= num_dwords
* 4;
682 assert(batch
->next
<= batch
->end
);
688 anv_reloc_list_append(struct anv_reloc_list
*list
, struct anv_device
*device
,
689 struct anv_reloc_list
*other
, uint32_t offset
)
691 anv_reloc_list_grow(list
, device
, other
->num_relocs
);
692 /* TODO: Handle failure */
694 memcpy(&list
->relocs
[list
->num_relocs
], &other
->relocs
[0],
695 other
->num_relocs
* sizeof(other
->relocs
[0]));
696 memcpy(&list
->reloc_bos
[list
->num_relocs
], &other
->reloc_bos
[0],
697 other
->num_relocs
* sizeof(other
->reloc_bos
[0]));
699 for (uint32_t i
= 0; i
< other
->num_relocs
; i
++)
700 list
->relocs
[i
+ list
->num_relocs
].offset
+= offset
;
702 list
->num_relocs
+= other
->num_relocs
;
706 anv_reloc_list_add(struct anv_reloc_list
*list
, struct anv_device
*device
,
707 uint32_t offset
, struct anv_bo
*target_bo
, uint32_t delta
)
709 struct drm_i915_gem_relocation_entry
*entry
;
712 anv_reloc_list_grow(list
, device
, 1);
713 /* TODO: Handle failure */
715 /* XXX: Can we use I915_EXEC_HANDLE_LUT? */
716 index
= list
->num_relocs
++;
717 list
->reloc_bos
[index
] = target_bo
;
718 entry
= &list
->relocs
[index
];
719 entry
->target_handle
= target_bo
->gem_handle
;
720 entry
->delta
= delta
;
721 entry
->offset
= offset
;
722 entry
->presumed_offset
= target_bo
->offset
;
723 entry
->read_domains
= 0;
724 entry
->write_domain
= 0;
726 return target_bo
->offset
+ delta
;
730 anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
)
732 uint32_t size
, offset
;
734 size
= other
->next
- other
->start
;
735 assert(size
% 4 == 0);
737 if (batch
->next
+ size
> batch
->end
)
738 batch
->extend_cb(batch
, batch
->user_data
);
740 assert(batch
->next
+ size
<= batch
->end
);
742 memcpy(batch
->next
, other
->start
, size
);
744 offset
= batch
->next
- batch
->start
;
745 anv_reloc_list_append(&batch
->relocs
, batch
->device
,
746 &other
->relocs
, offset
);
752 anv_batch_emit_reloc(struct anv_batch
*batch
,
753 void *location
, struct anv_bo
*bo
, uint32_t delta
)
755 return anv_reloc_list_add(&batch
->relocs
, batch
->device
,
756 location
- batch
->start
, bo
, delta
);
759 VkResult
anv_QueueSubmit(
761 uint32_t cmdBufferCount
,
762 const VkCmdBuffer
* pCmdBuffers
,
765 struct anv_queue
*queue
= (struct anv_queue
*) _queue
;
766 struct anv_device
*device
= queue
->device
;
767 struct anv_fence
*fence
= (struct anv_fence
*) _fence
;
770 for (uint32_t i
= 0; i
< cmdBufferCount
; i
++) {
771 struct anv_cmd_buffer
*cmd_buffer
=
772 (struct anv_cmd_buffer
*) pCmdBuffers
[i
];
774 if (device
->dump_aub
)
775 anv_cmd_buffer_dump(cmd_buffer
);
777 if (!device
->no_hw
) {
778 ret
= anv_gem_execbuffer(device
, &cmd_buffer
->execbuf
);
780 return vk_error(VK_ERROR_UNKNOWN
);
783 ret
= anv_gem_execbuffer(device
, &fence
->execbuf
);
785 return vk_error(VK_ERROR_UNKNOWN
);
788 for (uint32_t i
= 0; i
< cmd_buffer
->bo_count
; i
++)
789 cmd_buffer
->exec2_bos
[i
]->offset
= cmd_buffer
->exec2_objects
[i
].offset
;
791 *(uint32_t *)queue
->completed_serial
.map
= cmd_buffer
->serial
;
798 VkResult
anv_QueueAddMemReferences(
801 const VkDeviceMemory
* pMems
)
806 VkResult
anv_QueueRemoveMemReferences(
809 const VkDeviceMemory
* pMems
)
814 VkResult
anv_QueueWaitIdle(
817 struct anv_queue
*queue
= (struct anv_queue
*) _queue
;
819 return vkDeviceWaitIdle((VkDevice
) queue
->device
);
822 VkResult
anv_DeviceWaitIdle(
825 struct anv_device
*device
= (struct anv_device
*) _device
;
826 struct anv_state state
;
827 struct anv_batch batch
;
828 struct drm_i915_gem_execbuffer2 execbuf
;
829 struct drm_i915_gem_exec_object2 exec2_objects
[1];
830 struct anv_bo
*bo
= NULL
;
835 state
= anv_state_pool_alloc(&device
->dynamic_state_pool
, 32, 32);
836 bo
= &device
->dynamic_state_pool
.block_pool
->bo
;
837 batch
.start
= batch
.next
= state
.map
;
838 batch
.end
= state
.map
+ 32;
839 anv_batch_emit(&batch
, GEN8_MI_BATCH_BUFFER_END
);
840 anv_batch_emit(&batch
, GEN8_MI_NOOP
);
842 exec2_objects
[0].handle
= bo
->gem_handle
;
843 exec2_objects
[0].relocation_count
= 0;
844 exec2_objects
[0].relocs_ptr
= 0;
845 exec2_objects
[0].alignment
= 0;
846 exec2_objects
[0].offset
= bo
->offset
;
847 exec2_objects
[0].flags
= 0;
848 exec2_objects
[0].rsvd1
= 0;
849 exec2_objects
[0].rsvd2
= 0;
851 execbuf
.buffers_ptr
= (uintptr_t) exec2_objects
;
852 execbuf
.buffer_count
= 1;
853 execbuf
.batch_start_offset
= state
.offset
;
854 execbuf
.batch_len
= batch
.next
- state
.map
;
855 execbuf
.cliprects_ptr
= 0;
856 execbuf
.num_cliprects
= 0;
861 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
862 execbuf
.rsvd1
= device
->context_id
;
865 if (!device
->no_hw
) {
866 ret
= anv_gem_execbuffer(device
, &execbuf
);
868 result
= vk_error(VK_ERROR_UNKNOWN
);
873 ret
= anv_gem_wait(device
, bo
->gem_handle
, &timeout
);
875 result
= vk_error(VK_ERROR_UNKNOWN
);
880 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
885 anv_state_pool_free(&device
->dynamic_state_pool
, state
);
891 anv_device_alloc(struct anv_device
* device
,
894 VkSystemAllocType allocType
)
896 return device
->instance
->pfnAlloc(device
->instance
->pAllocUserData
,
903 anv_device_free(struct anv_device
* device
,
906 return device
->instance
->pfnFree(device
->instance
->pAllocUserData
,
911 anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
)
913 bo
->gem_handle
= anv_gem_create(device
, size
);
915 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
925 VkResult
anv_AllocMemory(
927 const VkMemoryAllocInfo
* pAllocInfo
,
928 VkDeviceMemory
* pMem
)
930 struct anv_device
*device
= (struct anv_device
*) _device
;
931 struct anv_device_memory
*mem
;
934 assert(pAllocInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO
);
936 mem
= anv_device_alloc(device
, sizeof(*mem
), 8,
937 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
939 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
941 result
= anv_bo_init_new(&mem
->bo
, device
, pAllocInfo
->allocationSize
);
942 if (result
!= VK_SUCCESS
)
945 *pMem
= (VkDeviceMemory
) mem
;
950 anv_device_free(device
, mem
);
955 VkResult
anv_FreeMemory(
959 struct anv_device
*device
= (struct anv_device
*) _device
;
960 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
963 anv_gem_munmap(mem
->bo
.map
, mem
->bo
.size
);
965 if (mem
->bo
.gem_handle
!= 0)
966 anv_gem_close(device
, mem
->bo
.gem_handle
);
968 anv_device_free(device
, mem
);
973 VkResult
anv_SetMemoryPriority(
976 VkMemoryPriority priority
)
981 VkResult
anv_MapMemory(
986 VkMemoryMapFlags flags
,
989 struct anv_device
*device
= (struct anv_device
*) _device
;
990 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
992 /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only
993 * takes a VkDeviceMemory pointer, it seems like only one map of the memory
994 * at a time is valid. We could just mmap up front and return an offset
995 * pointer here, but that may exhaust virtual memory on 32 bit
998 mem
->map
= anv_gem_mmap(device
, mem
->bo
.gem_handle
, offset
, size
);
999 mem
->map_size
= size
;
1006 VkResult
anv_UnmapMemory(
1008 VkDeviceMemory _mem
)
1010 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
1012 anv_gem_munmap(mem
->map
, mem
->map_size
);
1017 VkResult
anv_FlushMappedMemory(
1020 VkDeviceSize offset
,
1023 /* clflush here for !llc platforms */
1028 VkResult
anv_PinSystemMemory(
1030 const void* pSysMem
,
1032 VkDeviceMemory
* pMem
)
1037 VkResult
anv_GetMultiDeviceCompatibility(
1038 VkPhysicalDevice physicalDevice0
,
1039 VkPhysicalDevice physicalDevice1
,
1040 VkPhysicalDeviceCompatibilityInfo
* pInfo
)
1042 return VK_UNSUPPORTED
;
1045 VkResult
anv_OpenSharedMemory(
1047 const VkMemoryOpenInfo
* pOpenInfo
,
1048 VkDeviceMemory
* pMem
)
1050 return VK_UNSUPPORTED
;
1053 VkResult
anv_OpenSharedSemaphore(
1055 const VkSemaphoreOpenInfo
* pOpenInfo
,
1056 VkSemaphore
* pSemaphore
)
1058 return VK_UNSUPPORTED
;
1061 VkResult
anv_OpenPeerMemory(
1063 const VkPeerMemoryOpenInfo
* pOpenInfo
,
1064 VkDeviceMemory
* pMem
)
1066 return VK_UNSUPPORTED
;
1069 VkResult
anv_OpenPeerImage(
1071 const VkPeerImageOpenInfo
* pOpenInfo
,
1073 VkDeviceMemory
* pMem
)
1075 return VK_UNSUPPORTED
;
1078 VkResult
anv_DestroyObject(
1080 VkObjectType objType
,
1083 struct anv_device
*device
= (struct anv_device
*) _device
;
1084 struct anv_object
*object
= (struct anv_object
*) _object
;
1087 case VK_OBJECT_TYPE_INSTANCE
:
1088 return anv_DestroyInstance((VkInstance
) _object
);
1090 case VK_OBJECT_TYPE_PHYSICAL_DEVICE
:
1091 /* We don't want to actually destroy physical devices */
1094 case VK_OBJECT_TYPE_DEVICE
:
1095 assert(_device
== (VkDevice
) _object
);
1096 return anv_DestroyDevice((VkDevice
) _object
);
1098 case VK_OBJECT_TYPE_QUEUE
:
1102 case VK_OBJECT_TYPE_DEVICE_MEMORY
:
1103 return anv_FreeMemory(_device
, (VkDeviceMemory
) _object
);
1105 case VK_OBJECT_TYPE_DESCRIPTOR_POOL
:
1106 /* These are just dummys anyway, so we don't need to destroy them */
1109 case VK_OBJECT_TYPE_BUFFER
:
1110 case VK_OBJECT_TYPE_IMAGE
:
1111 case VK_OBJECT_TYPE_DEPTH_STENCIL_VIEW
:
1112 case VK_OBJECT_TYPE_SHADER
:
1113 case VK_OBJECT_TYPE_PIPELINE_LAYOUT
:
1114 case VK_OBJECT_TYPE_SAMPLER
:
1115 case VK_OBJECT_TYPE_DESCRIPTOR_SET
:
1116 case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT
:
1117 case VK_OBJECT_TYPE_DYNAMIC_RS_STATE
:
1118 case VK_OBJECT_TYPE_DYNAMIC_CB_STATE
:
1119 case VK_OBJECT_TYPE_DYNAMIC_DS_STATE
:
1120 case VK_OBJECT_TYPE_RENDER_PASS
:
1121 /* These are trivially destroyable */
1122 anv_device_free(device
, (void *) _object
);
1125 case VK_OBJECT_TYPE_COMMAND_BUFFER
:
1126 case VK_OBJECT_TYPE_PIPELINE
:
1127 case VK_OBJECT_TYPE_DYNAMIC_VP_STATE
:
1128 case VK_OBJECT_TYPE_FENCE
:
1129 case VK_OBJECT_TYPE_QUERY_POOL
:
1130 case VK_OBJECT_TYPE_FRAMEBUFFER
:
1131 case VK_OBJECT_TYPE_BUFFER_VIEW
:
1132 case VK_OBJECT_TYPE_IMAGE_VIEW
:
1133 case VK_OBJECT_TYPE_COLOR_ATTACHMENT_VIEW
:
1134 (object
->destructor
)(device
, object
, objType
);
1137 case VK_OBJECT_TYPE_SEMAPHORE
:
1138 case VK_OBJECT_TYPE_EVENT
:
1139 stub_return(VK_UNSUPPORTED
);
1142 unreachable("Invalid object type");
1147 fill_memory_requirements(
1148 VkObjectType objType
,
1150 VkMemoryRequirements
* memory_requirements
)
1152 struct anv_buffer
*buffer
;
1153 struct anv_image
*image
;
1155 memory_requirements
->memPropsAllowed
=
1156 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1157 VK_MEMORY_PROPERTY_HOST_DEVICE_COHERENT_BIT
|
1158 /* VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT | */
1159 VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT
|
1160 VK_MEMORY_PROPERTY_PREFER_HOST_LOCAL
|
1161 VK_MEMORY_PROPERTY_SHAREABLE_BIT
;
1163 memory_requirements
->memPropsRequired
= 0;
1166 case VK_OBJECT_TYPE_BUFFER
:
1167 buffer
= (struct anv_buffer
*) object
;
1168 memory_requirements
->size
= buffer
->size
;
1169 memory_requirements
->alignment
= 16;
1171 case VK_OBJECT_TYPE_IMAGE
:
1172 image
= (struct anv_image
*) object
;
1173 memory_requirements
->size
= image
->size
;
1174 memory_requirements
->alignment
= image
->alignment
;
1177 memory_requirements
->size
= 0;
1183 get_allocation_count(VkObjectType objType
)
1186 case VK_OBJECT_TYPE_BUFFER
:
1187 case VK_OBJECT_TYPE_IMAGE
:
1194 VkResult
anv_GetObjectInfo(
1196 VkObjectType objType
,
1198 VkObjectInfoType infoType
,
1202 VkMemoryRequirements memory_requirements
;
1206 case VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS
:
1207 *pDataSize
= sizeof(memory_requirements
);
1211 fill_memory_requirements(objType
, object
, pData
);
1214 case VK_OBJECT_INFO_TYPE_MEMORY_ALLOCATION_COUNT
:
1215 *pDataSize
= sizeof(count
);
1220 *count
= get_allocation_count(objType
);
1224 return vk_error(VK_UNSUPPORTED
);
1229 VkResult
anv_QueueBindObjectMemory(
1231 VkObjectType objType
,
1233 uint32_t allocationIdx
,
1234 VkDeviceMemory _mem
,
1235 VkDeviceSize memOffset
)
1237 struct anv_buffer
*buffer
;
1238 struct anv_image
*image
;
1239 struct anv_device_memory
*mem
= (struct anv_device_memory
*) _mem
;
1242 case VK_OBJECT_TYPE_BUFFER
:
1243 buffer
= (struct anv_buffer
*) object
;
1244 buffer
->bo
= &mem
->bo
;
1245 buffer
->offset
= memOffset
;
1247 case VK_OBJECT_TYPE_IMAGE
:
1248 image
= (struct anv_image
*) object
;
1249 image
->bo
= &mem
->bo
;
1250 image
->offset
= memOffset
;
1259 VkResult
anv_QueueBindObjectMemoryRange(
1261 VkObjectType objType
,
1263 uint32_t allocationIdx
,
1264 VkDeviceSize rangeOffset
,
1265 VkDeviceSize rangeSize
,
1267 VkDeviceSize memOffset
)
1269 stub_return(VK_UNSUPPORTED
);
1272 VkResult
anv_QueueBindImageMemoryRange(
1275 uint32_t allocationIdx
,
1276 const VkImageMemoryBindInfo
* pBindInfo
,
1278 VkDeviceSize memOffset
)
1280 stub_return(VK_UNSUPPORTED
);
1284 anv_fence_destroy(struct anv_device
*device
,
1285 struct anv_object
*object
,
1286 VkObjectType obj_type
)
1288 struct anv_fence
*fence
= (struct anv_fence
*) object
;
1290 assert(obj_type
== VK_OBJECT_TYPE_FENCE
);
1292 anv_gem_munmap(fence
->bo
.map
, fence
->bo
.size
);
1293 anv_gem_close(device
, fence
->bo
.gem_handle
);
1294 anv_device_free(device
, fence
);
1297 VkResult
anv_CreateFence(
1299 const VkFenceCreateInfo
* pCreateInfo
,
1302 struct anv_device
*device
= (struct anv_device
*) _device
;
1303 struct anv_fence
*fence
;
1304 struct anv_batch batch
;
1307 const uint32_t fence_size
= 128;
1309 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
);
1311 fence
= anv_device_alloc(device
, sizeof(*fence
), 8,
1312 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1314 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1316 result
= anv_bo_init_new(&fence
->bo
, device
, fence_size
);
1317 if (result
!= VK_SUCCESS
)
1320 fence
->base
.destructor
= anv_fence_destroy
;
1323 anv_gem_mmap(device
, fence
->bo
.gem_handle
, 0, fence
->bo
.size
);
1324 batch
.next
= batch
.start
= fence
->bo
.map
;
1325 batch
.end
= fence
->bo
.map
+ fence
->bo
.size
;
1326 anv_batch_emit(&batch
, GEN8_MI_BATCH_BUFFER_END
);
1327 anv_batch_emit(&batch
, GEN8_MI_NOOP
);
1329 fence
->exec2_objects
[0].handle
= fence
->bo
.gem_handle
;
1330 fence
->exec2_objects
[0].relocation_count
= 0;
1331 fence
->exec2_objects
[0].relocs_ptr
= 0;
1332 fence
->exec2_objects
[0].alignment
= 0;
1333 fence
->exec2_objects
[0].offset
= fence
->bo
.offset
;
1334 fence
->exec2_objects
[0].flags
= 0;
1335 fence
->exec2_objects
[0].rsvd1
= 0;
1336 fence
->exec2_objects
[0].rsvd2
= 0;
1338 fence
->execbuf
.buffers_ptr
= (uintptr_t) fence
->exec2_objects
;
1339 fence
->execbuf
.buffer_count
= 1;
1340 fence
->execbuf
.batch_start_offset
= 0;
1341 fence
->execbuf
.batch_len
= batch
.next
- fence
->bo
.map
;
1342 fence
->execbuf
.cliprects_ptr
= 0;
1343 fence
->execbuf
.num_cliprects
= 0;
1344 fence
->execbuf
.DR1
= 0;
1345 fence
->execbuf
.DR4
= 0;
1347 fence
->execbuf
.flags
=
1348 I915_EXEC_HANDLE_LUT
| I915_EXEC_NO_RELOC
| I915_EXEC_RENDER
;
1349 fence
->execbuf
.rsvd1
= device
->context_id
;
1350 fence
->execbuf
.rsvd2
= 0;
1352 *pFence
= (VkFence
) fence
;
1357 anv_device_free(device
, fence
);
1362 VkResult
anv_ResetFences(
1364 uint32_t fenceCount
,
1367 struct anv_fence
**fences
= (struct anv_fence
**) pFences
;
1369 for (uint32_t i
= 0; i
< fenceCount
; i
++)
1370 fences
[i
]->ready
= false;
1375 VkResult
anv_GetFenceStatus(
1379 struct anv_device
*device
= (struct anv_device
*) _device
;
1380 struct anv_fence
*fence
= (struct anv_fence
*) _fence
;
1387 ret
= anv_gem_wait(device
, fence
->bo
.gem_handle
, &t
);
1389 fence
->ready
= true;
1393 return VK_NOT_READY
;
1396 VkResult
anv_WaitForFences(
1398 uint32_t fenceCount
,
1399 const VkFence
* pFences
,
1403 struct anv_device
*device
= (struct anv_device
*) _device
;
1404 struct anv_fence
**fences
= (struct anv_fence
**) pFences
;
1405 int64_t t
= timeout
;
1408 /* FIXME: handle !waitAll */
1410 for (uint32_t i
= 0; i
< fenceCount
; i
++) {
1411 ret
= anv_gem_wait(device
, fences
[i
]->bo
.gem_handle
, &t
);
1412 if (ret
== -1 && errno
== ETIME
)
1415 return vk_error(VK_ERROR_UNKNOWN
);
1421 // Queue semaphore functions
1423 VkResult
anv_CreateSemaphore(
1425 const VkSemaphoreCreateInfo
* pCreateInfo
,
1426 VkSemaphore
* pSemaphore
)
1428 stub_return(VK_UNSUPPORTED
);
1431 VkResult
anv_QueueSignalSemaphore(
1433 VkSemaphore semaphore
)
1435 stub_return(VK_UNSUPPORTED
);
1438 VkResult
anv_QueueWaitSemaphore(
1440 VkSemaphore semaphore
)
1442 stub_return(VK_UNSUPPORTED
);
1447 VkResult
anv_CreateEvent(
1449 const VkEventCreateInfo
* pCreateInfo
,
1452 stub_return(VK_UNSUPPORTED
);
1455 VkResult
anv_GetEventStatus(
1459 stub_return(VK_UNSUPPORTED
);
1462 VkResult
anv_SetEvent(
1466 stub_return(VK_UNSUPPORTED
);
1469 VkResult
anv_ResetEvent(
1473 stub_return(VK_UNSUPPORTED
);
1478 VkResult
anv_CreateBuffer(
1480 const VkBufferCreateInfo
* pCreateInfo
,
1483 struct anv_device
*device
= (struct anv_device
*) _device
;
1484 struct anv_buffer
*buffer
;
1486 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1488 buffer
= anv_device_alloc(device
, sizeof(*buffer
), 8,
1489 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1491 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1493 buffer
->size
= pCreateInfo
->size
;
1497 *pBuffer
= (VkBuffer
) buffer
;
1502 // Buffer view functions
1505 fill_buffer_surface_state(void *state
, VkFormat format
,
1506 uint32_t offset
, uint32_t range
)
1508 const struct anv_format
*info
;
1510 info
= anv_format_for_vk_format(format
);
1511 /* This assumes RGBA float format. */
1512 uint32_t stride
= 4;
1513 uint32_t num_elements
= range
/ stride
;
1515 struct GEN8_RENDER_SURFACE_STATE surface_state
= {
1516 .SurfaceType
= SURFTYPE_BUFFER
,
1517 .SurfaceArray
= false,
1518 .SurfaceFormat
= info
->format
,
1519 .SurfaceVerticalAlignment
= VALIGN4
,
1520 .SurfaceHorizontalAlignment
= HALIGN4
,
1522 .VerticalLineStride
= 0,
1523 .VerticalLineStrideOffset
= 0,
1524 .SamplerL2BypassModeDisable
= true,
1525 .RenderCacheReadWriteMode
= WriteOnlyCache
,
1526 .MemoryObjectControlState
= GEN8_MOCS
,
1527 .BaseMipLevel
= 0.0,
1529 .Height
= (num_elements
>> 7) & 0x3fff,
1530 .Width
= num_elements
& 0x7f,
1531 .Depth
= (num_elements
>> 21) & 0x3f,
1532 .SurfacePitch
= stride
- 1,
1533 .MinimumArrayElement
= 0,
1534 .NumberofMultisamples
= MULTISAMPLECOUNT_1
,
1539 .AuxiliarySurfaceMode
= AUX_NONE
,
1541 .GreenClearColor
= 0,
1542 .BlueClearColor
= 0,
1543 .AlphaClearColor
= 0,
1544 .ShaderChannelSelectRed
= SCS_RED
,
1545 .ShaderChannelSelectGreen
= SCS_GREEN
,
1546 .ShaderChannelSelectBlue
= SCS_BLUE
,
1547 .ShaderChannelSelectAlpha
= SCS_ALPHA
,
1548 .ResourceMinLOD
= 0.0,
1549 /* FIXME: We assume that the image must be bound at this time. */
1550 .SurfaceBaseAddress
= { NULL
, offset
},
1553 GEN8_RENDER_SURFACE_STATE_pack(NULL
, state
, &surface_state
);
1556 VkResult
anv_CreateBufferView(
1558 const VkBufferViewCreateInfo
* pCreateInfo
,
1559 VkBufferView
* pView
)
1561 struct anv_device
*device
= (struct anv_device
*) _device
;
1562 struct anv_buffer
*buffer
= (struct anv_buffer
*) pCreateInfo
->buffer
;
1563 struct anv_surface_view
*view
;
1565 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO
);
1567 view
= anv_device_alloc(device
, sizeof(*view
), 8,
1568 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1570 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1572 view
->base
.destructor
= anv_surface_view_destroy
;
1574 view
->bo
= buffer
->bo
;
1575 view
->offset
= buffer
->offset
+ pCreateInfo
->offset
;
1576 view
->surface_state
=
1577 anv_state_pool_alloc(&device
->surface_state_pool
, 64, 64);
1578 view
->format
= pCreateInfo
->format
;
1579 view
->range
= pCreateInfo
->range
;
1581 fill_buffer_surface_state(view
->surface_state
.map
,
1582 pCreateInfo
->format
, view
->offset
, pCreateInfo
->range
);
1584 *pView
= (VkBufferView
) view
;
1589 // Sampler functions
1591 VkResult
anv_CreateSampler(
1593 const VkSamplerCreateInfo
* pCreateInfo
,
1594 VkSampler
* pSampler
)
1596 struct anv_device
*device
= (struct anv_device
*) _device
;
1597 struct anv_sampler
*sampler
;
1598 uint32_t mag_filter
, min_filter
, max_anisotropy
;
1600 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
1602 sampler
= anv_device_alloc(device
, sizeof(*sampler
), 8,
1603 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1605 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1607 static const uint32_t vk_to_gen_tex_filter
[] = {
1608 [VK_TEX_FILTER_NEAREST
] = MAPFILTER_NEAREST
,
1609 [VK_TEX_FILTER_LINEAR
] = MAPFILTER_LINEAR
1612 static const uint32_t vk_to_gen_mipmap_mode
[] = {
1613 [VK_TEX_MIPMAP_MODE_BASE
] = MIPFILTER_NONE
,
1614 [VK_TEX_MIPMAP_MODE_NEAREST
] = MIPFILTER_NEAREST
,
1615 [VK_TEX_MIPMAP_MODE_LINEAR
] = MIPFILTER_LINEAR
1618 static const uint32_t vk_to_gen_tex_address
[] = {
1619 [VK_TEX_ADDRESS_WRAP
] = TCM_WRAP
,
1620 [VK_TEX_ADDRESS_MIRROR
] = TCM_MIRROR
,
1621 [VK_TEX_ADDRESS_CLAMP
] = TCM_CLAMP
,
1622 [VK_TEX_ADDRESS_MIRROR_ONCE
] = TCM_MIRROR_ONCE
,
1623 [VK_TEX_ADDRESS_CLAMP_BORDER
] = TCM_CLAMP_BORDER
,
1626 static const uint32_t vk_to_gen_compare_op
[] = {
1627 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
1628 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
1629 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
1630 [VK_COMPARE_OP_LESS_EQUAL
] = PREFILTEROPLEQUAL
,
1631 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
1632 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
1633 [VK_COMPARE_OP_GREATER_EQUAL
] = PREFILTEROPGEQUAL
,
1634 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,
1637 if (pCreateInfo
->maxAnisotropy
> 1) {
1638 mag_filter
= MAPFILTER_ANISOTROPIC
;
1639 min_filter
= MAPFILTER_ANISOTROPIC
;
1640 max_anisotropy
= (pCreateInfo
->maxAnisotropy
- 2) / 2;
1642 mag_filter
= vk_to_gen_tex_filter
[pCreateInfo
->magFilter
];
1643 min_filter
= vk_to_gen_tex_filter
[pCreateInfo
->minFilter
];
1644 max_anisotropy
= RATIO21
;
1647 struct GEN8_SAMPLER_STATE sampler_state
= {
1648 .SamplerDisable
= false,
1649 .TextureBorderColorMode
= DX10OGL
,
1650 .LODPreClampMode
= 0,
1651 .BaseMipLevel
= 0.0,
1652 .MipModeFilter
= vk_to_gen_mipmap_mode
[pCreateInfo
->mipMode
],
1653 .MagModeFilter
= mag_filter
,
1654 .MinModeFilter
= min_filter
,
1655 .TextureLODBias
= pCreateInfo
->mipLodBias
* 256,
1656 .AnisotropicAlgorithm
= EWAApproximation
,
1657 .MinLOD
= pCreateInfo
->minLod
,
1658 .MaxLOD
= pCreateInfo
->maxLod
,
1659 .ChromaKeyEnable
= 0,
1660 .ChromaKeyIndex
= 0,
1662 .ShadowFunction
= vk_to_gen_compare_op
[pCreateInfo
->compareOp
],
1663 .CubeSurfaceControlMode
= 0,
1665 .IndirectStatePointer
=
1666 device
->float_border_colors
.offset
+
1667 pCreateInfo
->borderColor
* sizeof(float) * 4,
1669 .LODClampMagnificationMode
= MIPNONE
,
1670 .MaximumAnisotropy
= max_anisotropy
,
1671 .RAddressMinFilterRoundingEnable
= 0,
1672 .RAddressMagFilterRoundingEnable
= 0,
1673 .VAddressMinFilterRoundingEnable
= 0,
1674 .VAddressMagFilterRoundingEnable
= 0,
1675 .UAddressMinFilterRoundingEnable
= 0,
1676 .UAddressMagFilterRoundingEnable
= 0,
1677 .TrilinearFilterQuality
= 0,
1678 .NonnormalizedCoordinateEnable
= 0,
1679 .TCXAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressU
],
1680 .TCYAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressV
],
1681 .TCZAddressControlMode
= vk_to_gen_tex_address
[pCreateInfo
->addressW
],
1684 GEN8_SAMPLER_STATE_pack(NULL
, sampler
->state
, &sampler_state
);
1686 *pSampler
= (VkSampler
) sampler
;
1691 // Descriptor set functions
1693 VkResult
anv_CreateDescriptorSetLayout(
1695 const VkDescriptorSetLayoutCreateInfo
* pCreateInfo
,
1696 VkDescriptorSetLayout
* pSetLayout
)
1698 struct anv_device
*device
= (struct anv_device
*) _device
;
1699 struct anv_descriptor_set_layout
*set_layout
;
1701 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
);
1703 uint32_t sampler_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1704 uint32_t surface_count
[VK_NUM_SHADER_STAGE
] = { 0, };
1705 uint32_t num_dynamic_buffers
= 0;
1707 uint32_t stages
= 0;
1710 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1711 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1712 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1713 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1714 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1715 sampler_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1721 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1722 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1723 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1724 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1725 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1726 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1727 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1728 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1729 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1730 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1731 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1732 surface_count
[s
] += pCreateInfo
->pBinding
[i
].count
;
1738 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1739 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1740 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1741 num_dynamic_buffers
+= pCreateInfo
->pBinding
[i
].count
;
1747 stages
|= pCreateInfo
->pBinding
[i
].stageFlags
;
1748 count
+= pCreateInfo
->pBinding
[i
].count
;
1751 uint32_t sampler_total
= 0;
1752 uint32_t surface_total
= 0;
1753 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1754 sampler_total
+= sampler_count
[s
];
1755 surface_total
+= surface_count
[s
];
1758 size_t size
= sizeof(*set_layout
) +
1759 (sampler_total
+ surface_total
) * sizeof(set_layout
->entries
[0]);
1760 set_layout
= anv_device_alloc(device
, size
, 8,
1761 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1763 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1765 set_layout
->num_dynamic_buffers
= num_dynamic_buffers
;
1766 set_layout
->count
= count
;
1767 set_layout
->shader_stages
= stages
;
1769 struct anv_descriptor_slot
*p
= set_layout
->entries
;
1770 struct anv_descriptor_slot
*sampler
[VK_NUM_SHADER_STAGE
];
1771 struct anv_descriptor_slot
*surface
[VK_NUM_SHADER_STAGE
];
1772 for (uint32_t s
= 0; s
< VK_NUM_SHADER_STAGE
; s
++) {
1773 set_layout
->stage
[s
].surface_count
= surface_count
[s
];
1774 set_layout
->stage
[s
].surface_start
= surface
[s
] = p
;
1775 p
+= surface_count
[s
];
1776 set_layout
->stage
[s
].sampler_count
= sampler_count
[s
];
1777 set_layout
->stage
[s
].sampler_start
= sampler
[s
] = p
;
1778 p
+= sampler_count
[s
];
1781 uint32_t descriptor
= 0;
1782 int8_t dynamic_slot
= 0;
1784 for (uint32_t i
= 0; i
< pCreateInfo
->count
; i
++) {
1785 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1786 case VK_DESCRIPTOR_TYPE_SAMPLER
:
1787 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1788 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1789 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++) {
1790 sampler
[s
]->index
= descriptor
+ j
;
1791 sampler
[s
]->dynamic_slot
= -1;
1799 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1800 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1801 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1809 switch (pCreateInfo
->pBinding
[i
].descriptorType
) {
1810 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
:
1811 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
:
1812 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
:
1813 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
:
1814 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
:
1815 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
:
1816 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
:
1817 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
:
1818 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
:
1819 for_each_bit(s
, pCreateInfo
->pBinding
[i
].stageFlags
)
1820 for (uint32_t j
= 0; j
< pCreateInfo
->pBinding
[i
].count
; j
++) {
1821 surface
[s
]->index
= descriptor
+ j
;
1823 surface
[s
]->dynamic_slot
= dynamic_slot
+ j
;
1825 surface
[s
]->dynamic_slot
= -1;
1834 dynamic_slot
+= pCreateInfo
->pBinding
[i
].count
;
1836 descriptor
+= pCreateInfo
->pBinding
[i
].count
;
1839 *pSetLayout
= (VkDescriptorSetLayout
) set_layout
;
1844 VkResult
anv_BeginDescriptorPoolUpdate(
1846 VkDescriptorUpdateMode updateMode
)
1851 VkResult
anv_EndDescriptorPoolUpdate(
1858 VkResult
anv_CreateDescriptorPool(
1860 VkDescriptorPoolUsage poolUsage
,
1862 const VkDescriptorPoolCreateInfo
* pCreateInfo
,
1863 VkDescriptorPool
* pDescriptorPool
)
1865 *pDescriptorPool
= 1;
1870 VkResult
anv_ResetDescriptorPool(
1872 VkDescriptorPool descriptorPool
)
1877 VkResult
anv_AllocDescriptorSets(
1879 VkDescriptorPool descriptorPool
,
1880 VkDescriptorSetUsage setUsage
,
1882 const VkDescriptorSetLayout
* pSetLayouts
,
1883 VkDescriptorSet
* pDescriptorSets
,
1886 struct anv_device
*device
= (struct anv_device
*) _device
;
1887 const struct anv_descriptor_set_layout
*layout
;
1888 struct anv_descriptor_set
*set
;
1891 for (uint32_t i
= 0; i
< count
; i
++) {
1892 layout
= (struct anv_descriptor_set_layout
*) pSetLayouts
[i
];
1893 size
= sizeof(*set
) + layout
->count
* sizeof(set
->descriptors
[0]);
1894 set
= anv_device_alloc(device
, size
, 8,
1895 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
1898 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1901 /* Descriptor sets may not be 100% filled out so we need to memset to
1902 * ensure that we can properly detect and handle holes.
1904 memset(set
, 0, size
);
1906 pDescriptorSets
[i
] = (VkDescriptorSet
) set
;
1914 void anv_ClearDescriptorSets(
1916 VkDescriptorPool descriptorPool
,
1918 const VkDescriptorSet
* pDescriptorSets
)
1922 void anv_UpdateDescriptors(
1924 VkDescriptorSet descriptorSet
,
1925 uint32_t updateCount
,
1926 const void** ppUpdateArray
)
1928 struct anv_descriptor_set
*set
= (struct anv_descriptor_set
*) descriptorSet
;
1929 VkUpdateSamplers
*update_samplers
;
1930 VkUpdateSamplerTextures
*update_sampler_textures
;
1931 VkUpdateImages
*update_images
;
1932 VkUpdateBuffers
*update_buffers
;
1933 VkUpdateAsCopy
*update_as_copy
;
1935 for (uint32_t i
= 0; i
< updateCount
; i
++) {
1936 const struct anv_common
*common
= ppUpdateArray
[i
];
1938 switch (common
->sType
) {
1939 case VK_STRUCTURE_TYPE_UPDATE_SAMPLERS
:
1940 update_samplers
= (VkUpdateSamplers
*) common
;
1942 for (uint32_t j
= 0; j
< update_samplers
->count
; j
++) {
1943 set
->descriptors
[update_samplers
->binding
+ j
].sampler
=
1944 (struct anv_sampler
*) update_samplers
->pSamplers
[j
];
1948 case VK_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES
:
1949 /* FIXME: Shouldn't this be *_UPDATE_SAMPLER_IMAGES? */
1950 update_sampler_textures
= (VkUpdateSamplerTextures
*) common
;
1952 for (uint32_t j
= 0; j
< update_sampler_textures
->count
; j
++) {
1953 set
->descriptors
[update_sampler_textures
->binding
+ j
].view
=
1954 (struct anv_surface_view
*)
1955 update_sampler_textures
->pSamplerImageViews
[j
].pImageView
->view
;
1956 set
->descriptors
[update_sampler_textures
->binding
+ j
].sampler
=
1957 (struct anv_sampler
*)
1958 update_sampler_textures
->pSamplerImageViews
[j
].sampler
;
1962 case VK_STRUCTURE_TYPE_UPDATE_IMAGES
:
1963 update_images
= (VkUpdateImages
*) common
;
1965 for (uint32_t j
= 0; j
< update_images
->count
; j
++) {
1966 set
->descriptors
[update_images
->binding
+ j
].view
=
1967 (struct anv_surface_view
*) update_images
->pImageViews
[j
].view
;
1971 case VK_STRUCTURE_TYPE_UPDATE_BUFFERS
:
1972 update_buffers
= (VkUpdateBuffers
*) common
;
1974 for (uint32_t j
= 0; j
< update_buffers
->count
; j
++) {
1975 set
->descriptors
[update_buffers
->binding
+ j
].view
=
1976 (struct anv_surface_view
*) update_buffers
->pBufferViews
[j
].view
;
1978 /* FIXME: descriptor arrays? */
1981 case VK_STRUCTURE_TYPE_UPDATE_AS_COPY
:
1982 update_as_copy
= (VkUpdateAsCopy
*) common
;
1983 (void) update_as_copy
;
1992 // State object functions
1994 static inline int64_t
1995 clamp_int64(int64_t x
, int64_t min
, int64_t max
)
2006 anv_dynamic_vp_state_destroy(struct anv_device
*device
,
2007 struct anv_object
*object
,
2008 VkObjectType obj_type
)
2010 struct anv_dynamic_vp_state
*state
= (void *)object
;
2012 assert(obj_type
== VK_OBJECT_TYPE_DYNAMIC_VP_STATE
);
2014 anv_state_pool_free(&device
->dynamic_state_pool
, state
->sf_clip_vp
);
2015 anv_state_pool_free(&device
->dynamic_state_pool
, state
->cc_vp
);
2016 anv_state_pool_free(&device
->dynamic_state_pool
, state
->scissor
);
2018 anv_device_free(device
, state
);
2021 VkResult
anv_CreateDynamicViewportState(
2023 const VkDynamicVpStateCreateInfo
* pCreateInfo
,
2024 VkDynamicVpState
* pState
)
2026 struct anv_device
*device
= (struct anv_device
*) _device
;
2027 struct anv_dynamic_vp_state
*state
;
2029 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
);
2031 state
= anv_device_alloc(device
, sizeof(*state
), 8,
2032 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2034 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2036 state
->base
.destructor
= anv_dynamic_vp_state_destroy
;
2038 unsigned count
= pCreateInfo
->viewportAndScissorCount
;
2039 state
->sf_clip_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2041 state
->cc_vp
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2043 state
->scissor
= anv_state_pool_alloc(&device
->dynamic_state_pool
,
2046 for (uint32_t i
= 0; i
< pCreateInfo
->viewportAndScissorCount
; i
++) {
2047 const VkViewport
*vp
= &pCreateInfo
->pViewports
[i
];
2048 const VkRect
*s
= &pCreateInfo
->pScissors
[i
];
2050 struct GEN8_SF_CLIP_VIEWPORT sf_clip_viewport
= {
2051 .ViewportMatrixElementm00
= vp
->width
/ 2,
2052 .ViewportMatrixElementm11
= vp
->height
/ 2,
2053 .ViewportMatrixElementm22
= (vp
->maxDepth
- vp
->minDepth
) / 2,
2054 .ViewportMatrixElementm30
= vp
->originX
+ vp
->width
/ 2,
2055 .ViewportMatrixElementm31
= vp
->originY
+ vp
->height
/ 2,
2056 .ViewportMatrixElementm32
= (vp
->maxDepth
+ vp
->minDepth
) / 2,
2057 .XMinClipGuardband
= -1.0f
,
2058 .XMaxClipGuardband
= 1.0f
,
2059 .YMinClipGuardband
= -1.0f
,
2060 .YMaxClipGuardband
= 1.0f
,
2061 .XMinViewPort
= vp
->originX
,
2062 .XMaxViewPort
= vp
->originX
+ vp
->width
- 1,
2063 .YMinViewPort
= vp
->originY
,
2064 .YMaxViewPort
= vp
->originY
+ vp
->height
- 1,
2067 struct GEN8_CC_VIEWPORT cc_viewport
= {
2068 .MinimumDepth
= vp
->minDepth
,
2069 .MaximumDepth
= vp
->maxDepth
2072 /* Since xmax and ymax are inclusive, we have to have xmax < xmin or
2073 * ymax < ymin for empty clips. In case clip x, y, width height are all
2074 * 0, the clamps below produce 0 for xmin, ymin, xmax, ymax, which isn't
2075 * what we want. Just special case empty clips and produce a canonical
2077 static const struct GEN8_SCISSOR_RECT empty_scissor
= {
2078 .ScissorRectangleYMin
= 1,
2079 .ScissorRectangleXMin
= 1,
2080 .ScissorRectangleYMax
= 0,
2081 .ScissorRectangleXMax
= 0
2084 const int max
= 0xffff;
2085 struct GEN8_SCISSOR_RECT scissor
= {
2086 /* Do this math using int64_t so overflow gets clamped correctly. */
2087 .ScissorRectangleYMin
= clamp_int64(s
->offset
.y
, 0, max
),
2088 .ScissorRectangleXMin
= clamp_int64(s
->offset
.x
, 0, max
),
2089 .ScissorRectangleYMax
= clamp_int64((uint64_t) s
->offset
.y
+ s
->extent
.height
- 1, 0, max
),
2090 .ScissorRectangleXMax
= clamp_int64((uint64_t) s
->offset
.x
+ s
->extent
.width
- 1, 0, max
)
2093 GEN8_SF_CLIP_VIEWPORT_pack(NULL
, state
->sf_clip_vp
.map
+ i
* 64, &sf_clip_viewport
);
2094 GEN8_CC_VIEWPORT_pack(NULL
, state
->cc_vp
.map
+ i
* 32, &cc_viewport
);
2096 if (s
->extent
.width
<= 0 || s
->extent
.height
<= 0) {
2097 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &empty_scissor
);
2099 GEN8_SCISSOR_RECT_pack(NULL
, state
->scissor
.map
+ i
* 32, &scissor
);
2103 *pState
= (VkDynamicVpState
) state
;
2108 VkResult
anv_CreateDynamicRasterState(
2110 const VkDynamicRsStateCreateInfo
* pCreateInfo
,
2111 VkDynamicRsState
* pState
)
2113 struct anv_device
*device
= (struct anv_device
*) _device
;
2114 struct anv_dynamic_rs_state
*state
;
2116 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO
);
2118 state
= anv_device_alloc(device
, sizeof(*state
), 8,
2119 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2121 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2124 * float pointFadeThreshold;
2125 * // optional (GL45) - Size of point fade threshold
2128 struct GEN8_3DSTATE_SF sf
= {
2129 GEN8_3DSTATE_SF_header
,
2130 .LineWidth
= pCreateInfo
->lineWidth
,
2131 .PointWidth
= pCreateInfo
->pointSize
,
2134 GEN8_3DSTATE_SF_pack(NULL
, state
->state_sf
, &sf
);
2136 bool enable_bias
= pCreateInfo
->depthBias
!= 0.0f
||
2137 pCreateInfo
->slopeScaledDepthBias
!= 0.0f
;
2138 struct GEN8_3DSTATE_RASTER raster
= {
2139 .GlobalDepthOffsetEnableSolid
= enable_bias
,
2140 .GlobalDepthOffsetEnableWireframe
= enable_bias
,
2141 .GlobalDepthOffsetEnablePoint
= enable_bias
,
2142 .GlobalDepthOffsetConstant
= pCreateInfo
->depthBias
,
2143 .GlobalDepthOffsetScale
= pCreateInfo
->slopeScaledDepthBias
,
2144 .GlobalDepthOffsetClamp
= pCreateInfo
->depthBiasClamp
2147 GEN8_3DSTATE_RASTER_pack(NULL
, state
->state_raster
, &raster
);
2149 *pState
= (VkDynamicRsState
) state
;
2154 VkResult
anv_CreateDynamicColorBlendState(
2156 const VkDynamicCbStateCreateInfo
* pCreateInfo
,
2157 VkDynamicCbState
* pState
)
2159 struct anv_device
*device
= (struct anv_device
*) _device
;
2160 struct anv_dynamic_cb_state
*state
;
2162 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO
);
2164 state
= anv_device_alloc(device
, sizeof(*state
), 8,
2165 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2167 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2169 struct GEN8_COLOR_CALC_STATE color_calc_state
= {
2170 .BlendConstantColorRed
= pCreateInfo
->blendConst
[0],
2171 .BlendConstantColorGreen
= pCreateInfo
->blendConst
[1],
2172 .BlendConstantColorBlue
= pCreateInfo
->blendConst
[2],
2173 .BlendConstantColorAlpha
= pCreateInfo
->blendConst
[3]
2176 GEN8_COLOR_CALC_STATE_pack(NULL
, state
->state_color_calc
, &color_calc_state
);
2178 *pState
= (VkDynamicCbState
) state
;
2183 VkResult
anv_CreateDynamicDepthStencilState(
2185 const VkDynamicDsStateCreateInfo
* pCreateInfo
,
2186 VkDynamicDsState
* pState
)
2188 struct anv_device
*device
= (struct anv_device
*) _device
;
2189 struct anv_dynamic_ds_state
*state
;
2191 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO
);
2193 state
= anv_device_alloc(device
, sizeof(*state
), 8,
2194 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2196 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2198 struct GEN8_3DSTATE_WM_DEPTH_STENCIL wm_depth_stencil
= {
2199 GEN8_3DSTATE_WM_DEPTH_STENCIL_header
,
2201 /* Is this what we need to do? */
2202 .StencilBufferWriteEnable
= pCreateInfo
->stencilWriteMask
!= 0,
2204 .StencilTestMask
= pCreateInfo
->stencilReadMask
& 0xff,
2205 .StencilWriteMask
= pCreateInfo
->stencilWriteMask
& 0xff,
2207 .BackfaceStencilTestMask
= pCreateInfo
->stencilReadMask
& 0xff,
2208 .BackfaceStencilWriteMask
= pCreateInfo
->stencilWriteMask
& 0xff,
2211 GEN8_3DSTATE_WM_DEPTH_STENCIL_pack(NULL
, state
->state_wm_depth_stencil
,
2214 struct GEN8_COLOR_CALC_STATE color_calc_state
= {
2215 .StencilReferenceValue
= pCreateInfo
->stencilFrontRef
,
2216 .BackFaceStencilReferenceValue
= pCreateInfo
->stencilBackRef
2219 GEN8_COLOR_CALC_STATE_pack(NULL
, state
->state_color_calc
, &color_calc_state
);
2221 *pState
= (VkDynamicDsState
) state
;
2226 // Command buffer functions
2229 anv_cmd_buffer_destroy(struct anv_device
*device
,
2230 struct anv_object
*object
,
2231 VkObjectType obj_type
)
2233 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) object
;
2235 assert(obj_type
== VK_OBJECT_TYPE_COMMAND_BUFFER
);
2237 /* Destroy all of the batch buffers */
2238 struct anv_batch_bo
*bbo
= cmd_buffer
->last_batch_bo
;
2240 struct anv_batch_bo
*prev
= bbo
->prev_batch_bo
;
2241 anv_batch_bo_destroy(bbo
, device
);
2244 anv_reloc_list_finish(&cmd_buffer
->batch
.relocs
, device
);
2246 /* Destroy all of the surface state buffers */
2247 bbo
= cmd_buffer
->surface_batch_bo
;
2249 struct anv_batch_bo
*prev
= bbo
->prev_batch_bo
;
2250 anv_batch_bo_destroy(bbo
, device
);
2253 anv_reloc_list_finish(&cmd_buffer
->surface_relocs
, device
);
2255 anv_state_stream_finish(&cmd_buffer
->surface_state_stream
);
2256 anv_state_stream_finish(&cmd_buffer
->dynamic_state_stream
);
2257 anv_device_free(device
, cmd_buffer
->exec2_objects
);
2258 anv_device_free(device
, cmd_buffer
->exec2_bos
);
2259 anv_device_free(device
, cmd_buffer
);
2263 anv_cmd_buffer_chain_batch(struct anv_batch
*batch
, void *_data
)
2265 struct anv_cmd_buffer
*cmd_buffer
= _data
;
2267 struct anv_batch_bo
*new_bbo
, *old_bbo
= cmd_buffer
->last_batch_bo
;
2269 VkResult result
= anv_batch_bo_create(cmd_buffer
->device
, &new_bbo
);
2270 if (result
!= VK_SUCCESS
)
2273 /* We set the end of the batch a little short so we would be sure we
2274 * have room for the chaining command. Since we're about to emit the
2275 * chaining command, let's set it back where it should go.
2277 batch
->end
+= GEN8_MI_BATCH_BUFFER_START_length
* 4;
2278 assert(batch
->end
== old_bbo
->bo
.map
+ old_bbo
->bo
.size
);
2280 anv_batch_emit(batch
, GEN8_MI_BATCH_BUFFER_START
,
2281 GEN8_MI_BATCH_BUFFER_START_header
,
2282 ._2ndLevelBatchBuffer
= _1stlevelbatch
,
2283 .AddressSpaceIndicator
= ASI_PPGTT
,
2284 .BatchBufferStartAddress
= { &new_bbo
->bo
, 0 },
2287 /* Pad out to a 2-dword aligned boundary with zeros */
2288 if ((uintptr_t)batch
->next
% 8 != 0) {
2289 *(uint32_t *)batch
->next
= 0;
2293 anv_batch_bo_finish(cmd_buffer
->last_batch_bo
, batch
);
2295 new_bbo
->prev_batch_bo
= old_bbo
;
2296 cmd_buffer
->last_batch_bo
= new_bbo
;
2298 anv_batch_bo_start(new_bbo
, batch
, GEN8_MI_BATCH_BUFFER_START_length
* 4);
2303 VkResult
anv_CreateCommandBuffer(
2305 const VkCmdBufferCreateInfo
* pCreateInfo
,
2306 VkCmdBuffer
* pCmdBuffer
)
2308 struct anv_device
*device
= (struct anv_device
*) _device
;
2309 struct anv_cmd_buffer
*cmd_buffer
;
2312 cmd_buffer
= anv_device_alloc(device
, sizeof(*cmd_buffer
), 8,
2313 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
2314 if (cmd_buffer
== NULL
)
2315 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2317 cmd_buffer
->base
.destructor
= anv_cmd_buffer_destroy
;
2319 cmd_buffer
->device
= device
;
2320 cmd_buffer
->rs_state
= NULL
;
2321 cmd_buffer
->vp_state
= NULL
;
2322 cmd_buffer
->cb_state
= NULL
;
2323 cmd_buffer
->ds_state
= NULL
;
2324 memset(&cmd_buffer
->descriptors
, 0, sizeof(cmd_buffer
->descriptors
));
2326 result
= anv_batch_bo_create(device
, &cmd_buffer
->last_batch_bo
);
2327 if (result
!= VK_SUCCESS
)
2330 result
= anv_reloc_list_init(&cmd_buffer
->batch
.relocs
, device
);
2331 if (result
!= VK_SUCCESS
)
2334 cmd_buffer
->batch
.device
= device
;
2335 cmd_buffer
->batch
.extend_cb
= anv_cmd_buffer_chain_batch
;
2336 cmd_buffer
->batch
.user_data
= cmd_buffer
;
2338 anv_batch_bo_start(cmd_buffer
->last_batch_bo
, &cmd_buffer
->batch
,
2339 GEN8_MI_BATCH_BUFFER_START_length
* 4);
2341 result
= anv_batch_bo_create(device
, &cmd_buffer
->surface_batch_bo
);
2342 if (result
!= VK_SUCCESS
)
2343 goto fail_batch_relocs
;
2344 cmd_buffer
->surface_batch_bo
->first_reloc
= 0;
2346 result
= anv_reloc_list_init(&cmd_buffer
->surface_relocs
, device
);
2347 if (result
!= VK_SUCCESS
)
2348 goto fail_ss_batch_bo
;
2350 /* Start surface_next at 1 so surface offset 0 is invalid. */
2351 cmd_buffer
->surface_next
= 1;
2353 cmd_buffer
->exec2_objects
= NULL
;
2354 cmd_buffer
->exec2_bos
= NULL
;
2355 cmd_buffer
->exec2_array_length
= 0;
2357 anv_state_stream_init(&cmd_buffer
->surface_state_stream
,
2358 &device
->surface_state_block_pool
);
2359 anv_state_stream_init(&cmd_buffer
->dynamic_state_stream
,
2360 &device
->dynamic_state_block_pool
);
2362 cmd_buffer
->dirty
= 0;
2363 cmd_buffer
->vb_dirty
= 0;
2364 cmd_buffer
->descriptors_dirty
= 0;
2365 cmd_buffer
->pipeline
= NULL
;
2366 cmd_buffer
->vp_state
= NULL
;
2367 cmd_buffer
->rs_state
= NULL
;
2368 cmd_buffer
->ds_state
= NULL
;
2370 *pCmdBuffer
= (VkCmdBuffer
) cmd_buffer
;
2375 anv_batch_bo_destroy(cmd_buffer
->surface_batch_bo
, device
);
2377 anv_reloc_list_finish(&cmd_buffer
->batch
.relocs
, device
);
2379 anv_batch_bo_destroy(cmd_buffer
->last_batch_bo
, device
);
2381 anv_device_free(device
, cmd_buffer
);
2387 anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
)
2389 struct anv_device
*device
= cmd_buffer
->device
;
2391 anv_batch_emit(&cmd_buffer
->batch
, GEN8_STATE_BASE_ADDRESS
,
2392 .GeneralStateBaseAddress
= { NULL
, 0 },
2393 .GeneralStateMemoryObjectControlState
= GEN8_MOCS
,
2394 .GeneralStateBaseAddressModifyEnable
= true,
2395 .GeneralStateBufferSize
= 0xfffff,
2396 .GeneralStateBufferSizeModifyEnable
= true,
2398 .SurfaceStateBaseAddress
= { &cmd_buffer
->surface_batch_bo
->bo
, 0 },
2399 .SurfaceStateMemoryObjectControlState
= GEN8_MOCS
,
2400 .SurfaceStateBaseAddressModifyEnable
= true,
2402 .DynamicStateBaseAddress
= { &device
->dynamic_state_block_pool
.bo
, 0 },
2403 .DynamicStateMemoryObjectControlState
= GEN8_MOCS
,
2404 .DynamicStateBaseAddressModifyEnable
= true,
2405 .DynamicStateBufferSize
= 0xfffff,
2406 .DynamicStateBufferSizeModifyEnable
= true,
2408 .IndirectObjectBaseAddress
= { NULL
, 0 },
2409 .IndirectObjectMemoryObjectControlState
= GEN8_MOCS
,
2410 .IndirectObjectBaseAddressModifyEnable
= true,
2411 .IndirectObjectBufferSize
= 0xfffff,
2412 .IndirectObjectBufferSizeModifyEnable
= true,
2414 .InstructionBaseAddress
= { &device
->instruction_block_pool
.bo
, 0 },
2415 .InstructionMemoryObjectControlState
= GEN8_MOCS
,
2416 .InstructionBaseAddressModifyEnable
= true,
2417 .InstructionBufferSize
= 0xfffff,
2418 .InstructionBuffersizeModifyEnable
= true);
2421 VkResult
anv_BeginCommandBuffer(
2422 VkCmdBuffer cmdBuffer
,
2423 const VkCmdBufferBeginInfo
* pBeginInfo
)
2425 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2427 anv_cmd_buffer_emit_state_base_address(cmd_buffer
);
2428 cmd_buffer
->current_pipeline
= UINT32_MAX
;
2434 anv_cmd_buffer_add_bo(struct anv_cmd_buffer
*cmd_buffer
,
2436 struct drm_i915_gem_relocation_entry
*relocs
,
2439 struct drm_i915_gem_exec_object2
*obj
;
2441 if (bo
->index
< cmd_buffer
->bo_count
&&
2442 cmd_buffer
->exec2_bos
[bo
->index
] == bo
)
2445 if (cmd_buffer
->bo_count
>= cmd_buffer
->exec2_array_length
) {
2446 uint32_t new_len
= cmd_buffer
->exec2_objects
?
2447 cmd_buffer
->exec2_array_length
* 2 : 64;
2449 struct drm_i915_gem_exec_object2
*new_objects
=
2450 anv_device_alloc(cmd_buffer
->device
, new_len
* sizeof(*new_objects
),
2451 8, VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
2452 if (new_objects
== NULL
)
2453 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2455 struct anv_bo
**new_bos
=
2456 anv_device_alloc(cmd_buffer
->device
, new_len
* sizeof(*new_bos
),
2457 8, VK_SYSTEM_ALLOC_TYPE_INTERNAL
);
2458 if (new_objects
== NULL
) {
2459 anv_device_free(cmd_buffer
->device
, new_objects
);
2460 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2463 if (cmd_buffer
->exec2_objects
) {
2464 memcpy(new_objects
, cmd_buffer
->exec2_objects
,
2465 cmd_buffer
->bo_count
* sizeof(*new_objects
));
2466 memcpy(new_bos
, cmd_buffer
->exec2_bos
,
2467 cmd_buffer
->bo_count
* sizeof(*new_bos
));
2470 cmd_buffer
->exec2_objects
= new_objects
;
2471 cmd_buffer
->exec2_bos
= new_bos
;
2472 cmd_buffer
->exec2_array_length
= new_len
;
2475 assert(cmd_buffer
->bo_count
< cmd_buffer
->exec2_array_length
);
2477 bo
->index
= cmd_buffer
->bo_count
++;
2478 obj
= &cmd_buffer
->exec2_objects
[bo
->index
];
2479 cmd_buffer
->exec2_bos
[bo
->index
] = bo
;
2481 obj
->handle
= bo
->gem_handle
;
2482 obj
->relocation_count
= 0;
2483 obj
->relocs_ptr
= 0;
2485 obj
->offset
= bo
->offset
;
2491 obj
->relocation_count
= num_relocs
;
2492 obj
->relocs_ptr
= (uintptr_t) relocs
;
2499 anv_cmd_buffer_add_validate_bos(struct anv_cmd_buffer
*cmd_buffer
,
2500 struct anv_reloc_list
*list
)
2502 for (size_t i
= 0; i
< list
->num_relocs
; i
++)
2503 anv_cmd_buffer_add_bo(cmd_buffer
, list
->reloc_bos
[i
], NULL
, 0);
2507 anv_cmd_buffer_process_relocs(struct anv_cmd_buffer
*cmd_buffer
,
2508 struct anv_reloc_list
*list
)
2512 /* If the kernel supports I915_EXEC_NO_RELOC, it will compare offset in
2513 * struct drm_i915_gem_exec_object2 against the bos current offset and if
2514 * all bos haven't moved it will skip relocation processing alltogether.
2515 * If I915_EXEC_NO_RELOC is not supported, the kernel ignores the incoming
2516 * value of offset so we can set it either way. For that to work we need
2517 * to make sure all relocs use the same presumed offset.
2520 for (size_t i
= 0; i
< list
->num_relocs
; i
++) {
2521 bo
= list
->reloc_bos
[i
];
2522 if (bo
->offset
!= list
->relocs
[i
].presumed_offset
)
2523 cmd_buffer
->need_reloc
= true;
2525 list
->relocs
[i
].target_handle
= bo
->index
;
2529 VkResult
anv_EndCommandBuffer(
2530 VkCmdBuffer cmdBuffer
)
2532 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2533 struct anv_device
*device
= cmd_buffer
->device
;
2534 struct anv_batch
*batch
= &cmd_buffer
->batch
;
2536 anv_batch_emit(batch
, GEN8_MI_BATCH_BUFFER_END
);
2538 /* Round batch up to an even number of dwords. */
2539 if ((batch
->next
- batch
->start
) & 4)
2540 anv_batch_emit(batch
, GEN8_MI_NOOP
);
2542 anv_batch_bo_finish(cmd_buffer
->last_batch_bo
, &cmd_buffer
->batch
);
2543 cmd_buffer
->surface_batch_bo
->num_relocs
=
2544 cmd_buffer
->surface_relocs
.num_relocs
- cmd_buffer
->surface_batch_bo
->first_reloc
;
2545 cmd_buffer
->surface_batch_bo
->length
= cmd_buffer
->surface_next
;
2547 cmd_buffer
->bo_count
= 0;
2548 cmd_buffer
->need_reloc
= false;
2550 /* Lock for access to bo->index. */
2551 pthread_mutex_lock(&device
->mutex
);
2553 /* Add surface state bos first so we can add them with their relocs. */
2554 for (struct anv_batch_bo
*bbo
= cmd_buffer
->surface_batch_bo
;
2555 bbo
!= NULL
; bbo
= bbo
->prev_batch_bo
) {
2556 anv_cmd_buffer_add_bo(cmd_buffer
, &bbo
->bo
,
2557 &cmd_buffer
->surface_relocs
.relocs
[bbo
->first_reloc
],
2561 /* Add all of the BOs referenced by surface state */
2562 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &cmd_buffer
->surface_relocs
);
2564 /* Add all but the first batch BO */
2565 struct anv_batch_bo
*batch_bo
= cmd_buffer
->last_batch_bo
;
2566 while (batch_bo
->prev_batch_bo
) {
2567 anv_cmd_buffer_add_bo(cmd_buffer
, &batch_bo
->bo
,
2568 &batch
->relocs
.relocs
[batch_bo
->first_reloc
],
2569 batch_bo
->num_relocs
);
2570 batch_bo
= batch_bo
->prev_batch_bo
;
2573 /* Add everything referenced by the batches */
2574 anv_cmd_buffer_add_validate_bos(cmd_buffer
, &batch
->relocs
);
2576 /* Add the first batch bo last */
2577 assert(batch_bo
->prev_batch_bo
== NULL
&& batch_bo
->first_reloc
== 0);
2578 anv_cmd_buffer_add_bo(cmd_buffer
, &batch_bo
->bo
,
2579 &batch
->relocs
.relocs
[batch_bo
->first_reloc
],
2580 batch_bo
->num_relocs
);
2581 assert(batch_bo
->bo
.index
== cmd_buffer
->bo_count
- 1);
2583 anv_cmd_buffer_process_relocs(cmd_buffer
, &cmd_buffer
->surface_relocs
);
2584 anv_cmd_buffer_process_relocs(cmd_buffer
, &batch
->relocs
);
2586 cmd_buffer
->execbuf
.buffers_ptr
= (uintptr_t) cmd_buffer
->exec2_objects
;
2587 cmd_buffer
->execbuf
.buffer_count
= cmd_buffer
->bo_count
;
2588 cmd_buffer
->execbuf
.batch_start_offset
= 0;
2589 cmd_buffer
->execbuf
.batch_len
= batch
->next
- batch
->start
;
2590 cmd_buffer
->execbuf
.cliprects_ptr
= 0;
2591 cmd_buffer
->execbuf
.num_cliprects
= 0;
2592 cmd_buffer
->execbuf
.DR1
= 0;
2593 cmd_buffer
->execbuf
.DR4
= 0;
2595 cmd_buffer
->execbuf
.flags
= I915_EXEC_HANDLE_LUT
;
2596 if (!cmd_buffer
->need_reloc
)
2597 cmd_buffer
->execbuf
.flags
|= I915_EXEC_NO_RELOC
;
2598 cmd_buffer
->execbuf
.flags
|= I915_EXEC_RENDER
;
2599 cmd_buffer
->execbuf
.rsvd1
= device
->context_id
;
2600 cmd_buffer
->execbuf
.rsvd2
= 0;
2602 pthread_mutex_unlock(&device
->mutex
);
2607 VkResult
anv_ResetCommandBuffer(
2608 VkCmdBuffer cmdBuffer
)
2610 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2612 /* Delete all but the first batch bo */
2613 while (cmd_buffer
->last_batch_bo
->prev_batch_bo
) {
2614 struct anv_batch_bo
*prev
= cmd_buffer
->last_batch_bo
->prev_batch_bo
;
2615 anv_batch_bo_destroy(cmd_buffer
->last_batch_bo
, cmd_buffer
->device
);
2616 cmd_buffer
->last_batch_bo
= prev
;
2618 assert(cmd_buffer
->last_batch_bo
->prev_batch_bo
== NULL
);
2620 cmd_buffer
->batch
.relocs
.num_relocs
= 0;
2621 anv_batch_bo_start(cmd_buffer
->last_batch_bo
, &cmd_buffer
->batch
,
2622 GEN8_MI_BATCH_BUFFER_START_length
* 4);
2624 /* Delete all but the first batch bo */
2625 while (cmd_buffer
->surface_batch_bo
->prev_batch_bo
) {
2626 struct anv_batch_bo
*prev
= cmd_buffer
->surface_batch_bo
->prev_batch_bo
;
2627 anv_batch_bo_destroy(cmd_buffer
->surface_batch_bo
, cmd_buffer
->device
);
2628 cmd_buffer
->surface_batch_bo
= prev
;
2630 assert(cmd_buffer
->surface_batch_bo
->prev_batch_bo
== NULL
);
2632 cmd_buffer
->surface_next
= 1;
2633 cmd_buffer
->surface_relocs
.num_relocs
= 0;
2635 cmd_buffer
->rs_state
= NULL
;
2636 cmd_buffer
->vp_state
= NULL
;
2637 cmd_buffer
->cb_state
= NULL
;
2638 cmd_buffer
->ds_state
= NULL
;
2643 // Command buffer building functions
2645 void anv_CmdBindPipeline(
2646 VkCmdBuffer cmdBuffer
,
2647 VkPipelineBindPoint pipelineBindPoint
,
2648 VkPipeline _pipeline
)
2650 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2651 struct anv_pipeline
*pipeline
= (struct anv_pipeline
*) _pipeline
;
2653 switch (pipelineBindPoint
) {
2654 case VK_PIPELINE_BIND_POINT_COMPUTE
:
2655 cmd_buffer
->compute_pipeline
= pipeline
;
2656 cmd_buffer
->compute_dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
;
2659 case VK_PIPELINE_BIND_POINT_GRAPHICS
:
2660 cmd_buffer
->pipeline
= pipeline
;
2661 cmd_buffer
->vb_dirty
|= pipeline
->vb_used
;
2662 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
;
2666 assert(!"invalid bind point");
2671 void anv_CmdBindDynamicStateObject(
2672 VkCmdBuffer cmdBuffer
,
2673 VkStateBindPoint stateBindPoint
,
2674 VkDynamicStateObject dynamicState
)
2676 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2678 switch (stateBindPoint
) {
2679 case VK_STATE_BIND_POINT_VIEWPORT
:
2680 cmd_buffer
->vp_state
= (struct anv_dynamic_vp_state
*) dynamicState
;
2681 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_VP_DIRTY
;
2683 case VK_STATE_BIND_POINT_RASTER
:
2684 cmd_buffer
->rs_state
= (struct anv_dynamic_rs_state
*) dynamicState
;
2685 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_RS_DIRTY
;
2687 case VK_STATE_BIND_POINT_COLOR_BLEND
:
2688 cmd_buffer
->cb_state
= (struct anv_dynamic_cb_state
*) dynamicState
;
2689 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_CB_DIRTY
;
2691 case VK_STATE_BIND_POINT_DEPTH_STENCIL
:
2692 cmd_buffer
->ds_state
= (struct anv_dynamic_ds_state
*) dynamicState
;
2693 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_DS_DIRTY
;
2700 static struct anv_state
2701 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
,
2702 uint32_t size
, uint32_t alignment
)
2704 struct anv_state state
;
2706 state
.offset
= ALIGN_U32(cmd_buffer
->surface_next
, alignment
);
2707 if (state
.offset
+ size
> cmd_buffer
->surface_batch_bo
->bo
.size
)
2708 return (struct anv_state
) { 0 };
2710 state
.map
= cmd_buffer
->surface_batch_bo
->bo
.map
+ state
.offset
;
2711 state
.alloc_size
= size
;
2712 cmd_buffer
->surface_next
= state
.offset
+ size
;
2714 assert(state
.offset
+ size
<= cmd_buffer
->surface_batch_bo
->bo
.size
);
2720 anv_cmd_buffer_new_surface_state_bo(struct anv_cmd_buffer
*cmd_buffer
)
2722 struct anv_batch_bo
*new_bbo
, *old_bbo
= cmd_buffer
->surface_batch_bo
;
2724 /* Finish off the old buffer */
2725 old_bbo
->num_relocs
=
2726 cmd_buffer
->surface_relocs
.num_relocs
- old_bbo
->first_reloc
;
2727 old_bbo
->length
= cmd_buffer
->surface_next
;
2729 VkResult result
= anv_batch_bo_create(cmd_buffer
->device
, &new_bbo
);
2730 if (result
!= VK_SUCCESS
)
2733 new_bbo
->first_reloc
= cmd_buffer
->surface_relocs
.num_relocs
;
2734 cmd_buffer
->surface_next
= 1;
2736 new_bbo
->prev_batch_bo
= old_bbo
;
2737 cmd_buffer
->surface_batch_bo
= new_bbo
;
2739 /* Re-emit state base addresses so we get the new surface state base
2740 * address before we start emitting binding tables etc.
2742 anv_cmd_buffer_emit_state_base_address(cmd_buffer
);
2744 /* It seems like just changing the state base addresses isn't enough.
2745 * Invalidating the cache seems to be enough to cause things to
2746 * propagate. However, I'm not 100% sure what we're supposed to do.
2748 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
2749 .TextureCacheInvalidationEnable
= true);
2754 void anv_CmdBindDescriptorSets(
2755 VkCmdBuffer cmdBuffer
,
2756 VkPipelineBindPoint pipelineBindPoint
,
2759 const VkDescriptorSet
* pDescriptorSets
,
2760 uint32_t dynamicOffsetCount
,
2761 const uint32_t* pDynamicOffsets
)
2763 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2764 struct anv_pipeline_layout
*layout
;
2765 struct anv_descriptor_set
*set
;
2766 struct anv_descriptor_set_layout
*set_layout
;
2768 assert(firstSet
+ setCount
< MAX_SETS
);
2770 if (pipelineBindPoint
== VK_PIPELINE_BIND_POINT_GRAPHICS
)
2771 layout
= cmd_buffer
->pipeline
->layout
;
2773 layout
= cmd_buffer
->compute_pipeline
->layout
;
2775 uint32_t dynamic_slot
= 0;
2776 for (uint32_t i
= 0; i
< setCount
; i
++) {
2777 set
= (struct anv_descriptor_set
*) pDescriptorSets
[i
];
2778 set_layout
= layout
->set
[firstSet
+ i
].layout
;
2780 cmd_buffer
->descriptors
[firstSet
+ i
].set
= set
;
2782 assert(set_layout
->num_dynamic_buffers
<
2783 ARRAY_SIZE(cmd_buffer
->descriptors
[0].dynamic_offsets
));
2784 memcpy(cmd_buffer
->descriptors
[firstSet
+ i
].dynamic_offsets
,
2785 pDynamicOffsets
+ dynamic_slot
,
2786 set_layout
->num_dynamic_buffers
* sizeof(*pDynamicOffsets
));
2788 cmd_buffer
->descriptors_dirty
|= set_layout
->shader_stages
;
2790 dynamic_slot
+= set_layout
->num_dynamic_buffers
;
2794 void anv_CmdBindIndexBuffer(
2795 VkCmdBuffer cmdBuffer
,
2797 VkDeviceSize offset
,
2798 VkIndexType indexType
)
2800 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2801 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
2803 static const uint32_t vk_to_gen_index_type
[] = {
2804 [VK_INDEX_TYPE_UINT8
] = INDEX_BYTE
,
2805 [VK_INDEX_TYPE_UINT16
] = INDEX_WORD
,
2806 [VK_INDEX_TYPE_UINT32
] = INDEX_DWORD
,
2809 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_INDEX_BUFFER
,
2810 .IndexFormat
= vk_to_gen_index_type
[indexType
],
2811 .MemoryObjectControlState
= GEN8_MOCS
,
2812 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
2813 .BufferSize
= buffer
->size
- offset
);
2816 void anv_CmdBindVertexBuffers(
2817 VkCmdBuffer cmdBuffer
,
2818 uint32_t startBinding
,
2819 uint32_t bindingCount
,
2820 const VkBuffer
* pBuffers
,
2821 const VkDeviceSize
* pOffsets
)
2823 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
2824 struct anv_vertex_binding
*vb
= cmd_buffer
->vertex_bindings
;
2826 /* We have to defer setting up vertex buffer since we need the buffer
2827 * stride from the pipeline. */
2829 assert(startBinding
+ bindingCount
< MAX_VBS
);
2830 for (uint32_t i
= 0; i
< bindingCount
; i
++) {
2831 vb
[startBinding
+ i
].buffer
= (struct anv_buffer
*) pBuffers
[i
];
2832 vb
[startBinding
+ i
].offset
= pOffsets
[i
];
2833 cmd_buffer
->vb_dirty
|= 1 << (startBinding
+ i
);
2838 cmd_buffer_emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
2839 unsigned stage
, struct anv_state
*bt_state
)
2841 struct anv_pipeline_layout
*layout
;
2842 uint32_t color_attachments
, bias
, size
;
2844 if (stage
== VK_SHADER_STAGE_COMPUTE
)
2845 layout
= cmd_buffer
->compute_pipeline
->layout
;
2847 layout
= cmd_buffer
->pipeline
->layout
;
2849 if (stage
== VK_SHADER_STAGE_FRAGMENT
) {
2851 color_attachments
= cmd_buffer
->framebuffer
->color_attachment_count
;
2854 color_attachments
= 0;
2857 /* This is a little awkward: layout can be NULL but we still have to
2858 * allocate and set a binding table for the PS stage for render
2860 uint32_t surface_count
= layout
? layout
->stage
[stage
].surface_count
: 0;
2862 if (color_attachments
+ surface_count
== 0)
2865 size
= (bias
+ surface_count
) * sizeof(uint32_t);
2866 *bt_state
= anv_cmd_buffer_alloc_surface_state(cmd_buffer
, size
, 32);
2867 uint32_t *bt_map
= bt_state
->map
;
2869 if (bt_state
->map
== NULL
)
2870 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2872 for (uint32_t ca
= 0; ca
< color_attachments
; ca
++) {
2873 const struct anv_surface_view
*view
=
2874 cmd_buffer
->framebuffer
->color_attachments
[ca
];
2876 struct anv_state state
=
2877 anv_cmd_buffer_alloc_surface_state(cmd_buffer
, 64, 64);
2879 if (state
.map
== NULL
)
2880 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2882 memcpy(state
.map
, view
->surface_state
.map
, 64);
2884 /* The address goes in dwords 8 and 9 of the SURFACE_STATE */
2885 *(uint64_t *)(state
.map
+ 8 * 4) =
2886 anv_reloc_list_add(&cmd_buffer
->surface_relocs
,
2888 state
.offset
+ 8 * 4,
2889 view
->bo
, view
->offset
);
2891 bt_map
[ca
] = state
.offset
;
2897 for (uint32_t set
= 0; set
< layout
->num_sets
; set
++) {
2898 struct anv_descriptor_set_binding
*d
= &cmd_buffer
->descriptors
[set
];
2899 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[set
].layout
;
2900 struct anv_descriptor_slot
*surface_slots
=
2901 set_layout
->stage
[stage
].surface_start
;
2903 uint32_t start
= bias
+ layout
->set
[set
].surface_start
[stage
];
2905 for (uint32_t b
= 0; b
< set_layout
->stage
[stage
].surface_count
; b
++) {
2906 struct anv_surface_view
*view
=
2907 d
->set
->descriptors
[surface_slots
[b
].index
].view
;
2912 struct anv_state state
=
2913 anv_cmd_buffer_alloc_surface_state(cmd_buffer
, 64, 64);
2915 if (state
.map
== NULL
)
2916 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2919 if (surface_slots
[b
].dynamic_slot
>= 0) {
2920 uint32_t dynamic_offset
=
2921 d
->dynamic_offsets
[surface_slots
[b
].dynamic_slot
];
2923 offset
= view
->offset
+ dynamic_offset
;
2924 fill_buffer_surface_state(state
.map
, view
->format
, offset
,
2925 view
->range
- dynamic_offset
);
2927 offset
= view
->offset
;
2928 memcpy(state
.map
, view
->surface_state
.map
, 64);
2931 /* The address goes in dwords 8 and 9 of the SURFACE_STATE */
2932 *(uint64_t *)(state
.map
+ 8 * 4) =
2933 anv_reloc_list_add(&cmd_buffer
->surface_relocs
,
2935 state
.offset
+ 8 * 4,
2938 bt_map
[start
+ b
] = state
.offset
;
2946 cmd_buffer_emit_samplers(struct anv_cmd_buffer
*cmd_buffer
,
2947 unsigned stage
, struct anv_state
*state
)
2949 struct anv_pipeline_layout
*layout
;
2950 uint32_t sampler_count
;
2952 if (stage
== VK_SHADER_STAGE_COMPUTE
)
2953 layout
= cmd_buffer
->compute_pipeline
->layout
;
2955 layout
= cmd_buffer
->pipeline
->layout
;
2957 sampler_count
= layout
? layout
->stage
[stage
].sampler_count
: 0;
2958 if (sampler_count
== 0)
2961 uint32_t size
= sampler_count
* 16;
2962 *state
= anv_state_stream_alloc(&cmd_buffer
->dynamic_state_stream
, size
, 32);
2964 if (state
->map
== NULL
)
2965 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2967 for (uint32_t set
= 0; set
< layout
->num_sets
; set
++) {
2968 struct anv_descriptor_set_binding
*d
= &cmd_buffer
->descriptors
[set
];
2969 struct anv_descriptor_set_layout
*set_layout
= layout
->set
[set
].layout
;
2970 struct anv_descriptor_slot
*sampler_slots
=
2971 set_layout
->stage
[stage
].sampler_start
;
2973 uint32_t start
= layout
->set
[set
].sampler_start
[stage
];
2975 for (uint32_t b
= 0; b
< set_layout
->stage
[stage
].sampler_count
; b
++) {
2976 struct anv_sampler
*sampler
=
2977 d
->set
->descriptors
[sampler_slots
[b
].index
].sampler
;
2982 memcpy(state
->map
+ (start
+ b
) * 16,
2983 sampler
->state
, sizeof(sampler
->state
));
2991 flush_descriptor_set(struct anv_cmd_buffer
*cmd_buffer
, uint32_t stage
)
2993 struct anv_state surfaces
= { 0, }, samplers
= { 0, };
2996 result
= cmd_buffer_emit_samplers(cmd_buffer
, stage
, &samplers
);
2997 if (result
!= VK_SUCCESS
)
2999 result
= cmd_buffer_emit_binding_table(cmd_buffer
, stage
, &surfaces
);
3000 if (result
!= VK_SUCCESS
)
3003 static const uint32_t sampler_state_opcodes
[] = {
3004 [VK_SHADER_STAGE_VERTEX
] = 43,
3005 [VK_SHADER_STAGE_TESS_CONTROL
] = 44, /* HS */
3006 [VK_SHADER_STAGE_TESS_EVALUATION
] = 45, /* DS */
3007 [VK_SHADER_STAGE_GEOMETRY
] = 46,
3008 [VK_SHADER_STAGE_FRAGMENT
] = 47,
3009 [VK_SHADER_STAGE_COMPUTE
] = 0,
3012 static const uint32_t binding_table_opcodes
[] = {
3013 [VK_SHADER_STAGE_VERTEX
] = 38,
3014 [VK_SHADER_STAGE_TESS_CONTROL
] = 39,
3015 [VK_SHADER_STAGE_TESS_EVALUATION
] = 40,
3016 [VK_SHADER_STAGE_GEOMETRY
] = 41,
3017 [VK_SHADER_STAGE_FRAGMENT
] = 42,
3018 [VK_SHADER_STAGE_COMPUTE
] = 0,
3021 if (samplers
.alloc_size
> 0) {
3022 anv_batch_emit(&cmd_buffer
->batch
,
3023 GEN8_3DSTATE_SAMPLER_STATE_POINTERS_VS
,
3024 ._3DCommandSubOpcode
= sampler_state_opcodes
[stage
],
3025 .PointertoVSSamplerState
= samplers
.offset
);
3028 if (surfaces
.alloc_size
> 0) {
3029 anv_batch_emit(&cmd_buffer
->batch
,
3030 GEN8_3DSTATE_BINDING_TABLE_POINTERS_VS
,
3031 ._3DCommandSubOpcode
= binding_table_opcodes
[stage
],
3032 .PointertoVSBindingTable
= surfaces
.offset
);
3039 flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
)
3041 uint32_t s
, dirty
= cmd_buffer
->descriptors_dirty
&
3042 cmd_buffer
->pipeline
->active_stages
;
3045 for_each_bit(s
, dirty
) {
3046 result
= flush_descriptor_set(cmd_buffer
, s
);
3047 if (result
!= VK_SUCCESS
)
3051 if (result
!= VK_SUCCESS
) {
3052 assert(result
== VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3054 result
= anv_cmd_buffer_new_surface_state_bo(cmd_buffer
);
3055 assert(result
== VK_SUCCESS
);
3057 /* Re-emit all active binding tables */
3058 for_each_bit(s
, cmd_buffer
->pipeline
->active_stages
) {
3059 result
= flush_descriptor_set(cmd_buffer
, s
);
3061 /* It had better succeed this time */
3062 assert(result
== VK_SUCCESS
);
3066 cmd_buffer
->descriptors_dirty
&= ~cmd_buffer
->pipeline
->active_stages
;
3069 static struct anv_state
3070 anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
3071 uint32_t *a
, uint32_t dwords
, uint32_t alignment
)
3073 struct anv_state state
;
3075 state
= anv_state_stream_alloc(&cmd_buffer
->dynamic_state_stream
,
3076 dwords
* 4, alignment
);
3077 memcpy(state
.map
, a
, dwords
* 4);
3079 VG(VALGRIND_CHECK_MEM_IS_DEFINED(state
.map
, dwords
* 4));
3084 static struct anv_state
3085 anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
3086 uint32_t *a
, uint32_t *b
,
3087 uint32_t dwords
, uint32_t alignment
)
3089 struct anv_state state
;
3092 state
= anv_state_stream_alloc(&cmd_buffer
->dynamic_state_stream
,
3093 dwords
* 4, alignment
);
3095 for (uint32_t i
= 0; i
< dwords
; i
++)
3098 VG(VALGRIND_CHECK_MEM_IS_DEFINED(p
, dwords
* 4));
3104 flush_compute_descriptor_set(struct anv_cmd_buffer
*cmd_buffer
)
3106 struct anv_device
*device
= cmd_buffer
->device
;
3107 struct anv_pipeline
*pipeline
= cmd_buffer
->compute_pipeline
;
3108 struct anv_state surfaces
= { 0, }, samplers
= { 0, };
3111 result
= cmd_buffer_emit_samplers(cmd_buffer
,
3112 VK_SHADER_STAGE_COMPUTE
, &samplers
);
3113 if (result
!= VK_SUCCESS
)
3115 result
= cmd_buffer_emit_binding_table(cmd_buffer
,
3116 VK_SHADER_STAGE_COMPUTE
, &surfaces
);
3117 if (result
!= VK_SUCCESS
)
3120 struct GEN8_INTERFACE_DESCRIPTOR_DATA desc
= {
3121 .KernelStartPointer
= pipeline
->cs_simd
,
3122 .KernelStartPointerHigh
= 0,
3123 .BindingTablePointer
= surfaces
.offset
,
3124 .BindingTableEntryCount
= 0,
3125 .SamplerStatePointer
= samplers
.offset
,
3127 .NumberofThreadsinGPGPUThreadGroup
= 0 /* FIXME: Really? */
3130 uint32_t size
= GEN8_INTERFACE_DESCRIPTOR_DATA_length
* sizeof(uint32_t);
3131 struct anv_state state
=
3132 anv_state_pool_alloc(&device
->dynamic_state_pool
, size
, 64);
3134 GEN8_INTERFACE_DESCRIPTOR_DATA_pack(NULL
, state
.map
, &desc
);
3136 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MEDIA_INTERFACE_DESCRIPTOR_LOAD
,
3137 .InterfaceDescriptorTotalLength
= size
,
3138 .InterfaceDescriptorDataStartAddress
= state
.offset
);
3144 anv_cmd_buffer_flush_compute_state(struct anv_cmd_buffer
*cmd_buffer
)
3146 struct anv_pipeline
*pipeline
= cmd_buffer
->compute_pipeline
;
3149 assert(pipeline
->active_stages
== VK_SHADER_STAGE_COMPUTE_BIT
);
3151 if (cmd_buffer
->current_pipeline
!= GPGPU
) {
3152 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPELINE_SELECT
,
3153 .PipelineSelection
= GPGPU
);
3154 cmd_buffer
->current_pipeline
= GPGPU
;
3157 if (cmd_buffer
->compute_dirty
& ANV_CMD_BUFFER_PIPELINE_DIRTY
)
3158 anv_batch_emit_batch(&cmd_buffer
->batch
, &pipeline
->batch
);
3160 if ((cmd_buffer
->descriptors_dirty
& VK_SHADER_STAGE_COMPUTE_BIT
) ||
3161 (cmd_buffer
->compute_dirty
& ANV_CMD_BUFFER_PIPELINE_DIRTY
)) {
3162 result
= flush_compute_descriptor_set(cmd_buffer
);
3163 if (result
!= VK_SUCCESS
) {
3164 result
= anv_cmd_buffer_new_surface_state_bo(cmd_buffer
);
3165 assert(result
== VK_SUCCESS
);
3166 result
= flush_compute_descriptor_set(cmd_buffer
);
3167 assert(result
== VK_SUCCESS
);
3169 cmd_buffer
->descriptors_dirty
&= ~VK_SHADER_STAGE_COMPUTE
;
3172 cmd_buffer
->compute_dirty
= 0;
3176 anv_cmd_buffer_flush_state(struct anv_cmd_buffer
*cmd_buffer
)
3178 struct anv_pipeline
*pipeline
= cmd_buffer
->pipeline
;
3181 uint32_t vb_emit
= cmd_buffer
->vb_dirty
& pipeline
->vb_used
;
3183 assert((pipeline
->active_stages
& VK_SHADER_STAGE_COMPUTE_BIT
) == 0);
3185 if (cmd_buffer
->current_pipeline
!= _3D
) {
3186 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPELINE_SELECT
,
3187 .PipelineSelection
= _3D
);
3188 cmd_buffer
->current_pipeline
= _3D
;
3192 const uint32_t num_buffers
= __builtin_popcount(vb_emit
);
3193 const uint32_t num_dwords
= 1 + num_buffers
* 4;
3195 p
= anv_batch_emitn(&cmd_buffer
->batch
, num_dwords
,
3196 GEN8_3DSTATE_VERTEX_BUFFERS
);
3198 for_each_bit(vb
, vb_emit
) {
3199 struct anv_buffer
*buffer
= cmd_buffer
->vertex_bindings
[vb
].buffer
;
3200 uint32_t offset
= cmd_buffer
->vertex_bindings
[vb
].offset
;
3202 struct GEN8_VERTEX_BUFFER_STATE state
= {
3203 .VertexBufferIndex
= vb
,
3204 .MemoryObjectControlState
= GEN8_MOCS
,
3205 .AddressModifyEnable
= true,
3206 .BufferPitch
= pipeline
->binding_stride
[vb
],
3207 .BufferStartingAddress
= { buffer
->bo
, buffer
->offset
+ offset
},
3208 .BufferSize
= buffer
->size
- offset
3211 GEN8_VERTEX_BUFFER_STATE_pack(&cmd_buffer
->batch
, &p
[1 + i
* 4], &state
);
3216 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_PIPELINE_DIRTY
)
3217 anv_batch_emit_batch(&cmd_buffer
->batch
, &pipeline
->batch
);
3219 if (cmd_buffer
->descriptors_dirty
)
3220 flush_descriptor_sets(cmd_buffer
);
3222 if (cmd_buffer
->dirty
& ANV_CMD_BUFFER_VP_DIRTY
) {
3223 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_SCISSOR_STATE_POINTERS
,
3224 .ScissorRectPointer
= cmd_buffer
->vp_state
->scissor
.offset
);
3225 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_CC
,
3226 .CCViewportPointer
= cmd_buffer
->vp_state
->cc_vp
.offset
);
3227 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
,
3228 .SFClipViewportPointer
= cmd_buffer
->vp_state
->sf_clip_vp
.offset
);
3231 if (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_PIPELINE_DIRTY
| ANV_CMD_BUFFER_RS_DIRTY
)) {
3232 anv_batch_emit_merge(&cmd_buffer
->batch
,
3233 cmd_buffer
->rs_state
->state_sf
, pipeline
->state_sf
);
3234 anv_batch_emit_merge(&cmd_buffer
->batch
,
3235 cmd_buffer
->rs_state
->state_raster
, pipeline
->state_raster
);
3238 if (cmd_buffer
->ds_state
&&
3239 (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_PIPELINE_DIRTY
| ANV_CMD_BUFFER_DS_DIRTY
)))
3240 anv_batch_emit_merge(&cmd_buffer
->batch
,
3241 cmd_buffer
->ds_state
->state_wm_depth_stencil
,
3242 pipeline
->state_wm_depth_stencil
);
3244 if (cmd_buffer
->dirty
& (ANV_CMD_BUFFER_CB_DIRTY
| ANV_CMD_BUFFER_DS_DIRTY
)) {
3245 struct anv_state state
;
3246 if (cmd_buffer
->ds_state
== NULL
)
3247 state
= anv_cmd_buffer_emit_dynamic(cmd_buffer
,
3248 cmd_buffer
->cb_state
->state_color_calc
,
3249 GEN8_COLOR_CALC_STATE_length
, 64);
3250 else if (cmd_buffer
->cb_state
== NULL
)
3251 state
= anv_cmd_buffer_emit_dynamic(cmd_buffer
,
3252 cmd_buffer
->ds_state
->state_color_calc
,
3253 GEN8_COLOR_CALC_STATE_length
, 64);
3255 state
= anv_cmd_buffer_merge_dynamic(cmd_buffer
,
3256 cmd_buffer
->ds_state
->state_color_calc
,
3257 cmd_buffer
->cb_state
->state_color_calc
,
3258 GEN8_COLOR_CALC_STATE_length
, 64);
3260 anv_batch_emit(&cmd_buffer
->batch
,
3261 GEN8_3DSTATE_CC_STATE_POINTERS
,
3262 .ColorCalcStatePointer
= state
.offset
,
3263 .ColorCalcStatePointerValid
= true);
3266 cmd_buffer
->vb_dirty
&= ~vb_emit
;
3267 cmd_buffer
->dirty
= 0;
3271 VkCmdBuffer cmdBuffer
,
3272 uint32_t firstVertex
,
3273 uint32_t vertexCount
,
3274 uint32_t firstInstance
,
3275 uint32_t instanceCount
)
3277 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3279 anv_cmd_buffer_flush_state(cmd_buffer
);
3281 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
3282 .VertexAccessType
= SEQUENTIAL
,
3283 .VertexCountPerInstance
= vertexCount
,
3284 .StartVertexLocation
= firstVertex
,
3285 .InstanceCount
= instanceCount
,
3286 .StartInstanceLocation
= firstInstance
,
3287 .BaseVertexLocation
= 0);
3290 void anv_CmdDrawIndexed(
3291 VkCmdBuffer cmdBuffer
,
3292 uint32_t firstIndex
,
3293 uint32_t indexCount
,
3294 int32_t vertexOffset
,
3295 uint32_t firstInstance
,
3296 uint32_t instanceCount
)
3298 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3300 anv_cmd_buffer_flush_state(cmd_buffer
);
3302 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
3303 .VertexAccessType
= RANDOM
,
3304 .VertexCountPerInstance
= indexCount
,
3305 .StartVertexLocation
= firstIndex
,
3306 .InstanceCount
= instanceCount
,
3307 .StartInstanceLocation
= firstInstance
,
3308 .BaseVertexLocation
= vertexOffset
);
3312 anv_batch_lrm(struct anv_batch
*batch
,
3313 uint32_t reg
, struct anv_bo
*bo
, uint32_t offset
)
3315 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_MEM
,
3316 .RegisterAddress
= reg
,
3317 .MemoryAddress
= { bo
, offset
});
3321 anv_batch_lri(struct anv_batch
*batch
, uint32_t reg
, uint32_t imm
)
3323 anv_batch_emit(batch
, GEN8_MI_LOAD_REGISTER_IMM
,
3324 .RegisterOffset
= reg
,
3328 /* Auto-Draw / Indirect Registers */
3329 #define GEN7_3DPRIM_END_OFFSET 0x2420
3330 #define GEN7_3DPRIM_START_VERTEX 0x2430
3331 #define GEN7_3DPRIM_VERTEX_COUNT 0x2434
3332 #define GEN7_3DPRIM_INSTANCE_COUNT 0x2438
3333 #define GEN7_3DPRIM_START_INSTANCE 0x243C
3334 #define GEN7_3DPRIM_BASE_VERTEX 0x2440
3336 void anv_CmdDrawIndirect(
3337 VkCmdBuffer cmdBuffer
,
3339 VkDeviceSize offset
,
3343 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3344 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
3345 struct anv_bo
*bo
= buffer
->bo
;
3346 uint32_t bo_offset
= buffer
->offset
+ offset
;
3348 anv_cmd_buffer_flush_state(cmd_buffer
);
3350 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
3351 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
3352 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
3353 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 12);
3354 anv_batch_lri(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, 0);
3356 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
3357 .IndirectParameterEnable
= true,
3358 .VertexAccessType
= SEQUENTIAL
);
3361 void anv_CmdDrawIndexedIndirect(
3362 VkCmdBuffer cmdBuffer
,
3364 VkDeviceSize offset
,
3368 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3369 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
3370 struct anv_bo
*bo
= buffer
->bo
;
3371 uint32_t bo_offset
= buffer
->offset
+ offset
;
3373 anv_cmd_buffer_flush_state(cmd_buffer
);
3375 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_VERTEX_COUNT
, bo
, bo_offset
);
3376 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
, bo_offset
+ 4);
3377 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_VERTEX
, bo
, bo_offset
+ 8);
3378 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_BASE_VERTEX
, bo
, bo_offset
+ 12);
3379 anv_batch_lrm(&cmd_buffer
->batch
, GEN7_3DPRIM_START_INSTANCE
, bo
, bo_offset
+ 16);
3381 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DPRIMITIVE
,
3382 .IndirectParameterEnable
= true,
3383 .VertexAccessType
= RANDOM
);
3386 void anv_CmdDispatch(
3387 VkCmdBuffer cmdBuffer
,
3392 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3393 struct anv_pipeline
*pipeline
= cmd_buffer
->compute_pipeline
;
3394 struct brw_cs_prog_data
*prog_data
= &pipeline
->cs_prog_data
;
3396 anv_cmd_buffer_flush_compute_state(cmd_buffer
);
3398 anv_batch_emit(&cmd_buffer
->batch
, GEN8_GPGPU_WALKER
,
3399 .SIMDSize
= prog_data
->simd_size
/ 16,
3400 .ThreadDepthCounterMaximum
= 0,
3401 .ThreadHeightCounterMaximum
= 0,
3402 .ThreadWidthCounterMaximum
= pipeline
->cs_thread_width_max
,
3403 .ThreadGroupIDXDimension
= x
,
3404 .ThreadGroupIDYDimension
= y
,
3405 .ThreadGroupIDZDimension
= z
,
3406 .RightExecutionMask
= pipeline
->cs_right_mask
,
3407 .BottomExecutionMask
= 0xffffffff);
3409 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MEDIA_STATE_FLUSH
);
3412 #define GPGPU_DISPATCHDIMX 0x2500
3413 #define GPGPU_DISPATCHDIMY 0x2504
3414 #define GPGPU_DISPATCHDIMZ 0x2508
3416 void anv_CmdDispatchIndirect(
3417 VkCmdBuffer cmdBuffer
,
3419 VkDeviceSize offset
)
3421 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3422 struct anv_pipeline
*pipeline
= cmd_buffer
->compute_pipeline
;
3423 struct brw_cs_prog_data
*prog_data
= &pipeline
->cs_prog_data
;
3424 struct anv_buffer
*buffer
= (struct anv_buffer
*) _buffer
;
3425 struct anv_bo
*bo
= buffer
->bo
;
3426 uint32_t bo_offset
= buffer
->offset
+ offset
;
3428 anv_cmd_buffer_flush_compute_state(cmd_buffer
);
3430 anv_batch_lrm(&cmd_buffer
->batch
, GPGPU_DISPATCHDIMX
, bo
, bo_offset
);
3431 anv_batch_lrm(&cmd_buffer
->batch
, GPGPU_DISPATCHDIMY
, bo
, bo_offset
+ 4);
3432 anv_batch_lrm(&cmd_buffer
->batch
, GPGPU_DISPATCHDIMZ
, bo
, bo_offset
+ 8);
3434 anv_batch_emit(&cmd_buffer
->batch
, GEN8_GPGPU_WALKER
,
3435 .IndirectParameterEnable
= true,
3436 .SIMDSize
= prog_data
->simd_size
/ 16,
3437 .ThreadDepthCounterMaximum
= 0,
3438 .ThreadHeightCounterMaximum
= 0,
3439 .ThreadWidthCounterMaximum
= pipeline
->cs_thread_width_max
,
3440 .RightExecutionMask
= pipeline
->cs_right_mask
,
3441 .BottomExecutionMask
= 0xffffffff);
3443 anv_batch_emit(&cmd_buffer
->batch
, GEN8_MEDIA_STATE_FLUSH
);
3446 void anv_CmdSetEvent(
3447 VkCmdBuffer cmdBuffer
,
3449 VkPipeEvent pipeEvent
)
3454 void anv_CmdResetEvent(
3455 VkCmdBuffer cmdBuffer
,
3457 VkPipeEvent pipeEvent
)
3462 void anv_CmdWaitEvents(
3463 VkCmdBuffer cmdBuffer
,
3464 VkWaitEvent waitEvent
,
3465 uint32_t eventCount
,
3466 const VkEvent
* pEvents
,
3467 uint32_t memBarrierCount
,
3468 const void** ppMemBarriers
)
3473 void anv_CmdPipelineBarrier(
3474 VkCmdBuffer cmdBuffer
,
3475 VkWaitEvent waitEvent
,
3476 uint32_t pipeEventCount
,
3477 const VkPipeEvent
* pPipeEvents
,
3478 uint32_t memBarrierCount
,
3479 const void** ppMemBarriers
)
3481 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
3484 struct GEN8_PIPE_CONTROL cmd
= {
3485 GEN8_PIPE_CONTROL_header
,
3486 .PostSyncOperation
= NoWrite
,
3489 /* XXX: I think waitEvent is a no-op on our HW. We should verify that. */
3491 for (uint32_t i
= 0; i
< pipeEventCount
; i
++) {
3492 switch (pPipeEvents
[i
]) {
3493 case VK_PIPE_EVENT_TOP_OF_PIPE
:
3494 /* This is just what PIPE_CONTROL does */
3496 case VK_PIPE_EVENT_VERTEX_PROCESSING_COMPLETE
:
3497 case VK_PIPE_EVENT_LOCAL_FRAGMENT_PROCESSING_COMPLETE
:
3498 case VK_PIPE_EVENT_FRAGMENT_PROCESSING_COMPLETE
:
3499 cmd
.StallAtPixelScoreboard
= true;
3501 case VK_PIPE_EVENT_GRAPHICS_PIPELINE_COMPLETE
:
3502 case VK_PIPE_EVENT_COMPUTE_PIPELINE_COMPLETE
:
3503 case VK_PIPE_EVENT_TRANSFER_COMPLETE
:
3504 case VK_PIPE_EVENT_COMMANDS_COMPLETE
:
3505 cmd
.CommandStreamerStallEnable
= true;
3508 unreachable("Invalid VkPipeEvent");
3512 /* XXX: Right now, we're really dumb and just flush whatever categories
3513 * the app asks for. One of these days we may make this a bit better
3514 * but right now that's all the hardware allows for in most areas.
3516 VkMemoryOutputFlags out_flags
= 0;
3517 VkMemoryInputFlags in_flags
= 0;
3519 for (uint32_t i
= 0; i
< memBarrierCount
; i
++) {
3520 const struct anv_common
*common
= ppMemBarriers
[i
];
3521 switch (common
->sType
) {
3522 case VK_STRUCTURE_TYPE_MEMORY_BARRIER
: {
3523 const VkMemoryBarrier
*barrier
= (VkMemoryBarrier
*)common
;
3524 out_flags
|= barrier
->outputMask
;
3525 in_flags
|= barrier
->inputMask
;
3528 case VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER
: {
3529 const VkBufferMemoryBarrier
*barrier
= (VkBufferMemoryBarrier
*)common
;
3530 out_flags
|= barrier
->outputMask
;
3531 in_flags
|= barrier
->inputMask
;
3534 case VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER
: {
3535 const VkImageMemoryBarrier
*barrier
= (VkImageMemoryBarrier
*)common
;
3536 out_flags
|= barrier
->outputMask
;
3537 in_flags
|= barrier
->inputMask
;
3541 unreachable("Invalid memory barrier type");
3545 for_each_bit(b
, out_flags
) {
3546 switch ((VkMemoryOutputFlags
)(1 << b
)) {
3547 case VK_MEMORY_OUTPUT_CPU_WRITE_BIT
:
3548 break; /* FIXME: Little-core systems */
3549 case VK_MEMORY_OUTPUT_SHADER_WRITE_BIT
:
3550 cmd
.DCFlushEnable
= true;
3552 case VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT
:
3553 cmd
.RenderTargetCacheFlushEnable
= true;
3555 case VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT
:
3556 cmd
.DepthCacheFlushEnable
= true;
3558 case VK_MEMORY_OUTPUT_TRANSFER_BIT
:
3559 cmd
.RenderTargetCacheFlushEnable
= true;
3560 cmd
.DepthCacheFlushEnable
= true;
3563 unreachable("Invalid memory output flag");
3567 for_each_bit(b
, out_flags
) {
3568 switch ((VkMemoryInputFlags
)(1 << b
)) {
3569 case VK_MEMORY_INPUT_CPU_READ_BIT
:
3570 break; /* FIXME: Little-core systems */
3571 case VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT
:
3572 case VK_MEMORY_INPUT_INDEX_FETCH_BIT
:
3573 case VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT
:
3574 cmd
.VFCacheInvalidationEnable
= true;
3576 case VK_MEMORY_INPUT_UNIFORM_READ_BIT
:
3577 cmd
.ConstantCacheInvalidationEnable
= true;
3579 case VK_MEMORY_INPUT_SHADER_READ_BIT
:
3580 cmd
.DCFlushEnable
= true;
3581 cmd
.TextureCacheInvalidationEnable
= true;
3583 case VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT
:
3584 case VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT
:
3585 break; /* XXX: Hunh? */
3586 case VK_MEMORY_INPUT_TRANSFER_BIT
:
3587 cmd
.TextureCacheInvalidationEnable
= true;
3592 dw
= anv_batch_emit_dwords(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL_length
);
3593 GEN8_PIPE_CONTROL_pack(&cmd_buffer
->batch
, dw
, &cmd
);
3596 void anv_CmdInitAtomicCounters(
3597 VkCmdBuffer cmdBuffer
,
3598 VkPipelineBindPoint pipelineBindPoint
,
3599 uint32_t startCounter
,
3600 uint32_t counterCount
,
3601 const uint32_t* pData
)
3606 void anv_CmdLoadAtomicCounters(
3607 VkCmdBuffer cmdBuffer
,
3608 VkPipelineBindPoint pipelineBindPoint
,
3609 uint32_t startCounter
,
3610 uint32_t counterCount
,
3612 VkDeviceSize srcOffset
)
3617 void anv_CmdSaveAtomicCounters(
3618 VkCmdBuffer cmdBuffer
,
3619 VkPipelineBindPoint pipelineBindPoint
,
3620 uint32_t startCounter
,
3621 uint32_t counterCount
,
3622 VkBuffer destBuffer
,
3623 VkDeviceSize destOffset
)
3629 anv_framebuffer_destroy(struct anv_device
*device
,
3630 struct anv_object
*object
,
3631 VkObjectType obj_type
)
3633 struct anv_framebuffer
*fb
= (struct anv_framebuffer
*)object
;
3635 assert(obj_type
== VK_OBJECT_TYPE_FRAMEBUFFER
);
3637 anv_DestroyObject((VkDevice
) device
,
3638 VK_OBJECT_TYPE_DYNAMIC_VP_STATE
,
3641 anv_device_free(device
, fb
);
3644 VkResult
anv_CreateFramebuffer(
3646 const VkFramebufferCreateInfo
* pCreateInfo
,
3647 VkFramebuffer
* pFramebuffer
)
3649 struct anv_device
*device
= (struct anv_device
*) _device
;
3650 struct anv_framebuffer
*framebuffer
;
3652 static const struct anv_depth_stencil_view null_view
=
3653 { .depth_format
= D16_UNORM
, .depth_stride
= 0, .stencil_stride
= 0 };
3655 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3657 framebuffer
= anv_device_alloc(device
, sizeof(*framebuffer
), 8,
3658 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
3659 if (framebuffer
== NULL
)
3660 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3662 framebuffer
->base
.destructor
= anv_framebuffer_destroy
;
3664 framebuffer
->color_attachment_count
= pCreateInfo
->colorAttachmentCount
;
3665 for (uint32_t i
= 0; i
< pCreateInfo
->colorAttachmentCount
; i
++) {
3666 framebuffer
->color_attachments
[i
] =
3667 (struct anv_surface_view
*) pCreateInfo
->pColorAttachments
[i
].view
;
3670 if (pCreateInfo
->pDepthStencilAttachment
) {
3671 framebuffer
->depth_stencil
=
3672 (struct anv_depth_stencil_view
*) pCreateInfo
->pDepthStencilAttachment
->view
;
3674 framebuffer
->depth_stencil
= &null_view
;
3677 framebuffer
->sample_count
= pCreateInfo
->sampleCount
;
3678 framebuffer
->width
= pCreateInfo
->width
;
3679 framebuffer
->height
= pCreateInfo
->height
;
3680 framebuffer
->layers
= pCreateInfo
->layers
;
3682 anv_CreateDynamicViewportState((VkDevice
) device
,
3683 &(VkDynamicVpStateCreateInfo
) {
3684 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO
,
3685 .viewportAndScissorCount
= 1,
3686 .pViewports
= (VkViewport
[]) {
3690 .width
= pCreateInfo
->width
,
3691 .height
= pCreateInfo
->height
,
3696 .pScissors
= (VkRect
[]) {
3698 { pCreateInfo
->width
, pCreateInfo
->height
} },
3701 &framebuffer
->vp_state
);
3703 *pFramebuffer
= (VkFramebuffer
) framebuffer
;
3708 VkResult
anv_CreateRenderPass(
3710 const VkRenderPassCreateInfo
* pCreateInfo
,
3711 VkRenderPass
* pRenderPass
)
3713 struct anv_device
*device
= (struct anv_device
*) _device
;
3714 struct anv_render_pass
*pass
;
3717 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
);
3719 size
= sizeof(*pass
) +
3720 pCreateInfo
->layers
* sizeof(struct anv_render_pass_layer
);
3721 pass
= anv_device_alloc(device
, size
, 8,
3722 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
3724 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3726 pass
->render_area
= pCreateInfo
->renderArea
;
3728 pass
->num_layers
= pCreateInfo
->layers
;
3730 pass
->num_clear_layers
= 0;
3731 for (uint32_t i
= 0; i
< pCreateInfo
->layers
; i
++) {
3732 pass
->layers
[i
].color_load_op
= pCreateInfo
->pColorLoadOps
[i
];
3733 pass
->layers
[i
].clear_color
= pCreateInfo
->pColorLoadClearValues
[i
];
3734 if (pass
->layers
[i
].color_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
)
3735 pass
->num_clear_layers
++;
3738 *pRenderPass
= (VkRenderPass
) pass
;
3744 anv_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
,
3745 struct anv_render_pass
*pass
)
3747 const struct anv_depth_stencil_view
*view
=
3748 cmd_buffer
->framebuffer
->depth_stencil
;
3750 /* FIXME: Implement the PMA stall W/A */
3752 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DEPTH_BUFFER
,
3753 .SurfaceType
= SURFTYPE_2D
,
3754 .DepthWriteEnable
= view
->depth_stride
> 0,
3755 .StencilWriteEnable
= view
->stencil_stride
> 0,
3756 .HierarchicalDepthBufferEnable
= false,
3757 .SurfaceFormat
= view
->depth_format
,
3758 .SurfacePitch
= view
->depth_stride
> 0 ? view
->depth_stride
- 1 : 0,
3759 .SurfaceBaseAddress
= { view
->bo
, view
->depth_offset
},
3760 .Height
= pass
->render_area
.extent
.height
- 1,
3761 .Width
= pass
->render_area
.extent
.width
- 1,
3764 .MinimumArrayElement
= 0,
3765 .DepthBufferObjectControlState
= GEN8_MOCS
,
3766 .RenderTargetViewExtent
= 1 - 1,
3767 .SurfaceQPitch
= 0);
3769 /* Disable hierarchial depth buffers. */
3770 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_HIER_DEPTH_BUFFER
);
3772 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_STENCIL_BUFFER
,
3773 .StencilBufferEnable
= view
->stencil_stride
> 0,
3774 .StencilBufferObjectControlState
= GEN8_MOCS
,
3775 .SurfacePitch
= view
->stencil_stride
> 0 ? view
->stencil_stride
- 1 : 0,
3776 .SurfaceBaseAddress
= { view
->bo
, view
->stencil_offset
},
3777 .SurfaceQPitch
= 0);
3779 /* Clear the clear params. */
3780 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_CLEAR_PARAMS
);
3783 void anv_CmdBeginRenderPass(
3784 VkCmdBuffer cmdBuffer
,
3785 const VkRenderPassBegin
* pRenderPassBegin
)
3787 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*) cmdBuffer
;
3788 struct anv_render_pass
*pass
= (struct anv_render_pass
*) pRenderPassBegin
->renderPass
;
3789 struct anv_framebuffer
*framebuffer
=
3790 (struct anv_framebuffer
*) pRenderPassBegin
->framebuffer
;
3792 cmd_buffer
->framebuffer
= framebuffer
;
3794 cmd_buffer
->descriptors_dirty
|= VK_SHADER_STAGE_FRAGMENT_BIT
;
3796 anv_batch_emit(&cmd_buffer
->batch
, GEN8_3DSTATE_DRAWING_RECTANGLE
,
3797 .ClippedDrawingRectangleYMin
= pass
->render_area
.offset
.y
,
3798 .ClippedDrawingRectangleXMin
= pass
->render_area
.offset
.x
,
3799 .ClippedDrawingRectangleYMax
=
3800 pass
->render_area
.offset
.y
+ pass
->render_area
.extent
.height
- 1,
3801 .ClippedDrawingRectangleXMax
=
3802 pass
->render_area
.offset
.x
+ pass
->render_area
.extent
.width
- 1,
3803 .DrawingRectangleOriginY
= 0,
3804 .DrawingRectangleOriginX
= 0);
3806 anv_cmd_buffer_emit_depth_stencil(cmd_buffer
, pass
);
3808 anv_cmd_buffer_clear(cmd_buffer
, pass
);
3811 void anv_CmdEndRenderPass(
3812 VkCmdBuffer cmdBuffer
,
3813 VkRenderPass renderPass
)
3815 /* Emit a flushing pipe control at the end of a pass. This is kind of a
3816 * hack but it ensures that render targets always actually get written.
3817 * Eventually, we should do flushing based on image format transitions
3818 * or something of that nature.
3820 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
3821 anv_batch_emit(&cmd_buffer
->batch
, GEN8_PIPE_CONTROL
,
3822 .PostSyncOperation
= NoWrite
,
3823 .RenderTargetCacheFlushEnable
= true,
3824 .InstructionCacheInvalidateEnable
= true,
3825 .DepthCacheFlushEnable
= true,
3826 .VFCacheInvalidationEnable
= true,
3827 .TextureCacheInvalidationEnable
= true,
3828 .CommandStreamerStallEnable
= true);
3831 void vkCmdDbgMarkerBegin(
3832 VkCmdBuffer cmdBuffer
,
3833 const char* pMarker
)
3834 __attribute__ ((visibility ("default")));
3836 void vkCmdDbgMarkerEnd(
3837 VkCmdBuffer cmdBuffer
)
3838 __attribute__ ((visibility ("default")));
3840 VkResult
vkDbgSetObjectTag(
3845 __attribute__ ((visibility ("default")));
3848 void vkCmdDbgMarkerBegin(
3849 VkCmdBuffer cmdBuffer
,
3850 const char* pMarker
)
3854 void vkCmdDbgMarkerEnd(
3855 VkCmdBuffer cmdBuffer
)
3859 VkResult
vkDbgSetObjectTag(