2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #ifndef RADV_PRIVATE_H
29 #define RADV_PRIVATE_H
47 #include "compiler/shader_enums.h"
48 #include "util/macros.h"
49 #include "util/list.h"
50 #include "util/vk_alloc.h"
51 #include "main/macros.h"
53 #include "radv_radeon_winsys.h"
54 #include "ac_binary.h"
55 #include "ac_nir_to_llvm.h"
56 #include "radv_descriptor_set.h"
58 #include <llvm-c/TargetMachine.h>
60 /* Pre-declarations needed for WSI entrypoints */
63 typedef struct xcb_connection_t xcb_connection_t
;
64 typedef uint32_t xcb_visualid_t
;
65 typedef uint32_t xcb_window_t
;
67 #include <vulkan/vulkan.h>
68 #include <vulkan/vulkan_intel.h>
69 #include <vulkan/vk_icd.h>
71 #include "radv_entrypoints.h"
73 #include "wsi_common.h"
76 #define MAX_VERTEX_ATTRIBS 32
78 #define MAX_VIEWPORTS 16
79 #define MAX_SCISSORS 16
80 #define MAX_PUSH_CONSTANTS_SIZE 128
81 #define MAX_DYNAMIC_BUFFERS 16
83 #define MAX_SAMPLES_LOG2 4 /* SKL supports 16 samples */
84 #define NUM_META_FS_KEYS 11
86 #define NUM_DEPTH_CLEAR_PIPELINES 3
90 RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
97 RADV_MEM_TYPE_GTT_WRITE_COMBINE
,
98 RADV_MEM_TYPE_VRAM_CPU_ACCESS
,
99 RADV_MEM_TYPE_GTT_CACHED
,
103 #define radv_noreturn __attribute__((__noreturn__))
104 #define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
106 static inline uint32_t
107 align_u32(uint32_t v
, uint32_t a
)
109 assert(a
!= 0 && a
== (a
& -a
));
110 return (v
+ a
- 1) & ~(a
- 1);
113 static inline uint32_t
114 align_u32_npot(uint32_t v
, uint32_t a
)
116 return (v
+ a
- 1) / a
* a
;
119 static inline uint64_t
120 align_u64(uint64_t v
, uint64_t a
)
122 assert(a
!= 0 && a
== (a
& -a
));
123 return (v
+ a
- 1) & ~(a
- 1);
126 static inline int32_t
127 align_i32(int32_t v
, int32_t a
)
129 assert(a
!= 0 && a
== (a
& -a
));
130 return (v
+ a
- 1) & ~(a
- 1);
133 /** Alignment must be a power of 2. */
135 radv_is_aligned(uintmax_t n
, uintmax_t a
)
137 assert(a
== (a
& -a
));
138 return (n
& (a
- 1)) == 0;
141 static inline uint32_t
142 round_up_u32(uint32_t v
, uint32_t a
)
144 return (v
+ a
- 1) / a
;
147 static inline uint64_t
148 round_up_u64(uint64_t v
, uint64_t a
)
150 return (v
+ a
- 1) / a
;
153 static inline uint32_t
154 radv_minify(uint32_t n
, uint32_t levels
)
156 if (unlikely(n
== 0))
159 return MAX2(n
>> levels
, 1);
162 radv_clamp_f(float f
, float min
, float max
)
175 radv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
177 if (*inout_mask
& clear_mask
) {
178 *inout_mask
&= ~clear_mask
;
185 #define for_each_bit(b, dword) \
186 for (uint32_t __dword = (dword); \
187 (b) = __builtin_ffs(__dword) - 1, __dword; \
188 __dword &= ~(1 << (b)))
190 #define typed_memcpy(dest, src, count) ({ \
191 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
192 memcpy((dest), (src), (count) * sizeof(*(src))); \
195 #define zero(x) (memset(&(x), 0, sizeof(x)))
197 /* Whenever we generate an error, pass it through this function. Useful for
198 * debugging, where we can break on it. Only call at error site, not when
199 * propagating errors. Might be useful to plug in a stack trace here.
202 VkResult
__vk_errorf(VkResult error
, const char *file
, int line
, const char *format
, ...);
205 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
206 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
208 #define vk_error(error) error
209 #define vk_errorf(error, format, ...) error
212 void __radv_finishme(const char *file
, int line
, const char *format
, ...)
213 radv_printflike(3, 4);
214 void radv_loge(const char *format
, ...) radv_printflike(1, 2);
215 void radv_loge_v(const char *format
, va_list va
);
218 * Print a FINISHME message, including its source location.
220 #define radv_finishme(format, ...) \
222 static bool reported = false; \
224 __radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
229 /* A non-fatal assert. Useful for debugging. */
231 #define radv_assert(x) ({ \
232 if (unlikely(!(x))) \
233 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
236 #define radv_assert(x)
239 void radv_abortf(const char *format
, ...) radv_noreturn
radv_printflike(1, 2);
240 void radv_abortfv(const char *format
, va_list va
) radv_noreturn
;
242 #define stub_return(v) \
244 radv_finishme("stub %s", __func__); \
250 radv_finishme("stub %s", __func__); \
254 void *radv_resolve_entrypoint(uint32_t index
);
255 void *radv_lookup_entrypoint(const char *name
);
257 extern struct radv_dispatch_table dtable
;
259 struct radv_physical_device
{
260 VK_LOADER_DATA _loader_data
;
262 struct radv_instance
* instance
;
264 struct radeon_winsys
*ws
;
265 struct radeon_info rad_info
;
269 uint64_t aperture_size
;
270 int cmd_parser_version
;
271 uint32_t pci_vendor_id
;
272 uint32_t pci_device_id
;
274 uint8_t uuid
[VK_UUID_SIZE
];
276 struct wsi_device wsi_device
;
279 struct radv_instance
{
280 VK_LOADER_DATA _loader_data
;
282 VkAllocationCallbacks alloc
;
285 int physicalDeviceCount
;
286 struct radv_physical_device physicalDevice
;
289 VkResult
radv_init_wsi(struct radv_physical_device
*physical_device
);
290 void radv_finish_wsi(struct radv_physical_device
*physical_device
);
294 struct radv_pipeline_cache
{
295 struct radv_device
* device
;
296 pthread_mutex_t mutex
;
300 uint32_t kernel_count
;
301 struct cache_entry
** hash_table
;
304 VkAllocationCallbacks alloc
;
308 radv_pipeline_cache_init(struct radv_pipeline_cache
*cache
,
309 struct radv_device
*device
);
311 radv_pipeline_cache_finish(struct radv_pipeline_cache
*cache
);
313 radv_pipeline_cache_load(struct radv_pipeline_cache
*cache
,
314 const void *data
, size_t size
);
316 struct radv_shader_variant
*
317 radv_create_shader_variant_from_pipeline_cache(struct radv_device
*device
,
318 struct radv_pipeline_cache
*cache
,
319 const unsigned char *sha1
);
321 struct radv_shader_variant
*
322 radv_pipeline_cache_insert_shader(struct radv_pipeline_cache
*cache
,
323 const unsigned char *sha1
,
324 struct radv_shader_variant
*variant
,
325 const void *code
, unsigned code_size
);
327 void radv_shader_variant_destroy(struct radv_device
*device
,
328 struct radv_shader_variant
*variant
);
330 struct radv_meta_state
{
331 VkAllocationCallbacks alloc
;
333 struct radv_pipeline_cache cache
;
336 * Use array element `i` for images with `2^i` samples.
339 VkRenderPass render_pass
[NUM_META_FS_KEYS
];
340 struct radv_pipeline
*color_pipelines
[NUM_META_FS_KEYS
];
342 VkRenderPass depth_only_rp
[NUM_DEPTH_CLEAR_PIPELINES
];
343 struct radv_pipeline
*depth_only_pipeline
[NUM_DEPTH_CLEAR_PIPELINES
];
344 VkRenderPass stencil_only_rp
[NUM_DEPTH_CLEAR_PIPELINES
];
345 struct radv_pipeline
*stencil_only_pipeline
[NUM_DEPTH_CLEAR_PIPELINES
];
346 VkRenderPass depthstencil_rp
[NUM_DEPTH_CLEAR_PIPELINES
];
347 struct radv_pipeline
*depthstencil_pipeline
[NUM_DEPTH_CLEAR_PIPELINES
];
348 } clear
[1 + MAX_SAMPLES_LOG2
];
351 VkRenderPass render_pass
[NUM_META_FS_KEYS
];
353 /** Pipeline that blits from a 1D image. */
354 VkPipeline pipeline_1d_src
[NUM_META_FS_KEYS
];
356 /** Pipeline that blits from a 2D image. */
357 VkPipeline pipeline_2d_src
[NUM_META_FS_KEYS
];
359 /** Pipeline that blits from a 3D image. */
360 VkPipeline pipeline_3d_src
[NUM_META_FS_KEYS
];
362 VkRenderPass depth_only_rp
;
363 VkPipeline depth_only_1d_pipeline
;
364 VkPipeline depth_only_2d_pipeline
;
365 VkPipeline depth_only_3d_pipeline
;
367 VkRenderPass stencil_only_rp
;
368 VkPipeline stencil_only_1d_pipeline
;
369 VkPipeline stencil_only_2d_pipeline
;
370 VkPipeline stencil_only_3d_pipeline
;
371 VkPipelineLayout pipeline_layout
;
372 VkDescriptorSetLayout ds_layout
;
376 VkRenderPass render_passes
[NUM_META_FS_KEYS
];
378 VkPipelineLayout p_layouts
[2];
379 VkDescriptorSetLayout ds_layouts
[2];
380 VkPipeline pipelines
[2][NUM_META_FS_KEYS
];
382 VkRenderPass depth_only_rp
;
383 VkPipeline depth_only_pipeline
[2];
385 VkRenderPass stencil_only_rp
;
386 VkPipeline stencil_only_pipeline
[2];
390 VkPipelineLayout img_p_layout
;
391 VkDescriptorSetLayout img_ds_layout
;
395 VkRenderPass render_pass
;
396 VkPipelineLayout img_p_layout
;
397 VkDescriptorSetLayout img_ds_layout
;
407 VkDescriptorSetLayout ds_layout
;
408 VkPipelineLayout p_layout
;
411 VkPipeline i_pipeline
;
412 } rc
[MAX_SAMPLES_LOG2
];
416 VkPipeline decompress_pipeline
;
417 VkPipeline resummarize_pipeline
;
422 VkPipeline cmask_eliminate_pipeline
;
423 VkPipeline fmask_decompress_pipeline
;
428 VkPipelineLayout fill_p_layout
;
429 VkPipelineLayout copy_p_layout
;
430 VkDescriptorSetLayout fill_ds_layout
;
431 VkDescriptorSetLayout copy_ds_layout
;
432 VkPipeline fill_pipeline
;
433 VkPipeline copy_pipeline
;
438 VK_LOADER_DATA _loader_data
;
440 struct radv_device
* device
;
442 struct radv_state_pool
* pool
;
446 VK_LOADER_DATA _loader_data
;
448 VkAllocationCallbacks alloc
;
450 struct radv_instance
* instance
;
451 struct radeon_winsys
*ws
;
452 struct radeon_winsys_ctx
*hw_ctx
;
454 struct radv_meta_state meta_state
;
455 struct radv_queue queue
;
456 struct radeon_winsys_cs
*empty_cs
;
458 bool allow_fast_clears
;
460 bool shader_stats_dump
;
462 /* MSAA sample locations.
463 * The first index is the sample index.
464 * The second index is the coordinate: X, Y. */
465 float sample_locations_1x
[1][2];
466 float sample_locations_2x
[2][2];
467 float sample_locations_4x
[4][2];
468 float sample_locations_8x
[8][2];
469 float sample_locations_16x
[16][2];
472 struct radv_device_memory
{
473 struct radeon_winsys_bo
*bo
;
475 VkDeviceSize map_size
;
480 struct radv_descriptor_range
{
485 struct radv_descriptor_set
{
486 const struct radv_descriptor_set_layout
*layout
;
487 struct list_head descriptor_pool
;
490 struct radv_buffer_view
*buffer_views
;
491 struct radeon_winsys_bo
*bo
;
493 uint32_t *mapped_ptr
;
494 struct radv_descriptor_range
*dynamic_descriptors
;
495 struct radeon_winsys_bo
*descriptors
[0];
498 struct radv_descriptor_pool_free_node
{
504 struct radv_descriptor_pool
{
505 struct list_head descriptor_sets
;
507 struct radeon_winsys_bo
*bo
;
509 uint64_t current_offset
;
515 struct radv_descriptor_pool_free_node free_nodes
[];
519 struct radv_device
* device
;
522 VkBufferUsageFlags usage
;
525 struct radeon_winsys_bo
* bo
;
530 enum radv_cmd_dirty_bits
{
531 RADV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
532 RADV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
533 RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
534 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
535 RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
536 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
537 RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
538 RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
539 RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
540 RADV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
541 RADV_CMD_DIRTY_PIPELINE
= 1 << 9,
542 RADV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
543 RADV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
545 typedef uint32_t radv_cmd_dirty_mask_t
;
547 enum radv_cmd_flush_bits
{
548 RADV_CMD_FLAG_INV_ICACHE
= 1 << 0,
549 /* SMEM L1, other names: KCACHE, constant cache, DCACHE, data cache */
550 RADV_CMD_FLAG_INV_SMEM_L1
= 1 << 1,
551 /* VMEM L1 can optionally be bypassed (GLC=1). Other names: TC L1 */
552 RADV_CMD_FLAG_INV_VMEM_L1
= 1 << 2,
553 /* Used by everything except CB/DB, can be bypassed (SLC=1). Other names: TC L2 */
554 RADV_CMD_FLAG_INV_GLOBAL_L2
= 1 << 3,
555 /* Framebuffer caches */
556 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META
= 1 << 4,
557 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META
= 1 << 5,
558 RADV_CMD_FLAG_FLUSH_AND_INV_DB
= 1 << 6,
559 RADV_CMD_FLAG_FLUSH_AND_INV_CB
= 1 << 7,
560 /* Engine synchronization. */
561 RADV_CMD_FLAG_VS_PARTIAL_FLUSH
= 1 << 8,
562 RADV_CMD_FLAG_PS_PARTIAL_FLUSH
= 1 << 9,
563 RADV_CMD_FLAG_CS_PARTIAL_FLUSH
= 1 << 10,
564 RADV_CMD_FLAG_VGT_FLUSH
= 1 << 11,
566 RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER
= (RADV_CMD_FLAG_FLUSH_AND_INV_CB
|
567 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META
|
568 RADV_CMD_FLAG_FLUSH_AND_INV_DB
|
569 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META
)
572 struct radv_vertex_binding
{
573 struct radv_buffer
* buffer
;
577 struct radv_dynamic_state
{
580 VkViewport viewports
[MAX_VIEWPORTS
];
585 VkRect2D scissors
[MAX_SCISSORS
];
596 float blend_constants
[4];
606 } stencil_compare_mask
;
611 } stencil_write_mask
;
619 extern const struct radv_dynamic_state default_dynamic_state
;
621 void radv_dynamic_state_copy(struct radv_dynamic_state
*dest
,
622 const struct radv_dynamic_state
*src
,
625 * Attachment state when recording a renderpass instance.
627 * The clear value is valid only if there exists a pending clear.
629 struct radv_attachment_state
{
630 VkImageAspectFlags pending_clear_aspects
;
631 VkClearValue clear_value
;
632 VkImageLayout current_layout
;
635 struct radv_cmd_state
{
637 bool vertex_descriptors_dirty
;
638 radv_cmd_dirty_mask_t dirty
;
640 struct radv_pipeline
* pipeline
;
641 struct radv_pipeline
* emitted_pipeline
;
642 struct radv_pipeline
* compute_pipeline
;
643 struct radv_pipeline
* emitted_compute_pipeline
;
644 struct radv_framebuffer
* framebuffer
;
645 struct radv_render_pass
* pass
;
646 const struct radv_subpass
* subpass
;
647 struct radv_dynamic_state dynamic
;
648 struct radv_vertex_binding vertex_bindings
[MAX_VBS
];
649 struct radv_descriptor_set
* descriptors
[MAX_SETS
];
650 struct radv_attachment_state
* attachments
;
651 VkRect2D render_area
;
652 struct radv_buffer
* index_buffer
;
654 uint32_t index_offset
;
655 uint32_t last_primitive_reset_index
;
656 enum radv_cmd_flush_bits flush_bits
;
657 unsigned active_occlusion_queries
;
659 uint32_t descriptors_dirty
;
661 struct radv_cmd_pool
{
662 VkAllocationCallbacks alloc
;
663 struct list_head cmd_buffers
;
666 struct radv_cmd_buffer_upload
{
670 struct radeon_winsys_bo
*upload_bo
;
671 struct list_head list
;
674 struct radv_cmd_buffer
{
675 VK_LOADER_DATA _loader_data
;
677 struct radv_device
* device
;
679 struct radv_cmd_pool
* pool
;
680 struct list_head pool_link
;
682 VkCommandBufferUsageFlags usage_flags
;
683 VkCommandBufferLevel level
;
684 struct radeon_winsys_cs
*cs
;
685 struct radv_cmd_state state
;
687 uint8_t push_constants
[MAX_PUSH_CONSTANTS_SIZE
];
688 uint32_t dynamic_buffers
[16 * MAX_DYNAMIC_BUFFERS
];
689 VkShaderStageFlags push_constant_stages
;
691 struct radv_cmd_buffer_upload upload
;
698 void si_init_config(struct radv_physical_device
*physical_device
,
699 struct radv_cmd_buffer
*cmd_buffer
);
700 void si_write_viewport(struct radeon_winsys_cs
*cs
, int first_vp
,
701 int count
, const VkViewport
*viewports
);
702 void si_write_scissors(struct radeon_winsys_cs
*cs
, int first
,
703 int count
, const VkRect2D
*scissors
);
704 uint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer
*cmd_buffer
);
705 void si_emit_cache_flush(struct radv_cmd_buffer
*cmd_buffer
);
706 void si_cp_dma_buffer_copy(struct radv_cmd_buffer
*cmd_buffer
,
707 uint64_t src_va
, uint64_t dest_va
,
709 void si_cp_dma_clear_buffer(struct radv_cmd_buffer
*cmd_buffer
, uint64_t va
,
710 uint64_t size
, unsigned value
);
711 void radv_set_db_count_control(struct radv_cmd_buffer
*cmd_buffer
);
712 void radv_bind_descriptor_set(struct radv_cmd_buffer
*cmd_buffer
,
713 struct radv_descriptor_set
*set
,
716 radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer
*cmd_buffer
,
719 unsigned *out_offset
,
722 radv_cmd_buffer_set_subpass(struct radv_cmd_buffer
*cmd_buffer
,
723 const struct radv_subpass
*subpass
,
726 radv_cmd_buffer_upload_data(struct radv_cmd_buffer
*cmd_buffer
,
727 unsigned size
, unsigned alignmnet
,
728 const void *data
, unsigned *out_offset
);
730 radv_emit_framebuffer_state(struct radv_cmd_buffer
*cmd_buffer
);
731 void radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer
*cmd_buffer
);
732 void radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer
*cmd_buffer
);
733 void radv_cayman_emit_msaa_sample_locs(struct radeon_winsys_cs
*cs
, int nr_samples
);
734 unsigned radv_cayman_get_maxdist(int log_samples
);
735 void radv_device_init_msaa(struct radv_device
*device
);
736 void radv_set_depth_clear_regs(struct radv_cmd_buffer
*cmd_buffer
,
737 struct radv_image
*image
,
738 VkClearDepthStencilValue ds_clear_value
,
739 VkImageAspectFlags aspects
);
740 void radv_set_color_clear_regs(struct radv_cmd_buffer
*cmd_buffer
,
741 struct radv_image
*image
,
743 uint32_t color_values
[2]);
744 void radv_fill_buffer(struct radv_cmd_buffer
*cmd_buffer
,
745 struct radeon_winsys_bo
*bo
,
746 uint64_t offset
, uint64_t size
, uint32_t value
);
749 * Takes x,y,z as exact numbers of invocations, instead of blocks.
751 * Limitations: Can't call normal dispatch functions without binding or rebinding
752 * the compute pipeline.
754 void radv_unaligned_dispatch(
755 struct radv_cmd_buffer
*cmd_buffer
,
761 struct radeon_winsys_bo
*bo
;
767 struct radv_shader_module
{
768 struct nir_shader
* nir
;
769 unsigned char sha1
[20];
774 union ac_shader_variant_key
;
777 radv_hash_shader(unsigned char *hash
, struct radv_shader_module
*module
,
778 const char *entrypoint
,
779 const VkSpecializationInfo
*spec_info
,
780 const struct radv_pipeline_layout
*layout
,
781 const union ac_shader_variant_key
*key
);
783 static inline gl_shader_stage
784 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
786 assert(__builtin_popcount(vk_stage
) == 1);
787 return ffs(vk_stage
) - 1;
790 static inline VkShaderStageFlagBits
791 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
793 return (1 << mesa_stage
);
796 #define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
798 #define radv_foreach_stage(stage, stage_bits) \
799 for (gl_shader_stage stage, \
800 __tmp = (gl_shader_stage)((stage_bits) & RADV_STAGE_MASK); \
801 stage = __builtin_ffs(__tmp) - 1, __tmp; \
802 __tmp &= ~(1 << (stage)))
804 struct radv_shader_variant
{
807 struct radeon_winsys_bo
*bo
;
808 struct ac_shader_config config
;
809 struct ac_shader_variant_info info
;
815 struct radv_depth_stencil_state
{
816 uint32_t db_depth_control
;
817 uint32_t db_stencil_control
;
818 uint32_t db_render_control
;
819 uint32_t db_render_override2
;
822 struct radv_blend_state
{
823 uint32_t cb_color_control
;
824 uint32_t cb_target_mask
;
825 uint32_t sx_mrt0_blend_opt
[8];
826 uint32_t cb_blend_control
[8];
828 uint32_t spi_shader_col_format
;
829 uint32_t cb_shader_mask
;
830 uint32_t db_alpha_to_mask
;
833 unsigned radv_format_meta_fs_key(VkFormat format
);
835 struct radv_raster_state
{
836 uint32_t pa_cl_clip_cntl
;
837 uint32_t pa_cl_vs_out_cntl
;
838 uint32_t spi_interp_control
;
839 uint32_t pa_su_point_size
;
840 uint32_t pa_su_point_minmax
;
841 uint32_t pa_su_line_cntl
;
842 uint32_t pa_su_vtx_cntl
;
843 uint32_t pa_su_sc_mode_cntl
;
846 struct radv_multisample_state
{
848 uint32_t pa_sc_line_cntl
;
849 uint32_t pa_sc_mode_cntl_0
;
850 uint32_t pa_sc_mode_cntl_1
;
851 uint32_t pa_sc_aa_config
;
852 uint32_t pa_sc_aa_mask
[2];
853 unsigned num_samples
;
856 struct radv_pipeline
{
857 struct radv_device
* device
;
858 uint32_t dynamic_state_mask
;
859 struct radv_dynamic_state dynamic_state
;
861 struct radv_pipeline_layout
* layout
;
863 bool needs_data_cache
;
865 struct radv_shader_variant
* shaders
[MESA_SHADER_STAGES
];
866 VkShaderStageFlags active_stages
;
868 uint32_t va_rsrc_word3
[MAX_VERTEX_ATTRIBS
];
869 uint32_t va_format_size
[MAX_VERTEX_ATTRIBS
];
870 uint32_t va_binding
[MAX_VERTEX_ATTRIBS
];
871 uint32_t va_offset
[MAX_VERTEX_ATTRIBS
];
872 uint32_t num_vertex_attribs
;
873 uint32_t binding_stride
[MAX_VBS
];
877 struct radv_blend_state blend
;
878 struct radv_depth_stencil_state ds
;
879 struct radv_raster_state raster
;
880 struct radv_multisample_state ms
;
883 bool prim_restart_enable
;
888 struct radv_graphics_pipeline_create_info
{
891 bool db_stencil_clear
;
892 bool db_depth_disable_expclear
;
893 bool db_stencil_disable_expclear
;
894 bool db_flush_depth_inplace
;
895 bool db_flush_stencil_inplace
;
897 uint32_t custom_blend_mode
;
901 radv_pipeline_init(struct radv_pipeline
*pipeline
, struct radv_device
*device
,
902 struct radv_pipeline_cache
*cache
,
903 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
904 const struct radv_graphics_pipeline_create_info
*extra
,
905 const VkAllocationCallbacks
*alloc
);
908 radv_graphics_pipeline_create(VkDevice device
,
909 VkPipelineCache cache
,
910 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
911 const struct radv_graphics_pipeline_create_info
*extra
,
912 const VkAllocationCallbacks
*alloc
,
913 VkPipeline
*pPipeline
);
915 struct vk_format_description
;
916 uint32_t radv_translate_buffer_dataformat(const struct vk_format_description
*desc
,
918 uint32_t radv_translate_buffer_numformat(const struct vk_format_description
*desc
,
920 uint32_t radv_translate_colorformat(VkFormat format
);
921 uint32_t radv_translate_color_numformat(VkFormat format
,
922 const struct vk_format_description
*desc
,
924 uint32_t radv_colorformat_endian_swap(uint32_t colorformat
);
925 unsigned radv_translate_colorswap(VkFormat format
, bool do_endian_swap
);
926 uint32_t radv_translate_dbformat(VkFormat format
);
927 uint32_t radv_translate_tex_dataformat(VkFormat format
,
928 const struct vk_format_description
*desc
,
930 uint32_t radv_translate_tex_numformat(VkFormat format
,
931 const struct vk_format_description
*desc
,
933 bool radv_format_pack_clear_color(VkFormat format
,
934 uint32_t clear_vals
[2],
935 VkClearColorValue
*value
);
936 bool radv_is_colorbuffer_format_supported(VkFormat format
, bool *blendable
);
938 struct radv_fmask_info
{
942 unsigned pitch_in_pixels
;
943 unsigned bank_height
;
944 unsigned slice_tile_max
;
945 unsigned tile_mode_index
;
948 struct radv_cmask_info
{
952 unsigned slice_tile_max
;
953 unsigned base_address_reg
;
956 struct r600_htile_info
{
967 /* The original VkFormat provided by the client. This may not match any
968 * of the actual surface formats.
971 VkImageAspectFlags aspects
;
975 uint32_t samples
; /**< VkImageCreateInfo::samples */
976 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
977 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
983 struct radeon_winsys_bo
*bo
;
986 struct radeon_surf surface
;
988 struct radv_fmask_info fmask
;
989 struct radv_cmask_info cmask
;
990 uint32_t clear_value_offset
;
992 /* Depth buffer compression and fast clear. */
993 struct r600_htile_info htile
;
996 bool radv_layout_has_htile(const struct radv_image
*image
,
997 VkImageLayout layout
);
998 bool radv_layout_is_htile_compressed(const struct radv_image
*image
,
999 VkImageLayout layout
);
1000 bool radv_layout_can_expclear(const struct radv_image
*image
,
1001 VkImageLayout layout
);
1002 bool radv_layout_has_cmask(const struct radv_image
*image
,
1003 VkImageLayout layout
);
1004 static inline uint32_t
1005 radv_get_layerCount(const struct radv_image
*image
,
1006 const VkImageSubresourceRange
*range
)
1008 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
?
1009 image
->array_size
- range
->baseArrayLayer
: range
->layerCount
;
1012 static inline uint32_t
1013 radv_get_levelCount(const struct radv_image
*image
,
1014 const VkImageSubresourceRange
*range
)
1016 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
1017 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
1020 struct radeon_bo_metadata
;
1022 radv_init_metadata(struct radv_device
*device
,
1023 struct radv_image
*image
,
1024 struct radeon_bo_metadata
*metadata
);
1026 struct radv_image_view
{
1027 struct radv_image
*image
; /**< VkImageViewCreateInfo::image */
1028 struct radeon_winsys_bo
*bo
;
1030 VkImageViewType type
;
1031 VkImageAspectFlags aspect_mask
;
1033 uint32_t base_layer
;
1034 uint32_t layer_count
;
1036 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1038 uint32_t descriptor
[8];
1039 uint32_t fmask_descriptor
[8];
1042 struct radv_image_create_info
{
1043 const VkImageCreateInfo
*vk_info
;
1048 VkResult
radv_image_create(VkDevice _device
,
1049 const struct radv_image_create_info
*info
,
1050 const VkAllocationCallbacks
* alloc
,
1053 void radv_image_view_init(struct radv_image_view
*view
,
1054 struct radv_device
*device
,
1055 const VkImageViewCreateInfo
* pCreateInfo
,
1056 struct radv_cmd_buffer
*cmd_buffer
,
1057 VkImageUsageFlags usage_mask
);
1058 void radv_image_set_optimal_micro_tile_mode(struct radv_device
*device
,
1059 struct radv_image
*image
, uint32_t micro_tile_mode
);
1060 struct radv_buffer_view
{
1061 struct radeon_winsys_bo
*bo
;
1063 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1066 void radv_buffer_view_init(struct radv_buffer_view
*view
,
1067 struct radv_device
*device
,
1068 const VkBufferViewCreateInfo
* pCreateInfo
,
1069 struct radv_cmd_buffer
*cmd_buffer
);
1071 static inline struct VkExtent3D
1072 radv_sanitize_image_extent(const VkImageType imageType
,
1073 const struct VkExtent3D imageExtent
)
1075 switch (imageType
) {
1076 case VK_IMAGE_TYPE_1D
:
1077 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
1078 case VK_IMAGE_TYPE_2D
:
1079 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
1080 case VK_IMAGE_TYPE_3D
:
1083 unreachable("invalid image type");
1087 static inline struct VkOffset3D
1088 radv_sanitize_image_offset(const VkImageType imageType
,
1089 const struct VkOffset3D imageOffset
)
1091 switch (imageType
) {
1092 case VK_IMAGE_TYPE_1D
:
1093 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
1094 case VK_IMAGE_TYPE_2D
:
1095 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
1096 case VK_IMAGE_TYPE_3D
:
1099 unreachable("invalid image type");
1103 struct radv_sampler
{
1107 struct radv_color_buffer_info
{
1108 uint32_t cb_color_base
;
1109 uint32_t cb_color_pitch
;
1110 uint32_t cb_color_slice
;
1111 uint32_t cb_color_view
;
1112 uint32_t cb_color_info
;
1113 uint32_t cb_color_attrib
;
1114 uint32_t cb_dcc_control
;
1115 uint32_t cb_color_cmask
;
1116 uint32_t cb_color_cmask_slice
;
1117 uint32_t cb_color_fmask
;
1118 uint32_t cb_color_fmask_slice
;
1119 uint32_t cb_clear_value0
;
1120 uint32_t cb_clear_value1
;
1121 uint32_t cb_dcc_base
;
1122 uint32_t micro_tile_mode
;
1125 struct radv_ds_buffer_info
{
1126 uint32_t db_depth_info
;
1128 uint32_t db_stencil_info
;
1129 uint32_t db_z_read_base
;
1130 uint32_t db_stencil_read_base
;
1131 uint32_t db_z_write_base
;
1132 uint32_t db_stencil_write_base
;
1133 uint32_t db_depth_view
;
1134 uint32_t db_depth_size
;
1135 uint32_t db_depth_slice
;
1136 uint32_t db_htile_surface
;
1137 uint32_t db_htile_data_base
;
1138 uint32_t pa_su_poly_offset_db_fmt_cntl
;
1142 struct radv_attachment_info
{
1144 struct radv_color_buffer_info cb
;
1145 struct radv_ds_buffer_info ds
;
1147 struct radv_image_view
*attachment
;
1150 struct radv_framebuffer
{
1155 uint32_t attachment_count
;
1156 struct radv_attachment_info attachments
[0];
1159 struct radv_subpass_barrier
{
1160 VkPipelineStageFlags src_stage_mask
;
1161 VkAccessFlags src_access_mask
;
1162 VkAccessFlags dst_access_mask
;
1165 struct radv_subpass
{
1166 uint32_t input_count
;
1167 VkAttachmentReference
* input_attachments
;
1168 uint32_t color_count
;
1169 VkAttachmentReference
* color_attachments
;
1170 VkAttachmentReference
* resolve_attachments
;
1171 VkAttachmentReference depth_stencil_attachment
;
1173 /** Subpass has at least one resolve attachment */
1176 struct radv_subpass_barrier start_barrier
;
1179 struct radv_render_pass_attachment
{
1182 VkAttachmentLoadOp load_op
;
1183 VkAttachmentLoadOp stencil_load_op
;
1184 VkImageLayout initial_layout
;
1185 VkImageLayout final_layout
;
1188 struct radv_render_pass
{
1189 uint32_t attachment_count
;
1190 uint32_t subpass_count
;
1191 VkAttachmentReference
* subpass_attachments
;
1192 struct radv_render_pass_attachment
* attachments
;
1193 struct radv_subpass_barrier end_barrier
;
1194 struct radv_subpass subpasses
[0];
1197 VkResult
radv_device_init_meta(struct radv_device
*device
);
1198 void radv_device_finish_meta(struct radv_device
*device
);
1200 struct radv_query_pool
{
1201 struct radeon_winsys_bo
*bo
;
1203 uint32_t availability_offset
;
1209 radv_temp_descriptor_set_create(struct radv_device
*device
,
1210 struct radv_cmd_buffer
*cmd_buffer
,
1211 VkDescriptorSetLayout _layout
,
1212 VkDescriptorSet
*_set
);
1215 radv_temp_descriptor_set_destroy(struct radv_device
*device
,
1216 VkDescriptorSet _set
);
1217 void radv_initialise_cmask(struct radv_cmd_buffer
*cmd_buffer
,
1218 struct radv_image
*image
, uint32_t value
);
1219 void radv_initialize_dcc(struct radv_cmd_buffer
*cmd_buffer
,
1220 struct radv_image
*image
, uint32_t value
);
1223 struct radeon_winsys_fence
*fence
;
1228 #define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \
1230 static inline struct __radv_type * \
1231 __radv_type ## _from_handle(__VkType _handle) \
1233 return (struct __radv_type *) _handle; \
1236 static inline __VkType \
1237 __radv_type ## _to_handle(struct __radv_type *_obj) \
1239 return (__VkType) _obj; \
1242 #define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \
1244 static inline struct __radv_type * \
1245 __radv_type ## _from_handle(__VkType _handle) \
1247 return (struct __radv_type *)(uintptr_t) _handle; \
1250 static inline __VkType \
1251 __radv_type ## _to_handle(struct __radv_type *_obj) \
1253 return (__VkType)(uintptr_t) _obj; \
1256 #define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
1257 struct __radv_type *__name = __radv_type ## _from_handle(__handle)
1259 RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer
, VkCommandBuffer
)
1260 RADV_DEFINE_HANDLE_CASTS(radv_device
, VkDevice
)
1261 RADV_DEFINE_HANDLE_CASTS(radv_instance
, VkInstance
)
1262 RADV_DEFINE_HANDLE_CASTS(radv_physical_device
, VkPhysicalDevice
)
1263 RADV_DEFINE_HANDLE_CASTS(radv_queue
, VkQueue
)
1265 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool
, VkCommandPool
)
1266 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer
, VkBuffer
)
1267 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view
, VkBufferView
)
1268 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool
, VkDescriptorPool
)
1269 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set
, VkDescriptorSet
)
1270 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout
, VkDescriptorSetLayout
)
1271 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory
, VkDeviceMemory
)
1272 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence
, VkFence
)
1273 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event
, VkEvent
)
1274 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer
, VkFramebuffer
)
1275 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image
, VkImage
)
1276 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view
, VkImageView
);
1277 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache
, VkPipelineCache
)
1278 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline
, VkPipeline
)
1279 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout
, VkPipelineLayout
)
1280 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool
, VkQueryPool
)
1281 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass
, VkRenderPass
)
1282 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler
, VkSampler
)
1283 RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module
, VkShaderModule
)
1285 #define RADV_DEFINE_STRUCT_CASTS(__radv_type, __VkType) \
1287 static inline const __VkType * \
1288 __radv_type ## _to_ ## __VkType(const struct __radv_type *__radv_obj) \
1290 return (const __VkType *) __radv_obj; \
1293 #endif /* RADV_PRIVATE_H */