glsl: Factor out the sampler dim coordinate components switch statement.
I want to reuse this in NIR image intrinsics in backends, which just have dim/is_array. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3728>
This commit is contained in:
+27
-23
@@ -2582,29 +2582,8 @@ glsl_type::count_dword_slots(bool is_bindless) const
|
||||
int
|
||||
glsl_type::coordinate_components() const
|
||||
{
|
||||
int size;
|
||||
|
||||
switch (sampler_dimensionality) {
|
||||
case GLSL_SAMPLER_DIM_1D:
|
||||
case GLSL_SAMPLER_DIM_BUF:
|
||||
size = 1;
|
||||
break;
|
||||
case GLSL_SAMPLER_DIM_2D:
|
||||
case GLSL_SAMPLER_DIM_RECT:
|
||||
case GLSL_SAMPLER_DIM_MS:
|
||||
case GLSL_SAMPLER_DIM_EXTERNAL:
|
||||
case GLSL_SAMPLER_DIM_SUBPASS:
|
||||
size = 2;
|
||||
break;
|
||||
case GLSL_SAMPLER_DIM_3D:
|
||||
case GLSL_SAMPLER_DIM_CUBE:
|
||||
size = 3;
|
||||
break;
|
||||
default:
|
||||
assert(!"Should not get here.");
|
||||
size = 1;
|
||||
break;
|
||||
}
|
||||
enum glsl_sampler_dim dim = (enum glsl_sampler_dim)sampler_dimensionality;
|
||||
int size = glsl_get_sampler_dim_coordinate_components(dim);
|
||||
|
||||
/* Array textures need an additional component for the array index, except
|
||||
* for cubemap array images that behave like a 2D array of interleaved
|
||||
@@ -2937,3 +2916,28 @@ glsl_type::cl_size() const
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
int
|
||||
glsl_get_sampler_dim_coordinate_components(enum glsl_sampler_dim dim)
|
||||
{
|
||||
switch (dim) {
|
||||
case GLSL_SAMPLER_DIM_1D:
|
||||
case GLSL_SAMPLER_DIM_BUF:
|
||||
return 1;
|
||||
case GLSL_SAMPLER_DIM_2D:
|
||||
case GLSL_SAMPLER_DIM_RECT:
|
||||
case GLSL_SAMPLER_DIM_MS:
|
||||
case GLSL_SAMPLER_DIM_EXTERNAL:
|
||||
case GLSL_SAMPLER_DIM_SUBPASS:
|
||||
return 2;
|
||||
case GLSL_SAMPLER_DIM_3D:
|
||||
case GLSL_SAMPLER_DIM_CUBE:
|
||||
return 3;
|
||||
default:
|
||||
unreachable("Unknown sampler dim");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,10 +60,6 @@ void encode_type_to_blob(struct blob *blob, const struct glsl_type *type);
|
||||
|
||||
const struct glsl_type *decode_type_from_blob(struct blob_reader *blob);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef void (*glsl_type_size_align_func)(const struct glsl_type *type,
|
||||
unsigned *size, unsigned *align);
|
||||
|
||||
@@ -231,6 +227,9 @@ enum glsl_sampler_dim {
|
||||
GLSL_SAMPLER_DIM_SUBPASS_MS, /* for multisampled vulkan input attachments */
|
||||
};
|
||||
|
||||
int
|
||||
glsl_get_sampler_dim_coordinate_components(enum glsl_sampler_dim dim);
|
||||
|
||||
enum glsl_matrix_layout {
|
||||
/**
|
||||
* The layout of the matrix is inherited from the object containing the
|
||||
@@ -260,6 +259,8 @@ enum {
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
||||
#include "GL/gl.h"
|
||||
#include "util/ralloc.h"
|
||||
#include "main/menums.h" /* for gl_texture_index, C++'s enum rules are broken */
|
||||
|
||||
Reference in New Issue
Block a user