vulkan: Deduplicate mesa stage conversion

Across every driver...

v2: Add casts to appease -fpermissive used on CI.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9477>
This commit is contained in:
Alyssa Rosenzweig 2021-03-09 14:30:09 +00:00 committed by Marge Bot
parent 7ace3f3ef0
commit 06ebbde630
6 changed files with 19 additions and 62 deletions

View file

@ -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) \

View file

@ -40,6 +40,7 @@
#include "vk_instance.h"
#include "vk_physical_device.h"
#include "vk_shader_module.h"
#include "vk_util.h"
#include <xf86drm.h>
@ -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;

View file

@ -23,19 +23,7 @@
#include "a6xx.xml.h"
#include <vulkan/vulkan.h>
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)

View file

@ -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) \

View file

@ -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) \

View file

@ -24,6 +24,7 @@
#define VK_UTIL_H
#include "util/macros.h"
#include "compiler/shader_enums.h"
#include <string.h>
#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