From: Jonathan Marek Date: Thu, 5 Sep 2019 02:34:23 +0000 (-0400) Subject: freedreno/a2xx: formats update X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=feea5986a90d92ef6eb919eca31c5b53457cb035;p=mesa.git freedreno/a2xx: formats update For render formats, update fd2_pipe2color to only work with HW supported render formats, and remove the format whitelist is_format_supported. This patch enables float render formats (which work). For vertex/texture formats, use a generic function which translates using the bitsize of the channels. Since we fake support for some vertex formats, check for these in is_format_supported to avoid enabling them as sampler formats. Signed-off-by: Jonathan Marek Reviewed-by: Rob Clark --- diff --git a/src/freedreno/registers/a2xx.xml b/src/freedreno/registers/a2xx.xml index 2c7388d9fcd..4817ab31bb3 100644 --- a/src/freedreno/registers/a2xx.xml +++ b/src/freedreno/registers/a2xx.xml @@ -1561,11 +1561,11 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd"> - + - - + + diff --git a/src/gallium/drivers/freedreno/a2xx/fd2_gmem.c b/src/gallium/drivers/freedreno/a2xx/fd2_gmem.c index 82dc535a3fc..6a78db5377e 100644 --- a/src/gallium/drivers/freedreno/a2xx/fd2_gmem.c +++ b/src/gallium/drivers/freedreno/a2xx/fd2_gmem.c @@ -52,7 +52,6 @@ static uint32_t fmt2swap(enum pipe_format format) case PIPE_FORMAT_B5G5R5X1_UNORM: case PIPE_FORMAT_B4G4R4A4_UNORM: case PIPE_FORMAT_B4G4R4X4_UNORM: - /* TODO probably some more.. */ return 1; default: return 0; diff --git a/src/gallium/drivers/freedreno/a2xx/fd2_screen.c b/src/gallium/drivers/freedreno/a2xx/fd2_screen.c index cd57af11ac5..42c0c024e61 100644 --- a/src/gallium/drivers/freedreno/a2xx/fd2_screen.c +++ b/src/gallium/drivers/freedreno/a2xx/fd2_screen.c @@ -53,27 +53,20 @@ fd2_screen_is_format_supported(struct pipe_screen *pscreen, if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) return false; - /* TODO figure out how to render to other formats.. */ if ((usage & PIPE_BIND_RENDER_TARGET) && - ((format != PIPE_FORMAT_B5G6R5_UNORM) && - (format != PIPE_FORMAT_B5G5R5A1_UNORM) && - (format != PIPE_FORMAT_B5G5R5X1_UNORM) && - (format != PIPE_FORMAT_B4G4R4A4_UNORM) && - (format != PIPE_FORMAT_B4G4R4X4_UNORM) && - (format != PIPE_FORMAT_B8G8R8A8_UNORM) && - (format != PIPE_FORMAT_B8G8R8X8_UNORM) && - (format != PIPE_FORMAT_R8G8B8A8_UNORM) && - (format != PIPE_FORMAT_R8G8B8X8_UNORM))) { - DBG("not supported render target: format=%s, target=%d, sample_count=%d, usage=%x", - util_format_name(format), target, sample_count, usage); - return false; + fd2_pipe2color(format) != (enum a2xx_colorformatx)~0) { + retval |= PIPE_BIND_RENDER_TARGET; } - if ((usage & (PIPE_BIND_SAMPLER_VIEW | - PIPE_BIND_VERTEX_BUFFER)) && - (fd2_pipe2surface(format) != (enum a2xx_sq_surfaceformat)~0)) { - retval |= usage & (PIPE_BIND_SAMPLER_VIEW | - PIPE_BIND_VERTEX_BUFFER); + if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_VERTEX_BUFFER)) && + !util_format_is_srgb(format)) { + enum a2xx_sq_surfaceformat fmt = fd2_pipe2surface(format); + unsigned block_size = util_format_get_blocksize(format); + if (fmt != ~0) + retval |= usage & PIPE_BIND_VERTEX_BUFFER; + if (fmt != ~0 && block_size != 3 && block_size != 6 && + (block_size != 12 || format == PIPE_FORMAT_R32G32B32_FLOAT)) + retval |= usage & PIPE_BIND_SAMPLER_VIEW; } if ((usage & (PIPE_BIND_RENDER_TARGET | diff --git a/src/gallium/drivers/freedreno/a2xx/fd2_texture.c b/src/gallium/drivers/freedreno/a2xx/fd2_texture.c index 3aca767f285..7aa26ca5673 100644 --- a/src/gallium/drivers/freedreno/a2xx/fd2_texture.c +++ b/src/gallium/drivers/freedreno/a2xx/fd2_texture.c @@ -180,7 +180,16 @@ fd2_sampler_view_create(struct pipe_context *pctx, struct pipe_resource *prsc, so->base.reference.count = 1; so->base.context = pctx; + enum sq_tex_sign sign = SQ_TEX_SIGN_UNSIGNED; + if (util_format_is_snorm(cso->format)) + sign = SQ_TEX_SIGN_SIGNED; + /* note: SQ_TEX_SIGN_GAMMA same as SQ_TEX_SIGN_UNSIGNED (a200) */ + so->tex0 = + A2XX_SQ_TEX_0_SIGN_X(sign) | + A2XX_SQ_TEX_0_SIGN_Y(sign) | + A2XX_SQ_TEX_0_SIGN_Z(sign) | + A2XX_SQ_TEX_0_SIGN_W(sign) | A2XX_SQ_TEX_0_PITCH(rsc->slices[0].pitch) | COND(rsc->tile_mode, A2XX_SQ_TEX_0_TILED); so->tex1 = diff --git a/src/gallium/drivers/freedreno/a2xx/fd2_util.c b/src/gallium/drivers/freedreno/a2xx/fd2_util.c index 5957a6a4df5..af570701e54 100644 --- a/src/gallium/drivers/freedreno/a2xx/fd2_util.c +++ b/src/gallium/drivers/freedreno/a2xx/fd2_util.c @@ -32,181 +32,81 @@ enum a2xx_sq_surfaceformat fd2_pipe2surface(enum pipe_format format) { - switch (format) { - /* 8-bit buffers. */ - case PIPE_FORMAT_A8_UNORM: - case PIPE_FORMAT_A8_SNORM: - case PIPE_FORMAT_A8_UINT: - case PIPE_FORMAT_A8_SINT: - case PIPE_FORMAT_I8_UNORM: - case PIPE_FORMAT_I8_SNORM: - case PIPE_FORMAT_I8_UINT: - case PIPE_FORMAT_I8_SINT: - case PIPE_FORMAT_L8_UNORM: - case PIPE_FORMAT_L8_SNORM: - case PIPE_FORMAT_L8_UINT: - case PIPE_FORMAT_L8_SINT: - case PIPE_FORMAT_L8_SRGB: - case PIPE_FORMAT_R8_UNORM: - case PIPE_FORMAT_R8_SNORM: - case PIPE_FORMAT_R8_UINT: - case PIPE_FORMAT_R8_SINT: - return FMT_8; - - /* 16-bit buffers. */ - case PIPE_FORMAT_B5G6R5_UNORM: - return FMT_5_6_5; - case PIPE_FORMAT_B5G5R5A1_UNORM: - case PIPE_FORMAT_B5G5R5X1_UNORM: - return FMT_1_5_5_5; - case PIPE_FORMAT_B4G4R4A4_UNORM: - case PIPE_FORMAT_B4G4R4X4_UNORM: - return FMT_4_4_4_4; - case PIPE_FORMAT_Z16_UNORM: - return FMT_16; - case PIPE_FORMAT_L8A8_UNORM: - case PIPE_FORMAT_L8A8_SNORM: - case PIPE_FORMAT_L8A8_UINT: - case PIPE_FORMAT_L8A8_SINT: - case PIPE_FORMAT_L8A8_SRGB: - case PIPE_FORMAT_R8G8_UNORM: - case PIPE_FORMAT_R8G8_SNORM: - case PIPE_FORMAT_R8G8_UINT: - case PIPE_FORMAT_R8G8_SINT: - return FMT_8_8; - case PIPE_FORMAT_R16_UNORM: - case PIPE_FORMAT_R16_SNORM: - case PIPE_FORMAT_R16_UINT: - case PIPE_FORMAT_R16_SINT: - case PIPE_FORMAT_A16_UNORM: - case PIPE_FORMAT_A16_SNORM: - case PIPE_FORMAT_A16_UINT: - case PIPE_FORMAT_A16_SINT: - case PIPE_FORMAT_L16_UNORM: - case PIPE_FORMAT_L16_SNORM: - case PIPE_FORMAT_L16_UINT: - case PIPE_FORMAT_L16_SINT: - case PIPE_FORMAT_I16_UNORM: - case PIPE_FORMAT_I16_SNORM: - case PIPE_FORMAT_I16_UINT: - case PIPE_FORMAT_I16_SINT: - return FMT_16; - case PIPE_FORMAT_R16_FLOAT: - case PIPE_FORMAT_A16_FLOAT: - case PIPE_FORMAT_L16_FLOAT: - case PIPE_FORMAT_I16_FLOAT: - return FMT_16_FLOAT; - - /* 32-bit buffers. */ - case PIPE_FORMAT_A8B8G8R8_SRGB: - case PIPE_FORMAT_A8B8G8R8_UNORM: - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_B8G8R8A8_SRGB: - case PIPE_FORMAT_B8G8R8A8_UNORM: - case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_R8G8B8A8_SNORM: - case PIPE_FORMAT_R8G8B8A8_UNORM: - case PIPE_FORMAT_R8G8B8X8_UNORM: - case PIPE_FORMAT_R8SG8SB8UX8U_NORM: - case PIPE_FORMAT_X8B8G8R8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_R8G8B8_UNORM: - case PIPE_FORMAT_R8G8B8A8_SINT: - case PIPE_FORMAT_R8G8B8A8_UINT: - return FMT_8_8_8_8; - case PIPE_FORMAT_R10G10B10A2_UNORM: - case PIPE_FORMAT_R10G10B10X2_SNORM: - case PIPE_FORMAT_B10G10R10A2_UNORM: - case PIPE_FORMAT_B10G10R10A2_UINT: - case PIPE_FORMAT_R10SG10SB10SA2U_NORM: - return FMT_2_10_10_10; - case PIPE_FORMAT_Z24X8_UNORM: - case PIPE_FORMAT_Z24_UNORM_S8_UINT: - return FMT_24_8; - case PIPE_FORMAT_R32_UINT: - case PIPE_FORMAT_R32_SINT: - case PIPE_FORMAT_A32_UINT: - case PIPE_FORMAT_A32_SINT: - case PIPE_FORMAT_L32_UINT: - case PIPE_FORMAT_L32_SINT: - case PIPE_FORMAT_I32_UINT: - case PIPE_FORMAT_I32_SINT: - return FMT_32; - case PIPE_FORMAT_R32_FLOAT: - case PIPE_FORMAT_A32_FLOAT: - case PIPE_FORMAT_L32_FLOAT: - case PIPE_FORMAT_I32_FLOAT: - case PIPE_FORMAT_Z32_FLOAT: - return FMT_32_FLOAT; - case PIPE_FORMAT_R16G16_FLOAT: - case PIPE_FORMAT_L16A16_FLOAT: - return FMT_16_16_FLOAT; - case PIPE_FORMAT_R16G16_UNORM: - case PIPE_FORMAT_R16G16_SNORM: - case PIPE_FORMAT_R16G16_UINT: - case PIPE_FORMAT_R16G16_SINT: - case PIPE_FORMAT_L16A16_UNORM: - case PIPE_FORMAT_L16A16_SNORM: - case PIPE_FORMAT_L16A16_UINT: - case PIPE_FORMAT_L16A16_SINT: - return FMT_16_16; - - /* 64-bit buffers. */ - case PIPE_FORMAT_R16G16B16A16_UINT: - case PIPE_FORMAT_R16G16B16A16_SINT: - case PIPE_FORMAT_R16G16B16A16_UNORM: - case PIPE_FORMAT_R16G16B16A16_SNORM: - return FMT_16_16_16_16; - case PIPE_FORMAT_R16G16B16A16_FLOAT: - return FMT_16_16_16_16_FLOAT; - case PIPE_FORMAT_R32G32_FLOAT: - case PIPE_FORMAT_L32A32_FLOAT: - return FMT_32_32_FLOAT; - case PIPE_FORMAT_R32G32_SINT: - case PIPE_FORMAT_R32G32_UINT: - case PIPE_FORMAT_L32A32_UINT: - case PIPE_FORMAT_L32A32_SINT: - return FMT_32_32; - - /* 96-bit buffers. */ - case PIPE_FORMAT_R32G32B32_FLOAT: - return FMT_32_32_32_FLOAT; - - /* 128-bit buffers. */ - case PIPE_FORMAT_R32G32B32A32_SNORM: - case PIPE_FORMAT_R32G32B32A32_UNORM: - case PIPE_FORMAT_R32G32B32A32_SINT: - case PIPE_FORMAT_R32G32B32A32_UINT: - return FMT_32_32_32_32; - case PIPE_FORMAT_R32G32B32A32_FLOAT: - return FMT_32_32_32_32_FLOAT; - - /* Compressed textures. */ - case PIPE_FORMAT_ETC1_RGB8: - return FMT_ETC1_RGB; - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - return FMT_DXT1; - case PIPE_FORMAT_DXT3_RGBA: - return FMT_DXT2_3; - case PIPE_FORMAT_DXT5_RGBA: - return FMT_DXT4_5; - case PIPE_FORMAT_ATC_RGB: - return FMT_ATI_TC_555_565_RGB; - case PIPE_FORMAT_ATC_RGBA_EXPLICIT: - return FMT_ATI_TC_555_565_RGBA; - case PIPE_FORMAT_ATC_RGBA_INTERPOLATED: - return FMT_ATI_TC_555_565_RGBA_INTERP; - - /* YUV buffers. */ - case PIPE_FORMAT_UYVY: - return FMT_Cr_Y1_Cb_Y0; - case PIPE_FORMAT_YUYV: - return FMT_Y1_Cr_Y0_Cb; + const struct util_format_description *desc = util_format_description(format); + + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + switch (format) { + /* Compressed textures. */ + case PIPE_FORMAT_ETC1_RGB8: + return FMT_ETC1_RGB; + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + return FMT_DXT1; + case PIPE_FORMAT_DXT3_RGBA: + return FMT_DXT2_3; + case PIPE_FORMAT_DXT5_RGBA: + return FMT_DXT4_5; + case PIPE_FORMAT_ATC_RGB: + return FMT_ATI_TC_555_565_RGB; + case PIPE_FORMAT_ATC_RGBA_EXPLICIT: + return FMT_ATI_TC_555_565_RGBA; + case PIPE_FORMAT_ATC_RGBA_INTERPOLATED: + return FMT_ATI_TC_555_565_RGBA_INTERP; + /* YUV buffers. */ + case PIPE_FORMAT_UYVY: + return FMT_Y1_Cr_Y0_Cb; + case PIPE_FORMAT_YUYV: + return FMT_Cr_Y1_Cb_Y0; + default: + return ~0; + } + } - default: - return ~0; + uint32_t channel_size = 0; + for (unsigned i = 0; i < 4; i++) + channel_size |= desc->channel[i].size << i*8; + + /* Note: the 3 channel 24bpp/48bpp/96bpp formats are only for vertex fetch + * we can use the 4 channel format and ignore the 4th component just isn't used + * XXX: is it possible for the extra loaded component to cause a MMU fault? + */ + +#define CASE(r, g, b, a) case (r | g << 8 | b << 16 | a << 24) + if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) { + switch (channel_size) { + CASE(16, 0, 0, 0): return FMT_16_FLOAT; + CASE(16, 16, 0, 0): return FMT_16_16_FLOAT; + CASE(16, 16, 16, 0): return FMT_16_16_16_16_FLOAT; /* Note: only for vertex */ + CASE(16, 16, 16, 16): return FMT_16_16_16_16_FLOAT; + CASE(32, 0, 0, 0): return FMT_32_FLOAT; + CASE(32, 32, 0, 0): return FMT_32_32_FLOAT; + CASE(32, 32, 32, 0): return FMT_32_32_32_FLOAT; + CASE(32, 32, 32, 32): return FMT_32_32_32_32_FLOAT; + } + } else if (desc->is_unorm || desc->is_snorm) { + switch (channel_size) { + CASE( 8, 0, 0, 0): return FMT_8; + CASE( 8, 8, 0, 0): return FMT_8_8; + CASE( 8, 8, 8, 0): return FMT_8_8_8_8; /* Note: only for vertex */ + CASE( 8, 8, 8, 8): return FMT_8_8_8_8; + CASE(16, 0, 0, 0): return FMT_16; + CASE(16, 16, 0, 0): return FMT_16_16; + CASE(16, 16, 16, 0): return FMT_16_16_16_16; /* Note: only for vertex */ + CASE(16, 16, 16, 16): return FMT_16_16_16_16; + CASE(32, 0, 0, 0): return FMT_32; + CASE(32, 32, 0, 0): return FMT_32_32; + CASE(32, 32, 32, 0): return FMT_32_32_32_32; /* Note: only for vertex */ + CASE(32, 32, 32, 32): return FMT_32_32_32_32; + CASE( 4, 4, 4, 4): return FMT_4_4_4_4; + CASE( 5, 5, 5, 1): return FMT_1_5_5_5; + CASE( 5, 6, 5, 0): return FMT_5_6_5; + CASE(10, 10, 10, 2): return FMT_2_10_10_10; + CASE( 8, 24, 0, 0): return FMT_24_8; + } } +#undef CASE + + return ~0; } enum a2xx_colorformatx @@ -214,23 +114,7 @@ fd2_pipe2color(enum pipe_format format) { switch (format) { /* 8-bit buffers. */ - case PIPE_FORMAT_A8_UNORM: - case PIPE_FORMAT_A8_SNORM: - case PIPE_FORMAT_A8_UINT: - case PIPE_FORMAT_A8_SINT: - case PIPE_FORMAT_I8_UNORM: - case PIPE_FORMAT_I8_SNORM: - case PIPE_FORMAT_I8_UINT: - case PIPE_FORMAT_I8_SINT: - case PIPE_FORMAT_L8_UNORM: - case PIPE_FORMAT_L8_SNORM: - case PIPE_FORMAT_L8_UINT: - case PIPE_FORMAT_L8_SINT: - case PIPE_FORMAT_L8_SRGB: case PIPE_FORMAT_R8_UNORM: - case PIPE_FORMAT_R8_SNORM: - case PIPE_FORMAT_R8_UINT: - case PIPE_FORMAT_R8_SINT: return COLORX_8; /* 16-bit buffers. */ @@ -242,60 +126,31 @@ fd2_pipe2color(enum pipe_format format) case PIPE_FORMAT_B4G4R4A4_UNORM: case PIPE_FORMAT_B4G4R4X4_UNORM: return COLORX_4_4_4_4; - case PIPE_FORMAT_L8A8_UNORM: - case PIPE_FORMAT_L8A8_SNORM: - case PIPE_FORMAT_L8A8_UINT: - case PIPE_FORMAT_L8A8_SINT: - case PIPE_FORMAT_L8A8_SRGB: case PIPE_FORMAT_R8G8_UNORM: - case PIPE_FORMAT_R8G8_SNORM: - case PIPE_FORMAT_R8G8_UINT: - case PIPE_FORMAT_R8G8_SINT: - case PIPE_FORMAT_Z16_UNORM: return COLORX_8_8; - case PIPE_FORMAT_R16_FLOAT: - case PIPE_FORMAT_A16_FLOAT: - case PIPE_FORMAT_L16_FLOAT: - case PIPE_FORMAT_I16_FLOAT: - return COLORX_16_FLOAT; /* 32-bit buffers. */ - case PIPE_FORMAT_A8B8G8R8_SRGB: - case PIPE_FORMAT_A8B8G8R8_UNORM: - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_B8G8R8A8_SRGB: case PIPE_FORMAT_B8G8R8A8_UNORM: case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_R8G8B8A8_SNORM: case PIPE_FORMAT_R8G8B8A8_UNORM: case PIPE_FORMAT_R8G8B8X8_UNORM: - case PIPE_FORMAT_R8SG8SB8UX8U_NORM: - case PIPE_FORMAT_X8B8G8R8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_R8G8B8_UNORM: - case PIPE_FORMAT_R8G8B8A8_SINT: - case PIPE_FORMAT_R8G8B8A8_UINT: - case PIPE_FORMAT_Z24_UNORM_S8_UINT: - case PIPE_FORMAT_Z24X8_UNORM: return COLORX_8_8_8_8; - case PIPE_FORMAT_R32_FLOAT: - case PIPE_FORMAT_A32_FLOAT: - case PIPE_FORMAT_L32_FLOAT: - case PIPE_FORMAT_I32_FLOAT: - case PIPE_FORMAT_Z32_FLOAT: - return COLORX_32_FLOAT; + /* Note: snorm untested */ + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_R8G8B8X8_SNORM: + return COLORX_S8_8_8_8; + + /* float buffers */ + case PIPE_FORMAT_R16_FLOAT: + return COLORX_16_FLOAT; case PIPE_FORMAT_R16G16_FLOAT: - case PIPE_FORMAT_L16A16_FLOAT: return COLORX_16_16_FLOAT; - - /* 64-bit buffers. */ case PIPE_FORMAT_R16G16B16A16_FLOAT: return COLORX_16_16_16_16_FLOAT; + case PIPE_FORMAT_R32_FLOAT: + return COLORX_32_FLOAT; case PIPE_FORMAT_R32G32_FLOAT: - case PIPE_FORMAT_L32A32_FLOAT: return COLORX_32_32_FLOAT; - - /* 128-bit buffers. */ case PIPE_FORMAT_R32G32B32A32_FLOAT: return COLORX_32_32_32_32_FLOAT;