Mesa (master): glsl: Factor out the sampler dim coordinate components switch statement.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Feb 24 19:09:43 UTC 2020
Module: Mesa
Branch: master
Commit: 5072719e66b0f97a572f36e86bd5396ed2ebc915
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=5072719e66b0f97a572f36e86bd5396ed2ebc915
Author: Eric Anholt <eric at anholt.net>
Date: Wed Feb 5 14:36:01 2020 -0800
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 at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3728>
---
src/compiler/glsl_types.cpp | 50 ++++++++++++++++++++++++---------------------
src/compiler/glsl_types.h | 9 ++++----
2 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 3af8e034cd1..98139524337 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -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");
+ }
+}
+
+}
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index 4b1f0ab09ea..9b64427df67 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -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 */
More information about the mesa-commit
mailing list