[Bf-blender-cvs] [91cc1f38aef] master: GPUMaterial: Add support for different sampler state per image sampler

Clément Foucault noreply at git.blender.org
Wed Jun 3 16:24:13 CEST 2020


Commit: 91cc1f38aefdac70c2de2e19cec0d349329aa925
Author: Clément Foucault
Date:   Wed Jun 3 13:35:15 2020 +0200
Branches: master
https://developer.blender.org/rB91cc1f38aefdac70c2de2e19cec0d349329aa925

GPUMaterial: Add support for different sampler state per image sampler

This bridge between the new sampler state support from GPUTexture and
draw material handling.

The Sampler State is just the one from the texture for now. No change in
logic.

===================================================================

M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/gpu/GPU_material.h
M	source/blender/gpu/intern/gpu_node_graph.c
M	source/blender/nodes/shader/nodes/node_shader_tex_environment.c
M	source/blender/nodes/shader/nodes/node_shader_tex_image.c

===================================================================

diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index ebfcf29fc2d..376bc69b392 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -1274,12 +1274,13 @@ static DRWShadingGroup *drw_shgroup_material_create_ex(GPUPass *gpupass, DRWPass
 static void drw_shgroup_material_texture(DRWShadingGroup *grp,
                                          GPUMaterialTexture *tex,
                                          const char *name,
+                                         eGPUSamplerState state,
                                          int textarget)
 {
   GPUTexture *gputex = GPU_texture_from_blender(tex->ima, tex->iuser, NULL, textarget);
 
   int loc = GPU_shader_get_texture_binding(grp->shader, name);
-  drw_shgroup_uniform_create_ex(grp, loc, DRW_UNIFORM_TEXTURE, gputex, GPU_SAMPLER_MAX, 0, 1);
+  drw_shgroup_uniform_create_ex(grp, loc, DRW_UNIFORM_TEXTURE, gputex, state, 0, 1);
 
   GPUTexture **gputex_ref = BLI_memblock_alloc(DST.vmempool->images);
   *gputex_ref = gputex;
@@ -1295,11 +1296,14 @@ void DRW_shgroup_add_material_resources(DRWShadingGroup *grp, struct GPUMaterial
     if (tex->ima) {
       /* Image */
       if (tex->tiled_mapping_name[0]) {
-        drw_shgroup_material_texture(grp, tex, tex->sampler_name, GL_TEXTURE_2D_ARRAY);
-        drw_shgroup_material_texture(grp, tex, tex->tiled_mapping_name, GL_TEXTURE_1D_ARRAY);
+        drw_shgroup_material_texture(
+            grp, tex, tex->sampler_name, tex->sampler_state, GL_TEXTURE_2D_ARRAY);
+        drw_shgroup_material_texture(
+            grp, tex, tex->tiled_mapping_name, tex->sampler_state, GL_TEXTURE_1D_ARRAY);
       }
       else {
-        drw_shgroup_material_texture(grp, tex, tex->sampler_name, GL_TEXTURE_2D);
+        drw_shgroup_material_texture(
+            grp, tex, tex->sampler_name, tex->sampler_state, GL_TEXTURE_2D);
       }
     }
     else if (tex->colorband) {
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index c23960da1ed..eeb2d2caef2 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -29,6 +29,8 @@
 
 #include "BLI_sys_types.h" /* for bool */
 
+#include "GPU_texture.h" /* for eGPUSamplerState */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -138,8 +140,14 @@ typedef enum eGPUMaterialStatus {
 GPUNodeLink *GPU_constant(const float *num);
 GPUNodeLink *GPU_uniform(const float *num);
 GPUNodeLink *GPU_attribute(GPUMaterial *mat, CustomDataType type, const char *name);
-GPUNodeLink *GPU_image(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser);
-GPUNodeLink *GPU_image_tiled(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser);
+GPUNodeLink *GPU_image(GPUMaterial *mat,
+                       struct Image *ima,
+                       struct ImageUser *iuser,
+                       eGPUSamplerState sampler_state);
+GPUNodeLink *GPU_image_tiled(GPUMaterial *mat,
+                             struct Image *ima,
+                             struct ImageUser *iuser,
+                             eGPUSamplerState sampler_state);
 GPUNodeLink *GPU_image_tiled_mapping(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser);
 GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *layer);
 GPUNodeLink *GPU_volume_grid(GPUMaterial *mat, const char *name);
@@ -229,6 +237,7 @@ typedef struct GPUMaterialTexture {
   char sampler_name[32];       /* Name of sampler in GLSL. */
   char tiled_mapping_name[32]; /* Name of tile mapping sampler in GLSL. */
   int users;
+  int sampler_state; /* eGPUSamplerState */
 } GPUMaterialTexture;
 
 typedef struct GPUMaterialVolumeGrid {
diff --git a/source/blender/gpu/intern/gpu_node_graph.c b/source/blender/gpu/intern/gpu_node_graph.c
index 876a6bef670..17d97dc05e2 100644
--- a/source/blender/gpu/intern/gpu_node_graph.c
+++ b/source/blender/gpu/intern/gpu_node_graph.c
@@ -34,6 +34,8 @@
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
+#include "GPU_texture.h"
+
 #include "gpu_material_library.h"
 #include "gpu_node_graph.h"
 
@@ -298,13 +300,14 @@ static GPUMaterialTexture *gpu_node_graph_add_texture(GPUNodeGraph *graph,
                                                       Image *ima,
                                                       ImageUser *iuser,
                                                       struct GPUTexture **colorband,
-                                                      GPUNodeLinkType link_type)
+                                                      GPUNodeLinkType link_type,
+                                                      eGPUSamplerState sampler_state)
 {
   /* Find existing texture. */
   int num_textures = 0;
   GPUMaterialTexture *tex = graph->textures.first;
   for (; tex; tex = tex->next) {
-    if (tex->ima == ima && tex->colorband == colorband) {
+    if (tex->ima == ima && tex->colorband == colorband && tex->sampler_state == sampler_state) {
       break;
     }
     num_textures++;
@@ -316,6 +319,7 @@ static GPUMaterialTexture *gpu_node_graph_add_texture(GPUNodeGraph *graph,
     tex->ima = ima;
     tex->iuser = iuser;
     tex->colorband = colorband;
+    tex->sampler_state = sampler_state;
     BLI_snprintf(tex->sampler_name, sizeof(tex->sampler_name), "samp%d", num_textures);
     if (ELEM(link_type, GPU_NODE_LINK_IMAGE_TILED, GPU_NODE_LINK_IMAGE_TILED_MAPPING)) {
       BLI_snprintf(
@@ -389,21 +393,29 @@ GPUNodeLink *GPU_uniform(const float *num)
   return link;
 }
 
-GPUNodeLink *GPU_image(GPUMaterial *mat, Image *ima, ImageUser *iuser)
+GPUNodeLink *GPU_image(GPUMaterial *mat,
+                       Image *ima,
+                       ImageUser *iuser,
+                       eGPUSamplerState sampler_state)
 {
   GPUNodeGraph *graph = gpu_material_node_graph(mat);
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_IMAGE;
-  link->texture = gpu_node_graph_add_texture(graph, ima, iuser, NULL, link->link_type);
+  link->texture = gpu_node_graph_add_texture(
+      graph, ima, iuser, NULL, link->link_type, sampler_state);
   return link;
 }
 
-GPUNodeLink *GPU_image_tiled(GPUMaterial *mat, Image *ima, ImageUser *iuser)
+GPUNodeLink *GPU_image_tiled(GPUMaterial *mat,
+                             Image *ima,
+                             ImageUser *iuser,
+                             eGPUSamplerState sampler_state)
 {
   GPUNodeGraph *graph = gpu_material_node_graph(mat);
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_IMAGE_TILED;
-  link->texture = gpu_node_graph_add_texture(graph, ima, iuser, NULL, link->link_type);
+  link->texture = gpu_node_graph_add_texture(
+      graph, ima, iuser, NULL, link->link_type, sampler_state);
   return link;
 }
 
@@ -412,7 +424,8 @@ GPUNodeLink *GPU_image_tiled_mapping(GPUMaterial *mat, Image *ima, ImageUser *iu
   GPUNodeGraph *graph = gpu_material_node_graph(mat);
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_IMAGE_TILED_MAPPING;
-  link->texture = gpu_node_graph_add_texture(graph, ima, iuser, NULL, link->link_type);
+  link->texture = gpu_node_graph_add_texture(
+      graph, ima, iuser, NULL, link->link_type, GPU_SAMPLER_MAX);
   return link;
 }
 
@@ -424,7 +437,8 @@ GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *ro
   GPUNodeGraph *graph = gpu_material_node_graph(mat);
   GPUNodeLink *link = gpu_node_link_create();
   link->link_type = GPU_NODE_LINK_COLORBAND;
-  link->texture = gpu_node_graph_add_texture(graph, NULL, NULL, colorband, link->link_type);
+  link->texture = gpu_node_graph_add_texture(
+      graph, NULL, NULL, colorband, link->link_type, GPU_SAMPLER_MAX);
   return link;
 }
 
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
index fd4efb1b7ec..a62c2ee22b2 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
@@ -56,6 +56,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat,
   bNode *node_original = node->original ? node->original : node;
   NodeTexImage *tex_original = node_original->storage;
   ImageUser *iuser = &tex_original->iuser;
+  eGPUSamplerState sampler_state = GPU_SAMPLER_MAX;
 
   GPUNodeLink *outalpha;
 
@@ -78,7 +79,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat,
              "node_tex_environment_equirectangular",
              in[0].link,
              GPU_constant(&clamp_size),
-             GPU_image(mat, ima, iuser),
+             GPU_image(mat, ima, iuser, sampler_state),
              &in[0].link);
   }
   else {
@@ -93,7 +94,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat,
       GPU_link(mat,
                "node_tex_image_linear_no_mip",
                in[0].link,
-               GPU_image(mat, ima, iuser),
+               GPU_image(mat, ima, iuser, sampler_state),
                &out[0].link,
                &outalpha);
       break;
@@ -101,7 +102,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat,
       GPU_link(mat,
                "node_tex_image_nearest",
                in[0].link,
-               GPU_image(mat, ima, iuser),
+               GPU_image(mat, ima, iuser, sampler_state),
                &out[0].link,
                &outalpha);
       break;
@@ -109,7 +110,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat,
       GPU_link(mat,
                "node_tex_image_cubic",
                in[0].link,
-               GPU_image(mat, ima, iuser),
+               GPU_image(mat, ima, iuser, sampler_state),
                &out[0].link,
                &outalpha);
       break;
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c
index bfef9341913..87114fe23b5 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c
@@ -118,6 +118,8 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat,
 
   node_shad

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list