Commit f87ffd5c authored by Carl Worth's avatar Carl Worth
Browse files

glsl: Add convenience function get_sampler_instance



This is similar to the existing functions get_instance,
get_array_instance, etc. for getting a type singleton. The new
get_sampler_instance() function will be used by the upcoming shader
cache.
Reviewed-by: default avatarIan Romanick <ian.d.romanick@intel.com>
Reviewed-by: default avatarMatt Turner <mattst88@gmail.com>
parent 127c9724
......@@ -474,6 +474,117 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
return error_type;
}
const glsl_type *
glsl_type::get_sampler_instance(enum glsl_sampler_dim dim,
bool shadow,
bool array,
glsl_base_type type)
{
switch (type) {
case GLSL_TYPE_FLOAT:
switch (dim) {
case GLSL_SAMPLER_DIM_1D:
if (shadow)
return (array ? sampler1DArrayShadow_type : sampler1DShadow_type);
else
return (array ? sampler1DArray_type : sampler1D_type);
case GLSL_SAMPLER_DIM_2D:
if (shadow)
return (array ? sampler2DArrayShadow_type : sampler2DShadow_type);
else
return (array ? sampler2DArray_type : sampler2D_type);
case GLSL_SAMPLER_DIM_3D:
if (shadow || array)
return error_type;
else
return sampler3D_type;
case GLSL_SAMPLER_DIM_CUBE:
if (shadow)
return (array ? samplerCubeArrayShadow_type : samplerCubeShadow_type);
else
return (array ? samplerCubeArray_type : samplerCube_type);
case GLSL_SAMPLER_DIM_RECT:
if (array)
return error_type;
if (shadow)
return sampler2DRectShadow_type;
else
return sampler2DRect_type;
case GLSL_SAMPLER_DIM_BUF:
if (shadow || array)
return error_type;
else
return samplerBuffer_type;
case GLSL_SAMPLER_DIM_MS:
if (shadow)
return error_type;
return (array ? sampler2DMSArray_type : sampler2DMS_type);
case GLSL_SAMPLER_DIM_EXTERNAL:
if (shadow || array)
return error_type;
else
return samplerExternalOES_type;
}
case GLSL_TYPE_INT:
if (shadow)
return error_type;
switch (dim) {
case GLSL_SAMPLER_DIM_1D:
return (array ? isampler1DArray_type : isampler1D_type);
case GLSL_SAMPLER_DIM_2D:
return (array ? isampler2DArray_type : isampler2D_type);
case GLSL_SAMPLER_DIM_3D:
if (array)
return error_type;
return isampler3D_type;
case GLSL_SAMPLER_DIM_CUBE:
return (array ? isamplerCubeArray_type : isamplerCube_type);
case GLSL_SAMPLER_DIM_RECT:
if (array)
return error_type;
return isampler2DRect_type;
case GLSL_SAMPLER_DIM_BUF:
if (array)
return error_type;
return isamplerBuffer_type;
case GLSL_SAMPLER_DIM_MS:
return (array ? isampler2DMSArray_type : isampler2DMS_type);
case GLSL_SAMPLER_DIM_EXTERNAL:
return error_type;
}
case GLSL_TYPE_UINT:
if (shadow)
return error_type;
switch (dim) {
case GLSL_SAMPLER_DIM_1D:
return (array ? usampler1DArray_type : usampler1D_type);
case GLSL_SAMPLER_DIM_2D:
return (array ? usampler2DArray_type : usampler2D_type);
case GLSL_SAMPLER_DIM_3D:
if (array)
return error_type;
return usampler3D_type;
case GLSL_SAMPLER_DIM_CUBE:
return (array ? usamplerCubeArray_type : usamplerCube_type);
case GLSL_SAMPLER_DIM_RECT:
if (array)
return error_type;
return usampler2DRect_type;
case GLSL_SAMPLER_DIM_BUF:
if (array)
return error_type;
return usamplerBuffer_type;
case GLSL_SAMPLER_DIM_MS:
return (array ? usampler2DMSArray_type : usampler2DMS_type);
case GLSL_SAMPLER_DIM_EXTERNAL:
return error_type;
}
default:
return error_type;
}
unreachable("switch statement above should be complete");
}
const glsl_type *
glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
......
......@@ -243,6 +243,15 @@ struct glsl_type {
static const glsl_type *get_instance(unsigned base_type, unsigned rows,
unsigned columns);
/**
* Get the instance of a sampler type
*/
static const glsl_type *get_sampler_instance(enum glsl_sampler_dim dim,
bool shadow,
bool array,
glsl_base_type type);
/**
* Get the instance of an array type
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment