diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 0e65cf99922..1fda72f45b3 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -61,6 +61,7 @@ #include "vk_format.h" #include "vk_physical_device.h" #include "vk_shader_module.h" +#include "vk_util.h" #include "radv_radeon_winsys.h" #include "ac_binary.h" @@ -1648,19 +1649,6 @@ radv_hash_shaders(unsigned char *hash, const struct radv_pipeline_key *key, uint32_t flags); -static inline gl_shader_stage -vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage) -{ - assert(util_bitcount(vk_stage) == 1); - return ffs(vk_stage) - 1; -} - -static inline VkShaderStageFlagBits -mesa_to_vk_shader_stage(gl_shader_stage mesa_stage) -{ - return (1 << mesa_stage); -} - #define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1) #define radv_foreach_stage(stage, stage_bits) \ diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index e9140fe0e14..4abb67979ff 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -40,6 +40,7 @@ #include "vk_instance.h" #include "vk_physical_device.h" #include "vk_shader_module.h" +#include "vk_util.h" #include @@ -1356,16 +1357,6 @@ struct v3dv_event { int state; }; -/* FIXME: the same function at anv, radv and tu, perhaps create common - * place? - */ -static inline gl_shader_stage -vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage) -{ - assert(__builtin_popcount(vk_stage) == 1); - return ffs(vk_stage) - 1; -} - struct v3dv_shader_variant { broadcom_shader_stage stage; diff --git a/src/freedreno/vulkan/tu_util.h b/src/freedreno/vulkan/tu_util.h index 8f629a7ba59..9c42cfdbad6 100644 --- a/src/freedreno/vulkan/tu_util.h +++ b/src/freedreno/vulkan/tu_util.h @@ -23,19 +23,7 @@ #include "a6xx.xml.h" #include - -static inline gl_shader_stage -vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage) -{ - assert(__builtin_popcount(vk_stage) == 1); - return util_logbase2(vk_stage); -} - -static inline VkShaderStageFlagBits -mesa_to_vk_shader_stage(gl_shader_stage mesa_stage) -{ - return 1 << mesa_stage; -} +#include "vk_util.h" #define TU_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1) diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index 71d90d23555..1b9aca1d03f 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -53,6 +53,7 @@ typedef uint32_t xcb_window_t; #include "vk_instance.h" #include "vk_physical_device.h" #include "vk_shader_module.h" +#include "vk_util.h" #include "wsi_common.h" @@ -119,19 +120,6 @@ void __lvp_finishme(const char *file, int line, const char *format, ...) return; \ } while (0) -static inline gl_shader_stage -vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage) -{ - assert(__builtin_popcount(vk_stage) == 1); - return ffs(vk_stage) - 1; -} - -static inline VkShaderStageFlagBits -mesa_to_vk_shader_stage(gl_shader_stage mesa_stage) -{ - return (1 << mesa_stage); -} - #define LVP_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1) #define lvp_foreach_stage(stage, stage_bits) \ diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index f01c7fbd84b..57aa4ee75ca 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -68,6 +68,7 @@ #include "vk_instance.h" #include "vk_physical_device.h" #include "vk_shader_module.h" +#include "vk_util.h" /* Pre-declarations needed for WSI entrypoints */ struct wl_surface; @@ -3220,19 +3221,6 @@ struct anv_semaphore { void anv_semaphore_reset_temporary(struct anv_device *device, struct anv_semaphore *semaphore); -static inline gl_shader_stage -vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage) -{ - assert(__builtin_popcount(vk_stage) == 1); - return ffs(vk_stage) - 1; -} - -static inline VkShaderStageFlagBits -mesa_to_vk_shader_stage(gl_shader_stage mesa_stage) -{ - return (1 << mesa_stage); -} - #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1) #define anv_foreach_stage(stage, stage_bits) \ diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h index 6e1dc7c1cc9..31f3edb0d9f 100644 --- a/src/vulkan/util/vk_util.h +++ b/src/vulkan/util/vk_util.h @@ -24,6 +24,7 @@ #define VK_UTIL_H #include "util/macros.h" +#include "compiler/shader_enums.h" #include #ifdef __cplusplus @@ -240,6 +241,19 @@ struct vk_pipeline_cache_header { memcpy((dest), (src), (count) * sizeof(*(src))); \ } while (0) +static inline gl_shader_stage +vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage) +{ + assert(__builtin_popcount((uint32_t) vk_stage) == 1); + return (gl_shader_stage) (ffs((uint32_t) vk_stage) - 1); +} + +static inline VkShaderStageFlagBits +mesa_to_vk_shader_stage(gl_shader_stage mesa_stage) +{ + return (VkShaderStageFlagBits) (1 << ((uint32_t) mesa_stage)); +} + #ifdef __cplusplus } #endif