| 1 |
|
| 2 |
. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef KK_SHADER_H |
| 9 |
#define KK_SHADER_H 1 |
| 10 |
|
| 11 |
#include "kk_device_memory.h" |
| 12 |
#include "kk_private.h" |
| 13 |
|
| 14 |
#include "kosmickrisp/bridge/mtl_format.h" |
| 15 |
|
| 16 |
#include "vk_pipeline_cache.h" |
| 17 |
|
| 18 |
#include "vk_shader.h" |
| 19 |
|
| 20 |
struct kk_cmd_buffer; |
| 21 |
|
| 22 |
struct kk_shader_info { |
| 23 |
mesa_shader_stage stage; |
| 24 |
union { |
| 25 |
|
| 26 |
struct { |
| 27 |
|
| 28 |
char *frag_msl_code; |
| 29 |
char *frag_entrypoint_name; |
| 30 |
|
| 31 |
|
| 32 |
uint32_t attribs_read; |
| 33 |
uint32_t sample_count; |
| 34 |
|
| 35 |
|
| 36 |
enum mtl_primitive_topology_class topology; |
| 37 |
enum mtl_pixel_format rt_formats[MAX_DRAW_BUFFERS]; |
| 38 |
enum mtl_pixel_format d_format; |
| 39 |
enum mtl_pixel_format s_format; |
| 40 |
uint32_t view_mask; |
| 41 |
VkCompareOp depth_compare_op; |
| 42 |
struct { |
| 43 |
uint8_t depth_fail; |
| 44 |
uint8_t fail; |
| 45 |
uint8_t pass; |
| 46 |
uint8_t compare; |
| 47 |
uint8_t compare_mask; |
| 48 |
uint8_t write_mask; |
| 49 |
} stencil_front, stencil_back; |
| 50 |
uint8_t color_attachment_count; |
| 51 |
bool has_ms; |
| 52 |
bool has_alpha_to_coverage_enabled; |
| 53 |
bool has_alpha_to_one_enabled; |
| 54 |
bool has_ds; |
| 55 |
bool has_depth_write; |
| 56 |
bool has_stencil_test; |
| 57 |
} vs; |
| 58 |
|
| 59 |
struct { |
| 60 |
struct mtl_size local_size; |
| 61 |
} cs; |
| 62 |
}; |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
struct kk_pipeline_handles { |
| 67 |
union { |
| 68 |
struct { |
| 69 |
mtl_render_pipeline_state *handle; |
| 70 |
mtl_depth_stencil_state *ds_handle; |
| 71 |
} gfx; |
| 72 |
mtl_compute_pipeline_state *cs; |
| 73 |
}; |
| 74 |
}; |
| 75 |
|
| 76 |
struct kk_shader { |
| 77 |
struct vk_shader vk; |
| 78 |
|
| 79 |
struct kk_pipeline_handles pipeline; |
| 80 |
struct kk_shader_info info; |
| 81 |
const char *entrypoint_name; |
| 82 |
const char *msl_code; |
| 83 |
}; |
| 84 |
|
| 85 |
VK_DEFINE_NONDISP_HANDLE_CASTS(kk_shader, vk.base, VkShaderEXT, |
| 86 |
VK_OBJECT_TYPE_SHADER_EXT); |
| 87 |
|
| 88 |
extern const struct vk_device_shader_ops kk_device_shader_ops; |
| 89 |
|
| 90 |
static inline nir_address_format |
| 91 |
kk_buffer_addr_format(VkPipelineRobustnessBufferBehaviorEXT robustness) |
| 92 |
{ |
| 93 |
switch (robustness) { |
| 94 |
case VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT: |
| 95 |
return nir_address_format_64bit_global_32bit_offset; |
| 96 |
case VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_EXT: |
| 97 |
case VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_2_EXT: |
| 98 |
return nir_address_format_64bit_bounded_global; |
| 99 |
default: |
| 100 |
UNREACHABLE("Invalid robust buffer access behavior"); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
bool |
| 105 |
kk_nir_lower_descriptors(nir_shader *nir, |
| 106 |
const struct vk_pipeline_robustness_state *rs, |
| 107 |
uint32_t set_layout_count, |
| 108 |
struct vk_descriptor_set_layout *const *set_layouts); |
| 109 |
|
| 110 |
bool kk_nir_lower_textures(nir_shader *nir); |
| 111 |
|
| 112 |
bool kk_nir_lower_vs_multiview(nir_shader *nir, uint32_t view_mask); |
| 113 |
bool kk_nir_lower_fs_multiview(nir_shader *nir, uint32_t view_mask); |
| 114 |
|
| 115 |
VkResult kk_compile_nir_shader(struct kk_device *dev, nir_shader *nir, |
| 116 |
const VkAllocationCallbacks *alloc, |
| 117 |
struct kk_shader **shader_out); |
| 118 |
|
| 119 |
void kk_cmd_bind_compute_shader(struct kk_cmd_buffer *cmd, |
| 120 |
struct kk_shader *shader); |
| 121 |
|
| 122 |
#endif |