diff --git a/src/broadcom/common/v3d_util.c b/src/broadcom/common/v3d_util.c index 2eb1582712a..5fe0336f6ed 100644 --- a/src/broadcom/common/v3d_util.c +++ b/src/broadcom/common/v3d_util.c @@ -122,3 +122,24 @@ v3d_choose_tile_size(uint32_t color_attachment_count, uint32_t max_color_bpp, *width = tile_sizes[idx * 2]; *height = tile_sizes[idx * 2 + 1]; } + +/* Translates a pipe swizzle to the swizzle values used in the + * TEXTURE_SHADER_STATE packet. + */ +uint32_t +v3d_translate_pipe_swizzle(enum pipe_swizzle swizzle) +{ + switch (swizzle) { + case PIPE_SWIZZLE_0: + return 0; + case PIPE_SWIZZLE_1: + return 1; + case PIPE_SWIZZLE_X: + case PIPE_SWIZZLE_Y: + case PIPE_SWIZZLE_Z: + case PIPE_SWIZZLE_W: + return 2 + swizzle; + default: + unreachable("unknown swizzle"); + } +} diff --git a/src/broadcom/common/v3d_util.h b/src/broadcom/common/v3d_util.h index 3d25adc9e1a..d3cca0ce6a5 100644 --- a/src/broadcom/common/v3d_util.h +++ b/src/broadcom/common/v3d_util.h @@ -25,6 +25,7 @@ #define V3D_UTIL_H #include "common/v3d_device_info.h" +#include "pipe/p_defines.h" uint32_t v3d_csd_choose_workgroups_per_supergroup(struct v3d_device_info *devinfo, @@ -39,4 +40,7 @@ v3d_choose_tile_size(uint32_t color_attachment_count, uint32_t max_color_bpp, bool msaa, bool double_buffer, uint32_t *width, uint32_t *height); +uint32_t +v3d_translate_pipe_swizzle(enum pipe_swizzle swizzle); + #endif diff --git a/src/broadcom/vulkan/v3dvx_image.c b/src/broadcom/vulkan/v3dvx_image.c index 52cd6ad914c..cbe9f3c8a75 100644 --- a/src/broadcom/vulkan/v3dvx_image.c +++ b/src/broadcom/vulkan/v3dvx_image.c @@ -26,30 +26,6 @@ #include "broadcom/cle/v3dx_pack.h" #include "broadcom/compiler/v3d_compiler.h" -/* - * This method translates pipe_swizzle to the swizzle values used at the - * packet TEXTURE_SHADER_STATE - * - * FIXME: C&P from v3d, common place? - */ -static uint32_t -translate_swizzle(unsigned char pipe_swizzle) -{ - switch (pipe_swizzle) { - case PIPE_SWIZZLE_0: - return 0; - case PIPE_SWIZZLE_1: - return 1; - case PIPE_SWIZZLE_X: - case PIPE_SWIZZLE_Y: - case PIPE_SWIZZLE_Z: - case PIPE_SWIZZLE_W: - return 2 + pipe_swizzle; - default: - unreachable("unknown swizzle"); - } -} - /* * Packs and ensure bo for the shader state (the latter can be temporal). */ @@ -93,10 +69,10 @@ pack_texture_shader_state_helper(struct v3dv_device *device, tex.max_level = image_view->vk.base_mip_level + image_view->vk.level_count - 1; - tex.swizzle_r = translate_swizzle(image_view->swizzle[0]); - tex.swizzle_g = translate_swizzle(image_view->swizzle[1]); - tex.swizzle_b = translate_swizzle(image_view->swizzle[2]); - tex.swizzle_a = translate_swizzle(image_view->swizzle[3]); + tex.swizzle_r = v3d_translate_pipe_swizzle(image_view->swizzle[0]); + tex.swizzle_g = v3d_translate_pipe_swizzle(image_view->swizzle[1]); + tex.swizzle_b = v3d_translate_pipe_swizzle(image_view->swizzle[2]); + tex.swizzle_a = v3d_translate_pipe_swizzle(image_view->swizzle[3]); tex.reverse_standard_border_color = image_view->channel_reverse; @@ -163,10 +139,10 @@ v3dX(pack_texture_shader_state_from_buffer_view)(struct v3dv_device *device, const struct v3dv_buffer *buffer = buffer_view->buffer; v3dvx_pack(buffer_view->texture_shader_state, TEXTURE_SHADER_STATE, tex) { - tex.swizzle_r = translate_swizzle(PIPE_SWIZZLE_X); - tex.swizzle_g = translate_swizzle(PIPE_SWIZZLE_Y); - tex.swizzle_b = translate_swizzle(PIPE_SWIZZLE_Z); - tex.swizzle_a = translate_swizzle(PIPE_SWIZZLE_W); + tex.swizzle_r = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_X); + tex.swizzle_g = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_Y); + tex.swizzle_b = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_Z); + tex.swizzle_a = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_W); tex.image_depth = 1; diff --git a/src/gallium/drivers/v3d/v3dx_emit.c b/src/gallium/drivers/v3d/v3dx_emit.c index 44e755fba22..e47753d3637 100644 --- a/src/gallium/drivers/v3d/v3dx_emit.c +++ b/src/gallium/drivers/v3d/v3dx_emit.c @@ -26,6 +26,7 @@ #include "v3d_context.h" #include "broadcom/common/v3d_macros.h" #include "broadcom/cle/v3dx_pack.h" +#include "broadcom/common/v3d_util.h" #include "broadcom/compiler/v3d_compiler.h" static uint8_t @@ -110,24 +111,6 @@ swizzled_border_color(const struct v3d_device_info *devinfo, } } -static uint32_t -translate_swizzle(unsigned char pipe_swizzle) -{ - switch (pipe_swizzle) { - case PIPE_SWIZZLE_0: - return 0; - case PIPE_SWIZZLE_1: - return 1; - case PIPE_SWIZZLE_X: - case PIPE_SWIZZLE_Y: - case PIPE_SWIZZLE_Z: - case PIPE_SWIZZLE_W: - return 2 + pipe_swizzle; - default: - unreachable("unknown swizzle"); - } -} - static void emit_one_texture(struct v3d_context *v3d, struct v3d_texture_stateobj *stage_tex, int i) @@ -195,15 +178,15 @@ emit_one_texture(struct v3d_context *v3d, struct v3d_texture_stateobj *stage_tex * the shader, because you need the Y/Z/W channels to be defined. */ if (return_size == 32) { - unpacked.swizzle_r = translate_swizzle(PIPE_SWIZZLE_X); - unpacked.swizzle_g = translate_swizzle(PIPE_SWIZZLE_Y); - unpacked.swizzle_b = translate_swizzle(PIPE_SWIZZLE_Z); - unpacked.swizzle_a = translate_swizzle(PIPE_SWIZZLE_W); + unpacked.swizzle_r = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_X); + unpacked.swizzle_g = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_Y); + unpacked.swizzle_b = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_Z); + unpacked.swizzle_a = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_W); } else { - unpacked.swizzle_r = translate_swizzle(sview->swizzle[0]); - unpacked.swizzle_g = translate_swizzle(sview->swizzle[1]); - unpacked.swizzle_b = translate_swizzle(sview->swizzle[2]); - unpacked.swizzle_a = translate_swizzle(sview->swizzle[3]); + unpacked.swizzle_r = v3d_translate_pipe_swizzle(sview->swizzle[0]); + unpacked.swizzle_g = v3d_translate_pipe_swizzle(sview->swizzle[1]); + unpacked.swizzle_b = v3d_translate_pipe_swizzle(sview->swizzle[2]); + unpacked.swizzle_a = v3d_translate_pipe_swizzle(sview->swizzle[3]); } int min_img_filter = psampler->min_img_filter; diff --git a/src/gallium/drivers/v3d/v3dx_state.c b/src/gallium/drivers/v3d/v3dx_state.c index ce293218447..b4d1a53f75f 100644 --- a/src/gallium/drivers/v3d/v3dx_state.c +++ b/src/gallium/drivers/v3d/v3dx_state.c @@ -35,6 +35,7 @@ #include "v3d_context.h" #include "broadcom/common/v3d_tiling.h" #include "broadcom/common/v3d_macros.h" +#include "broadcom/common/v3d_util.h" #include "broadcom/compiler/v3d_compiler.h" #include "broadcom/cle/v3dx_pack.h" @@ -836,26 +837,6 @@ v3d_sampler_state_delete(struct pipe_context *pctx, free(psampler); } -#if V3D_VERSION >= 40 -static uint32_t -translate_swizzle(unsigned char pipe_swizzle) -{ - switch (pipe_swizzle) { - case PIPE_SWIZZLE_0: - return 0; - case PIPE_SWIZZLE_1: - return 1; - case PIPE_SWIZZLE_X: - case PIPE_SWIZZLE_Y: - case PIPE_SWIZZLE_Z: - case PIPE_SWIZZLE_W: - return 2 + pipe_swizzle; - default: - unreachable("unknown swizzle"); - } -} -#endif - static void v3d_setup_texture_shader_state_from_buffer(struct V3DX(TEXTURE_SHADER_STATE) *tex, struct pipe_resource *prsc, @@ -991,10 +972,10 @@ v3dX(create_texture_shader_state_bo)(struct v3d_context *v3d, tex.srgb = util_format_is_srgb(cso->format); #if V3D_VERSION >= 40 - tex.swizzle_r = translate_swizzle(so->swizzle[0]); - tex.swizzle_g = translate_swizzle(so->swizzle[1]); - tex.swizzle_b = translate_swizzle(so->swizzle[2]); - tex.swizzle_a = translate_swizzle(so->swizzle[3]); + tex.swizzle_r = v3d_translate_pipe_swizzle(so->swizzle[0]); + tex.swizzle_g = v3d_translate_pipe_swizzle(so->swizzle[1]); + tex.swizzle_b = v3d_translate_pipe_swizzle(so->swizzle[2]); + tex.swizzle_a = v3d_translate_pipe_swizzle(so->swizzle[3]); #endif if (prsc->nr_samples > 1 && V3D_VERSION < 40) { @@ -1413,10 +1394,10 @@ v3d_create_image_view_texture_shader_state(struct v3d_context *v3d, iview->base.u.buf.size); } - tex.swizzle_r = translate_swizzle(PIPE_SWIZZLE_X); - tex.swizzle_g = translate_swizzle(PIPE_SWIZZLE_Y); - tex.swizzle_b = translate_swizzle(PIPE_SWIZZLE_Z); - tex.swizzle_a = translate_swizzle(PIPE_SWIZZLE_W); + tex.swizzle_r = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_X); + tex.swizzle_g = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_Y); + tex.swizzle_b = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_Z); + tex.swizzle_a = v3d_translate_pipe_swizzle(PIPE_SWIZZLE_W); tex.texture_type = v3d_get_tex_format(&v3d->screen->devinfo, iview->base.format);