*/
bool
-v3d_gl_format_is_return_32(GLenum format)
+v3d_gl_format_is_return_32(enum pipe_format format)
{
- switch (format) {
- case GL_R8:
- case GL_R8_SNORM:
- case GL_R8UI:
- case GL_R8I:
- case GL_RG8:
- case GL_RG8_SNORM:
- case GL_RG8UI:
- case GL_RG8I:
- case GL_RGBA8:
- case GL_RGBA8_SNORM:
- case GL_RGBA8UI:
- case GL_RGBA8I:
- case GL_R11F_G11F_B10F:
- case GL_RGB10_A2:
- case GL_RGB10_A2UI:
- case GL_R16F:
- case GL_R16UI:
- case GL_R16I:
- case GL_RG16F:
- case GL_RG16UI:
- case GL_RG16I:
- case GL_RGBA16F:
- case GL_RGBA16UI:
- case GL_RGBA16I:
- return false;
- case GL_R16:
- case GL_R16_SNORM:
- case GL_RG16:
- case GL_RG16_SNORM:
- case GL_RGBA16:
- case GL_RGBA16_SNORM:
- case GL_R32F:
- case GL_R32UI:
- case GL_R32I:
- case GL_RG32F:
- case GL_RG32UI:
- case GL_RG32I:
- case GL_RGBA32F:
- case GL_RGBA32UI:
- case GL_RGBA32I:
- return true;
- default:
- unreachable("Invalid image format");
- }
+ const struct util_format_description *desc =
+ util_format_description(format);
+ const struct util_format_channel_description *chan = &desc->channel[0];
+
+ return chan->size > 16 || (chan->size == 16 && chan->normalized);
}
/* Packs a 32-bit vector of colors in the range [0, (1 << bits[i]) - 1] to a
return nir_vec(b, results, DIV_ROUND_UP(offset, 32));
}
-static nir_ssa_def *
-pack_unorm(nir_builder *b, nir_ssa_def *color, const unsigned *bits,
- int num_components)
-{
- color = nir_channels(b, color, (1 << num_components) - 1);
- color = nir_format_float_to_unorm(b, color, bits);
- return pack_bits(b, color, bits, color->num_components, false);
-}
-
-static nir_ssa_def *
-pack_snorm(nir_builder *b, nir_ssa_def *color, const unsigned *bits,
- int num_components)
-{
- color = nir_channels(b, color, (1 << num_components) - 1);
- color = nir_format_float_to_snorm(b, color, bits);
- return pack_bits(b, color, bits, color->num_components, true);
-}
-
-static nir_ssa_def *
-pack_uint(nir_builder *b, nir_ssa_def *color, const unsigned *bits,
- int num_components)
-{
- color = nir_channels(b, color, (1 << num_components) - 1);
- color = nir_format_clamp_uint(b, color, bits);
- return pack_bits(b, color, bits, num_components, false);
-}
-
-static nir_ssa_def *
-pack_sint(nir_builder *b, nir_ssa_def *color, const unsigned *bits,
- int num_components)
-{
- color = nir_channels(b, color, (1 << num_components) - 1);
- color = nir_format_clamp_sint(b, color, bits);
- return pack_bits(b, color, bits, num_components, true);
-}
-
-static nir_ssa_def *
-pack_half(nir_builder *b, nir_ssa_def *color, const unsigned *bits,
- int num_components)
-{
- color = nir_channels(b, color, (1 << num_components) - 1);
- color = nir_format_float_to_half(b, color);
- return pack_bits(b, color, bits, color->num_components, false);
-}
-
static void
v3d_nir_lower_image_store(nir_builder *b, nir_intrinsic_instr *instr)
{
nir_variable *var = nir_intrinsic_get_var(instr, 0);
- GLenum format = var->data.image.format;
- static const unsigned bits_8[4] = {8, 8, 8, 8};
- static const unsigned bits_16[4] = {16, 16, 16, 16};
- static const unsigned bits_1010102[4] = {10, 10, 10, 2};
+ enum pipe_format format = var->data.image.format;
+ const struct util_format_description *desc =
+ util_format_description(format);
+ const struct util_format_channel_description *r_chan = &desc->channel[0];
+ unsigned num_components = util_format_get_nr_components(format);
b->cursor = nir_before_instr(&instr->instr);
- nir_ssa_def *unformatted = nir_ssa_for_src(b, instr->src[3], 4);
+ nir_ssa_def *color = nir_channels(b,
+ nir_ssa_for_src(b, instr->src[3], 4),
+ (1 << num_components) - 1);
nir_ssa_def *formatted = NULL;
- switch (format) {
- case GL_RGBA32F:
- case GL_RGBA32UI:
- case GL_RGBA32I:
- /* For 4-component 32-bit components, there's no packing to be
- * done.
- */
- return;
- case GL_R32F:
- case GL_R32UI:
- case GL_R32I:
- /* For other 32-bit components, just reduce the size of
- * the input vector.
+ if (format == PIPE_FORMAT_R11G11B10_FLOAT) {
+ formatted = nir_format_pack_11f11f10f(b, color);
+ } else if (format == PIPE_FORMAT_R9G9B9E5_FLOAT) {
+ formatted = nir_format_pack_r9g9b9e5(b, color);
+ } else if (r_chan->size == 32) {
+ /* For 32-bit formats, we just have to move the vector
+ * across (possibly reducing the number of channels).
*/
- formatted = nir_channels(b, unformatted, 1);
- break;
- case GL_RG32F:
- case GL_RG32UI:
- case GL_RG32I:
- formatted = nir_channels(b, unformatted, 2);
- break;
-
- case GL_R8:
- formatted = pack_unorm(b, unformatted, bits_8, 1);
- break;
- case GL_RG8:
- formatted = pack_unorm(b, unformatted, bits_8, 2);
- break;
- case GL_RGBA8:
- formatted = pack_unorm(b, unformatted, bits_8, 4);
- break;
-
- case GL_R8_SNORM:
- formatted = pack_snorm(b, unformatted, bits_8, 1);
- break;
- case GL_RG8_SNORM:
- formatted = pack_snorm(b, unformatted, bits_8, 2);
- break;
- case GL_RGBA8_SNORM:
- formatted = pack_snorm(b, unformatted, bits_8, 4);
- break;
-
- case GL_R16:
- formatted = pack_unorm(b, unformatted, bits_16, 1);
- break;
- case GL_RG16:
- formatted = pack_unorm(b, unformatted, bits_16, 2);
- break;
- case GL_RGBA16:
- formatted = pack_unorm(b, unformatted, bits_16, 4);
- break;
-
- case GL_R16_SNORM:
- formatted = pack_snorm(b, unformatted, bits_16, 1);
- break;
- case GL_RG16_SNORM:
- formatted = pack_snorm(b, unformatted, bits_16, 2);
- break;
- case GL_RGBA16_SNORM:
- formatted = pack_snorm(b, unformatted, bits_16, 4);
- break;
-
- case GL_R16F:
- formatted = pack_half(b, unformatted, bits_16, 1);
- break;
- case GL_RG16F:
- formatted = pack_half(b, unformatted, bits_16, 2);
- break;
- case GL_RGBA16F:
- formatted = pack_half(b, unformatted, bits_16, 4);
- break;
-
- case GL_R8UI:
- formatted = pack_uint(b, unformatted, bits_8, 1);
- break;
- case GL_R8I:
- formatted = pack_sint(b, unformatted, bits_8, 1);
- break;
- case GL_RG8UI:
- formatted = pack_uint(b, unformatted, bits_8, 2);
- break;
- case GL_RG8I:
- formatted = pack_sint(b, unformatted, bits_8, 2);
- break;
- case GL_RGBA8UI:
- formatted = pack_uint(b, unformatted, bits_8, 4);
- break;
- case GL_RGBA8I:
- formatted = pack_sint(b, unformatted, bits_8, 4);
- break;
-
- case GL_R16UI:
- formatted = pack_uint(b, unformatted, bits_16, 1);
- break;
- case GL_R16I:
- formatted = pack_sint(b, unformatted, bits_16, 1);
- break;
- case GL_RG16UI:
- formatted = pack_uint(b, unformatted, bits_16, 2);
- break;
- case GL_RG16I:
- formatted = pack_sint(b, unformatted, bits_16, 2);
- break;
- case GL_RGBA16UI:
- formatted = pack_uint(b, unformatted, bits_16, 4);
- break;
- case GL_RGBA16I:
- formatted = pack_sint(b, unformatted, bits_16, 4);
- break;
-
- case GL_R11F_G11F_B10F:
- formatted = nir_format_pack_11f11f10f(b, unformatted);
- break;
- case GL_RGB9_E5:
- formatted = nir_format_pack_r9g9b9e5(b, unformatted);
- break;
-
- case GL_RGB10_A2:
- formatted = pack_unorm(b, unformatted, bits_1010102, 4);
- break;
+ formatted = color;
+ } else {
+ static const unsigned bits_8[4] = {8, 8, 8, 8};
+ static const unsigned bits_16[4] = {16, 16, 16, 16};
+ static const unsigned bits_1010102[4] = {10, 10, 10, 2};
+ const unsigned *bits;
+
+ switch (r_chan->size) {
+ case 8:
+ bits = bits_8;
+ break;
+ case 10:
+ bits = bits_1010102;
+ break;
+ case 16:
+ bits = bits_16;
+ break;
+ default:
+ unreachable("unrecognized bits");
+ }
- case GL_RGB10_A2UI:
- formatted = pack_uint(b, unformatted, bits_1010102, 4);
- break;
+ bool pack_mask = false;
+ if (r_chan->pure_integer &&
+ r_chan->type == UTIL_FORMAT_TYPE_SIGNED) {
+ formatted = nir_format_clamp_sint(b, color, bits);
+ pack_mask = true;
+ } else if (r_chan->pure_integer &&
+ r_chan->type == UTIL_FORMAT_TYPE_UNSIGNED) {
+ formatted = nir_format_clamp_uint(b, color, bits);
+ } else if (r_chan->normalized &&
+ r_chan->type == UTIL_FORMAT_TYPE_SIGNED) {
+ formatted = nir_format_float_to_snorm(b, color, bits);
+ pack_mask = true;
+ } else if (r_chan->normalized &&
+ r_chan->type == UTIL_FORMAT_TYPE_UNSIGNED) {
+ formatted = nir_format_float_to_unorm(b, color, bits);
+ } else {
+ assert(r_chan->size == 16);
+ assert(r_chan->type == UTIL_FORMAT_TYPE_FLOAT);
+ formatted = nir_format_float_to_half(b, color);
+ }
- default:
- unreachable("bad format");
+ formatted = pack_bits(b, formatted, bits, num_components,
+ pack_mask);
}
nir_instr_rewrite_src(&instr->instr, &instr->src[3],
* \note
* This field is only valid if \c explicit_image_format is set.
*/
- GLenum image_format;
+ enum pipe_format image_format;
/**
* Arrangement of invocations used to calculate derivatives in a compute
"`writeonly' must have a format layout qualifier");
}
}
- var->data.image_format = GL_NONE;
+ var->data.image_format = PIPE_FORMAT_NONE;
}
/* From page 70 of the GLSL ES 3.1 specification:
* readonly or the memory qualifier writeonly."
*/
if (state->es_shader &&
- var->data.image_format != GL_R32F &&
- var->data.image_format != GL_R32I &&
- var->data.image_format != GL_R32UI &&
+ var->data.image_format != PIPE_FORMAT_R32_FLOAT &&
+ var->data.image_format != PIPE_FORMAT_R32_SINT &&
+ var->data.image_format != PIPE_FORMAT_R32_UINT &&
!var->data.memory_read_only &&
!var->data.memory_write_only) {
_mesa_glsl_error(loc, state, "image variables of format other than r32f, "
* size4x32 rgba32f rgba32i rgba32ui"
*/
if (strncmp(this->type->specifier->type_name, "image", strlen("image")) == 0) {
- this->type->qualifier.image_format = GL_R8 +
- this->type->qualifier.image_format - GL_R8I;
+ switch (this->type->qualifier.image_format) {
+ case PIPE_FORMAT_R8_SINT:
+ /* No valid qualifier in this case, driver will need to look at
+ * the underlying image's format (just like no qualifier being
+ * present).
+ */
+ this->type->qualifier.image_format = PIPE_FORMAT_NONE;
+ break;
+ case PIPE_FORMAT_R16_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R16_FLOAT;
+ break;
+ case PIPE_FORMAT_R32_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R32_FLOAT;
+ break;
+ case PIPE_FORMAT_R32G32_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R32G32_FLOAT;
+ break;
+ case PIPE_FORMAT_R32G32B32A32_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+ break;
+ default:
+ unreachable("Unknown image format");
+ }
this->type->qualifier.image_base_type = GLSL_TYPE_FLOAT;
} else if (strncmp(this->type->specifier->type_name, "uimage", strlen("uimage")) == 0) {
- this->type->qualifier.image_format = GL_R8UI +
- this->type->qualifier.image_format - GL_R8I;
+ switch (this->type->qualifier.image_format) {
+ case PIPE_FORMAT_R8_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R8_UINT;
+ break;
+ case PIPE_FORMAT_R16_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R16_UINT;
+ break;
+ case PIPE_FORMAT_R32_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R32_UINT;
+ break;
+ case PIPE_FORMAT_R32G32_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R32G32_UINT;
+ break;
+ case PIPE_FORMAT_R32G32B32A32_SINT:
+ this->type->qualifier.image_format = PIPE_FORMAT_R32G32B32A32_UINT;
+ break;
+ default:
+ unreachable("Unknown image format");
+ }
this->type->qualifier.image_base_type = GLSL_TYPE_UINT;
} else if (strncmp(this->type->specifier->type_name, "iimage", strlen("iimage")) == 0) {
this->type->qualifier.image_base_type = GLSL_TYPE_INT;
"qualifier");
}
- fields[i].image_format = GL_NONE;
+ fields[i].image_format = PIPE_FORMAT_NONE;
}
}
}
this->fields[this->num_fields].memory_coherent = 0;
this->fields[this->num_fields].memory_volatile = 0;
this->fields[this->num_fields].memory_restrict = 0;
- this->fields[this->num_fields].image_format = 0;
+ this->fields[this->num_fields].image_format = PIPE_FORMAT_NONE;
this->fields[this->num_fields].explicit_xfb_buffer = 0;
this->fields[this->num_fields].xfb_buffer = -1;
this->fields[this->num_fields].xfb_stride = -1;
#include "compiler/glsl_types.h"
#include "main/context.h"
#include "util/u_string.h"
+#include "util/format/u_format.h"
#ifdef _MSC_VER
#pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
if (!$$.flags.i) {
static const struct {
const char *name;
- GLenum format;
+ enum pipe_format format;
glsl_base_type base_type;
/** Minimum desktop GLSL version required for the image
* format. Use 130 if already present in the original
bool nv_image_formats;
bool ext_qualifiers;
} map[] = {
- { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false, false },
- { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false, false },
- { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false, false },
- { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false, false },
- { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false, false },
- { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true, false },
- { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false, false },
- { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true, false },
- { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true, false },
- { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true, false },
- { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false, false },
- { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true, false },
- { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true, false },
- { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false, false },
- { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false, false },
- { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false, false },
- { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true, false },
- { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true, false },
- { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true, false },
- { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false, false },
- { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true, false },
- { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true, false },
- { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false, false },
- { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false, false },
- { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
- { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rgba32f", PIPE_FORMAT_R32G32B32A32_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false },
+ { "rgba16f", PIPE_FORMAT_R16G16B16A16_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false },
+ { "rg32f", PIPE_FORMAT_R32G32_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rg16f", PIPE_FORMAT_R16G16_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "r11f_g11f_b10f", PIPE_FORMAT_R11G11B10_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "r32f", PIPE_FORMAT_R32_FLOAT, GLSL_TYPE_FLOAT, 130, 310, false, false },
+ { "r16f", PIPE_FORMAT_R16_FLOAT, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rgba32ui", PIPE_FORMAT_R32G32B32A32_UINT, GLSL_TYPE_UINT, 130, 310, false, false },
+ { "rgba16ui", PIPE_FORMAT_R16G16B16A16_UINT, GLSL_TYPE_UINT, 130, 310, false, false },
+ { "rgb10_a2ui", PIPE_FORMAT_R10G10B10A2_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
+ { "rgba8ui", PIPE_FORMAT_R8G8B8A8_UINT, GLSL_TYPE_UINT, 130, 310, false, false },
+ { "rg32ui", PIPE_FORMAT_R32G32_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
+ { "rg16ui", PIPE_FORMAT_R16G16_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
+ { "rg8ui", PIPE_FORMAT_R8G8_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
+ { "r32ui", PIPE_FORMAT_R32_UINT, GLSL_TYPE_UINT, 130, 310, false, false },
+ { "r16ui", PIPE_FORMAT_R16_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
+ { "r8ui", PIPE_FORMAT_R8_UINT, GLSL_TYPE_UINT, 130, 0, true, false },
+ { "rgba32i", PIPE_FORMAT_R32G32B32A32_SINT, GLSL_TYPE_INT, 130, 310, false, false },
+ { "rgba16i", PIPE_FORMAT_R16G16B16A16_SINT, GLSL_TYPE_INT, 130, 310, false, false },
+ { "rgba8i", PIPE_FORMAT_R8G8B8A8_SINT, GLSL_TYPE_INT, 130, 310, false, false },
+ { "rg32i", PIPE_FORMAT_R32G32_SINT, GLSL_TYPE_INT, 130, 0, true, false },
+ { "rg16i", PIPE_FORMAT_R16G16_SINT, GLSL_TYPE_INT, 130, 0, true, false },
+ { "rg8i", PIPE_FORMAT_R8G8_SINT, GLSL_TYPE_INT, 130, 0, true, false },
+ { "r32i", PIPE_FORMAT_R32_SINT, GLSL_TYPE_INT, 130, 310, false, false },
+ { "r16i", PIPE_FORMAT_R16_SINT, GLSL_TYPE_INT, 130, 0, true, false },
+ { "r8i", PIPE_FORMAT_R8_SINT, GLSL_TYPE_INT, 130, 0, true, false },
+ { "rgba16", PIPE_FORMAT_R16G16B16A16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rgb10_a2", PIPE_FORMAT_R10G10B10A2_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rgba8", PIPE_FORMAT_R8G8B8A8_UNORM, GLSL_TYPE_FLOAT, 130, 310, false, false },
+ { "rg16", PIPE_FORMAT_R16G16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rg8", PIPE_FORMAT_R8G8_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "r16", PIPE_FORMAT_R16_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "r8", PIPE_FORMAT_R8_UNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rgba16_snorm", PIPE_FORMAT_R16G16B16A16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rgba8_snorm", PIPE_FORMAT_R8G8B8A8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false, false },
+ { "rg16_snorm", PIPE_FORMAT_R16G16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "rg8_snorm", PIPE_FORMAT_R8G8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "r16_snorm", PIPE_FORMAT_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
+ { "r8_snorm", PIPE_FORMAT_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true, false },
/* From GL_EXT_shader_image_load_store: */
/* base_type is incorrect but it'll be patched later when we know
* the variable type. See ast_to_hir.cpp */
- { "size1x8", GL_R8I, GLSL_TYPE_VOID, 130, 0, false, true },
- { "size1x16", GL_R16I, GLSL_TYPE_VOID, 130, 0, false, true },
- { "size1x32", GL_R32I, GLSL_TYPE_VOID, 130, 0, false, true },
- { "size2x32", GL_RG32I, GLSL_TYPE_VOID, 130, 0, false, true },
- { "size4x32", GL_RGBA32I, GLSL_TYPE_VOID, 130, 0, false, true },
+ { "size1x8", PIPE_FORMAT_R8_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
+ { "size1x16", PIPE_FORMAT_R16_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
+ { "size1x32", PIPE_FORMAT_R32_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
+ { "size2x32", PIPE_FORMAT_R32G32_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
+ { "size4x32", PIPE_FORMAT_R32G32B32A32_SINT, GLSL_TYPE_VOID, 130, 0, false, true },
};
for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
this->data.fb_fetch_output = false;
this->data.bindless = false;
this->data.bound = false;
- this->data.image_format = GL_NONE;
+ this->data.image_format = PIPE_FORMAT_NONE;
this->data._num_state_slots = 0;
this->data.param_index = 0;
this->data.stream = 0;
#include <stdlib.h>
#include "util/ralloc.h"
+#include "util/format/u_format.h"
#include "compiler/glsl_types.h"
#include "list.h"
#include "ir_visitor.h"
uint8_t warn_extension_index;
public:
- /** Image internal format if specified explicitly, otherwise GL_NONE. */
- uint16_t image_format;
+ /**
+ * Image internal format if specified explicitly, otherwise
+ * PIPE_FORMAT_NONE.
+ */
+ enum pipe_format image_format;
private:
/**
#include "shader_enums.h"
#include "c11/threads.h"
#include "util/blob.h"
+#include "util/format/u_format.h"
#include "util/macros.h"
#ifdef __cplusplus
/**
* Layout format, applicable to image variables only.
*/
- unsigned image_format:16;
+ enum pipe_format image_format;
/**
* Any of the xfb_* qualifiers trigger the shader to be in transform
sample(0), matrix_layout(GLSL_MATRIX_LAYOUT_INHERITED), patch(0), \
precision(_precision), memory_read_only(0), \
memory_write_only(0), memory_coherent(0), memory_volatile(0), \
- memory_restrict(0), image_format(0), explicit_xfb_buffer(0), \
+ memory_restrict(0), image_format(PIPE_FORMAT_NONE), \
+ explicit_xfb_buffer(0), \
implicit_sized_array(0)
glsl_struct_field(const struct glsl_type *_type,
#include "util/bitscan.h"
#include "util/bitset.h"
#include "util/macros.h"
+#include "util/format/u_format.h"
#include "compiler/nir_types.h"
#include "compiler/shader_enums.h"
#include "compiler/shader_info.h"
union {
struct {
- /** Image internal format if specified explicitly, otherwise GL_NONE. */
- uint16_t format; /* GLenum */
+ /** Image internal format if specified explicitly, otherwise PIPE_FORMAT_NONE. */
+ enum pipe_format format;
} image;
struct {
INTRINSIC_IDX_ACCESSORS(access, ACCESS, enum gl_access_qualifier)
INTRINSIC_IDX_ACCESSORS(src_access, SRC_ACCESS, enum gl_access_qualifier)
INTRINSIC_IDX_ACCESSORS(dst_access, DST_ACCESS, enum gl_access_qualifier)
-INTRINSIC_IDX_ACCESSORS(format, FORMAT, unsigned)
+INTRINSIC_IDX_ACCESSORS(format, FORMAT, enum pipe_format)
INTRINSIC_IDX_ACCESSORS(align_mul, ALIGN_MUL, unsigned)
INTRINSIC_IDX_ACCESSORS(align_offset, ALIGN_OFFSET, unsigned)
INTRINSIC_IDX_ACCESSORS(desc_type, DESC_TYPE, unsigned)
fprintf(fp, "%s%s%s%s%s%s", coher, volat, restr, ronly, wonly, reorder);
if (glsl_get_base_type(glsl_without_array(var->type)) == GLSL_TYPE_IMAGE) {
-#define FORMAT_CASE(x) case x: fprintf(fp, #x " "); break
- switch (var->data.image.format) {
- FORMAT_CASE(GL_RGBA32F);
- FORMAT_CASE(GL_RGBA32UI);
- FORMAT_CASE(GL_RGBA32I);
- FORMAT_CASE(GL_R32F);
- FORMAT_CASE(GL_R32UI);
- FORMAT_CASE(GL_R32I);
- FORMAT_CASE(GL_RG32F);
- FORMAT_CASE(GL_RG32UI);
- FORMAT_CASE(GL_RG32I);
- FORMAT_CASE(GL_R8);
- FORMAT_CASE(GL_RG8);
- FORMAT_CASE(GL_RGBA8);
- FORMAT_CASE(GL_R8_SNORM);
- FORMAT_CASE(GL_RG8_SNORM);
- FORMAT_CASE(GL_RGBA8_SNORM);
- FORMAT_CASE(GL_R16);
- FORMAT_CASE(GL_RG16);
- FORMAT_CASE(GL_RGBA16);
- FORMAT_CASE(GL_R16_SNORM);
- FORMAT_CASE(GL_RG16_SNORM);
- FORMAT_CASE(GL_RGBA16_SNORM);
- FORMAT_CASE(GL_R16F);
- FORMAT_CASE(GL_RG16F);
- FORMAT_CASE(GL_RGBA16F);
- FORMAT_CASE(GL_R8UI);
- FORMAT_CASE(GL_R8I);
- FORMAT_CASE(GL_RG8UI);
- FORMAT_CASE(GL_RG8I);
- FORMAT_CASE(GL_RGBA8UI);
- FORMAT_CASE(GL_RGBA8I);
- FORMAT_CASE(GL_R16UI);
- FORMAT_CASE(GL_R16I);
- FORMAT_CASE(GL_RG16UI);
- FORMAT_CASE(GL_RG16I);
- FORMAT_CASE(GL_RGBA16UI);
- FORMAT_CASE(GL_RGBA16I);
- FORMAT_CASE(GL_R11F_G11F_B10F);
- FORMAT_CASE(GL_RGB9_E5);
- FORMAT_CASE(GL_RGB10_A2);
- FORMAT_CASE(GL_RGB10_A2UI);
- default: /* Including the normal GL_NONE */
- break;
- }
-#undef FORMAT_CASE
+ fprintf(fp, "%s ", util_format_short_name(var->data.image.format));
}
fprintf(fp, "%s %s", glsl_get_type_name(var->type),
#include "nir/nir_deref.h"
#include "spirv_info.h"
+#include "util/format/u_format.h"
#include "util/u_math.h"
#include <stdio.h>
translate_image_format(struct vtn_builder *b, SpvImageFormat format)
{
switch (format) {
- case SpvImageFormatUnknown: return 0; /* GL_NONE */
- case SpvImageFormatRgba32f: return 0x8814; /* GL_RGBA32F */
- case SpvImageFormatRgba16f: return 0x881A; /* GL_RGBA16F */
- case SpvImageFormatR32f: return 0x822E; /* GL_R32F */
- case SpvImageFormatRgba8: return 0x8058; /* GL_RGBA8 */
- case SpvImageFormatRgba8Snorm: return 0x8F97; /* GL_RGBA8_SNORM */
- case SpvImageFormatRg32f: return 0x8230; /* GL_RG32F */
- case SpvImageFormatRg16f: return 0x822F; /* GL_RG16F */
- case SpvImageFormatR11fG11fB10f: return 0x8C3A; /* GL_R11F_G11F_B10F */
- case SpvImageFormatR16f: return 0x822D; /* GL_R16F */
- case SpvImageFormatRgba16: return 0x805B; /* GL_RGBA16 */
- case SpvImageFormatRgb10A2: return 0x8059; /* GL_RGB10_A2 */
- case SpvImageFormatRg16: return 0x822C; /* GL_RG16 */
- case SpvImageFormatRg8: return 0x822B; /* GL_RG8 */
- case SpvImageFormatR16: return 0x822A; /* GL_R16 */
- case SpvImageFormatR8: return 0x8229; /* GL_R8 */
- case SpvImageFormatRgba16Snorm: return 0x8F9B; /* GL_RGBA16_SNORM */
- case SpvImageFormatRg16Snorm: return 0x8F99; /* GL_RG16_SNORM */
- case SpvImageFormatRg8Snorm: return 0x8F95; /* GL_RG8_SNORM */
- case SpvImageFormatR16Snorm: return 0x8F98; /* GL_R16_SNORM */
- case SpvImageFormatR8Snorm: return 0x8F94; /* GL_R8_SNORM */
- case SpvImageFormatRgba32i: return 0x8D82; /* GL_RGBA32I */
- case SpvImageFormatRgba16i: return 0x8D88; /* GL_RGBA16I */
- case SpvImageFormatRgba8i: return 0x8D8E; /* GL_RGBA8I */
- case SpvImageFormatR32i: return 0x8235; /* GL_R32I */
- case SpvImageFormatRg32i: return 0x823B; /* GL_RG32I */
- case SpvImageFormatRg16i: return 0x8239; /* GL_RG16I */
- case SpvImageFormatRg8i: return 0x8237; /* GL_RG8I */
- case SpvImageFormatR16i: return 0x8233; /* GL_R16I */
- case SpvImageFormatR8i: return 0x8231; /* GL_R8I */
- case SpvImageFormatRgba32ui: return 0x8D70; /* GL_RGBA32UI */
- case SpvImageFormatRgba16ui: return 0x8D76; /* GL_RGBA16UI */
- case SpvImageFormatRgba8ui: return 0x8D7C; /* GL_RGBA8UI */
- case SpvImageFormatR32ui: return 0x8236; /* GL_R32UI */
- case SpvImageFormatRgb10a2ui: return 0x906F; /* GL_RGB10_A2UI */
- case SpvImageFormatRg32ui: return 0x823C; /* GL_RG32UI */
- case SpvImageFormatRg16ui: return 0x823A; /* GL_RG16UI */
- case SpvImageFormatRg8ui: return 0x8238; /* GL_RG8UI */
- case SpvImageFormatR16ui: return 0x8234; /* GL_R16UI */
- case SpvImageFormatR8ui: return 0x8232; /* GL_R8UI */
+ case SpvImageFormatUnknown: return PIPE_FORMAT_NONE;
+ case SpvImageFormatRgba32f: return PIPE_FORMAT_R32G32B32A32_FLOAT;
+ case SpvImageFormatRgba16f: return PIPE_FORMAT_R16G16B16A16_FLOAT;
+ case SpvImageFormatR32f: return PIPE_FORMAT_R32_FLOAT;
+ case SpvImageFormatRgba8: return PIPE_FORMAT_R8G8B8A8_UNORM;
+ case SpvImageFormatRgba8Snorm: return PIPE_FORMAT_R8G8B8A8_SNORM;
+ case SpvImageFormatRg32f: return PIPE_FORMAT_R32G32_FLOAT;
+ case SpvImageFormatRg16f: return PIPE_FORMAT_R16G16_FLOAT;
+ case SpvImageFormatR11fG11fB10f: return PIPE_FORMAT_R11G11B10_FLOAT;
+ case SpvImageFormatR16f: return PIPE_FORMAT_R16_FLOAT;
+ case SpvImageFormatRgba16: return PIPE_FORMAT_R16G16B16A16_UNORM;
+ case SpvImageFormatRgb10A2: return PIPE_FORMAT_R10G10B10A2_UNORM;
+ case SpvImageFormatRg16: return PIPE_FORMAT_R16G16_UNORM;
+ case SpvImageFormatRg8: return PIPE_FORMAT_R8G8_UNORM;
+ case SpvImageFormatR16: return PIPE_FORMAT_R16_UNORM;
+ case SpvImageFormatR8: return PIPE_FORMAT_R8_UNORM;
+ case SpvImageFormatRgba16Snorm: return PIPE_FORMAT_R16G16B16A16_SNORM;
+ case SpvImageFormatRg16Snorm: return PIPE_FORMAT_R16G16_SNORM;
+ case SpvImageFormatRg8Snorm: return PIPE_FORMAT_R8G8_SNORM;
+ case SpvImageFormatR16Snorm: return PIPE_FORMAT_R16_SNORM;
+ case SpvImageFormatR8Snorm: return PIPE_FORMAT_R8_SNORM;
+ case SpvImageFormatRgba32i: return PIPE_FORMAT_R32G32B32A32_SINT;
+ case SpvImageFormatRgba16i: return PIPE_FORMAT_R16G16B16A16_SINT;
+ case SpvImageFormatRgba8i: return PIPE_FORMAT_R8G8B8A8_SINT;
+ case SpvImageFormatR32i: return PIPE_FORMAT_R32_SINT;
+ case SpvImageFormatRg32i: return PIPE_FORMAT_R32G32_SINT;
+ case SpvImageFormatRg16i: return PIPE_FORMAT_R16G16_SINT;
+ case SpvImageFormatRg8i: return PIPE_FORMAT_R8G8_SINT;
+ case SpvImageFormatR16i: return PIPE_FORMAT_R16_SINT;
+ case SpvImageFormatR8i: return PIPE_FORMAT_R8_SINT;
+ case SpvImageFormatRgba32ui: return PIPE_FORMAT_R32G32B32A32_UINT;
+ case SpvImageFormatRgba16ui: return PIPE_FORMAT_R16G16B16A16_UINT;
+ case SpvImageFormatRgba8ui: return PIPE_FORMAT_R8G8B8A8_UINT;
+ case SpvImageFormatR32ui: return PIPE_FORMAT_R32_UINT;
+ case SpvImageFormatRgb10a2ui: return PIPE_FORMAT_R10G10B10A2_UINT;
+ case SpvImageFormatRg32ui: return PIPE_FORMAT_R32G32_UINT;
+ case SpvImageFormatRg16ui: return PIPE_FORMAT_R16G16_UINT;
+ case SpvImageFormatRg8ui: return PIPE_FORMAT_R8G8_UINT;
+ case SpvImageFormatR16ui: return PIPE_FORMAT_R16_UINT;
+ case SpvImageFormatR8ui: return PIPE_FORMAT_R8_UINT;
default:
vtn_fail("Invalid image format: %s (%u)",
spirv_imageformat_to_string(format), format);
unsigned ncoords = ir3_get_image_coords(var, NULL);
unsigned slot = ir3_get_image_slot(nir_src_as_deref(intr->src[0]));
unsigned ibo_idx = ir3_image_to_ibo(ctx->so->shader, slot);
- unsigned ncomp = ir3_get_num_components_for_glformat(var->data.image.format);
+ unsigned ncomp = ir3_get_num_components_for_image_format(var->data.image.format);
/* src0 is value
* src1 is coords
unsigned ncoords = ir3_get_image_coords(var, NULL);
unsigned slot = ir3_get_image_slot(nir_src_as_deref(intr->src[0]));
unsigned ibo_idx = ir3_image_to_ibo(ctx->so->shader, slot);
- unsigned ncomp = ir3_get_num_components_for_glformat(var->data.image.format);
+ unsigned ncomp = ir3_get_num_components_for_image_format(var->data.image.format);
/* src0 is offset, src1 is value:
*/
* GL_NV_image_formats extension.
*/
unsigned
-ir3_get_num_components_for_glformat(GLuint format)
+ir3_get_num_components_for_image_format(GLuint format)
{
- switch (format) {
- case GL_R32F:
- case GL_R32I:
- case GL_R32UI:
- case GL_R16F:
- case GL_R16I:
- case GL_R16UI:
- case GL_R16:
- case GL_R16_SNORM:
- case GL_R8I:
- case GL_R8UI:
- case GL_R8:
- case GL_R8_SNORM:
- return 1;
-
- case GL_RG32F:
- case GL_RG32I:
- case GL_RG32UI:
- case GL_RG16F:
- case GL_RG16I:
- case GL_RG16UI:
- case GL_RG16:
- case GL_RG16_SNORM:
- case GL_RG8I:
- case GL_RG8UI:
- case GL_RG8:
- case GL_RG8_SNORM:
- return 2;
-
- case GL_R11F_G11F_B10F:
- return 3;
-
- case GL_RGBA32F:
- case GL_RGBA32I:
- case GL_RGBA32UI:
- case GL_RGBA16F:
- case GL_RGBA16I:
- case GL_RGBA16UI:
- case GL_RGBA16:
- case GL_RGBA16_SNORM:
- case GL_RGBA8I:
- case GL_RGBA8UI:
- case GL_RGBA8:
- case GL_RGBA8_SNORM:
- case GL_RGB10_A2UI:
- case GL_RGB10_A2:
+ if (format == PIPE_FORMAT_NONE)
return 4;
-
- case GL_NONE:
- /* Omitting the image format qualifier is allowed on desktop GL
- * profiles. Assuming 4 components is always safe.
- */
- return 4;
-
- default:
- /* Return 4 components also for all other formats we don't know
- * about. The format should have been validated already by
- * the higher level API, but drop a debug message just in case.
- */
- debug_printf("Unhandled GL format %u while emitting imageStore()\n",
- format);
- return 4;
- }
+ else
+ return util_format_get_nr_components(format);
}
unsigned ir3_get_image_slot(nir_deref_instr *deref);
unsigned ir3_get_image_coords(const nir_variable *var, unsigned *flagsp);
type_t ir3_get_image_type(const nir_variable *var);
-unsigned ir3_get_num_components_for_glformat(GLuint format);
+unsigned ir3_get_num_components_for_image_format(GLuint format);
#endif /* IR3_IMAGE_H_ */
bool is_array,
enum glsl_base_type base_type,
enum gl_access_qualifier access,
- GLenum format)
+ enum pipe_format format)
{
nir_variable *var = c->images[binding];
return access;
}
-static GLenum
-get_image_format(struct tgsi_full_instruction *tgsi_inst)
-{
- switch (tgsi_inst->Memory.Format) {
- case PIPE_FORMAT_NONE:
- return GL_NONE;
-
- case PIPE_FORMAT_R8_UNORM:
- return GL_R8;
- case PIPE_FORMAT_R8G8_UNORM:
- return GL_RG8;
- case PIPE_FORMAT_R8G8B8A8_UNORM:
- return GL_RGBA8;
- case PIPE_FORMAT_R16_UNORM:
- return GL_R16;
- case PIPE_FORMAT_R16G16_UNORM:
- return GL_RG16;
- case PIPE_FORMAT_R16G16B16A16_UNORM:
- return GL_RGBA16;
-
- case PIPE_FORMAT_R8_SNORM:
- return GL_R8_SNORM;
- case PIPE_FORMAT_R8G8_SNORM:
- return GL_RG8_SNORM;
- case PIPE_FORMAT_R8G8B8A8_SNORM:
- return GL_RGBA8_SNORM;
- case PIPE_FORMAT_R16_SNORM:
- return GL_R16_SNORM;
- case PIPE_FORMAT_R16G16_SNORM:
- return GL_RG16_SNORM;
- case PIPE_FORMAT_R16G16B16A16_SNORM:
- return GL_RGBA16_SNORM;
-
- case PIPE_FORMAT_R8_UINT:
- return GL_R8UI;
- case PIPE_FORMAT_R8G8_UINT:
- return GL_RG8UI;
- case PIPE_FORMAT_R8G8B8A8_UINT:
- return GL_RGBA8UI;
- case PIPE_FORMAT_R16_UINT:
- return GL_R16UI;
- case PIPE_FORMAT_R16G16_UINT:
- return GL_RG16UI;
- case PIPE_FORMAT_R16G16B16A16_UINT:
- return GL_RGBA16UI;
- case PIPE_FORMAT_R32_UINT:
- return GL_R32UI;
- case PIPE_FORMAT_R32G32_UINT:
- return GL_RG32UI;
- case PIPE_FORMAT_R32G32B32A32_UINT:
- return GL_RGBA32UI;
-
- case PIPE_FORMAT_R8_SINT:
- return GL_R8I;
- case PIPE_FORMAT_R8G8_SINT:
- return GL_RG8I;
- case PIPE_FORMAT_R8G8B8A8_SINT:
- return GL_RGBA8I;
- case PIPE_FORMAT_R16_SINT:
- return GL_R16I;
- case PIPE_FORMAT_R16G16_SINT:
- return GL_RG16I;
- case PIPE_FORMAT_R16G16B16A16_SINT:
- return GL_RGBA16I;
- case PIPE_FORMAT_R32_SINT:
- return GL_R32I;
- case PIPE_FORMAT_R32G32_SINT:
- return GL_RG32I;
- case PIPE_FORMAT_R32G32B32A32_SINT:
- return GL_RGBA32I;
-
- case PIPE_FORMAT_R16_FLOAT:
- return GL_R16F;
- case PIPE_FORMAT_R16G16_FLOAT:
- return GL_RG16F;
- case PIPE_FORMAT_R16G16B16A16_FLOAT:
- return GL_RGBA16F;
- case PIPE_FORMAT_R32_FLOAT:
- return GL_R32F;
- case PIPE_FORMAT_R32G32_FLOAT:
- return GL_RG32F;
- case PIPE_FORMAT_R32G32B32A32_FLOAT:
- return GL_RGBA32F;
-
- case PIPE_FORMAT_R11G11B10_FLOAT:
- return GL_R11F_G11F_B10F;
- case PIPE_FORMAT_R10G10B10A2_UINT:
- return GL_RGB10_A2UI;
- case PIPE_FORMAT_R10G10B10A2_UNORM:
- return GL_RGB10_A2;
-
- default:
- unreachable("unhandled image format");
- }
-}
-
static void
ttn_mem(struct ttn_compile *c, nir_alu_dest dest, nir_ssa_def **src)
{
enum glsl_base_type base_type = get_image_base_type(tgsi_inst);
enum gl_access_qualifier access = get_mem_qualifier(tgsi_inst);
- GLenum format = get_image_format(tgsi_inst);
nir_variable *image =
get_image_var(c, resource_index,
- dim, is_array, base_type, access, format);
+ dim, is_array, base_type, access,
+ tgsi_inst->Memory.Format);
nir_deref_instr *image_deref = nir_build_deref_var(b, image);
const struct glsl_type *type = image_deref->type;
{ "BGRA8", 4, { 8, 8, 8, 8 }, UNORM, true },
};
+const struct TexInstruction::ImgFormatDesc *
+TexInstruction::translateImgFormat(enum pipe_format format)
+{
+
+#define FMT_CASE(a, b) \
+ case PIPE_FORMAT_ ## a: return &formatTable[nv50_ir::FMT_ ## b]
+
+ switch (format) {
+ FMT_CASE(NONE, NONE);
+
+ FMT_CASE(R32G32B32A32_FLOAT, RGBA32F);
+ FMT_CASE(R16G16B16A16_FLOAT, RGBA16F);
+ FMT_CASE(R32G32_FLOAT, RG32F);
+ FMT_CASE(R16G16_FLOAT, RG16F);
+ FMT_CASE(R11G11B10_FLOAT, R11G11B10F);
+ FMT_CASE(R32_FLOAT, R32F);
+ FMT_CASE(R16_FLOAT, R16F);
+
+ FMT_CASE(R32G32B32A32_UINT, RGBA32UI);
+ FMT_CASE(R16G16B16A16_UINT, RGBA16UI);
+ FMT_CASE(R10G10B10A2_UINT, RGB10A2UI);
+ FMT_CASE(R8G8B8A8_UINT, RGBA8UI);
+ FMT_CASE(R32G32_UINT, RG32UI);
+ FMT_CASE(R16G16_UINT, RG16UI);
+ FMT_CASE(R8G8_UINT, RG8UI);
+ FMT_CASE(R32_UINT, R32UI);
+ FMT_CASE(R16_UINT, R16UI);
+ FMT_CASE(R8_UINT, R8UI);
+
+ FMT_CASE(R32G32B32A32_SINT, RGBA32I);
+ FMT_CASE(R16G16B16A16_SINT, RGBA16I);
+ FMT_CASE(R8G8B8A8_SINT, RGBA8I);
+ FMT_CASE(R32G32_SINT, RG32I);
+ FMT_CASE(R16G16_SINT, RG16I);
+ FMT_CASE(R8G8_SINT, RG8I);
+ FMT_CASE(R32_SINT, R32I);
+ FMT_CASE(R16_SINT, R16I);
+ FMT_CASE(R8_SINT, R8I);
+
+ FMT_CASE(R16G16B16A16_UNORM, RGBA16);
+ FMT_CASE(R10G10B10A2_UNORM, RGB10A2);
+ FMT_CASE(R8G8B8A8_UNORM, RGBA8);
+ FMT_CASE(R16G16_UNORM, RG16);
+ FMT_CASE(R8G8_UNORM, RG8);
+ FMT_CASE(R16_UNORM, R16);
+ FMT_CASE(R8_UNORM, R8);
+
+ FMT_CASE(R16G16B16A16_SNORM, RGBA16_SNORM);
+ FMT_CASE(R8G8B8A8_SNORM, RGBA8_SNORM);
+ FMT_CASE(R16G16_SNORM, RG16_SNORM);
+ FMT_CASE(R8G8_SNORM, RG8_SNORM);
+ FMT_CASE(R16_SNORM, R16_SNORM);
+ FMT_CASE(R8_SNORM, R8_SNORM);
+
+ FMT_CASE(B8G8R8A8_UNORM, BGRA8);
+
+ default:
+ assert(!"Unexpected format");
+ return &formatTable[nv50_ir::FMT_NONE];
+ }
+}
+
void
TexInstruction::setIndirectR(Value *v)
{
};
static const struct ImgFormatDesc formatTable[IMG_FORMAT_COUNT];
+ static const struct ImgFormatDesc *translateImgFormat(
+ enum pipe_format format);
public:
TexInstruction(Function *, operation);
LValues& convert(nir_register *);
LValues& convert(nir_ssa_def *);
- ImgFormat convertGLImgFormat(GLuint);
-
Value* getSrc(nir_alu_src *, uint8_t component = 0);
Value* getSrc(nir_register *, uint8_t);
Value* getSrc(nir_src *, uint8_t, bool indirect = false);
}
}
-ImgFormat
-Converter::convertGLImgFormat(GLuint format)
-{
-#define FMT_CASE(a, b) \
- case GL_ ## a: return nv50_ir::FMT_ ## b
-
- switch (format) {
- FMT_CASE(NONE, NONE);
-
- FMT_CASE(RGBA32F, RGBA32F);
- FMT_CASE(RGBA16F, RGBA16F);
- FMT_CASE(RG32F, RG32F);
- FMT_CASE(RG16F, RG16F);
- FMT_CASE(R11F_G11F_B10F, R11G11B10F);
- FMT_CASE(R32F, R32F);
- FMT_CASE(R16F, R16F);
-
- FMT_CASE(RGBA32UI, RGBA32UI);
- FMT_CASE(RGBA16UI, RGBA16UI);
- FMT_CASE(RGB10_A2UI, RGB10A2UI);
- FMT_CASE(RGBA8UI, RGBA8UI);
- FMT_CASE(RG32UI, RG32UI);
- FMT_CASE(RG16UI, RG16UI);
- FMT_CASE(RG8UI, RG8UI);
- FMT_CASE(R32UI, R32UI);
- FMT_CASE(R16UI, R16UI);
- FMT_CASE(R8UI, R8UI);
-
- FMT_CASE(RGBA32I, RGBA32I);
- FMT_CASE(RGBA16I, RGBA16I);
- FMT_CASE(RGBA8I, RGBA8I);
- FMT_CASE(RG32I, RG32I);
- FMT_CASE(RG16I, RG16I);
- FMT_CASE(RG8I, RG8I);
- FMT_CASE(R32I, R32I);
- FMT_CASE(R16I, R16I);
- FMT_CASE(R8I, R8I);
-
- FMT_CASE(RGBA16, RGBA16);
- FMT_CASE(RGB10_A2, RGB10A2);
- FMT_CASE(RGBA8, RGBA8);
- FMT_CASE(RG16, RG16);
- FMT_CASE(RG8, RG8);
- FMT_CASE(R16, R16);
- FMT_CASE(R8, R8);
-
- FMT_CASE(RGBA16_SNORM, RGBA16_SNORM);
- FMT_CASE(RGBA8_SNORM, RGBA8_SNORM);
- FMT_CASE(RG16_SNORM, RG16_SNORM);
- FMT_CASE(RG8_SNORM, RG8_SNORM);
- FMT_CASE(R16_SNORM, R16_SNORM);
- FMT_CASE(R8_SNORM, R8_SNORM);
-
- FMT_CASE(BGRA_INTEGER, BGRA8);
- default:
- ERROR("unknown format %x\n", format);
- assert(false);
- return nv50_ir::FMT_NONE;
- }
-#undef FMT_CASE
-}
-
bool
Converter::visit(nir_intrinsic_instr *insn)
{
TexInstruction *texi = mkTex(getOperation(op), target.getEnum(), location, 0, defs, srcs);
texi->tex.bindless = false;
- texi->tex.format = &nv50_ir::TexInstruction::formatTable[convertGLImgFormat(nir_intrinsic_format(insn))];
+ texi->tex.format = nv50_ir::TexInstruction::translateImgFormat(nir_intrinsic_format(insn));
texi->tex.mask = mask;
texi->tex.bindless = true;
texi->cache = convert(nir_intrinsic_access(insn));
TexInstruction *texi = mkTex(getOperation(op), target.getEnum(), location, 0, defs, srcs);
texi->tex.bindless = false;
- texi->tex.format = &nv50_ir::TexInstruction::formatTable[convertGLImgFormat(tex->data.image.format)];
+ texi->tex.format = nv50_ir::TexInstruction::translateImgFormat(tex->data.image.format);
texi->tex.mask = mask;
texi->cache = getCacheModeFromVar(tex);
texi->setType(ty);
static nv50_ir::TexTarget translateTexture(uint texTarg);
static nv50_ir::SVSemantic translateSysVal(uint sysval);
static nv50_ir::CacheMode translateCacheMode(uint qualifier);
-static nv50_ir::ImgFormat translateImgFormat(uint format);
class Instruction
{
nv50_ir::TexInstruction::Target getTexture(const Source *, int s) const;
const nv50_ir::TexInstruction::ImgFormatDesc *getImageFormat() const {
- return &nv50_ir::TexInstruction::formatTable[
- translateImgFormat(insn->Memory.Format)];
+ return nv50_ir::TexInstruction::translateImgFormat((enum pipe_format)insn->Memory.Format);
}
nv50_ir::TexTarget getImageTarget() const {
return nv50_ir::CACHE_CA;
}
-static nv50_ir::ImgFormat translateImgFormat(uint format)
-{
-
-#define FMT_CASE(a, b) \
- case PIPE_FORMAT_ ## a: return nv50_ir::FMT_ ## b
-
- switch (format) {
- FMT_CASE(NONE, NONE);
-
- FMT_CASE(R32G32B32A32_FLOAT, RGBA32F);
- FMT_CASE(R16G16B16A16_FLOAT, RGBA16F);
- FMT_CASE(R32G32_FLOAT, RG32F);
- FMT_CASE(R16G16_FLOAT, RG16F);
- FMT_CASE(R11G11B10_FLOAT, R11G11B10F);
- FMT_CASE(R32_FLOAT, R32F);
- FMT_CASE(R16_FLOAT, R16F);
-
- FMT_CASE(R32G32B32A32_UINT, RGBA32UI);
- FMT_CASE(R16G16B16A16_UINT, RGBA16UI);
- FMT_CASE(R10G10B10A2_UINT, RGB10A2UI);
- FMT_CASE(R8G8B8A8_UINT, RGBA8UI);
- FMT_CASE(R32G32_UINT, RG32UI);
- FMT_CASE(R16G16_UINT, RG16UI);
- FMT_CASE(R8G8_UINT, RG8UI);
- FMT_CASE(R32_UINT, R32UI);
- FMT_CASE(R16_UINT, R16UI);
- FMT_CASE(R8_UINT, R8UI);
-
- FMT_CASE(R32G32B32A32_SINT, RGBA32I);
- FMT_CASE(R16G16B16A16_SINT, RGBA16I);
- FMT_CASE(R8G8B8A8_SINT, RGBA8I);
- FMT_CASE(R32G32_SINT, RG32I);
- FMT_CASE(R16G16_SINT, RG16I);
- FMT_CASE(R8G8_SINT, RG8I);
- FMT_CASE(R32_SINT, R32I);
- FMT_CASE(R16_SINT, R16I);
- FMT_CASE(R8_SINT, R8I);
-
- FMT_CASE(R16G16B16A16_UNORM, RGBA16);
- FMT_CASE(R10G10B10A2_UNORM, RGB10A2);
- FMT_CASE(R8G8B8A8_UNORM, RGBA8);
- FMT_CASE(R16G16_UNORM, RG16);
- FMT_CASE(R8G8_UNORM, RG8);
- FMT_CASE(R16_UNORM, R16);
- FMT_CASE(R8_UNORM, R8);
-
- FMT_CASE(R16G16B16A16_SNORM, RGBA16_SNORM);
- FMT_CASE(R8G8B8A8_SNORM, RGBA8_SNORM);
- FMT_CASE(R16G16_SNORM, RG16_SNORM);
- FMT_CASE(R8G8_SNORM, RG8_SNORM);
- FMT_CASE(R16_SNORM, R16_SNORM);
- FMT_CASE(R8_SNORM, R8_SNORM);
-
- FMT_CASE(B8G8R8A8_UNORM, BGRA8);
- }
-
- assert(!"Unexpected format");
- return nv50_ir::FMT_NONE;
-}
-
nv50_ir::DataType Instruction::inferSrcType() const
{
switch (getOpcode()) {
#include "compiler/nir/nir_builder.h"
#include "compiler/nir/nir_format_convert.h"
-/* The higher compiler layers use the GL enums for image formats even if
- * they come in from SPIR-V or Vulkan. We need to turn them into an ISL
- * enum before we can use them.
- */
-static enum isl_format
-isl_format_for_gl_format(uint32_t gl_format)
-{
- switch (gl_format) {
- case GL_R8: return ISL_FORMAT_R8_UNORM;
- case GL_R8_SNORM: return ISL_FORMAT_R8_SNORM;
- case GL_R8UI: return ISL_FORMAT_R8_UINT;
- case GL_R8I: return ISL_FORMAT_R8_SINT;
- case GL_RG8: return ISL_FORMAT_R8G8_UNORM;
- case GL_RG8_SNORM: return ISL_FORMAT_R8G8_SNORM;
- case GL_RG8UI: return ISL_FORMAT_R8G8_UINT;
- case GL_RG8I: return ISL_FORMAT_R8G8_SINT;
- case GL_RGBA8: return ISL_FORMAT_R8G8B8A8_UNORM;
- case GL_RGBA8_SNORM: return ISL_FORMAT_R8G8B8A8_SNORM;
- case GL_RGBA8UI: return ISL_FORMAT_R8G8B8A8_UINT;
- case GL_RGBA8I: return ISL_FORMAT_R8G8B8A8_SINT;
- case GL_R11F_G11F_B10F: return ISL_FORMAT_R11G11B10_FLOAT;
- case GL_RGB10_A2: return ISL_FORMAT_R10G10B10A2_UNORM;
- case GL_RGB10_A2UI: return ISL_FORMAT_R10G10B10A2_UINT;
- case GL_R16: return ISL_FORMAT_R16_UNORM;
- case GL_R16_SNORM: return ISL_FORMAT_R16_SNORM;
- case GL_R16F: return ISL_FORMAT_R16_FLOAT;
- case GL_R16UI: return ISL_FORMAT_R16_UINT;
- case GL_R16I: return ISL_FORMAT_R16_SINT;
- case GL_RG16: return ISL_FORMAT_R16G16_UNORM;
- case GL_RG16_SNORM: return ISL_FORMAT_R16G16_SNORM;
- case GL_RG16F: return ISL_FORMAT_R16G16_FLOAT;
- case GL_RG16UI: return ISL_FORMAT_R16G16_UINT;
- case GL_RG16I: return ISL_FORMAT_R16G16_SINT;
- case GL_RGBA16: return ISL_FORMAT_R16G16B16A16_UNORM;
- case GL_RGBA16_SNORM: return ISL_FORMAT_R16G16B16A16_SNORM;
- case GL_RGBA16F: return ISL_FORMAT_R16G16B16A16_FLOAT;
- case GL_RGBA16UI: return ISL_FORMAT_R16G16B16A16_UINT;
- case GL_RGBA16I: return ISL_FORMAT_R16G16B16A16_SINT;
- case GL_R32F: return ISL_FORMAT_R32_FLOAT;
- case GL_R32UI: return ISL_FORMAT_R32_UINT;
- case GL_R32I: return ISL_FORMAT_R32_SINT;
- case GL_RG32F: return ISL_FORMAT_R32G32_FLOAT;
- case GL_RG32UI: return ISL_FORMAT_R32G32_UINT;
- case GL_RG32I: return ISL_FORMAT_R32G32_SINT;
- case GL_RGBA32F: return ISL_FORMAT_R32G32B32A32_FLOAT;
- case GL_RGBA32UI: return ISL_FORMAT_R32G32B32A32_UINT;
- case GL_RGBA32I: return ISL_FORMAT_R32G32B32A32_SINT;
- case GL_NONE: return ISL_FORMAT_UNSUPPORTED;
- default:
- assert(!"Invalid image format");
- return ISL_FORMAT_UNSUPPORTED;
- }
-}
-
static nir_ssa_def *
_load_image_param(nir_builder *b, nir_deref_instr *deref, unsigned offset)
{
nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
nir_variable *var = nir_deref_instr_get_variable(deref);
const enum isl_format image_fmt =
- isl_format_for_gl_format(var->data.image.format);
+ isl_format_for_pipe_format(var->data.image.format);
if (isl_has_matching_typed_storage_image_format(devinfo, image_fmt)) {
const enum isl_format lower_fmt =
return false;
const enum isl_format image_fmt =
- isl_format_for_gl_format(var->data.image.format);
+ isl_format_for_pipe_format(var->data.image.format);
if (isl_has_matching_typed_storage_image_format(devinfo, image_fmt)) {
const enum isl_format lower_fmt =
* so we fall back and let the back-end emit a TXS for this.
*/
const enum isl_format image_fmt =
- isl_format_for_gl_format(var->data.image.format);
+ isl_format_for_pipe_format(var->data.image.format);
if (isl_has_matching_typed_storage_image_format(devinfo, image_fmt))
return false;
get_image_qualifiers(ir_dereference *ir, const glsl_type **type,
bool *memory_coherent, bool *memory_volatile,
bool *memory_restrict, bool *memory_read_only,
- unsigned *image_format)
+ enum pipe_format *image_format)
{
switch (ir->ir_type) {
unsigned sampler_array_size = 1, sampler_base = 0;
bool memory_coherent = false, memory_volatile = false,
memory_restrict = false, memory_read_only = false;
- unsigned image_format = 0;
+ enum pipe_format image_format = PIPE_FORMAT_NONE;
const glsl_type *type = NULL;
get_image_qualifiers(img, &type, &memory_coherent, &memory_volatile,
}
inst->tex_target = type->sampler_index();
- inst->image_format = st_mesa_format_to_pipe_format(st_context(ctx),
- _mesa_get_shader_image_format(image_format));
+ inst->image_format = image_format;
inst->read_only = memory_read_only;
if (memory_coherent)