compiler/types: Add a texture type

This is separate from images and samplers.  It's a texture (not a
storage image) without a sampler.  We also add C-visible helpers to
convert between sampler and image types.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13389>
This commit is contained in:
Jason Ekstrand 2021-10-15 13:56:57 -05:00 committed by Marge Bot
parent 7558c9cb07
commit 3ace6b968b
14 changed files with 267 additions and 6 deletions

View File

@ -133,6 +133,50 @@ DECL_TYPE(sampler2DRectShadow, GL_SAMPLER_2D_RECT_SHADOW, GLSL_TYPE_SA
DECL_TYPE(samplerExternalOES, GL_SAMPLER_EXTERNAL_OES, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_EXTERNAL, 0, 0, GLSL_TYPE_FLOAT) DECL_TYPE(samplerExternalOES, GL_SAMPLER_EXTERNAL_OES, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_EXTERNAL, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(texture1D, GL_SAMPLER_1D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(texture2D, GL_SAMPLER_2D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(texture3D, GL_SAMPLER_3D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(textureCube, GL_SAMPLER_CUBE, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(texture1DArray, GL_SAMPLER_1D_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(texture2DArray, GL_SAMPLER_2D_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(textureCubeArray, GL_SAMPLER_CUBE_MAP_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(texture2DRect, GL_SAMPLER_2D_RECT, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(textureBuffer, GL_SAMPLER_BUFFER, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(texture2DMS, GL_SAMPLER_2D_MULTISAMPLE, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(texture2DMSArray, GL_SAMPLER_2D_MULTISAMPLE_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_FLOAT)
DECL_TYPE(itexture1D, GL_INT_SAMPLER_1D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(itexture2D, GL_INT_SAMPLER_2D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(itexture3D, GL_INT_SAMPLER_3D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(itextureCube, GL_INT_SAMPLER_CUBE, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(itexture1DArray, GL_INT_SAMPLER_1D_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_INT)
DECL_TYPE(itexture2DArray, GL_INT_SAMPLER_2D_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_INT)
DECL_TYPE(itextureCubeArray, GL_INT_SAMPLER_CUBE_MAP_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_INT)
DECL_TYPE(itexture2DRect, GL_INT_SAMPLER_2D_RECT, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(itextureBuffer, GL_INT_SAMPLER_BUFFER, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(itexture2DMS, GL_INT_SAMPLER_2D_MULTISAMPLE, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_INT)
DECL_TYPE(itexture2DMSArray, GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_INT)
DECL_TYPE(utexture1D, GL_UNSIGNED_INT_SAMPLER_1D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(utexture2D, GL_UNSIGNED_INT_SAMPLER_2D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(utexture3D, GL_UNSIGNED_INT_SAMPLER_3D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(utextureCube, GL_UNSIGNED_INT_SAMPLER_CUBE, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_CUBE, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(utexture1DArray, GL_UNSIGNED_INT_SAMPLER_1D_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_UINT)
DECL_TYPE(utexture2DArray, GL_UNSIGNED_INT_SAMPLER_2D_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_UINT)
DECL_TYPE(utextureCubeArray, GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_CUBE, 0, 1, GLSL_TYPE_UINT)
DECL_TYPE(utexture2DRect, GL_UNSIGNED_INT_SAMPLER_2D_RECT, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_RECT, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(utextureBuffer, GL_UNSIGNED_INT_SAMPLER_BUFFER, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(utexture2DMS, GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_MS, 0, 0, GLSL_TYPE_UINT)
DECL_TYPE(utexture2DMSArray, GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_MS, 0, 1, GLSL_TYPE_UINT)
/* OpenCL image types */
DECL_TYPE(vtexture1D, GL_SAMPLER_1D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_VOID)
DECL_TYPE(vtexture2D, GL_SAMPLER_2D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_VOID)
DECL_TYPE(vtexture3D, GL_SAMPLER_3D, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_VOID)
DECL_TYPE(vtexture1DArray, GL_SAMPLER_1D_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_1D, 0, 1, GLSL_TYPE_VOID)
DECL_TYPE(vtexture2DArray, GL_SAMPLER_2D_ARRAY, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_2D, 0, 1, GLSL_TYPE_VOID)
DECL_TYPE(vtextureBuffer, GL_SAMPLER_BUFFER, GLSL_TYPE_TEXTURE, GLSL_SAMPLER_DIM_BUF, 0, 0, GLSL_TYPE_VOID)
DECL_TYPE(image1D, GL_IMAGE_1D, GLSL_TYPE_IMAGE, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT) DECL_TYPE(image1D, GL_IMAGE_1D, GLSL_TYPE_IMAGE, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(image2D, GL_IMAGE_2D, GLSL_TYPE_IMAGE, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT) DECL_TYPE(image2D, GL_IMAGE_2D, GLSL_TYPE_IMAGE, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(image3D, GL_IMAGE_3D, GLSL_TYPE_IMAGE, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT) DECL_TYPE(image3D, GL_IMAGE_3D, GLSL_TYPE_IMAGE, GLSL_SAMPLER_DIM_3D, 0, 0, GLSL_TYPE_FLOAT)

View File

@ -1182,6 +1182,7 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
case GLSL_TYPE_ERROR: case GLSL_TYPE_ERROR:
case GLSL_TYPE_VOID: case GLSL_TYPE_VOID:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_INTERFACE: case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:
@ -4222,6 +4223,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
case GLSL_TYPE_INT64: case GLSL_TYPE_INT64:
break; break;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
if (state->has_bindless()) if (state->has_bindless())
break; break;
@ -5432,6 +5434,7 @@ ast_declarator_list::hir(exec_list *instructions,
error = !state->is_version(410, 0) && !state->ARB_vertex_attrib_64bit_enable; error = !state->is_version(410, 0) && !state->ARB_vertex_attrib_64bit_enable;
break; break;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
error = !state->has_bindless(); error = !state->has_bindless();
break; break;
@ -7228,6 +7231,7 @@ is_valid_default_precision_type(const struct glsl_type *const type)
/* "int" and "float" are valid, but vectors and matrices are not. */ /* "int" and "float" are valid, but vectors and matrices are not. */
return type->vector_elements == 1 && type->matrix_columns == 1; return type->vector_elements == 1 && type->matrix_columns == 1;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:
return true; return true;

View File

@ -152,6 +152,7 @@ copy_constant_to_storage(union gl_constant_value *storage,
break; break;
case GLSL_TYPE_ARRAY: case GLSL_TYPE_ARRAY:
case GLSL_TYPE_STRUCT: case GLSL_TYPE_STRUCT:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_INTERFACE: case GLSL_TYPE_INTERFACE:

View File

@ -354,6 +354,7 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
case GLSL_TYPE_UINT8: case GLSL_TYPE_UINT8:
case GLSL_TYPE_INT8: case GLSL_TYPE_INT8:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
return new(mem_ctx) ir_constant(this->type, &this->value); return new(mem_ctx) ir_constant(this->type, &this->value);

View File

@ -74,6 +74,7 @@ copy_constant_to_storage(union gl_constant_value *storage,
break; break;
case GLSL_TYPE_ARRAY: case GLSL_TYPE_ARRAY:
case GLSL_TYPE_STRUCT: case GLSL_TYPE_STRUCT:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_INTERFACE: case GLSL_TYPE_INTERFACE:

View File

@ -84,6 +84,7 @@ generate_data_element(void *mem_ctx, const glsl_type *type,
case GLSL_TYPE_UINT: case GLSL_TYPE_UINT:
case GLSL_TYPE_INT: case GLSL_TYPE_INT:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
data.i[i] = values[idx]; data.i[i] = values[idx];
break; break;
@ -129,6 +130,7 @@ generate_data_element(void *mem_ctx, const glsl_type *type,
case GLSL_TYPE_UINT: case GLSL_TYPE_UINT:
case GLSL_TYPE_INT: case GLSL_TYPE_INT:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
ASSERT_EQ(data.i[i], val->value.i[i]); ASSERT_EQ(data.i[i], val->value.i[i]);
break; break;
@ -262,6 +264,7 @@ verify_data(gl_constant_value *storage, unsigned storage_array_size,
case GLSL_TYPE_UINT: case GLSL_TYPE_UINT:
case GLSL_TYPE_INT: case GLSL_TYPE_INT:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
EXPECT_EQ(val->value.i[i], storage[i].i); EXPECT_EQ(val->value.i[i], storage[i].i);
break; break;

View File

@ -460,6 +460,7 @@ const glsl_type *glsl_type::get_bare_type() const
this->length); this->length);
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID: case GLSL_TYPE_VOID:
@ -950,6 +951,118 @@ glsl_type::get_sampler_instance(enum glsl_sampler_dim dim,
unreachable("switch statement above should be complete"); unreachable("switch statement above should be complete");
} }
const glsl_type *
glsl_type::get_texture_instance(enum glsl_sampler_dim dim,
bool array, glsl_base_type type)
{
switch (type) {
case GLSL_TYPE_FLOAT:
switch (dim) {
case GLSL_SAMPLER_DIM_1D:
return (array ? texture1DArray_type : texture1D_type);
case GLSL_SAMPLER_DIM_2D:
return (array ? texture2DArray_type : texture2D_type);
case GLSL_SAMPLER_DIM_3D:
return texture3D_type;
case GLSL_SAMPLER_DIM_CUBE:
return (array ? textureCubeArray_type : textureCube_type);
case GLSL_SAMPLER_DIM_RECT:
if (array)
return error_type;
else
return texture2DRect_type;
case GLSL_SAMPLER_DIM_BUF:
if (array)
return error_type;
else
return textureBuffer_type;
case GLSL_SAMPLER_DIM_MS:
return (array ? texture2DMSArray_type : texture2DMS_type);
case GLSL_SAMPLER_DIM_SUBPASS:
return subpassInput_type;
case GLSL_SAMPLER_DIM_SUBPASS_MS:
return subpassInputMS_type;
case GLSL_SAMPLER_DIM_EXTERNAL:
return error_type;
}
case GLSL_TYPE_INT:
switch (dim) {
case GLSL_SAMPLER_DIM_1D:
return (array ? itexture1DArray_type : itexture1D_type);
case GLSL_SAMPLER_DIM_2D:
return (array ? itexture2DArray_type : itexture2D_type);
case GLSL_SAMPLER_DIM_3D:
if (array)
return error_type;
return itexture3D_type;
case GLSL_SAMPLER_DIM_CUBE:
return (array ? itextureCubeArray_type : itextureCube_type);
case GLSL_SAMPLER_DIM_RECT:
if (array)
return error_type;
return itexture2DRect_type;
case GLSL_SAMPLER_DIM_BUF:
if (array)
return error_type;
return itextureBuffer_type;
case GLSL_SAMPLER_DIM_MS:
return (array ? itexture2DMSArray_type : itexture2DMS_type);
case GLSL_SAMPLER_DIM_SUBPASS:
return isubpassInput_type;
case GLSL_SAMPLER_DIM_SUBPASS_MS:
return isubpassInputMS_type;
case GLSL_SAMPLER_DIM_EXTERNAL:
return error_type;
}
case GLSL_TYPE_UINT:
switch (dim) {
case GLSL_SAMPLER_DIM_1D:
return (array ? utexture1DArray_type : utexture1D_type);
case GLSL_SAMPLER_DIM_2D:
return (array ? utexture2DArray_type : utexture2D_type);
case GLSL_SAMPLER_DIM_3D:
if (array)
return error_type;
return utexture3D_type;
case GLSL_SAMPLER_DIM_CUBE:
return (array ? utextureCubeArray_type : utextureCube_type);
case GLSL_SAMPLER_DIM_RECT:
if (array)
return error_type;
return utexture2DRect_type;
case GLSL_SAMPLER_DIM_BUF:
if (array)
return error_type;
return utextureBuffer_type;
case GLSL_SAMPLER_DIM_MS:
return (array ? utexture2DMSArray_type : utexture2DMS_type);
case GLSL_SAMPLER_DIM_SUBPASS:
return usubpassInput_type;
case GLSL_SAMPLER_DIM_SUBPASS_MS:
return usubpassInputMS_type;
case GLSL_SAMPLER_DIM_EXTERNAL:
return error_type;
}
case GLSL_TYPE_VOID:
switch (dim) {
case GLSL_SAMPLER_DIM_1D:
return (array ? vtexture1DArray_type : vtexture1D_type);
case GLSL_SAMPLER_DIM_2D:
return (array ? vtexture2DArray_type : vtexture2D_type);
case GLSL_SAMPLER_DIM_3D:
return (array ? error_type : vtexture3D_type);
case GLSL_SAMPLER_DIM_BUF:
return (array ? error_type : vbuffer_type);
default:
return error_type;
}
default:
return error_type;
}
unreachable("switch statement above should be complete");
}
const glsl_type * const glsl_type *
glsl_type::get_image_instance(enum glsl_sampler_dim dim, glsl_type::get_image_instance(enum glsl_sampler_dim dim,
bool array, glsl_base_type type) bool array, glsl_base_type type)
@ -1630,6 +1743,7 @@ glsl_type::component_slots() const
return this->length * this->fields.array->component_slots(); return this->length * this->fields.array->component_slots();
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
return 2; return 2;
@ -1696,6 +1810,7 @@ glsl_type::component_slots_aligned(unsigned offset) const
} }
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
return 2 + ((offset % 4) == 3 ? 1 : 0); return 2 + ((offset % 4) == 3 ? 1 : 0);
@ -1772,6 +1887,7 @@ glsl_type::uniform_locations() const
case GLSL_TYPE_INT64: case GLSL_TYPE_INT64:
case GLSL_TYPE_BOOL: case GLSL_TYPE_BOOL:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_SUBROUTINE: case GLSL_TYPE_SUBROUTINE:
return 1; return 1;
@ -2810,6 +2926,7 @@ glsl_type::count_vec4_slots(bool is_gl_vertex_input, bool is_bindless) const
} }
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
if (!is_bindless) if (!is_bindless)
return 0; return 0;
@ -2849,6 +2966,7 @@ glsl_type::count_dword_slots(bool is_bindless) const
return DIV_ROUND_UP(this->components(), 4); return DIV_ROUND_UP(this->components(), 4);
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
if (!is_bindless) if (!is_bindless)
return 0; return 0;
FALLTHROUGH; FALLTHROUGH;
@ -3022,6 +3140,7 @@ encode_type_to_blob(struct blob *blob, const glsl_type *type)
blob_write_uint32(blob, type->explicit_alignment); blob_write_uint32(blob, type->explicit_alignment);
return; return;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
encoded.sampler.dimensionality = type->sampler_dimensionality; encoded.sampler.dimensionality = type->sampler_dimensionality;
if (type->base_type == GLSL_TYPE_SAMPLER) if (type->base_type == GLSL_TYPE_SAMPLER)
@ -3134,6 +3253,10 @@ decode_type_from_blob(struct blob_reader *blob)
encoded.sampler.shadow, encoded.sampler.shadow,
encoded.sampler.array, encoded.sampler.array,
(glsl_base_type) encoded.sampler.sampled_type); (glsl_base_type) encoded.sampler.sampled_type);
case GLSL_TYPE_TEXTURE:
return glsl_type::get_texture_instance((enum glsl_sampler_dim)encoded.sampler.dimensionality,
encoded.sampler.array,
(glsl_base_type) encoded.sampler.sampled_type);
case GLSL_TYPE_SUBROUTINE: case GLSL_TYPE_SUBROUTINE:
return glsl_type::get_subroutine_instance(blob_read_string(blob)); return glsl_type::get_subroutine_instance(blob_read_string(blob));
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:

View File

@ -84,6 +84,7 @@ enum glsl_base_type {
GLSL_TYPE_INT64, GLSL_TYPE_INT64,
GLSL_TYPE_BOOL, GLSL_TYPE_BOOL,
GLSL_TYPE_SAMPLER, GLSL_TYPE_SAMPLER,
GLSL_TYPE_TEXTURE,
GLSL_TYPE_IMAGE, GLSL_TYPE_IMAGE,
GLSL_TYPE_ATOMIC_UINT, GLSL_TYPE_ATOMIC_UINT,
GLSL_TYPE_STRUCT, GLSL_TYPE_STRUCT,
@ -122,6 +123,7 @@ static unsigned glsl_base_type_bit_size(enum glsl_base_type type)
case GLSL_TYPE_INT64: case GLSL_TYPE_INT64:
case GLSL_TYPE_UINT64: case GLSL_TYPE_UINT64:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
return 64; return 64;
@ -158,6 +160,7 @@ static inline bool glsl_base_type_is_integer(enum glsl_base_type type)
type == GLSL_TYPE_INT64 || type == GLSL_TYPE_INT64 ||
type == GLSL_TYPE_BOOL || type == GLSL_TYPE_BOOL ||
type == GLSL_TYPE_SAMPLER || type == GLSL_TYPE_SAMPLER ||
type == GLSL_TYPE_TEXTURE ||
type == GLSL_TYPE_IMAGE; type == GLSL_TYPE_IMAGE;
} }
@ -188,6 +191,7 @@ glsl_base_type_get_bit_size(const enum glsl_base_type base_type)
case GLSL_TYPE_UINT64: case GLSL_TYPE_UINT64:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
return 64; return 64;
default: default:
@ -459,6 +463,10 @@ public:
bool array, bool array,
glsl_base_type type); glsl_base_type type);
static const glsl_type *get_texture_instance(enum glsl_sampler_dim dim,
bool array,
glsl_base_type type);
static const glsl_type *get_image_instance(enum glsl_sampler_dim dim, static const glsl_type *get_image_instance(enum glsl_sampler_dim dim,
bool array, glsl_base_type type); bool array, glsl_base_type type);
@ -941,6 +949,14 @@ public:
return base_type == GLSL_TYPE_SAMPLER; return base_type == GLSL_TYPE_SAMPLER;
} }
/**
* Query whether or not a type is a texture
*/
bool is_texture() const
{
return base_type == GLSL_TYPE_TEXTURE;
}
/** /**
* Query whether or not type is a sampler, or for struct, interface and * Query whether or not type is a sampler, or for struct, interface and
* array types, contains a sampler. * array types, contains a sampler.

View File

@ -1185,6 +1185,7 @@ nir_get_nir_type_for_glsl_base_type(enum glsl_base_type base_type)
break; break;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_STRUCT: case GLSL_TYPE_STRUCT:

View File

@ -110,6 +110,24 @@ glsl_get_function_param(const glsl_type *type, unsigned index)
return &type->fields.parameters[index + 1]; return &type->fields.parameters[index + 1];
} }
const glsl_type *
glsl_texture_type_to_sampler(const glsl_type *type, bool is_shadow)
{
assert(glsl_type_is_texture(type));
return glsl_sampler_type((glsl_sampler_dim)type->sampler_dimensionality,
is_shadow, type->sampler_array,
(glsl_base_type)type->sampled_type);
}
const glsl_type *
glsl_sampler_type_to_texture(const glsl_type *type)
{
assert(glsl_type_is_sampler(type) && !glsl_type_is_bare_sampler(type));
return glsl_texture_type((glsl_sampler_dim)type->sampler_dimensionality,
type->sampler_array,
(glsl_base_type)type->sampled_type);
}
const struct glsl_type * const struct glsl_type *
glsl_get_column_type(const struct glsl_type *type) glsl_get_column_type(const struct glsl_type *type)
{ {
@ -199,14 +217,18 @@ glsl_get_struct_elem_name(const struct glsl_type *type, unsigned index)
glsl_sampler_dim glsl_sampler_dim
glsl_get_sampler_dim(const struct glsl_type *type) glsl_get_sampler_dim(const struct glsl_type *type)
{ {
assert(glsl_type_is_sampler(type) || glsl_type_is_image(type)); assert(glsl_type_is_sampler(type) ||
glsl_type_is_texture(type) ||
glsl_type_is_image(type));
return (glsl_sampler_dim)type->sampler_dimensionality; return (glsl_sampler_dim)type->sampler_dimensionality;
} }
glsl_base_type glsl_base_type
glsl_get_sampler_result_type(const struct glsl_type *type) glsl_get_sampler_result_type(const struct glsl_type *type)
{ {
assert(glsl_type_is_sampler(type) || glsl_type_is_image(type)); assert(glsl_type_is_sampler(type) ||
glsl_type_is_texture(type) ||
glsl_type_is_image(type));
return (glsl_base_type)type->sampled_type; return (glsl_base_type)type->sampled_type;
} }
@ -220,7 +242,9 @@ glsl_get_sampler_target(const struct glsl_type *type)
int int
glsl_get_sampler_coordinate_components(const struct glsl_type *type) glsl_get_sampler_coordinate_components(const struct glsl_type *type)
{ {
assert(glsl_type_is_sampler(type) || glsl_type_is_image(type)); assert(glsl_type_is_sampler(type) ||
glsl_type_is_texture(type) ||
glsl_type_is_image(type));
return type->coordinate_components(); return type->coordinate_components();
} }
@ -340,6 +364,18 @@ glsl_type_is_sampler(const struct glsl_type *type)
return type->is_sampler(); return type->is_sampler();
} }
bool
glsl_type_is_bare_sampler(const struct glsl_type *type)
{
return type->is_sampler() && type->sampled_type == GLSL_TYPE_VOID;
}
bool
glsl_type_is_texture(const struct glsl_type *type)
{
return type->is_texture();
}
bool bool
glsl_type_is_image(const struct glsl_type *type) glsl_type_is_image(const struct glsl_type *type)
{ {
@ -356,7 +392,9 @@ glsl_sampler_type_is_shadow(const struct glsl_type *type)
bool bool
glsl_sampler_type_is_array(const struct glsl_type *type) glsl_sampler_type_is_array(const struct glsl_type *type)
{ {
assert(glsl_type_is_sampler(type) || glsl_type_is_image(type)); assert(glsl_type_is_sampler(type) ||
glsl_type_is_texture(type) ||
glsl_type_is_image(type));
return type->sampler_array; return type->sampler_array;
} }
@ -642,6 +680,13 @@ glsl_bare_shadow_sampler_type()
return glsl_type::samplerShadow_type; return glsl_type::samplerShadow_type;
} }
const struct glsl_type *
glsl_texture_type(enum glsl_sampler_dim dim, bool is_array,
enum glsl_base_type base_type)
{
return glsl_type::get_texture_instance(dim, is_array, base_type);
}
const struct glsl_type * const struct glsl_type *
glsl_image_type(enum glsl_sampler_dim dim, bool is_array, glsl_image_type(enum glsl_sampler_dim dim, bool is_array,
enum glsl_base_type base_type) enum glsl_base_type base_type)
@ -771,6 +816,7 @@ glsl_get_natural_size_align_bytes(const struct glsl_type *type,
break; break;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
/* Bindless samplers and images. */ /* Bindless samplers and images. */
*size = 8; *size = 8;
@ -829,6 +875,7 @@ glsl_get_vec4_size_align_bytes(const struct glsl_type *type,
break; break;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_SUBROUTINE: case GLSL_TYPE_SUBROUTINE:
@ -913,6 +960,12 @@ glsl_type_get_sampler_count(const struct glsl_type *type)
return glsl_type_count(type, GLSL_TYPE_SAMPLER); return glsl_type_count(type, GLSL_TYPE_SAMPLER);
} }
unsigned
glsl_type_get_texture_count(const struct glsl_type *type)
{
return glsl_type_count(type, GLSL_TYPE_TEXTURE);
}
unsigned unsigned
glsl_type_get_image_count(const struct glsl_type *type) glsl_type_get_image_count(const struct glsl_type *type)
{ {

View File

@ -79,6 +79,11 @@ glsl_get_function_return_type(const struct glsl_type *type);
const struct glsl_function_param * const struct glsl_function_param *
glsl_get_function_param(const struct glsl_type *type, unsigned index); glsl_get_function_param(const struct glsl_type *type, unsigned index);
const struct glsl_type *
glsl_texture_type_to_sampler(const struct glsl_type *type, bool is_shadow);
const struct glsl_type *
glsl_sampler_type_to_texture(const struct glsl_type *type);
GLenum glsl_get_gl_type(const struct glsl_type *type); GLenum glsl_get_gl_type(const struct glsl_type *type);
enum glsl_base_type glsl_get_base_type(const struct glsl_type *type); enum glsl_base_type glsl_get_base_type(const struct glsl_type *type);
@ -149,6 +154,8 @@ bool glsl_type_is_struct(const struct glsl_type *type);
bool glsl_type_is_interface(const struct glsl_type *type); bool glsl_type_is_interface(const struct glsl_type *type);
bool glsl_type_is_struct_or_ifc(const struct glsl_type *type); bool glsl_type_is_struct_or_ifc(const struct glsl_type *type);
bool glsl_type_is_sampler(const struct glsl_type *type); bool glsl_type_is_sampler(const struct glsl_type *type);
bool glsl_type_is_bare_sampler(const struct glsl_type *type);
bool glsl_type_is_texture(const struct glsl_type *type);
bool glsl_type_is_image(const struct glsl_type *type); bool glsl_type_is_image(const struct glsl_type *type);
bool glsl_type_is_dual_slot(const struct glsl_type *type); bool glsl_type_is_dual_slot(const struct glsl_type *type);
bool glsl_type_is_numeric(const struct glsl_type *type); bool glsl_type_is_numeric(const struct glsl_type *type);
@ -212,6 +219,9 @@ const struct glsl_type *glsl_sampler_type(enum glsl_sampler_dim dim,
enum glsl_base_type base_type); enum glsl_base_type base_type);
const struct glsl_type *glsl_bare_sampler_type(); const struct glsl_type *glsl_bare_sampler_type();
const struct glsl_type *glsl_bare_shadow_sampler_type(); const struct glsl_type *glsl_bare_shadow_sampler_type();
const struct glsl_type *glsl_texture_type(enum glsl_sampler_dim dim,
bool is_array,
enum glsl_base_type base_type);
const struct glsl_type *glsl_image_type(enum glsl_sampler_dim dim, const struct glsl_type *glsl_image_type(enum glsl_sampler_dim dim,
bool is_array, bool is_array,
enum glsl_base_type base_type); enum glsl_base_type base_type);
@ -241,6 +251,7 @@ const struct glsl_type *glsl_get_explicit_type_for_size_align(const struct glsl_
const struct glsl_type *glsl_type_replace_vec3_with_vec4(const struct glsl_type *type); const struct glsl_type *glsl_type_replace_vec3_with_vec4(const struct glsl_type *type);
unsigned glsl_type_get_sampler_count(const struct glsl_type *type); unsigned glsl_type_get_sampler_count(const struct glsl_type *type);
unsigned glsl_type_get_texture_count(const struct glsl_type *type);
unsigned glsl_type_get_image_count(const struct glsl_type *type); unsigned glsl_type_get_image_count(const struct glsl_type *type);
bool glsl_type_is_leaf(const struct glsl_type *type); bool glsl_type_is_leaf(const struct glsl_type *type);

View File

@ -57,6 +57,7 @@ brw_type_for_base_type(const struct glsl_type *type)
case GLSL_TYPE_STRUCT: case GLSL_TYPE_STRUCT:
case GLSL_TYPE_INTERFACE: case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:
/* These should be overridden with the type of the member when /* These should be overridden with the type of the member when
* dereferenced into. BRW_REGISTER_TYPE_UD seems like a likely * dereferenced into. BRW_REGISTER_TYPE_UD seems like a likely

View File

@ -610,8 +610,9 @@ type_size_xvec4(const struct glsl_type *type, bool as_vec4, bool bindless)
return 1; return 1;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
/* Samplers take up no register space, since they're baked in at case GLSL_TYPE_TEXTURE:
* link time. /* Samplers and textures take up no register space, since they're baked
* in at link time.
*/ */
return bindless ? 1 : 0; return bindless ? 1 : 0;
case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ATOMIC_UINT:

View File

@ -2543,6 +2543,7 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
columns = 1; columns = 1;
break; break;
case GLSL_TYPE_SAMPLER: case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE: case GLSL_TYPE_IMAGE:
case GLSL_TYPE_SUBROUTINE: case GLSL_TYPE_SUBROUTINE:
format = uniform_native; format = uniform_native;