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 #define GEN8_MOCS { \
554 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
555 .TargetCache = L3DefertoPATforLLCeLLCselection, \
559 struct anv_device_memory
{
561 VkDeviceSize map_size
;
565 struct anv_dynamic_vp_state
{
566 struct anv_state sf_clip_vp
;
567 struct anv_state cc_vp
;
568 struct anv_state scissor
;
571 struct anv_dynamic_rs_state
{
572 uint32_t state_sf
[GEN8_3DSTATE_SF_length
];
573 uint32_t state_raster
[GEN8_3DSTATE_RASTER_length
];
576 struct anv_dynamic_ds_state
{
577 uint32_t state_wm_depth_stencil
[GEN8_3DSTATE_WM_DEPTH_STENCIL_length
];
578 uint32_t state_color_calc
[GEN8_COLOR_CALC_STATE_length
];
581 struct anv_dynamic_cb_state
{
582 uint32_t state_color_calc
[GEN8_COLOR_CALC_STATE_length
];
586 struct anv_descriptor_slot
{
591 struct anv_descriptor_set_layout
{
593 uint32_t surface_count
;
594 struct anv_descriptor_slot
*surface_start
;
595 uint32_t sampler_count
;
596 struct anv_descriptor_slot
*sampler_start
;
597 } stage
[VK_SHADER_STAGE_NUM
];
600 uint32_t num_dynamic_buffers
;
601 uint32_t shader_stages
;
602 struct anv_descriptor_slot entries
[0];
605 struct anv_descriptor
{
606 struct anv_sampler
*sampler
;
607 struct anv_surface_view
*view
;
610 struct anv_descriptor_set
{
611 struct anv_descriptor descriptors
[0];
615 anv_descriptor_set_create(struct anv_device
*device
,
616 const struct anv_descriptor_set_layout
*layout
,
617 struct anv_descriptor_set
**out_set
);
620 anv_descriptor_set_destroy(struct anv_device
*device
,
621 struct anv_descriptor_set
*set
);
627 struct anv_pipeline_layout
{
629 struct anv_descriptor_set_layout
*layout
;
630 uint32_t surface_start
[VK_SHADER_STAGE_NUM
];
631 uint32_t sampler_start
[VK_SHADER_STAGE_NUM
];
637 uint32_t surface_count
;
638 uint32_t sampler_count
;
639 } stage
[VK_SHADER_STAGE_NUM
];
643 struct anv_device
* device
;
651 #define ANV_CMD_BUFFER_PIPELINE_DIRTY (1 << 0)
652 #define ANV_CMD_BUFFER_RS_DIRTY (1 << 2)
653 #define ANV_CMD_BUFFER_DS_DIRTY (1 << 3)
654 #define ANV_CMD_BUFFER_CB_DIRTY (1 << 4)
655 #define ANV_CMD_BUFFER_VP_DIRTY (1 << 5)
656 #define ANV_CMD_BUFFER_INDEX_BUFFER_DIRTY (1 << 6)
658 struct anv_vertex_binding
{
659 struct anv_buffer
* buffer
;
663 struct anv_descriptor_set_binding
{
664 struct anv_descriptor_set
* set
;
665 uint32_t dynamic_offsets
[128];
668 /** State required while building cmd buffer */
669 struct anv_cmd_state
{
670 uint32_t current_pipeline
;
673 uint32_t compute_dirty
;
674 uint32_t descriptors_dirty
;
675 uint32_t scratch_size
;
676 struct anv_pipeline
* pipeline
;
677 struct anv_pipeline
* compute_pipeline
;
678 struct anv_framebuffer
* framebuffer
;
679 struct anv_render_pass
* pass
;
680 struct anv_subpass
* subpass
;
681 struct anv_dynamic_rs_state
* rs_state
;
682 struct anv_dynamic_ds_state
* ds_state
;
683 struct anv_dynamic_vp_state
* vp_state
;
684 struct anv_dynamic_cb_state
* cb_state
;
685 uint32_t state_vf
[GEN8_3DSTATE_VF_length
];
686 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
687 struct anv_descriptor_set_binding descriptors
[MAX_SETS
];
690 struct anv_cmd_pool
{
691 struct list_head cmd_buffers
;
694 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
696 enum anv_cmd_buffer_exec_mode
{
697 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
698 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
699 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
700 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
703 struct anv_cmd_buffer
{
704 struct anv_device
* device
;
706 struct list_head pool_link
;
708 struct anv_batch batch
;
710 /* Fields required for the actual chain of anv_batch_bo's.
712 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
714 struct list_head batch_bos
;
715 struct list_head surface_bos
;
716 uint32_t surface_next
;
717 enum anv_cmd_buffer_exec_mode exec_mode
;
719 /* A vector of anv_batch_bo pointers for every batch or surface buffer
720 * referenced by this command buffer
722 * initialized by anv_cmd_buffer_init_batch_bo_chain()
724 struct anv_vector seen_bbos
;
726 /* Information needed for execbuf
728 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
731 struct drm_i915_gem_execbuffer2 execbuf
;
733 struct drm_i915_gem_exec_object2
* objects
;
735 struct anv_bo
** bos
;
737 /* Allocated length of the 'objects' and 'bos' arrays */
738 uint32_t array_length
;
743 /* Serial for tracking buffer completion */
746 /* Stream objects for storing temporary data */
747 struct anv_state_stream surface_state_stream
;
748 struct anv_state_stream dynamic_state_stream
;
750 VkCmdBufferOptimizeFlags opt_flags
;
751 VkCmdBufferLevel level
;
753 struct anv_cmd_state state
;
756 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
757 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
758 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
759 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
760 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
761 struct anv_cmd_buffer
*secondary
);
762 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
765 anv_cmd_buffer_current_surface_bo(struct anv_cmd_buffer
*cmd_buffer
);
766 struct anv_reloc_list
*
767 anv_cmd_buffer_current_surface_relocs(struct anv_cmd_buffer
*cmd_buffer
);
769 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
,
770 uint32_t size
, uint32_t alignment
);
772 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
773 uint32_t size
, uint32_t alignment
);
775 VkResult
anv_cmd_buffer_new_surface_state_bo(struct anv_cmd_buffer
*cmd_buffer
);
777 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
779 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
780 struct anv_subpass
*subpass
);
782 void anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
,
783 struct anv_render_pass
*pass
,
784 const VkClearValue
*clear_values
);
786 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
790 struct drm_i915_gem_execbuffer2 execbuf
;
791 struct drm_i915_gem_exec_object2 exec2_objects
[1];
795 struct anv_shader_module
{
801 struct anv_shader_module
* module
;
805 struct anv_pipeline
{
806 struct anv_device
* device
;
807 struct anv_batch batch
;
808 uint32_t batch_data
[256];
809 struct anv_reloc_list batch_relocs
;
810 struct anv_shader
* shaders
[VK_SHADER_STAGE_NUM
];
811 struct anv_pipeline_layout
* layout
;
814 struct brw_vs_prog_data vs_prog_data
;
815 struct brw_wm_prog_data wm_prog_data
;
816 struct brw_gs_prog_data gs_prog_data
;
817 struct brw_cs_prog_data cs_prog_data
;
818 bool writes_point_size
;
819 struct brw_stage_prog_data
* prog_data
[VK_SHADER_STAGE_NUM
];
820 uint32_t scratch_start
[VK_SHADER_STAGE_NUM
];
821 uint32_t total_scratch
;
825 uint32_t nr_vs_entries
;
828 uint32_t nr_gs_entries
;
831 uint32_t active_stages
;
832 struct anv_state_stream program_stream
;
833 struct anv_state blend_state
;
838 uint32_t gs_vertex_count
;
842 uint32_t binding_stride
[MAX_VBS
];
844 uint32_t state_sf
[GEN8_3DSTATE_SF_length
];
845 uint32_t state_vf
[GEN8_3DSTATE_VF_length
];
846 uint32_t state_raster
[GEN8_3DSTATE_RASTER_length
];
847 uint32_t state_wm_depth_stencil
[GEN8_3DSTATE_WM_DEPTH_STENCIL_length
];
849 uint32_t cs_thread_width_max
;
850 uint32_t cs_right_mask
;
853 struct anv_pipeline_create_info
{
855 bool disable_viewport
;
856 bool disable_scissor
;
862 anv_pipeline_create(VkDevice device
,
863 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
864 const struct anv_pipeline_create_info
*extra
,
865 VkPipeline
*pPipeline
);
867 struct anv_compiler
*anv_compiler_create(struct anv_device
*device
);
868 void anv_compiler_destroy(struct anv_compiler
*compiler
);
869 int anv_compiler_run(struct anv_compiler
*compiler
, struct anv_pipeline
*pipeline
);
870 void anv_compiler_free(struct anv_pipeline
*pipeline
);
873 const VkFormat vk_format
;
875 uint16_t surface_format
; /**< RENDER_SURFACE_STATE.SurfaceFormat */
876 uint8_t cpp
; /**< Bytes-per-pixel of anv_format::surface_format. */
877 uint8_t num_channels
;
878 uint16_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
883 * Stencil formats are often a special case. To reduce the number of lookups
884 * into the VkFormat-to-anv_format translation table when working with
885 * stencil, here is the handle to the table's entry for VK_FORMAT_S8_UINT.
887 extern const struct anv_format
*const anv_format_s8_uint
;
889 const struct anv_format
*
890 anv_format_for_vk_format(VkFormat format
);
891 bool anv_is_vk_format_depth_or_stencil(VkFormat format
);
894 * A proxy for the color surfaces, depth surfaces, and stencil surfaces.
898 * Offset from VkImage's base address, as bound by vkBindImageMemory().
902 uint32_t stride
; /**< RENDER_SURFACE_STATE.SurfacePitch */
903 uint16_t qpitch
; /**< RENDER_SURFACE_STATE.QPitch */
906 * \name Alignment of miptree images, in units of pixels.
908 * These fields contain the real alignment values, not the values to be
909 * given to the GPU. For example, if h_align is 4, then program the GPU
913 uint8_t h_align
; /**< RENDER_SURFACE_STATE.SurfaceHorizontalAlignment */
914 uint8_t v_align
; /**< RENDER_SURFACE_STATE.SurfaceVerticalAlignment */
917 uint8_t tile_mode
; /**< RENDER_SURFACE_STATE.TileMode */
922 const struct anv_format
*format
;
934 struct anv_swap_chain
*swap_chain
;
936 /** RENDER_SURFACE_STATE.SurfaceType */
939 /** Primary surface is either color or depth. */
940 struct anv_surface primary_surface
;
942 /** Stencil surface is optional. */
943 struct anv_surface stencil_surface
;
946 struct anv_surface_view
{
947 struct anv_state surface_state
; /**< RENDER_SURFACE_STATE */
949 uint32_t offset
; /**< VkBufferCreateInfo::offset */
950 uint32_t range
; /**< VkBufferCreateInfo::range */
951 const struct anv_format
*format
; /**< VkBufferCreateInfo::format */
954 struct anv_buffer_view
{
955 struct anv_surface_view view
;
958 struct anv_image_view
{
959 struct anv_surface_view view
;
963 enum anv_attachment_view_type
{
964 ANV_ATTACHMENT_VIEW_TYPE_COLOR
,
965 ANV_ATTACHMENT_VIEW_TYPE_DEPTH_STENCIL
,
968 struct anv_attachment_view
{
969 enum anv_attachment_view_type attachment_type
;
973 struct anv_color_attachment_view
{
974 struct anv_attachment_view base
;
975 struct anv_surface_view view
;
978 struct anv_depth_stencil_view
{
979 struct anv_attachment_view base
;
983 uint32_t depth_offset
; /**< Offset into bo. */
984 uint32_t depth_stride
; /**< 3DSTATE_DEPTH_BUFFER.SurfacePitch */
985 uint32_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
986 uint16_t depth_qpitch
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceQPitch */
988 uint32_t stencil_offset
; /**< Offset into bo. */
989 uint32_t stencil_stride
; /**< 3DSTATE_STENCIL_BUFFER.SurfacePitch */
990 uint16_t stencil_qpitch
; /**< 3DSTATE_STENCIL_BUFFER.SurfaceQPitch */
993 struct anv_image_create_info
{
994 const VkImageCreateInfo
*vk_info
;
995 bool force_tile_mode
;
1000 VkResult
anv_image_create(VkDevice _device
,
1001 const struct anv_image_create_info
*info
,
1004 void anv_image_view_init(struct anv_image_view
*view
,
1005 struct anv_device
*device
,
1006 const VkImageViewCreateInfo
* pCreateInfo
,
1007 struct anv_cmd_buffer
*cmd_buffer
);
1009 void anv_color_attachment_view_init(struct anv_color_attachment_view
*view
,
1010 struct anv_device
*device
,
1011 const VkAttachmentViewCreateInfo
* pCreateInfo
,
1012 struct anv_cmd_buffer
*cmd_buffer
);
1013 void anv_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1014 uint32_t offset
, uint32_t range
);
1016 void anv_surface_view_fini(struct anv_device
*device
,
1017 struct anv_surface_view
*view
);
1019 struct anv_sampler
{
1023 struct anv_framebuffer
{
1028 /* Viewport for clears */
1029 VkDynamicViewportState vp_state
;
1031 uint32_t attachment_count
;
1032 const struct anv_attachment_view
* attachments
[0];
1035 struct anv_subpass
{
1036 uint32_t input_count
;
1037 uint32_t * input_attachments
;
1038 uint32_t color_count
;
1039 uint32_t * color_attachments
;
1040 uint32_t * resolve_attachments
;
1041 uint32_t depth_stencil_attachment
;
1044 struct anv_render_pass_attachment
{
1047 VkAttachmentLoadOp load_op
;
1048 VkAttachmentLoadOp stencil_load_op
;
1051 struct anv_render_pass
{
1052 uint32_t attachment_count
;
1053 uint32_t subpass_count
;
1055 struct anv_render_pass_attachment
* attachments
;
1056 struct anv_subpass subpasses
[0];
1059 void anv_device_init_meta(struct anv_device
*device
);
1060 void anv_device_finish_meta(struct anv_device
*device
);
1062 void *anv_lookup_entrypoint(const char *name
);
1064 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1066 static inline struct __anv_type * \
1067 __anv_type ## _from_handle(__VkType _handle) \
1069 return (struct __anv_type *) _handle; \
1072 static inline __VkType \
1073 __anv_type ## _to_handle(struct __anv_type *_obj) \
1075 return (__VkType) _obj; \
1078 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1080 static inline struct __anv_type * \
1081 __anv_type ## _from_handle(__VkType _handle) \
1083 return (struct __anv_type *) _handle.handle; \
1086 static inline __VkType \
1087 __anv_type ## _to_handle(struct __anv_type *_obj) \
1089 return (__VkType) { .handle = (uint64_t) _obj }; \
1092 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1093 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1095 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCmdBuffer
)
1096 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1097 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1098 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1099 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1100 ANV_DEFINE_HANDLE_CASTS(anv_swap_chain
, VkSwapChainWSI
);
1102 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCmdPool
)
1103 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_attachment_view
, VkAttachmentView
)
1104 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1105 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
);
1106 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1107 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1108 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1109 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_cb_state
, VkDynamicColorBlendState
)
1110 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_ds_state
, VkDynamicDepthStencilState
)
1111 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_rs_state
, VkDynamicRasterState
)
1112 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_vp_state
, VkDynamicViewportState
)
1113 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1114 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1115 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1116 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1117 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1118 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1119 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1120 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1121 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1122 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader
, VkShader
)
1123 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1125 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1127 static inline const __VkType * \
1128 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1130 return (const __VkType *) __anv_obj; \
1133 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1134 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1136 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1137 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1138 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)