From ab9da6bc49d9e767feaa052446bce4bdf5ec6b4b Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 26 May 2025 12:48:10 -0400 Subject: [PATCH] hk: gate min LOD emulation on the feature Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/vulkan/hk_cmd_draw.c | 3 ++- src/asahi/vulkan/hk_device.c | 3 ++- src/asahi/vulkan/hk_shader.c | 30 ++++++++++++++++++++++++++---- src/asahi/vulkan/hk_shader.h | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/asahi/vulkan/hk_cmd_draw.c b/src/asahi/vulkan/hk_cmd_draw.c index c96902256b5..479119b1df5 100644 --- a/src/asahi/vulkan/hk_cmd_draw.c +++ b/src/asahi/vulkan/hk_cmd_draw.c @@ -57,6 +57,7 @@ #include "vk_graphics_state.h" #include "vk_pipeline.h" #include "vk_render_pass.h" +#include "vk_shader.h" #include "vk_standard_sample_locations.h" #include "vk_util.h" @@ -1313,7 +1314,7 @@ hk_build_meta_shader_locked(struct hk_device *dev, struct hk_internal_key *key, hk_preprocess_nir_internal(dev->vk.physical, b.shader); struct hk_api_shader *s; - if (hk_compile_shader(dev, &info, NULL, NULL, &s) != VK_SUCCESS) + if (hk_compile_shader(dev, &info, NULL, NULL, NULL, &s) != VK_SUCCESS) return NULL; /* ..and cache it before we return. The key is on the stack right now, so diff --git a/src/asahi/vulkan/hk_device.c b/src/asahi/vulkan/hk_device.c index 3245adfe7a4..81ed3822984 100644 --- a/src/asahi/vulkan/hk_device.c +++ b/src/asahi/vulkan/hk_device.c @@ -32,6 +32,7 @@ #include "vk_debug_utils.h" #include "vk_device.h" #include "vk_pipeline_cache.h" +#include "vk_shader.h" #include #include @@ -483,7 +484,7 @@ hk_CreateDevice(VkPhysicalDevice physicalDevice, .robustness = &vk_robustness_disabled, .stage = MESA_SHADER_FRAGMENT, }; - hk_compile_shader(dev, &info, NULL, pAllocator, &dev->null_fs); + hk_compile_shader(dev, &info, NULL, NULL, pAllocator, &dev->null_fs); if (!dev->null_fs) { result = VK_ERROR_OUT_OF_HOST_MEMORY; goto fail_meta; diff --git a/src/asahi/vulkan/hk_shader.c b/src/asahi/vulkan/hk_shader.c index cf7e4be8ff9..972612177a0 100644 --- a/src/asahi/vulkan/hk_shader.c +++ b/src/asahi/vulkan/hk_shader.c @@ -222,6 +222,19 @@ hk_populate_fs_key(struct hk_fs_key *key, key->force_sample_shading = true; } +enum hk_feature_key { + HK_FEAT_MIN_LOD = BITFIELD_BIT(0), +}; + +static enum hk_feature_key +hk_make_feature_key(const struct vk_features *features) +{ + if (!features) + return ~0U; + + return (features->minLod ? HK_FEAT_MIN_LOD : 0); +} + static void hk_hash_graphics_state(struct vk_physical_device *device, const struct vk_graphics_pipeline_state *state, @@ -238,6 +251,10 @@ hk_hash_graphics_state(struct vk_physical_device *device, const bool is_multiview = state->rp->view_mask != 0; _mesa_blake3_update(&blake3_ctx, &is_multiview, sizeof(is_multiview)); } + + enum hk_feature_key feature_key = hk_make_feature_key(features); + _mesa_blake3_update(&blake3_ctx, &feature_key, sizeof(feature_key)); + _mesa_blake3_final(&blake3_ctx, blake3_out); } @@ -636,7 +653,8 @@ static void hk_lower_nir(struct hk_device *dev, nir_shader *nir, const struct vk_pipeline_robustness_state *rs, bool is_multiview, uint32_t set_layout_count, - struct vk_descriptor_set_layout *const *set_layouts) + struct vk_descriptor_set_layout *const *set_layouts, + enum hk_feature_key features) { if (HK_PERF(dev, NOROBUST)) { rs = &vk_robustness_disabled; @@ -694,7 +712,9 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, */ NIR_PASS(_, nir, agx_nir_lower_texture_early, true /* support_lod_bias */); - NIR_PASS(_, nir, agx_nir_lower_image_view_min_lod); + if (features & HK_FEAT_MIN_LOD) { + NIR_PASS(_, nir, agx_nir_lower_image_view_min_lod); + } if (!HK_PERF(dev, NOBORDER)) { NIR_PASS(_, nir, agx_nir_lower_custom_border); @@ -1054,10 +1074,12 @@ hk_lower_hw_vs(nir_shader *nir, struct hk_shader *shader) VkResult hk_compile_shader(struct hk_device *dev, struct vk_shader_compile_info *info, const struct vk_graphics_pipeline_state *state, + const struct vk_features *vk_features, const VkAllocationCallbacks *pAllocator, struct hk_api_shader **shader_out) { VkResult result; + enum hk_feature_key features = hk_make_feature_key(vk_features); /* We consume the NIR, regardless of success or failure */ nir_shader *nir = info->nir; @@ -1076,7 +1098,7 @@ hk_compile_shader(struct hk_device *dev, struct vk_shader_compile_info *info, const bool is_multiview = state && state->rp->view_mask != 0; hk_lower_nir(dev, nir, info->robustness, is_multiview, - info->set_layout_count, info->set_layouts); + info->set_layout_count, info->set_layouts, features); gl_shader_stage sw_stage = nir->info.stage; @@ -1263,7 +1285,7 @@ hk_compile_shaders(struct vk_device *vk_dev, uint32_t shader_count, for (uint32_t i = 0; i < shader_count; i++) { VkResult result = - hk_compile_shader(dev, &infos[i], state, pAllocator, + hk_compile_shader(dev, &infos[i], state, features, pAllocator, (struct hk_api_shader **)&shaders_out[i]); if (result != VK_SUCCESS) { /* Clean up all the shaders before this point */ diff --git a/src/asahi/vulkan/hk_shader.h b/src/asahi/vulkan/hk_shader.h index 4f47b3dbcde..0b83d3c9590 100644 --- a/src/asahi/vulkan/hk_shader.h +++ b/src/asahi/vulkan/hk_shader.h @@ -362,6 +362,7 @@ hk_nir_lower_descriptors(nir_shader *nir, VkResult hk_compile_shader(struct hk_device *dev, struct vk_shader_compile_info *info, const struct vk_graphics_pipeline_state *state, + const struct vk_features *features, const VkAllocationCallbacks *pAllocator, struct hk_api_shader **shader_out);