[Mesa-dev] [RFC PATCH 06/26] glsl: add new 'bindless' parameter to get_{sampler, image}_instance()

Samuel Pitoiset samuel.pitoiset at gmail.com
Tue Apr 11 16:48:17 UTC 2017


For replacing sampler/image types to the corresponding bindless
type, it's convenient to re-use get_{sampler,image}_instance()
instead of doing a one-by-one comparison.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/compiler/glsl/shader_cache.cpp |   6 +-
 src/compiler/glsl_types.cpp        | 221 +++++++++++++++++++++++++++----------
 src/compiler/glsl_types.h          |   7 +-
 src/compiler/nir_types.cpp         |   5 +-
 4 files changed, 176 insertions(+), 63 deletions(-)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index f5e6a22bb9..06d772e2f4 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -164,13 +164,15 @@ decode_type_from_blob(struct blob_reader *blob)
       return glsl_type::get_sampler_instance((enum glsl_sampler_dim) ((u >> 4) & 0x07),
                                              (u >> 3) & 0x01,
                                              (u >> 2) & 0x01,
-                                             (glsl_base_type) ((u >> 0) & 0x03));
+                                             (glsl_base_type) ((u >> 0) & 0x03),
+                                             false);
    case GLSL_TYPE_SUBROUTINE:
       return glsl_type::get_subroutine_instance(blob_read_string(blob));
    case GLSL_TYPE_IMAGE:
       return glsl_type::get_image_instance((enum glsl_sampler_dim) ((u >> 3) & 0x07),
                                              (u >> 2) & 0x01,
-                                             (glsl_base_type) ((u >> 0) & 0x03));
+                                             (glsl_base_type) ((u >> 0) & 0x03),
+                                             false);
    case GLSL_TYPE_ATOMIC_UINT:
       return glsl_type::atomic_uint_type;
    case GLSL_TYPE_ARRAY: {
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index c7a41b785e..cf0fe71d1a 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -668,49 +668,82 @@ const glsl_type *
 glsl_type::get_sampler_instance(enum glsl_sampler_dim dim,
                                 bool shadow,
                                 bool array,
-                                glsl_base_type type)
+                                glsl_base_type type,
+                                bool bindless)
 {
    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);
+         if (bindless) {
+            if (shadow)
+               return (array ? sampler1DArrayShadowBindless_type : sampler1DShadowBindless_type);
+            else
+               return (array ? sampler1DArrayBindless_type : sampler1DBindless_type);
+
+         } else {
+            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);
+         if (bindless) {
+            if (shadow)
+               return (array ? sampler2DArrayShadowBindless_type : sampler2DShadowBindless_type);
+            else
+               return (array ? sampler2DArrayBindless_type : sampler2DBindless_type);
+         } else {
+            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;
+            return bindless ? sampler3DBindless_type : sampler3D_type;
       case GLSL_SAMPLER_DIM_CUBE:
-         if (shadow)
-            return (array ? samplerCubeArrayShadow_type : samplerCubeShadow_type);
-         else
-            return (array ? samplerCubeArray_type : samplerCube_type);
+         if (bindless) {
+             if (shadow)
+               return (array ? samplerCubeArrayShadowBindless_type : samplerCubeShadowBindless_type);
+            else
+               return (array ? samplerCubeArrayBindless_type : samplerCubeBindless_type);
+         } else {
+            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;
+         if (bindless) {
+            if (shadow)
+               return sampler2DRectShadowBindless_type;
+            else
+               return sampler2DRectBindless_type;
+         } else {
+            if (shadow)
+               return sampler2DRectShadow_type;
+            else
+               return sampler2DRect_type;
+         }
       case GLSL_SAMPLER_DIM_BUF:
          if (shadow || array)
             return error_type;
          else
-            return samplerBuffer_type;
+            return bindless ? samplerBufferBindless_type : samplerBuffer_type;
       case GLSL_SAMPLER_DIM_MS:
          if (shadow)
             return error_type;
-         return (array ? sampler2DMSArray_type : sampler2DMS_type);
+         if (bindless)
+            return (array ? sampler2DMSArrayBindless_type : sampler2DMSBindless_type);
+         else
+            return (array ? sampler2DMSArray_type : sampler2DMS_type);
       case GLSL_SAMPLER_DIM_EXTERNAL:
-         if (shadow || array)
+         if (shadow || array || bindless)
             return error_type;
          else
             return samplerExternalOES_type;
@@ -723,25 +756,37 @@ glsl_type::get_sampler_instance(enum glsl_sampler_dim dim,
          return error_type;
       switch (dim) {
       case GLSL_SAMPLER_DIM_1D:
-         return (array ? isampler1DArray_type : isampler1D_type);
+         if (bindless)
+            return (array ? isampler1DArrayBindless_type : isampler1DBindless_type);
+         else
+            return (array ? isampler1DArray_type : isampler1D_type);
       case GLSL_SAMPLER_DIM_2D:
-         return (array ? isampler2DArray_type : isampler2D_type);
+         if (bindless)
+            return (array ? isampler2DArrayBindless_type : isampler2DBindless_type);
+         else
+            return (array ? isampler2DArray_type : isampler2D_type);
       case GLSL_SAMPLER_DIM_3D:
          if (array)
             return error_type;
-         return isampler3D_type;
+         return bindless ? isampler2DBindless_type : isampler3D_type;
       case GLSL_SAMPLER_DIM_CUBE:
-         return (array ? isamplerCubeArray_type : isamplerCube_type);
+         if (bindless)
+            return (array ? isamplerCubeArrayBindless_type : isamplerCubeBindless_type);
+         else
+            return (array ? isamplerCubeArray_type : isamplerCube_type);
       case GLSL_SAMPLER_DIM_RECT:
          if (array)
             return error_type;
-         return isampler2DRect_type;
+         return bindless ? isampler2DRectBindless_type : isampler2DRect_type;
       case GLSL_SAMPLER_DIM_BUF:
          if (array)
             return error_type;
-         return isamplerBuffer_type;
+         return bindless ? isamplerBufferBindless_type : isamplerBuffer_type;
       case GLSL_SAMPLER_DIM_MS:
-         return (array ? isampler2DMSArray_type : isampler2DMS_type);
+         if (bindless)
+            return (array ? isampler2DMSArrayBindless_type : isampler2DMSBindless_type);
+         else
+            return (array ? isampler2DMSArray_type : isampler2DMS_type);
       case GLSL_SAMPLER_DIM_EXTERNAL:
          return error_type;
       case GLSL_SAMPLER_DIM_SUBPASS:
@@ -753,25 +798,37 @@ glsl_type::get_sampler_instance(enum glsl_sampler_dim dim,
          return error_type;
       switch (dim) {
       case GLSL_SAMPLER_DIM_1D:
-         return (array ? usampler1DArray_type : usampler1D_type);
+         if (bindless)
+            return (array ? usampler1DArrayBindless_type : usampler1DBindless_type);
+         else
+            return (array ? usampler1DArray_type : usampler1D_type);
       case GLSL_SAMPLER_DIM_2D:
-         return (array ? usampler2DArray_type : usampler2D_type);
+         if (bindless)
+            return (array ? usampler2DArrayBindless_type : usampler2DBindless_type);
+         else
+            return (array ? usampler2DArray_type : usampler2D_type);
       case GLSL_SAMPLER_DIM_3D:
          if (array)
             return error_type;
-         return usampler3D_type;
+         return bindless ? usampler3DBindless_type : usampler3D_type;
       case GLSL_SAMPLER_DIM_CUBE:
-         return (array ? usamplerCubeArray_type : usamplerCube_type);
+         if (bindless)
+            return (array ? usamplerCubeArrayBindless_type : usamplerCubeBindless_type);
+         else
+            return (array ? usamplerCubeArray_type : usamplerCube_type);
       case GLSL_SAMPLER_DIM_RECT:
          if (array)
             return error_type;
-         return usampler2DRect_type;
+         return bindless ? usampler2DRectBindless_type : usampler2DRect_type;
       case GLSL_SAMPLER_DIM_BUF:
          if (array)
             return error_type;
-         return usamplerBuffer_type;
+         return bindless ? usamplerBufferBindless_type : usamplerBuffer_type;
       case GLSL_SAMPLER_DIM_MS:
-         return (array ? usampler2DMSArray_type : usampler2DMS_type);
+         if (bindless)
+            return (array ? usampler2DMSArrayBindless_type : usampler2DMSBindless_type);
+         else
+            return (array ? usampler2DMSArray_type : usampler2DMS_type);
       case GLSL_SAMPLER_DIM_EXTERNAL:
          return error_type;
       case GLSL_SAMPLER_DIM_SUBPASS:
@@ -787,34 +844,52 @@ glsl_type::get_sampler_instance(enum glsl_sampler_dim dim,
 
 const glsl_type *
 glsl_type::get_image_instance(enum glsl_sampler_dim dim,
-                              bool array, glsl_base_type type)
+                              bool array,
+                              glsl_base_type type,
+                              bool bindless)
 {
    switch (type) {
    case GLSL_TYPE_FLOAT:
       switch (dim) {
       case GLSL_SAMPLER_DIM_1D:
-         return (array ? image1DArray_type : image1D_type);
+         if (bindless)
+            return (array ? image1DArrayBindless_type : image1DBindless_type);
+         else
+            return (array ? image1DArray_type : image1D_type);
       case GLSL_SAMPLER_DIM_2D:
-         return (array ? image2DArray_type : image2D_type);
+         if (bindless)
+            return (array ? image2DArrayBindless_type : image2DBindless_type);
+         else
+            return (array ? image2DArray_type : image2D_type);
       case GLSL_SAMPLER_DIM_3D:
-         return image3D_type;
+         return bindless ? image3DBindless_type : image3D_type;
       case GLSL_SAMPLER_DIM_CUBE:
-         return (array ? imageCubeArray_type : imageCube_type);
+         if (bindless)
+            return (array ? imageCubeArrayBindless_type : imageCubeBindless_type);
+         else
+            return (array ? imageCubeArray_type : imageCube_type);
       case GLSL_SAMPLER_DIM_RECT:
          if (array)
             return error_type;
          else
-            return image2DRect_type;
+            return bindless ?  image2DRectBindless_type : image2DRect_type;
       case GLSL_SAMPLER_DIM_BUF:
          if (array)
             return error_type;
          else
-            return imageBuffer_type;
+            return bindless ? imageBufferBindless_type : imageBuffer_type;
       case GLSL_SAMPLER_DIM_MS:
-         return (array ? image2DMSArray_type : image2DMS_type);
+         if (bindless)
+            return (array ? image2DMSArrayBindless_type : image2DMSBindless_type);
+         else
+            return (array ? image2DMSArray_type : image2DMS_type);
       case GLSL_SAMPLER_DIM_SUBPASS:
+         if (bindless)
+            return error_type;
          return subpassInput_type;
       case GLSL_SAMPLER_DIM_SUBPASS_MS:
+         if (bindless)
+            return error_type;
          return subpassInputMS_type;
       case GLSL_SAMPLER_DIM_EXTERNAL:
          return error_type;
@@ -822,28 +897,44 @@ glsl_type::get_image_instance(enum glsl_sampler_dim dim,
    case GLSL_TYPE_INT:
       switch (dim) {
       case GLSL_SAMPLER_DIM_1D:
-         return (array ? iimage1DArray_type : iimage1D_type);
+         if (bindless)
+            return (array ? iimage1DArrayBindless_type : iimage1DBindless_type);
+         else
+            return (array ? iimage1DArray_type : iimage1D_type);
       case GLSL_SAMPLER_DIM_2D:
-         return (array ? iimage2DArray_type : iimage2D_type);
+         if (bindless)
+            return (array ? iimage2DArrayBindless_type : iimage2DBindless_type);
+         else
+            return (array ? iimage2DArray_type : iimage2D_type);
       case GLSL_SAMPLER_DIM_3D:
          if (array)
             return error_type;
-         return iimage3D_type;
+         return bindless ? iimage3DBindless_type : iimage3D_type;
       case GLSL_SAMPLER_DIM_CUBE:
-         return (array ? iimageCubeArray_type : iimageCube_type);
+         if (bindless)
+            return (array ? iimageCubeArrayBindless_type : iimageCubeBindless_type);
+         else
+            return (array ? iimageCubeArray_type : iimageCube_type);
       case GLSL_SAMPLER_DIM_RECT:
          if (array)
             return error_type;
-         return iimage2DRect_type;
+         return bindless ? iimage2DRectBindless_type : iimage2DRect_type;
       case GLSL_SAMPLER_DIM_BUF:
          if (array)
             return error_type;
-         return iimageBuffer_type;
+         return bindless ? iimageBufferBindless_type : iimageBuffer_type;
       case GLSL_SAMPLER_DIM_MS:
-         return (array ? iimage2DMSArray_type : iimage2DMS_type);
+         if (bindless)
+            return (array ? iimage2DMSArrayBindless_type : iimage2DMSBindless_type);
+         else
+            return (array ? iimage2DMSArray_type : iimage2DMS_type);
       case GLSL_SAMPLER_DIM_SUBPASS:
+         if (bindless)
+            return error_type;
          return isubpassInput_type;
       case GLSL_SAMPLER_DIM_SUBPASS_MS:
+         if (bindless)
+            return error_type;
          return isubpassInputMS_type;
       case GLSL_SAMPLER_DIM_EXTERNAL:
          return error_type;
@@ -851,28 +942,44 @@ glsl_type::get_image_instance(enum glsl_sampler_dim dim,
    case GLSL_TYPE_UINT:
       switch (dim) {
       case GLSL_SAMPLER_DIM_1D:
-         return (array ? uimage1DArray_type : uimage1D_type);
+         if (bindless)
+            return (array ? uimage1DArrayBindless_type : uimage1DBindless_type);
+         else
+            return (array ? uimage1DArray_type : uimage1D_type);
       case GLSL_SAMPLER_DIM_2D:
-         return (array ? uimage2DArray_type : uimage2D_type);
+         if (bindless)
+            return (array ? uimage2DArrayBindless_type : uimage2DBindless_type);
+         else
+            return (array ? uimage2DArray_type : uimage2D_type);
       case GLSL_SAMPLER_DIM_3D:
          if (array)
             return error_type;
-         return uimage3D_type;
+         return bindless ? uimage3DBindless_type : uimage3D_type;
       case GLSL_SAMPLER_DIM_CUBE:
-         return (array ? uimageCubeArray_type : uimageCube_type);
+         if (bindless)
+            return (array ? uimageCubeArrayBindless_type : uimageCubeBindless_type);
+         else
+            return (array ? uimageCubeArray_type : uimageCube_type);
       case GLSL_SAMPLER_DIM_RECT:
          if (array)
             return error_type;
-         return uimage2DRect_type;
+         return bindless ? uimage2DRectBindless_type : uimage2DRect_type;
       case GLSL_SAMPLER_DIM_BUF:
          if (array)
             return error_type;
-         return uimageBuffer_type;
+         return bindless ? uimageBufferBindless_type : uimageBuffer_type;
       case GLSL_SAMPLER_DIM_MS:
-         return (array ? uimage2DMSArray_type : uimage2DMS_type);
+         if (bindless)
+            return (array ? uimage2DMSArrayBindless_type : uimage2DMSBindless_type);
+         else
+            return (array ? uimage2DMSArray_type : uimage2DMS_type);
       case GLSL_SAMPLER_DIM_SUBPASS:
+         if (bindless)
+            return error_type;
          return usubpassInput_type;
       case GLSL_SAMPLER_DIM_SUBPASS_MS:
+         if (bindless)
+            return error_type;
          return usubpassInputMS_type;
       case GLSL_SAMPLER_DIM_EXTERNAL:
          return error_type;
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index 230fc7dbee..28391ddcbe 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -269,10 +269,13 @@ struct glsl_type {
    static const glsl_type *get_sampler_instance(enum glsl_sampler_dim dim,
                                                 bool shadow,
                                                 bool array,
-                                                glsl_base_type type);
+                                                glsl_base_type type,
+                                                bool bindless);
 
    static const glsl_type *get_image_instance(enum glsl_sampler_dim dim,
-                                              bool array, glsl_base_type type);
+                                              bool array,
+                                              glsl_base_type type,
+                                              bool bindless);
 
    /**
     * Get the instance of an array type
diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
index 52fd0e95c8..8d32f6fdee 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -343,7 +343,8 @@ const struct glsl_type *
 glsl_sampler_type(enum glsl_sampler_dim dim, bool is_shadow, bool is_array,
                   enum glsl_base_type base_type)
 {
-   return glsl_type::get_sampler_instance(dim, is_shadow, is_array, base_type);
+   return glsl_type::get_sampler_instance(dim, is_shadow, is_array, base_type,
+                                          false);
 }
 
 const struct glsl_type *
@@ -356,7 +357,7 @@ const struct glsl_type *
 glsl_image_type(enum glsl_sampler_dim dim, bool is_array,
                 enum glsl_base_type base_type)
 {
-   return glsl_type::get_image_instance(dim, is_array, base_type);
+   return glsl_type::get_image_instance(dim, is_array, base_type, false);
 }
 
 const glsl_type *
-- 
2.12.2



More information about the mesa-dev mailing list