We may want to add e.g. VKD3D_SHADER_SWIZZLE_ONE and VKD3D_SHADER_SWIZZLE_ZERO in the future.
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- include/vkd3d_shader.h | 22 ++++++++++++++++------ libs/vkd3d-shader/dxbc.c | 9 +++++++-- 2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h index 1ece69d..f437b24 100644 --- a/include/vkd3d_shader.h +++ b/include/vkd3d_shader.h @@ -741,17 +741,27 @@ enum vkd3d_shader_swizzle_component VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SWIZZLE_COMPONENT), };
-#define VKD3D_SHADER_SWIZZLE_MASK (0x3u) -#define VKD3D_SHADER_SWIZZLE_SHIFT(idx) (2u * (idx)) +#define VKD3D_SHADER_SWIZZLE_MASK (0xffu) +#define VKD3D_SHADER_SWIZZLE_SHIFT(idx) (8u * (idx))
#define VKD3D_SHADER_SWIZZLE(x, y, z, w) \ - (((VKD3D_SHADER_SWIZZLE_ ## x) << VKD3D_SHADER_SWIZZLE_SHIFT(0)) \ - | ((VKD3D_SHADER_SWIZZLE_ ## y) << VKD3D_SHADER_SWIZZLE_SHIFT(1)) \ - | ((VKD3D_SHADER_SWIZZLE_ ## z) << VKD3D_SHADER_SWIZZLE_SHIFT(2)) \ - | ((VKD3D_SHADER_SWIZZLE_ ## w) << VKD3D_SHADER_SWIZZLE_SHIFT(3))) + vkd3d_shader_create_swizzle(VKD3D_SHADER_SWIZZLE_ ## x, \ + VKD3D_SHADER_SWIZZLE_ ## y, \ + VKD3D_SHADER_SWIZZLE_ ## z, \ + VKD3D_SHADER_SWIZZLE_ ## w)
#define VKD3D_SHADER_NO_SWIZZLE VKD3D_SHADER_SWIZZLE(X, Y, Z, W)
+static inline uint32_t vkd3d_shader_create_swizzle(enum vkd3d_shader_swizzle_component x, + enum vkd3d_shader_swizzle_component y, enum vkd3d_shader_swizzle_component z, + enum vkd3d_shader_swizzle_component w) +{ + return ((x & VKD3D_SHADER_SWIZZLE_MASK) << VKD3D_SHADER_SWIZZLE_SHIFT(0)) + | ((y & VKD3D_SHADER_SWIZZLE_MASK) << VKD3D_SHADER_SWIZZLE_SHIFT(1)) + | ((z & VKD3D_SHADER_SWIZZLE_MASK) << VKD3D_SHADER_SWIZZLE_SHIFT(2)) + | ((w & VKD3D_SHADER_SWIZZLE_MASK) << VKD3D_SHADER_SWIZZLE_SHIFT(3)); +} + #ifndef VKD3D_SHADER_NO_PROTOTYPES
const char *vkd3d_shader_get_version(unsigned int *major, unsigned int *minor); diff --git a/libs/vkd3d-shader/dxbc.c b/libs/vkd3d-shader/dxbc.c index 89e3c0e..94e4621 100644 --- a/libs/vkd3d-shader/dxbc.c +++ b/libs/vkd3d-shader/dxbc.c @@ -1638,6 +1638,11 @@ static bool shader_sm4_is_scalar_register(const struct vkd3d_shader_register *re } }
+static uint32_t swizzle_from_sm4(uint32_t s) +{ + return vkd3d_shader_create_swizzle(s & 0x3, (s >> 2) & 0x3, (s >> 4) & 0x3, (s >> 6) & 0x3); +} + static bool shader_sm4_read_src_param(struct vkd3d_sm4_data *priv, const DWORD **ptr, const DWORD *end, enum vkd3d_data_type data_type, struct vkd3d_shader_src_param *src_param) { @@ -1676,11 +1681,11 @@ static bool shader_sm4_read_src_param(struct vkd3d_sm4_data *priv, const DWORD *
case VKD3D_SM4_SWIZZLE_SCALAR: src_param->swizzle = (token & VKD3D_SM4_SWIZZLE_MASK) >> VKD3D_SM4_SWIZZLE_SHIFT; - src_param->swizzle = (src_param->swizzle & 0x3) * 0x55; + src_param->swizzle = (src_param->swizzle & 0x3) * 0x01010101; break;
case VKD3D_SM4_SWIZZLE_VEC4: - src_param->swizzle = (token & VKD3D_SM4_SWIZZLE_MASK) >> VKD3D_SM4_SWIZZLE_SHIFT; + src_param->swizzle = swizzle_from_sm4((token & VKD3D_SM4_SWIZZLE_MASK) >> VKD3D_SM4_SWIZZLE_SHIFT); break;
default: