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
37 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
42 #include "brw_device_info.h"
43 #include "util/macros.h"
44 #include "util/list.h"
47 #include <vulkan/vulkan.h>
48 #include <vulkan/vulkan_intel.h>
49 #include <vulkan/vk_wsi_lunarg.h>
51 #include "anv_entrypoints.h"
53 #include "brw_context.h"
59 #define anv_noreturn __attribute__((__noreturn__))
60 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
62 #define MIN(a, b) ((a) < (b) ? (a) : (b))
63 #define MAX(a, b) ((a) > (b) ? (a) : (b))
65 static inline uint32_t
66 align_u32(uint32_t v
, uint32_t a
)
68 return (v
+ a
- 1) & ~(a
- 1);
72 align_i32(int32_t v
, int32_t a
)
74 return (v
+ a
- 1) & ~(a
- 1);
77 /** Alignment must be a power of 2. */
79 anv_is_aligned(uintmax_t n
, uintmax_t a
)
81 assert(a
== (a
& -a
));
82 return (n
& (a
- 1)) == 0;
85 static inline uint32_t
86 anv_minify(uint32_t n
, uint32_t levels
)
91 return MAX(n
>> levels
, 1);
95 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
97 if (*inout_mask
& clear_mask
) {
98 *inout_mask
&= ~clear_mask
;
105 #define for_each_bit(b, dword) \
106 for (uint32_t __dword = (dword); \
107 (b) = __builtin_ffs(__dword) - 1, __dword; \
108 __dword &= ~(1 << (b)))
110 /* Define no kernel as 1, since that's an illegal offset for a kernel */
114 VkStructureType sType
;
118 /* Whenever we generate an error, pass it through this function. Useful for
119 * debugging, where we can break on it. Only call at error site, not when
120 * propagating errors. Might be useful to plug in a stack trace here.
123 static inline VkResult
124 vk_error(VkResult error
)
127 fprintf(stderr
, "vk_error: %x\n", error
);
133 void __anv_finishme(const char *file
, int line
, const char *format
, ...)
134 anv_printflike(3, 4);
135 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
136 void anv_loge_v(const char *format
, va_list va
);
139 * Print a FINISHME message, including its source location.
141 #define anv_finishme(format, ...) \
142 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
144 /* A non-fatal assert. Useful for debugging. */
146 #define anv_assert(x) ({ \
147 if (unlikely(!(x))) \
148 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
151 #define anv_assert(x)
154 void anv_abortf(const char *format
, ...) anv_noreturn
anv_printflike(1, 2);
155 void anv_abortfv(const char *format
, va_list va
) anv_noreturn
;
157 #define stub_return(v) \
159 anv_finishme("stub %s", __func__); \
165 anv_finishme("stub %s", __func__); \
170 * A dynamically growable, circular buffer. Elements are added at head and
171 * removed from tail. head and tail are free-running uint32_t indices and we
172 * only compute the modulo with size when accessing the array. This way,
173 * number of bytes in the queue is always head - tail, even in case of
180 uint32_t element_size
;
185 int anv_vector_init(struct anv_vector
*queue
, uint32_t element_size
, uint32_t size
);
186 void *anv_vector_add(struct anv_vector
*queue
);
187 void *anv_vector_remove(struct anv_vector
*queue
);
190 anv_vector_length(struct anv_vector
*queue
)
192 return (queue
->head
- queue
->tail
) / queue
->element_size
;
196 anv_vector_finish(struct anv_vector
*queue
)
201 #define anv_vector_foreach(elem, queue) \
202 static_assert(__builtin_types_compatible_p(__typeof__(queue), struct anv_vector *), ""); \
203 for (uint32_t __anv_vector_offset = (queue)->tail; \
204 elem = (queue)->data + (__anv_vector_offset & ((queue)->size - 1)), __anv_vector_offset < (queue)->head; \
205 __anv_vector_offset += (queue)->element_size)
215 /* Represents a lock-free linked list of "free" things. This is used by
216 * both the block pool and the state pools. Unfortunately, in order to
217 * solve the ABA problem, we can't use a single uint32_t head.
219 union anv_free_list
{
223 /* A simple count that is incremented every time the head changes. */
229 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
231 struct anv_block_state
{
241 struct anv_block_pool
{
242 struct anv_device
*device
;
249 * Array of mmaps and gem handles owned by the block pool, reclaimed when
250 * the block pool is destroyed.
252 struct anv_vector mmap_cleanups
;
256 union anv_free_list free_list
;
257 struct anv_block_state state
;
260 static inline uint32_t
261 anv_block_pool_size(struct anv_block_pool
*pool
)
263 return pool
->state
.end
;
272 struct anv_fixed_size_state_pool
{
274 union anv_free_list free_list
;
275 struct anv_block_state block
;
278 #define ANV_MIN_STATE_SIZE_LOG2 6
279 #define ANV_MAX_STATE_SIZE_LOG2 10
281 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2)
283 struct anv_state_pool
{
284 struct anv_block_pool
*block_pool
;
285 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
288 struct anv_state_stream
{
289 struct anv_block_pool
*block_pool
;
291 uint32_t current_block
;
295 void anv_block_pool_init(struct anv_block_pool
*pool
,
296 struct anv_device
*device
, uint32_t block_size
);
297 void anv_block_pool_finish(struct anv_block_pool
*pool
);
298 uint32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
299 void anv_block_pool_free(struct anv_block_pool
*pool
, uint32_t offset
);
300 void anv_state_pool_init(struct anv_state_pool
*pool
,
301 struct anv_block_pool
*block_pool
);
302 void anv_state_pool_finish(struct anv_state_pool
*pool
);
303 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
304 size_t state_size
, size_t alignment
);
305 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
306 void anv_state_stream_init(struct anv_state_stream
*stream
,
307 struct anv_block_pool
*block_pool
);
308 void anv_state_stream_finish(struct anv_state_stream
*stream
);
309 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
310 uint32_t size
, uint32_t alignment
);
313 * Implements a pool of re-usable BOs. The interface is identical to that
314 * of block_pool except that each block is its own BO.
317 struct anv_device
*device
;
324 void anv_bo_pool_init(struct anv_bo_pool
*pool
,
325 struct anv_device
*device
, uint32_t block_size
);
326 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
327 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
);
328 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
330 struct anv_physical_device
{
331 struct anv_instance
* instance
;
335 const struct brw_device_info
* info
;
336 uint64_t aperture_size
;
339 struct anv_instance
{
340 void * pAllocUserData
;
341 PFN_vkAllocFunction pfnAlloc
;
342 PFN_vkFreeFunction pfnFree
;
344 uint32_t physicalDeviceCount
;
345 struct anv_physical_device physicalDevice
;
348 struct anv_meta_state
{
355 VkPipelineLayout pipeline_layout
;
356 VkDescriptorSetLayout ds_layout
;
360 VkDynamicRasterState rs_state
;
361 VkDynamicColorBlendState cb_state
;
362 VkDynamicDepthStencilState ds_state
;
367 struct anv_device
* device
;
369 struct anv_state_pool
* pool
;
372 * Serial number of the most recently completed batch executed on the
375 struct anv_state completed_serial
;
378 * The next batch submitted to the engine will be assigned this serial
381 uint32_t next_serial
;
383 uint32_t last_collected_serial
;
387 struct anv_instance
* instance
;
389 struct brw_device_info info
;
393 struct anv_bo_pool batch_bo_pool
;
395 struct anv_block_pool dynamic_state_block_pool
;
396 struct anv_state_pool dynamic_state_pool
;
398 struct anv_block_pool instruction_block_pool
;
399 struct anv_block_pool surface_state_block_pool
;
400 struct anv_state_pool surface_state_pool
;
402 struct anv_meta_state meta_state
;
404 struct anv_state border_colors
;
406 struct anv_queue queue
;
408 struct anv_block_pool scratch_block_pool
;
410 struct anv_compiler
* compiler
;
411 pthread_mutex_t mutex
;
415 anv_device_alloc(struct anv_device
* device
,
418 VkSystemAllocType allocType
);
421 anv_device_free(struct anv_device
* device
,
424 void* anv_gem_mmap(struct anv_device
*device
,
425 uint32_t gem_handle
, uint64_t offset
, uint64_t size
);
426 void anv_gem_munmap(void *p
, uint64_t size
);
427 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
428 void anv_gem_close(struct anv_device
*device
, int gem_handle
);
429 int anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
430 int anv_gem_wait(struct anv_device
*device
, int gem_handle
, int64_t *timeout_ns
);
431 int anv_gem_execbuffer(struct anv_device
*device
,
432 struct drm_i915_gem_execbuffer2
*execbuf
);
433 int anv_gem_set_tiling(struct anv_device
*device
, int gem_handle
,
434 uint32_t stride
, uint32_t tiling
);
435 int anv_gem_create_context(struct anv_device
*device
);
436 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
437 int anv_gem_get_param(int fd
, uint32_t param
);
438 int anv_gem_get_aperture(int fd
, uint64_t *size
);
439 int anv_gem_handle_to_fd(struct anv_device
*device
, int gem_handle
);
440 int anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
441 int anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
443 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
445 struct anv_reloc_list
{
448 struct drm_i915_gem_relocation_entry
* relocs
;
449 struct anv_bo
** reloc_bos
;
452 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
453 struct anv_device
*device
);
454 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
455 struct anv_device
*device
);
457 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
458 struct anv_device
*device
,
459 uint32_t offset
, struct anv_bo
*target_bo
,
462 struct anv_batch_bo
{
463 /* Link in the anv_cmd_buffer.owned_batch_bos list */
464 struct list_head link
;
468 /* Bytes actually consumed in this batch BO */
471 struct anv_reloc_list relocs
;
475 struct anv_device
* device
;
481 struct anv_reloc_list
* relocs
;
483 /* This callback is called (with the associated user data) in the event
484 * that the batch runs out of space.
486 VkResult (*extend_cb
)(struct anv_batch
*, void *);
490 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
491 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
492 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
493 void *location
, struct anv_bo
*bo
, uint32_t offset
);
500 #define __gen_address_type struct anv_address
501 #define __gen_user_data struct anv_batch
503 static inline uint64_t
504 __gen_combine_address(struct anv_batch
*batch
, void *location
,
505 const struct anv_address address
, uint32_t delta
)
507 if (address
.bo
== NULL
) {
510 assert(batch
->start
<= location
&& location
< batch
->end
);
512 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
516 #include "gen7_pack.h"
517 #include "gen75_pack.h"
518 #undef GEN8_3DSTATE_MULTISAMPLE
519 #include "gen8_pack.h"
521 #define anv_batch_emit(batch, cmd, ...) do { \
522 void *__dst = anv_batch_emit_dwords(batch, cmd ## _length); \
523 struct cmd __template = { \
527 cmd ## _pack(batch, __dst, &__template); \
528 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__dst, cmd ## _length * 4)); \
531 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
532 void *__dst = anv_batch_emit_dwords(batch, n); \
533 struct cmd __template = { \
535 .DwordLength = n - cmd ## _length_bias, \
538 cmd ## _pack(batch, __dst, &__template); \
542 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
546 assert(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
547 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
548 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
549 dw[i] = (dwords0)[i] | (dwords1)[i]; \
550 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
553 static const struct GEN7_MEMORY_OBJECT_CONTROL_STATE GEN7_MOCS
= {
554 .GraphicsDataTypeGFDT
= 0,
555 .LLCCacheabilityControlLLCCC
= 0,
556 .L3CacheabilityControlL3CC
= 0
559 #define GEN8_MOCS { \
560 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
561 .TargetCache = L3DefertoPATforLLCeLLCselection, \
565 struct anv_device_memory
{
567 VkDeviceSize map_size
;
571 struct anv_dynamic_vp_state
{
572 struct anv_state sf_clip_vp
;
573 struct anv_state cc_vp
;
574 struct anv_state scissor
;
577 struct anv_dynamic_rs_state
{
579 uint32_t sf
[GEN7_3DSTATE_SF_length
];
583 uint32_t sf
[GEN8_3DSTATE_SF_length
];
584 uint32_t raster
[GEN8_3DSTATE_RASTER_length
];
588 struct anv_dynamic_ds_state
{
590 uint32_t depth_stencil_state
[GEN7_DEPTH_STENCIL_STATE_length
];
591 uint32_t color_calc_state
[GEN8_COLOR_CALC_STATE_length
];
595 uint32_t wm_depth_stencil
[GEN8_3DSTATE_WM_DEPTH_STENCIL_length
];
596 uint32_t color_calc_state
[GEN8_COLOR_CALC_STATE_length
];
600 struct anv_dynamic_cb_state
{
601 uint32_t color_calc_state
[GEN8_COLOR_CALC_STATE_length
];
605 struct anv_descriptor_slot
{
610 struct anv_descriptor_set_layout
{
612 uint32_t surface_count
;
613 struct anv_descriptor_slot
*surface_start
;
614 uint32_t sampler_count
;
615 struct anv_descriptor_slot
*sampler_start
;
616 } stage
[VK_SHADER_STAGE_NUM
];
619 uint32_t num_dynamic_buffers
;
620 uint32_t shader_stages
;
621 struct anv_descriptor_slot entries
[0];
624 struct anv_descriptor
{
625 struct anv_sampler
*sampler
;
626 struct anv_surface_view
*view
;
629 struct anv_descriptor_set
{
630 struct anv_descriptor descriptors
[0];
634 anv_descriptor_set_create(struct anv_device
*device
,
635 const struct anv_descriptor_set_layout
*layout
,
636 struct anv_descriptor_set
**out_set
);
639 anv_descriptor_set_destroy(struct anv_device
*device
,
640 struct anv_descriptor_set
*set
);
646 struct anv_pipeline_layout
{
648 struct anv_descriptor_set_layout
*layout
;
649 uint32_t surface_start
[VK_SHADER_STAGE_NUM
];
650 uint32_t sampler_start
[VK_SHADER_STAGE_NUM
];
656 uint32_t surface_count
;
657 uint32_t sampler_count
;
658 } stage
[VK_SHADER_STAGE_NUM
];
662 struct anv_device
* device
;
670 #define ANV_CMD_BUFFER_PIPELINE_DIRTY (1 << 0)
671 #define ANV_CMD_BUFFER_RS_DIRTY (1 << 2)
672 #define ANV_CMD_BUFFER_DS_DIRTY (1 << 3)
673 #define ANV_CMD_BUFFER_CB_DIRTY (1 << 4)
674 #define ANV_CMD_BUFFER_VP_DIRTY (1 << 5)
675 #define ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY (1 << 6)
677 struct anv_vertex_binding
{
678 struct anv_buffer
* buffer
;
682 struct anv_descriptor_set_binding
{
683 struct anv_descriptor_set
* set
;
684 uint32_t dynamic_offsets
[128];
687 /** State required while building cmd buffer */
688 struct anv_cmd_state
{
689 uint32_t current_pipeline
;
692 uint32_t compute_dirty
;
693 uint32_t descriptors_dirty
;
694 uint32_t scratch_size
;
695 struct anv_pipeline
* pipeline
;
696 struct anv_pipeline
* compute_pipeline
;
697 struct anv_framebuffer
* framebuffer
;
698 struct anv_render_pass
* pass
;
699 struct anv_subpass
* subpass
;
700 struct anv_dynamic_rs_state
* rs_state
;
701 struct anv_dynamic_ds_state
* ds_state
;
702 struct anv_dynamic_vp_state
* vp_state
;
703 struct anv_dynamic_cb_state
* cb_state
;
704 uint32_t state_vf
[GEN8_3DSTATE_VF_length
];
705 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
706 struct anv_descriptor_set_binding descriptors
[MAX_SETS
];
709 struct anv_buffer
* index_buffer
;
711 uint32_t index_offset
;
715 struct anv_cmd_pool
{
716 struct list_head cmd_buffers
;
719 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
721 enum anv_cmd_buffer_exec_mode
{
722 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
723 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
724 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
725 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
728 struct anv_cmd_buffer
{
729 struct anv_device
* device
;
731 struct list_head pool_link
;
733 struct anv_batch batch
;
735 /* Fields required for the actual chain of anv_batch_bo's.
737 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
739 struct list_head batch_bos
;
740 struct list_head surface_bos
;
741 uint32_t surface_next
;
742 enum anv_cmd_buffer_exec_mode exec_mode
;
744 /* A vector of anv_batch_bo pointers for every batch or surface buffer
745 * referenced by this command buffer
747 * initialized by anv_cmd_buffer_init_batch_bo_chain()
749 struct anv_vector seen_bbos
;
751 /* Information needed for execbuf
753 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
756 struct drm_i915_gem_execbuffer2 execbuf
;
758 struct drm_i915_gem_exec_object2
* objects
;
760 struct anv_bo
** bos
;
762 /* Allocated length of the 'objects' and 'bos' arrays */
763 uint32_t array_length
;
768 /* Serial for tracking buffer completion */
771 /* Stream objects for storing temporary data */
772 struct anv_state_stream surface_state_stream
;
773 struct anv_state_stream dynamic_state_stream
;
775 VkCmdBufferOptimizeFlags opt_flags
;
776 VkCmdBufferLevel level
;
778 struct anv_cmd_state state
;
781 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
782 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
783 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
784 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
785 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
786 struct anv_cmd_buffer
*secondary
);
787 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
789 VkResult
anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
790 unsigned stage
, struct anv_state
*bt_state
);
791 VkResult
anv_cmd_buffer_emit_samplers(struct anv_cmd_buffer
*cmd_buffer
,
792 unsigned stage
, struct anv_state
*state
);
793 void anv_flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
);
795 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
796 uint32_t *a
, uint32_t dwords
,
798 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
799 uint32_t *a
, uint32_t *b
,
800 uint32_t dwords
, uint32_t alignment
);
801 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
802 struct anv_subpass
*subpass
);
805 anv_cmd_buffer_current_surface_bo(struct anv_cmd_buffer
*cmd_buffer
);
806 struct anv_reloc_list
*
807 anv_cmd_buffer_current_surface_relocs(struct anv_cmd_buffer
*cmd_buffer
);
809 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
,
810 uint32_t size
, uint32_t alignment
);
812 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
813 uint32_t size
, uint32_t alignment
);
815 VkResult
anv_cmd_buffer_new_surface_state_bo(struct anv_cmd_buffer
*cmd_buffer
);
817 void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
818 void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
820 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
822 void gen7_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
823 struct anv_subpass
*subpass
);
825 void gen8_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
826 struct anv_subpass
*subpass
);
828 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
829 struct anv_subpass
*subpass
);
831 void anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
,
832 struct anv_render_pass
*pass
,
833 const VkClearValue
*clear_values
);
835 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
839 struct drm_i915_gem_execbuffer2 execbuf
;
840 struct drm_i915_gem_exec_object2 exec2_objects
[1];
844 struct anv_shader_module
{
850 struct anv_shader_module
* module
;
854 struct anv_pipeline
{
855 struct anv_device
* device
;
856 struct anv_batch batch
;
857 uint32_t batch_data
[256];
858 struct anv_reloc_list batch_relocs
;
859 struct anv_shader
* shaders
[VK_SHADER_STAGE_NUM
];
860 struct anv_pipeline_layout
* layout
;
863 struct brw_vs_prog_data vs_prog_data
;
864 struct brw_wm_prog_data wm_prog_data
;
865 struct brw_gs_prog_data gs_prog_data
;
866 struct brw_cs_prog_data cs_prog_data
;
867 bool writes_point_size
;
868 struct brw_stage_prog_data
* prog_data
[VK_SHADER_STAGE_NUM
];
869 uint32_t scratch_start
[VK_SHADER_STAGE_NUM
];
870 uint32_t total_scratch
;
874 uint32_t nr_vs_entries
;
877 uint32_t nr_gs_entries
;
880 uint32_t active_stages
;
881 struct anv_state_stream program_stream
;
882 struct anv_state blend_state
;
889 uint32_t ps_grf_start0
;
890 uint32_t ps_grf_start2
;
892 uint32_t gs_vertex_count
;
896 uint32_t binding_stride
[MAX_VBS
];
897 bool instancing_enable
[MAX_VBS
];
898 bool primitive_restart
;
901 uint32_t cs_thread_width_max
;
902 uint32_t cs_right_mask
;
905 uint32_t sf
[GEN7_3DSTATE_SF_length
];
906 uint32_t depth_stencil_state
[GEN7_DEPTH_STENCIL_STATE_length
];
910 uint32_t sf
[GEN8_3DSTATE_SF_length
];
911 uint32_t vf
[GEN8_3DSTATE_VF_length
];
912 uint32_t raster
[GEN8_3DSTATE_RASTER_length
];
913 uint32_t wm_depth_stencil
[GEN8_3DSTATE_WM_DEPTH_STENCIL_length
];
917 struct anv_graphics_pipeline_create_info
{
919 bool disable_viewport
;
920 bool disable_scissor
;
926 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
927 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
928 const struct anv_graphics_pipeline_create_info
*extra
);
931 anv_graphics_pipeline_create(VkDevice device
,
932 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
933 const struct anv_graphics_pipeline_create_info
*extra
,
934 VkPipeline
*pPipeline
);
937 gen7_graphics_pipeline_create(VkDevice _device
,
938 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
939 const struct anv_graphics_pipeline_create_info
*extra
,
940 VkPipeline
*pPipeline
);
943 gen8_graphics_pipeline_create(VkDevice _device
,
944 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
945 const struct anv_graphics_pipeline_create_info
*extra
,
946 VkPipeline
*pPipeline
);
948 gen7_compute_pipeline_create(VkDevice _device
,
949 const VkComputePipelineCreateInfo
*pCreateInfo
,
950 VkPipeline
*pPipeline
);
953 gen8_compute_pipeline_create(VkDevice _device
,
954 const VkComputePipelineCreateInfo
*pCreateInfo
,
955 VkPipeline
*pPipeline
);
957 struct anv_compiler
*anv_compiler_create(struct anv_device
*device
);
958 void anv_compiler_destroy(struct anv_compiler
*compiler
);
959 int anv_compiler_run(struct anv_compiler
*compiler
, struct anv_pipeline
*pipeline
);
960 void anv_compiler_free(struct anv_pipeline
*pipeline
);
963 const VkFormat vk_format
;
965 uint16_t surface_format
; /**< RENDER_SURFACE_STATE.SurfaceFormat */
966 uint8_t cpp
; /**< Bytes-per-pixel of anv_format::surface_format. */
967 uint8_t num_channels
;
968 uint16_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
973 * Stencil formats are often a special case. To reduce the number of lookups
974 * into the VkFormat-to-anv_format translation table when working with
975 * stencil, here is the handle to the table's entry for VK_FORMAT_S8_UINT.
977 extern const struct anv_format
*const anv_format_s8_uint
;
979 const struct anv_format
*
980 anv_format_for_vk_format(VkFormat format
);
983 anv_format_is_color(const struct anv_format
*format
)
985 return !format
->depth_format
&& !format
->has_stencil
;
989 anv_format_is_depth_or_stencil(const struct anv_format
*format
)
991 return format
->depth_format
|| format
->has_stencil
;
994 struct anv_image_view_info
{
995 uint8_t surface_type
; /**< RENDER_SURFACE_STATE.SurfaceType */
996 bool is_array
:1; /**< RENDER_SURFACE_STATE.SurfaceArray */
997 bool is_cube
:1; /**< RENDER_SURFACE_STATE.CubeFaceEnable* */
1000 const struct anv_image_view_info
*
1001 anv_image_view_info_for_vk_image_view_type(VkImageViewType type
);
1004 * A proxy for the color surfaces, depth surfaces, and stencil surfaces.
1006 struct anv_surface
{
1008 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1012 uint32_t stride
; /**< RENDER_SURFACE_STATE.SurfacePitch */
1013 uint16_t qpitch
; /**< RENDER_SURFACE_STATE.QPitch */
1016 * \name Alignment of miptree images, in units of pixels.
1018 * These fields contain the real alignment values, not the values to be
1019 * given to the GPU. For example, if h_align is 4, then program the GPU
1023 uint8_t h_align
; /**< RENDER_SURFACE_STATE.SurfaceHorizontalAlignment */
1024 uint8_t v_align
; /**< RENDER_SURFACE_STATE.SurfaceVerticalAlignment */
1027 uint8_t tile_mode
; /**< RENDER_SURFACE_STATE.TileMode */
1032 const struct anv_format
*format
;
1035 uint32_t array_size
;
1040 /* Set when bound */
1042 VkDeviceSize offset
;
1044 struct anv_swap_chain
*swap_chain
;
1046 /** RENDER_SURFACE_STATE.SurfaceType */
1049 /** Primary surface is either color or depth. */
1050 struct anv_surface primary_surface
;
1052 /** Stencil surface is optional. */
1053 struct anv_surface stencil_surface
;
1056 struct anv_surface_view
{
1057 struct anv_state surface_state
; /**< RENDER_SURFACE_STATE */
1059 uint32_t offset
; /**< VkBufferCreateInfo::offset */
1060 uint32_t range
; /**< VkBufferCreateInfo::range */
1061 const struct anv_format
*format
; /**< VkBufferCreateInfo::format */
1064 struct anv_buffer_view
{
1065 struct anv_surface_view view
;
1068 struct anv_image_view
{
1069 struct anv_surface_view view
;
1073 enum anv_attachment_view_type
{
1074 ANV_ATTACHMENT_VIEW_TYPE_COLOR
,
1075 ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL
,
1078 struct anv_attachment_view
{
1079 enum anv_attachment_view_type attachment_type
;
1083 struct anv_color_attachment_view
{
1084 struct anv_attachment_view base
;
1085 struct anv_surface_view view
;
1088 struct anv_depth_stencil_view
{
1089 struct anv_attachment_view base
;
1093 uint32_t depth_offset
; /**< Offset into bo. */
1094 uint32_t depth_stride
; /**< 3DSTATE_DEPTH_BUFFER.SurfacePitch */
1095 uint32_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
1096 uint16_t depth_qpitch
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceQPitch */
1098 uint32_t stencil_offset
; /**< Offset into bo. */
1099 uint32_t stencil_stride
; /**< 3DSTATE_STENCIL_BUFFER.SurfacePitch */
1100 uint16_t stencil_qpitch
; /**< 3DSTATE_STENCIL_BUFFER.SurfaceQPitch */
1103 struct anv_image_create_info
{
1104 const VkImageCreateInfo
*vk_info
;
1105 bool force_tile_mode
;
1110 VkResult
anv_image_create(VkDevice _device
,
1111 const struct anv_image_create_info
*info
,
1114 void anv_image_view_init(struct anv_image_view
*view
,
1115 struct anv_device
*device
,
1116 const VkImageViewCreateInfo
* pCreateInfo
,
1117 struct anv_cmd_buffer
*cmd_buffer
);
1120 gen7_image_view_init(struct anv_image_view
*iview
,
1121 struct anv_device
*device
,
1122 const VkImageViewCreateInfo
* pCreateInfo
,
1123 struct anv_cmd_buffer
*cmd_buffer
);
1126 gen8_image_view_init(struct anv_image_view
*iview
,
1127 struct anv_device
*device
,
1128 const VkImageViewCreateInfo
* pCreateInfo
,
1129 struct anv_cmd_buffer
*cmd_buffer
);
1131 void anv_color_attachment_view_init(struct anv_color_attachment_view
*view
,
1132 struct anv_device
*device
,
1133 const VkAttachmentViewCreateInfo
* pCreateInfo
,
1134 struct anv_cmd_buffer
*cmd_buffer
);
1136 void gen7_color_attachment_view_init(struct anv_color_attachment_view
*aview
,
1137 struct anv_device
*device
,
1138 const VkAttachmentViewCreateInfo
* pCreateInfo
,
1139 struct anv_cmd_buffer
*cmd_buffer
);
1141 void gen8_color_attachment_view_init(struct anv_color_attachment_view
*aview
,
1142 struct anv_device
*device
,
1143 const VkAttachmentViewCreateInfo
* pCreateInfo
,
1144 struct anv_cmd_buffer
*cmd_buffer
);
1146 VkResult
anv_buffer_view_create(struct anv_device
*device
,
1147 const VkBufferViewCreateInfo
*pCreateInfo
,
1148 struct anv_buffer_view
**view_out
);
1150 void anv_fill_buffer_surface_state(struct anv_device
*device
, void *state
,
1151 const struct anv_format
*format
,
1152 uint32_t offset
, uint32_t range
);
1154 void gen7_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1155 uint32_t offset
, uint32_t range
);
1156 void gen8_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1157 uint32_t offset
, uint32_t range
);
1159 void anv_surface_view_fini(struct anv_device
*device
,
1160 struct anv_surface_view
*view
);
1162 struct anv_sampler
{
1166 struct anv_framebuffer
{
1171 /* Viewport for clears */
1172 VkDynamicViewportState vp_state
;
1174 uint32_t attachment_count
;
1175 const struct anv_attachment_view
* attachments
[0];
1178 struct anv_subpass
{
1179 uint32_t input_count
;
1180 uint32_t * input_attachments
;
1181 uint32_t color_count
;
1182 uint32_t * color_attachments
;
1183 uint32_t * resolve_attachments
;
1184 uint32_t depth_stencil_attachment
;
1187 struct anv_render_pass_attachment
{
1188 const struct anv_format
*format
;
1190 VkAttachmentLoadOp load_op
;
1191 VkAttachmentLoadOp stencil_load_op
;
1194 struct anv_render_pass
{
1195 uint32_t attachment_count
;
1196 uint32_t subpass_count
;
1198 uint32_t num_color_clear_attachments
;
1199 bool has_depth_clear_attachment
;
1200 bool has_stencil_clear_attachment
;
1202 struct anv_render_pass_attachment
* attachments
;
1203 struct anv_subpass subpasses
[0];
1206 struct anv_query_pool_slot
{
1212 struct anv_query_pool
{
1218 void anv_device_init_meta(struct anv_device
*device
);
1219 void anv_device_finish_meta(struct anv_device
*device
);
1221 void *anv_lookup_entrypoint(const char *name
);
1223 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1225 static inline struct __anv_type * \
1226 __anv_type ## _from_handle(__VkType _handle) \
1228 return (struct __anv_type *) _handle; \
1231 static inline __VkType \
1232 __anv_type ## _to_handle(struct __anv_type *_obj) \
1234 return (__VkType) _obj; \
1237 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1239 static inline struct __anv_type * \
1240 __anv_type ## _from_handle(__VkType _handle) \
1242 return (struct __anv_type *) _handle.handle; \
1245 static inline __VkType \
1246 __anv_type ## _to_handle(struct __anv_type *_obj) \
1248 return (__VkType) { .handle = (uint64_t) _obj }; \
1251 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1252 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1254 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCmdBuffer
)
1255 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1256 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1257 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1258 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1259 ANV_DEFINE_HANDLE_CASTS(anv_swap_chain
, VkSwapChainWSI
);
1261 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCmdPool
)
1262 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_attachment_view
, VkAttachmentView
)
1263 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1264 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
);
1265 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1266 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1267 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1268 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_cb_state
, VkDynamicColorBlendState
)
1269 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_ds_state
, VkDynamicDepthStencilState
)
1270 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_rs_state
, VkDynamicRasterState
)
1271 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_vp_state
, VkDynamicViewportState
)
1272 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1273 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1274 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1275 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1276 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1277 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1278 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1279 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1280 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1281 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader
, VkShader
)
1282 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1284 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1286 static inline const __VkType * \
1287 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1289 return (const __VkType *) __anv_obj; \
1292 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1293 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1295 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1296 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1297 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)