ac,radv,radeonsi: add a common helper for translating swizzle

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29268>
This commit is contained in:
Samuel Pitoiset
2024-05-16 16:34:30 +02:00
committed by Marge Bot
parent 2487a87552
commit 64fefc1179
7 changed files with 54 additions and 69 deletions
+20
View File
@@ -11,6 +11,26 @@
#include "sid.h"
#include "util/u_math.h"
#include "util/format/u_format.h"
unsigned
ac_map_swizzle(unsigned swizzle)
{
switch (swizzle) {
case PIPE_SWIZZLE_Y:
return V_008F0C_SQ_SEL_Y;
case PIPE_SWIZZLE_Z:
return V_008F0C_SQ_SEL_Z;
case PIPE_SWIZZLE_W:
return V_008F0C_SQ_SEL_W;
case PIPE_SWIZZLE_0:
return V_008F0C_SQ_SEL_0;
case PIPE_SWIZZLE_1:
return V_008F0C_SQ_SEL_1;
default: /* PIPE_SWIZZLE_X */
return V_008F0C_SQ_SEL_X;
}
}
void
ac_build_sampler_descriptor(const enum amd_gfx_level gfx_level, const struct ac_sampler_state *state, uint32_t desc[4])
+3
View File
@@ -15,6 +15,9 @@
extern "C" {
#endif
unsigned
ac_map_swizzle(unsigned swizzle);
struct ac_sampler_state {
unsigned address_mode_u : 3;
unsigned address_mode_v : 3;
+3 -2
View File
@@ -8,6 +8,7 @@
* SPDX-License-Identifier: MIT
*/
#include "ac_descriptors.h"
#include "gfx10_format_table.h"
#include "radv_buffer.h"
@@ -42,8 +43,8 @@ radv_make_texel_buffer_descriptor(struct radv_device *device, uint64_t va, VkFor
range /= stride;
}
rsrc_word3 = S_008F0C_DST_SEL_X(radv_map_swizzle(swizzle[0])) | S_008F0C_DST_SEL_Y(radv_map_swizzle(swizzle[1])) |
S_008F0C_DST_SEL_Z(radv_map_swizzle(swizzle[2])) | S_008F0C_DST_SEL_W(radv_map_swizzle(swizzle[3]));
rsrc_word3 = S_008F0C_DST_SEL_X(ac_map_swizzle(swizzle[0])) | S_008F0C_DST_SEL_Y(ac_map_swizzle(swizzle[1])) |
S_008F0C_DST_SEL_Z(ac_map_swizzle(swizzle[2])) | S_008F0C_DST_SEL_W(ac_map_swizzle(swizzle[3]));
if (pdev->info.gfx_level >= GFX10) {
const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&pdev->info)[vk_format_to_pipe_format(vk_format)];
-19
View File
@@ -715,25 +715,6 @@ radv_get_surface_flags(struct radv_device *device, struct radv_image *image, uns
return flags;
}
unsigned
radv_map_swizzle(unsigned swizzle)
{
switch (swizzle) {
case PIPE_SWIZZLE_Y:
return V_008F0C_SQ_SEL_Y;
case PIPE_SWIZZLE_Z:
return V_008F0C_SQ_SEL_Z;
case PIPE_SWIZZLE_W:
return V_008F0C_SQ_SEL_W;
case PIPE_SWIZZLE_0:
return V_008F0C_SQ_SEL_0;
case PIPE_SWIZZLE_1:
return V_008F0C_SQ_SEL_1;
default: /* PIPE_SWIZZLE_X */
return V_008F0C_SQ_SEL_X;
}
}
void
radv_compose_swizzle(const struct util_format_description *desc, const VkComponentMapping *mapping,
enum pipe_swizzle swizzle[4])
-2
View File
@@ -311,8 +311,6 @@ bool radv_image_use_dcc_image_stores(const struct radv_device *device, const str
bool radv_image_use_dcc_predication(const struct radv_device *device, const struct radv_image *image);
unsigned radv_map_swizzle(unsigned swizzle);
void radv_compose_swizzle(const struct util_format_description *desc, const VkComponentMapping *mapping,
enum pipe_swizzle swizzle[4]);
+4 -4
View File
@@ -161,8 +161,8 @@ gfx10_make_texture_descriptor(struct radv_device *device, struct radv_image *ima
state[1] = S_00A004_FORMAT_GFX10(img_format) | S_00A004_WIDTH_LO(width - 1);
state[2] = S_00A008_WIDTH_HI((width - 1) >> 2) | S_00A008_HEIGHT(height - 1) |
S_00A008_RESOURCE_LEVEL(pdev->info.gfx_level < GFX11);
state[3] = S_00A00C_DST_SEL_X(radv_map_swizzle(swizzle[0])) | S_00A00C_DST_SEL_Y(radv_map_swizzle(swizzle[1])) |
S_00A00C_DST_SEL_Z(radv_map_swizzle(swizzle[2])) | S_00A00C_DST_SEL_W(radv_map_swizzle(swizzle[3])) |
state[3] = S_00A00C_DST_SEL_X(ac_map_swizzle(swizzle[0])) | S_00A00C_DST_SEL_Y(ac_map_swizzle(swizzle[1])) |
S_00A00C_DST_SEL_Z(ac_map_swizzle(swizzle[2])) | S_00A00C_DST_SEL_W(ac_map_swizzle(swizzle[3])) |
S_00A00C_BASE_LEVEL(image->vk.samples > 1 ? 0 : first_level) |
S_00A00C_LAST_LEVEL_GFX10(image->vk.samples > 1 ? util_logbase2(image->vk.samples) : last_level) |
S_00A00C_BC_SWIZZLE(ac_border_color_swizzle(desc)) | S_00A00C_TYPE(type);
@@ -297,8 +297,8 @@ gfx6_make_texture_descriptor(struct radv_device *device, struct radv_image *imag
state[1] = (S_008F14_MIN_LOD(util_unsigned_fixed(CLAMP(min_lod, 0, 15), 8)) | S_008F14_DATA_FORMAT(data_format) |
S_008F14_NUM_FORMAT(num_format));
state[2] = (S_008F18_WIDTH(width - 1) | S_008F18_HEIGHT(height - 1) | S_008F18_PERF_MOD(4));
state[3] = (S_008F1C_DST_SEL_X(radv_map_swizzle(swizzle[0])) | S_008F1C_DST_SEL_Y(radv_map_swizzle(swizzle[1])) |
S_008F1C_DST_SEL_Z(radv_map_swizzle(swizzle[2])) | S_008F1C_DST_SEL_W(radv_map_swizzle(swizzle[3])) |
state[3] = (S_008F1C_DST_SEL_X(ac_map_swizzle(swizzle[0])) | S_008F1C_DST_SEL_Y(ac_map_swizzle(swizzle[1])) |
S_008F1C_DST_SEL_Z(ac_map_swizzle(swizzle[2])) | S_008F1C_DST_SEL_W(ac_map_swizzle(swizzle[3])) |
S_008F1C_BASE_LEVEL(image->vk.samples > 1 ? 0 : first_level) |
S_008F1C_LAST_LEVEL(image->vk.samples > 1 ? util_logbase2(image->vk.samples) : last_level) |
S_008F1C_TYPE(type));
+24 -42
View File
@@ -22,24 +22,6 @@
#include "ac_formats.h"
#include "gfx10_format_table.h"
static unsigned si_map_swizzle(unsigned swizzle)
{
switch (swizzle) {
case PIPE_SWIZZLE_Y:
return V_008F0C_SQ_SEL_Y;
case PIPE_SWIZZLE_Z:
return V_008F0C_SQ_SEL_Z;
case PIPE_SWIZZLE_W:
return V_008F0C_SQ_SEL_W;
case PIPE_SWIZZLE_0:
return V_008F0C_SQ_SEL_0;
case PIPE_SWIZZLE_1:
return V_008F0C_SQ_SEL_1;
default: /* PIPE_SWIZZLE_X */
return V_008F0C_SQ_SEL_X;
}
}
/* 12.4 fixed-point */
static unsigned si_pack_float_12p4(float x)
{
@@ -4442,10 +4424,10 @@ void si_make_buffer_descriptor(struct si_screen *screen, struct si_resource *buf
state[4] = 0;
state[5] = S_008F04_STRIDE(stride);
state[6] = num_records;
state[7] = S_008F0C_DST_SEL_X(si_map_swizzle(desc->swizzle[0])) |
S_008F0C_DST_SEL_Y(si_map_swizzle(desc->swizzle[1])) |
S_008F0C_DST_SEL_Z(si_map_swizzle(desc->swizzle[2])) |
S_008F0C_DST_SEL_W(si_map_swizzle(desc->swizzle[3]));
state[7] = S_008F0C_DST_SEL_X(ac_map_swizzle(desc->swizzle[0])) |
S_008F0C_DST_SEL_Y(ac_map_swizzle(desc->swizzle[1])) |
S_008F0C_DST_SEL_Z(ac_map_swizzle(desc->swizzle[2])) |
S_008F0C_DST_SEL_W(ac_map_swizzle(desc->swizzle[3]));
if (screen->info.gfx_level >= GFX10) {
const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&screen->info)[format];
@@ -4555,10 +4537,10 @@ static void cdna_emu_make_image_descriptor(struct si_screen *screen, struct si_t
state[0] = 0;
state[1] = S_008F04_STRIDE(stride);
state[2] = num_records;
state[3] = S_008F0C_DST_SEL_X(si_map_swizzle(swizzle[0])) |
S_008F0C_DST_SEL_Y(si_map_swizzle(swizzle[1])) |
S_008F0C_DST_SEL_Z(si_map_swizzle(swizzle[2])) |
S_008F0C_DST_SEL_W(si_map_swizzle(swizzle[3]));
state[3] = S_008F0C_DST_SEL_X(ac_map_swizzle(swizzle[0])) |
S_008F0C_DST_SEL_Y(ac_map_swizzle(swizzle[1])) |
S_008F0C_DST_SEL_Z(ac_map_swizzle(swizzle[2])) |
S_008F0C_DST_SEL_W(ac_map_swizzle(swizzle[3]));
if (screen->info.gfx_level >= GFX10) {
const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&screen->info)[pipe_format];
@@ -4679,10 +4661,10 @@ static void gfx10_make_texture_descriptor(
S_00A004_WIDTH_LO(width - 1);
state[2] = S_00A008_WIDTH_HI((width - 1) >> 2) |
S_00A008_HEIGHT(height - 1);
state[3] = S_00A00C_DST_SEL_X(si_map_swizzle(swizzle[0])) |
S_00A00C_DST_SEL_Y(si_map_swizzle(swizzle[1])) |
S_00A00C_DST_SEL_Z(si_map_swizzle(swizzle[2])) |
S_00A00C_DST_SEL_W(si_map_swizzle(swizzle[3])) |
state[3] = S_00A00C_DST_SEL_X(ac_map_swizzle(swizzle[0])) |
S_00A00C_DST_SEL_Y(ac_map_swizzle(swizzle[1])) |
S_00A00C_DST_SEL_Z(ac_map_swizzle(swizzle[2])) |
S_00A00C_DST_SEL_W(ac_map_swizzle(swizzle[3])) |
S_00A00C_NO_EDGE_CLAMP(res->last_level > 0 &&
util_format_is_compressed(res->format) &&
!util_format_is_compressed(pipe_format)) |
@@ -4706,10 +4688,10 @@ static void gfx10_make_texture_descriptor(
S_00A008_RESOURCE_LEVEL(screen->info.gfx_level < GFX11);
state[3] =
S_00A00C_DST_SEL_X(si_map_swizzle(swizzle[0])) |
S_00A00C_DST_SEL_Y(si_map_swizzle(swizzle[1])) |
S_00A00C_DST_SEL_Z(si_map_swizzle(swizzle[2])) |
S_00A00C_DST_SEL_W(si_map_swizzle(swizzle[3])) |
S_00A00C_DST_SEL_X(ac_map_swizzle(swizzle[0])) |
S_00A00C_DST_SEL_Y(ac_map_swizzle(swizzle[1])) |
S_00A00C_DST_SEL_Z(ac_map_swizzle(swizzle[2])) |
S_00A00C_DST_SEL_W(ac_map_swizzle(swizzle[3])) |
S_00A00C_BASE_LEVEL(res->nr_samples > 1 ? 0 : first_level) |
S_00A00C_LAST_LEVEL_GFX10(res->nr_samples > 1 ? util_logbase2(res->nr_samples) : last_level) |
S_00A00C_BC_SWIZZLE(ac_border_color_swizzle(desc)) | S_00A00C_TYPE(type);
@@ -4857,10 +4839,10 @@ static void si_make_texture_descriptor(struct si_screen *screen, struct si_textu
state[0] = 0;
state[1] = (S_008F14_DATA_FORMAT(data_format) | S_008F14_NUM_FORMAT(num_format));
state[2] = (S_008F18_WIDTH(width - 1) | S_008F18_HEIGHT(height - 1) | S_008F18_PERF_MOD(4));
state[3] = (S_008F1C_DST_SEL_X(si_map_swizzle(swizzle[0])) |
S_008F1C_DST_SEL_Y(si_map_swizzle(swizzle[1])) |
S_008F1C_DST_SEL_Z(si_map_swizzle(swizzle[2])) |
S_008F1C_DST_SEL_W(si_map_swizzle(swizzle[3])) |
state[3] = (S_008F1C_DST_SEL_X(ac_map_swizzle(swizzle[0])) |
S_008F1C_DST_SEL_Y(ac_map_swizzle(swizzle[1])) |
S_008F1C_DST_SEL_Z(ac_map_swizzle(swizzle[2])) |
S_008F1C_DST_SEL_W(ac_map_swizzle(swizzle[3])) |
S_008F1C_BASE_LEVEL(num_samples > 1 ? 0 : first_level) |
S_008F1C_LAST_LEVEL(num_samples > 1 ? util_logbase2(num_samples) : last_level) |
S_008F1C_TYPE(type));
@@ -5474,10 +5456,10 @@ static void *si_create_vertex_elements(struct pipe_context *ctx, unsigned count,
v->vb_alignment_check_mask |= 1 << vbo_index;
}
v->elem[i].rsrc_word3 = S_008F0C_DST_SEL_X(si_map_swizzle(desc->swizzle[0])) |
S_008F0C_DST_SEL_Y(si_map_swizzle(desc->swizzle[1])) |
S_008F0C_DST_SEL_Z(si_map_swizzle(desc->swizzle[2])) |
S_008F0C_DST_SEL_W(si_map_swizzle(desc->swizzle[3]));
v->elem[i].rsrc_word3 = S_008F0C_DST_SEL_X(ac_map_swizzle(desc->swizzle[0])) |
S_008F0C_DST_SEL_Y(ac_map_swizzle(desc->swizzle[1])) |
S_008F0C_DST_SEL_Z(ac_map_swizzle(desc->swizzle[2])) |
S_008F0C_DST_SEL_W(ac_map_swizzle(desc->swizzle[3]));
if (sscreen->info.gfx_level >= GFX10) {
const struct gfx10_format *fmt = &ac_get_gfx10_format_table(&sscreen->info)[elements[i].src_format];