[Bf-blender-cvs] [322dc723165] master: Cleanup: refactor GPU material attribute and texture requests
Brecht Van Lommel
noreply at git.blender.org
Sat Feb 15 21:13:33 CET 2020
Commit: 322dc723165a705c34df1e3246e500da1a9927de
Author: Brecht Van Lommel
Date: Fri Feb 14 10:47:20 2020 +0100
Branches: master
https://developer.blender.org/rB322dc723165a705c34df1e3246e500da1a9927de
Cleanup: refactor GPU material attribute and texture requests
===================================================================
M source/blender/draw/intern/draw_cache_impl_curve.c
M source/blender/draw/intern/draw_cache_impl_mesh.c
M source/blender/draw/intern/draw_manager_data.c
M source/blender/gpu/GPU_material.h
M source/blender/gpu/GPU_shader.h
M source/blender/gpu/intern/gpu_codegen.c
M source/blender/gpu/intern/gpu_material.c
M source/blender/gpu/intern/gpu_node_graph.c
M source/blender/gpu/intern/gpu_node_graph.h
===================================================================
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
index 1c3996e2290..20eff0fb6b8 100644
--- a/source/blender/draw/intern/draw_cache_impl_curve.c
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -307,16 +307,16 @@ static void curve_cd_calc_used_gpu_layers(int *cd_layers,
struct GPUMaterial **gpumat_array,
int gpumat_array_len)
{
- GPUVertAttrLayers gpu_attrs = {{{0}}};
for (int i = 0; i < gpumat_array_len; i++) {
struct GPUMaterial *gpumat = gpumat_array[i];
if (gpumat == NULL) {
continue;
}
- GPU_material_vertex_attrs(gpumat, &gpu_attrs);
- for (int j = 0; j < gpu_attrs.totlayer; j++) {
- const char *name = gpu_attrs.layer[j].name;
- int type = gpu_attrs.layer[j].type;
+
+ ListBase gpu_attrs = GPU_material_attributes(gpumat);
+ for (GPUMaterialAttribute *gpu_attr = gpu_attrs.first; gpu_attr; gpu_attr = gpu_attr->next) {
+ const char *name = gpu_attr->name;
+ int type = gpu_attr->type;
/* Curves cannot have named layers.
* Note: We could relax this assumption later. */
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index ed60e16c7cc..5b273159cdf 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -142,11 +142,10 @@ static DRW_MeshCDMask mesh_cd_calc_used_gpu_layers(const Mesh *me,
for (int i = 0; i < gpumat_array_len; i++) {
GPUMaterial *gpumat = gpumat_array[i];
if (gpumat) {
- GPUVertAttrLayers gpu_attrs;
- GPU_material_vertex_attrs(gpumat, &gpu_attrs);
- for (int j = 0; j < gpu_attrs.totlayer; j++) {
- const char *name = gpu_attrs.layer[j].name;
- int type = gpu_attrs.layer[j].type;
+ ListBase gpu_attrs = GPU_material_attributes(gpumat);
+ for (GPUMaterialAttribute *gpu_attr = gpu_attrs.first; gpu_attr; gpu_attr = gpu_attr->next) {
+ const char *name = gpu_attr->name;
+ int type = gpu_attr->type;
int layer = -1;
if (type == CD_AUTO_FROM_NAME) {
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index 1b2195b8e41..0af68181478 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -49,7 +49,6 @@
#include "GPU_material.h"
#include "intern/gpu_codegen.h"
-#include "intern/gpu_node_graph.h"
/* -------------------------------------------------------------------- */
/** \name Uniform Buffer Object (DRW_uniformbuffer)
@@ -1207,40 +1206,39 @@ static DRWShadingGroup *drw_shgroup_material_create_ex(GPUPass *gpupass, DRWPass
static DRWShadingGroup *drw_shgroup_material_inputs(DRWShadingGroup *grp,
struct GPUMaterial *material)
{
- ListBase *inputs = GPU_material_get_inputs(material);
+ ListBase textures = GPU_material_textures(material);
- /* Converting dynamic GPUInput to DRWUniform */
- for (GPUInput *input = inputs->first; input; input = input->next) {
- /* Textures */
- if (input->source == GPU_SOURCE_TEX) {
- GPUTexture *tex = NULL;
+ /* Bind all textures needed by the material. */
+ for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
+ GPUTexture *gputex;
- if (input->ima) {
- GPUTexture **tex_ref = BLI_memblock_alloc(DST.vmempool->images);
+ if (tex->ima) {
+ /* Image */
+ GPUTexture **gputex_ref = BLI_memblock_alloc(DST.vmempool->images);
- int textarget;
- if (input->type == GPU_TEX2D_ARRAY) {
- textarget = GL_TEXTURE_2D_ARRAY;
- }
- else if (input->type == GPU_TEX1D_ARRAY) {
- textarget = GL_TEXTURE_1D_ARRAY;
- }
- else {
- textarget = GL_TEXTURE_2D;
- }
- *tex_ref = tex = GPU_texture_from_blender(input->ima, input->iuser, NULL, textarget);
-
- GPU_texture_ref(tex);
+ int textarget;
+ if (tex->type == GPU_TEX2D_ARRAY) {
+ textarget = GL_TEXTURE_2D_ARRAY;
+ }
+ else if (tex->type == GPU_TEX1D_ARRAY) {
+ textarget = GL_TEXTURE_1D_ARRAY;
}
else {
- /* Color Ramps */
- tex = *input->coba;
+ textarget = GL_TEXTURE_2D;
}
+ *gputex_ref = gputex = GPU_texture_from_blender(tex->ima, tex->iuser, NULL, textarget);
- if (input->bindtex) {
- drw_shgroup_uniform_create_ex(grp, input->shaderloc, DRW_UNIFORM_TEXTURE, tex, 0, 1);
- }
+ GPU_texture_ref(gputex);
+ }
+ else if (tex->colorband) {
+ /* Color Ramp */
+ gputex = *tex->colorband;
}
+ else {
+ continue;
+ }
+
+ DRW_shgroup_uniform_texture(grp, tex->shadername, gputex);
}
GPUUniformBuffer *ubo = GPU_material_uniform_buffer_get(material);
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index 8c166ed6b64..075829065df 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -39,7 +39,6 @@ struct GPUNodeLink;
struct GPUNodeStack;
struct GPUTexture;
struct GPUUniformBuffer;
-struct GPUVertAttrLayers;
struct Image;
struct ImageUser;
struct ListBase;
@@ -161,7 +160,6 @@ GPUNodeLink *GPU_uniformbuffer_link_out(struct GPUMaterial *mat,
const int index);
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link);
-eGPUBuiltin GPU_get_material_builtins(GPUMaterial *material);
void GPU_material_sss_profile_create(GPUMaterial *material,
float radii[3],
@@ -201,8 +199,6 @@ struct GPUUniformBuffer *GPU_material_uniform_buffer_get(GPUMaterial *material);
void GPU_material_uniform_buffer_create(GPUMaterial *material, ListBase *inputs);
struct GPUUniformBuffer *GPU_material_create_sss_profile_ubo(void);
-void GPU_material_vertex_attrs(GPUMaterial *material, struct GPUVertAttrLayers *attrs);
-
bool GPU_material_use_domain_surface(GPUMaterial *mat);
bool GPU_material_use_domain_volume(GPUMaterial *mat);
@@ -213,6 +209,28 @@ void GPU_pass_cache_init(void);
void GPU_pass_cache_garbage_collect(void);
void GPU_pass_cache_free(void);
+/* Requested Material Attributes and Textures */
+
+typedef struct GPUMaterialAttribute {
+ struct GPUMaterialAttribute *next, *prev;
+ int type; /* CustomDataType */
+ char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
+ int id;
+} GPUMaterialAttribute;
+
+typedef struct GPUMaterialTexture {
+ struct GPUMaterialTexture *next, *prev;
+ eGPUType type;
+ struct Image *ima;
+ struct ImageUser *iuser;
+ struct GPUTexture **colorband;
+ char shadername[32]; /* Name of sampler in GLSL. */
+ int id;
+} GPUMaterialTexture;
+
+ListBase GPU_material_attributes(GPUMaterial *material);
+ListBase GPU_material_textures(GPUMaterial *material);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 1339873ec67..d5716cd1b31 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -382,16 +382,6 @@ void GPU_shader_free_builtin_shaders(void);
* This makes sure the GPUVertexFormat name buffer does not overflow. */
#define GPU_MAX_ATTR 15
-typedef struct GPUVertAttrLayers {
- struct {
- int type; /* CustomDataType */
- int attr_id;
- char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
- } layer[GPU_MAX_ATTR];
-
- int totlayer;
-} GPUVertAttrLayers;
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 2f9af536b8c..ed6bf20cff4 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -70,16 +70,13 @@ extern char datatoc_common_view_lib_glsl[];
static GPUPass *pass_cache = NULL;
static SpinLock pass_cache_spin;
-static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, GPUVertAttrLayers *attrs)
+static uint32_t gpu_pass_hash(const char *frag_gen, const char *defs, ListBase *attributes)
{
BLI_HashMurmur2A hm2a;
BLI_hash_mm2a_init(&hm2a, 0);
BLI_hash_mm2a_add(&hm2a, (uchar *)frag_gen, strlen(frag_gen));
- if (attrs) {
- for (int att_idx = 0; att_idx < attrs->totlayer; att_idx++) {
- char *name = attrs->layer[att_idx].name;
- BLI_hash_mm2a_add(&hm2a, (uchar *)name, strlen(name));
- }
+ for (GPUMaterialAttribute *attr = attributes->first; attr; attr = attr->next) {
+ BLI_hash_mm2a_add(&hm2a, (uchar *)attr->name, strlen(attr->name));
}
if (defs) {
BLI_hash_mm2a_add(&hm2a, (uchar *)defs, strlen(defs));
@@ -302,55 +299,17 @@ static const char *gpu_builtin_name(eGPUBuiltin builtin)
}
}
-/* assign only one texid per buffer to avoid sampling the same texture twice */
-static void codegen_set_texid(GHash *bindhash, GPUInput *input, int *texid, void *key1, int key2)
-{
- GHashPair pair = {key1, POINTER_FROM_INT(key2)};
- if (BLI_ghash_haskey(bindhash, &pair)) {
- /* Reuse existing texid */
- input->texid = POINTER_AS_INT(BLI_ghash_lookup(bindhash, &pair));
- }
- else {
- /* Allocate new texid */
- input->texid = *texid;
- (*texid)++;
- input->bindtex = true;
- void *key = BLI_ghashutil_pairalloc(key1, POINTER_FROM_INT(key2));
- BLI_ghash_insert(bindhash, key, POINTER_FROM_INT(input->texid));
- }
-}
-
static void codegen_set_unique_ids(ListBase *nodes)
{
- GHash *bindhash;
GPUNode *node;
GPUInput *input;
GPUOutput *output;
- int id = 1, texid = 0;
-
- bindhash = BLI_ghash_pair_new("codegen_set_unique_ids1 gh");
+ int id = 1;
for (node = nodes->first; node; node = node->next) {
for (input = node->inputs.first; input; input = input->next) {
/* set id for unique names of uniform variables */
input->id = id++;
-
- /* set texid used for settings texture slot */
- if (codegen_input_has_texture(input)) {
- input->bindtex = false;
- if (input->ima) {
- /* input is texture from image */
- codegen_set_texid(bindhash, inpu
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list