Blender  V3.3
GPU_material.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #pragma once
9 
10 #include "DNA_customdata_types.h" /* for eCustomDataType */
11 #include "DNA_image_types.h"
12 #include "DNA_listBase.h"
13 
14 #include "BLI_sys_types.h" /* for bool */
15 
16 #include "GPU_shader.h" /* for GPUShaderCreateInfo */
17 #include "GPU_texture.h" /* for eGPUSamplerState */
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 struct GHash;
24 struct GPUMaterial;
25 struct GPUNode;
26 struct GPUNodeLink;
27 struct GPUNodeStack;
28 struct GPUTexture;
29 struct GPUUniformBuf;
30 struct Image;
31 struct ImageUser;
32 struct ListBase;
33 struct Main;
34 struct Material;
35 struct Scene;
36 struct bNode;
37 struct bNodeTree;
38 
39 typedef struct GPUMaterial GPUMaterial;
40 typedef struct GPUNode GPUNode;
41 typedef struct GPUNodeLink GPUNodeLink;
42 
43 /* Functions to create GPU Materials nodes. */
44 
45 typedef enum eGPUType {
46  /* Keep in sync with GPU_DATATYPE_STR */
47  /* The value indicates the number of elements in each type */
48  GPU_NONE = 0,
49  GPU_FLOAT = 1,
50  GPU_VEC2 = 2,
51  GPU_VEC3 = 3,
52  GPU_VEC4 = 4,
53  GPU_MAT3 = 9,
54  GPU_MAT4 = 16,
56 
57  /* Values not in GPU_DATATYPE_STR */
59  GPU_TEX2D = 1002,
61  GPU_TEX3D = 1004,
62 
63  /* GLSL Struct types */
64  GPU_CLOSURE = 1007,
65 
66  /* Opengl Attributes */
67  GPU_ATTR = 3001,
69 
70 typedef enum eGPUMaterialFlag {
71  GPU_MATFLAG_DIFFUSE = (1 << 0),
73  GPU_MATFLAG_GLOSSY = (1 << 2),
74  GPU_MATFLAG_REFRACT = (1 << 3),
77  GPU_MATFLAG_HOLDOUT = (1 << 6),
79  GPU_MATFLAG_AO = (1 << 8),
81 
83  GPU_MATFLAG_AOV = (1 << 11),
84 
86 
87  /* Optimization to only add the branches of the principled shader that are necessary. */
93 
94  /* Tells the render engine the material was just compiled or updated. */
95  GPU_MATFLAG_UPDATED = (1 << 29),
96 
97  /* HACK(fclem) Tells the environment texture node to not bail out if empty. */
100 
102 
103 typedef struct GPUNodeStack {
105  float vec[4];
106  struct GPUNodeLink *link;
107  bool hasinput;
108  bool hasoutput;
109  short sockettype;
110  bool end;
112 
113 typedef enum eGPUMaterialStatus {
119 
120 typedef enum eGPUDefaultValue {
124 
125 typedef struct GPUCodegenOutput {
126  char *attr_load;
127  /* Node-tree functions calls. */
129  char *surface;
130  char *volume;
131  char *thickness;
133 
136 
137 typedef void (*GPUCodegenCallbackFn)(void *thunk, GPUMaterial *mat, GPUCodegenOutput *codegen);
138 
139 GPUNodeLink *GPU_constant(const float *num);
140 GPUNodeLink *GPU_uniform(const float *num);
141 GPUNodeLink *GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name);
149  const char *name,
150  eGPUDefaultValue default_value);
151 GPUNodeLink *GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli);
153  struct Image *ima,
154  struct ImageUser *iuser,
155  eGPUSamplerState sampler_state);
157  struct Image *ima,
158  struct ImageUser *iuser,
159  eGPUSamplerState sampler_state);
160 GPUNodeLink *GPU_image_tiled_mapping(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser);
161 GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *row);
162 
168 GPUNodeLink *GPU_differentiate_float_function(const char *function_name);
169 
170 bool GPU_link(GPUMaterial *mat, const char *name, ...);
171 bool GPU_stack_link(GPUMaterial *mat,
172  struct bNode *node,
173  const char *name,
174  GPUNodeStack *in,
175  GPUNodeStack *out,
176  ...);
178  struct bNode *node,
179  struct GPUNodeStack *stack,
180  int index);
181 
186 
188 
198  eGPUType return_type,
199  GPUNodeLink **link);
200 
203  int sample_len,
204  struct GPUTexture **tex_profile);
205 
210  const void *engine_type,
211  int options);
218  struct Material *ma,
219  struct bNodeTree *ntree,
220  struct ListBase *gpumaterials,
221  const char *name,
222  uint64_t shader_uuid,
223  bool is_volume_shader,
224  bool is_lookdev,
226  void *thunk);
227 
229 void GPU_material_free(struct ListBase *gpumaterial);
230 
233 
234 void GPU_materials_free(struct Main *bmain);
235 
248 
257 
260 
262 bool GPU_material_flag_get(const GPUMaterial *mat, eGPUMaterialFlag flag);
266 
267 void GPU_pass_cache_init(void);
269 void GPU_pass_cache_free(void);
270 
271 /* Requested Material Attributes and Textures */
272 
273 typedef struct GPUMaterialAttribute {
275  int type; /* eCustomDataType */
276  char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
277  char input_name[12 + 1]; /* GPU_MAX_SAFE_ATTR_NAME + 1 */
279  eGPUDefaultValue default_value; /* Only for volumes attributes. */
280  int id;
281  int users;
289 
290 typedef struct GPUMaterialTexture {
292  struct Image *ima;
293  struct ImageUser iuser;
296  char sampler_name[32]; /* Name of sampler in GLSL. */
297  char tiled_mapping_name[32]; /* Name of tile mapping sampler in GLSL. */
298  int users;
299  int sampler_state; /* eGPUSamplerState */
301 
304 
305 typedef struct GPUUniformAttr {
307 
308  /* Meaningful part of the attribute set key. */
309  char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
310  bool use_dupli;
311 
312  /* Helper fields used by code generation. */
313  short id;
314  int users;
316 
317 typedef struct GPUUniformAttrList {
318  ListBase list; /* GPUUniformAttr */
319 
320  /* List length and hash code precomputed for fast lookup and comparison. */
321  unsigned int count, hash_code;
323 
325 
326 struct GHash *GPU_uniform_attr_list_hash_new(const char *info);
329 
330 #ifdef __cplusplus
331 }
332 #endif
eCustomDataType
These structs are the foundation for all linked lists in the library system.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
GPUMaterial * GPU_material_from_nodetree(struct Scene *scene, struct Material *ma, struct bNodeTree *ntree, struct ListBase *gpumaterials, const char *name, uint64_t shader_uuid, bool is_volume_shader, bool is_lookdev, GPUCodegenCallbackFn callback, void *thunk)
Definition: gpu_material.c:624
struct GPUUniformAttrList GPUUniformAttrList
ENUM_OPERATORS(eGPUMaterialFlag, GPU_MATFLAG_LOOKDEV_HACK)
eGPUDefaultValue
Definition: GPU_material.h:120
@ GPU_DEFAULT_1
Definition: GPU_material.h:122
@ GPU_DEFAULT_0
Definition: GPU_material.h:121
uint64_t GPU_material_uuid_get(GPUMaterial *mat)
Definition: gpu_material.c:619
void GPU_material_free(struct ListBase *gpumaterial)
Definition: gpu_material.c:171
void GPU_material_acquire(GPUMaterial *mat)
Definition: gpu_material.c:702
GPUUniformAttrList * GPU_material_uniform_attributes(GPUMaterial *material)
Definition: gpu_material.c:226
void GPU_material_compile(GPUMaterial *mat)
Definition: gpu_material.c:712
void GPU_uniform_attr_list_copy(GPUUniformAttrList *dest, GPUUniformAttrList *src)
struct GPUShader * GPU_material_get_shader(GPUMaterial *material)
Definition: gpu_material.c:191
void GPU_material_output_surface(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:503
struct GHash * GPU_uniform_attr_list_hash_new(const char *info)
bool GPU_material_has_surface_output(GPUMaterial *mat)
Definition: gpu_material.c:586
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
void GPU_material_status_set(GPUMaterial *mat, eGPUMaterialStatus status)
Definition: gpu_material.c:579
void(* GPUCodegenCallbackFn)(void *thunk, GPUMaterial *mat, GPUCodegenOutput *codegen)
Definition: GPU_material.h:137
GPUNodeLink * GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *row)
GPUNodeLink * GPU_uniformbuf_link_out(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *stack, int index)
struct GPUMaterialAttribute GPUMaterialAttribute
GPUNodeLink * GPU_image(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser, eGPUSamplerState sampler_state)
void GPU_materials_free(struct Main *bmain)
Definition: gpu_material.c:747
void GPU_material_output_displacement(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:519
GPUNodeLink * GPU_attribute_default_color(GPUMaterial *mat)
void GPU_material_output_thickness(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:526
GPUNodeLink * GPU_image_tiled_mapping(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser)
GPUNodeLink * GPU_differentiate_float_function(const char *function_name)
void GPU_material_add_output_link_aov(GPUMaterial *material, GPUNodeLink *link, int hash)
Definition: gpu_material.c:533
struct GPUCodegenOutput GPUCodegenOutput
GPUNodeLink * GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli)
void GPU_pass_cache_free(void)
Definition: gpu_codegen.cc:789
bool GPU_material_flag_get(const GPUMaterial *mat, eGPUMaterialFlag flag)
Definition: gpu_material.c:601
GPUNodeLink * GPU_attribute_with_default(GPUMaterial *mat, eCustomDataType type, const char *name, eGPUDefaultValue default_value)
bool GPU_material_recalc_flag_get(GPUMaterial *mat)
Definition: gpu_material.c:612
ListBase GPU_material_textures(GPUMaterial *material)
Definition: gpu_material.c:221
char * GPU_material_split_sub_function(GPUMaterial *material, eGPUType return_type, GPUNodeLink **link)
Definition: gpu_material.c:541
struct Scene * GPU_material_scene(GPUMaterial *material)
Definition: gpu_material.c:181
bool GPU_material_sss_profile_create(GPUMaterial *material, float radii[3])
Definition: gpu_material.c:438
void GPU_material_release(GPUMaterial *mat)
Definition: gpu_material.c:707
GPUNodeLink * GPU_constant(const float *num)
eGPUMaterialStatus GPU_material_status(GPUMaterial *mat)
Definition: gpu_material.c:574
eGPUMaterialFlag
Definition: GPU_material.h:70
@ GPU_MATFLAG_UPDATED
Definition: GPU_material.h:95
@ GPU_MATFLAG_AOV
Definition: GPU_material.h:83
@ GPU_MATFLAG_SHADER_TO_RGBA
Definition: GPU_material.h:78
@ GPU_MATFLAG_EMISSION
Definition: GPU_material.h:75
@ GPU_MATFLAG_PRINCIPLED_GLASS
Definition: GPU_material.h:91
@ GPU_MATFLAG_OBJECT_INFO
Definition: GPU_material.h:82
@ GPU_MATFLAG_GLOSSY
Definition: GPU_material.h:73
@ GPU_MATFLAG_PRINCIPLED_DIELECTRIC
Definition: GPU_material.h:90
@ GPU_MATFLAG_AO
Definition: GPU_material.h:79
@ GPU_MATFLAG_REFRACT
Definition: GPU_material.h:74
@ GPU_MATFLAG_BARYCENTRIC
Definition: GPU_material.h:85
@ GPU_MATFLAG_PRINCIPLED_CLEARCOAT
Definition: GPU_material.h:88
@ GPU_MATFLAG_LOOKDEV_HACK
Definition: GPU_material.h:98
@ GPU_MATFLAG_CLEARCOAT
Definition: GPU_material.h:80
@ GPU_MATFLAG_PRINCIPLED_ANY
Definition: GPU_material.h:92
@ GPU_MATFLAG_HOLDOUT
Definition: GPU_material.h:77
@ GPU_MATFLAG_DIFFUSE
Definition: GPU_material.h:71
@ GPU_MATFLAG_TRANSPARENT
Definition: GPU_material.h:76
@ GPU_MATFLAG_SUBSURFACE
Definition: GPU_material.h:72
@ GPU_MATFLAG_PRINCIPLED_METALLIC
Definition: GPU_material.h:89
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
Definition: gpu_material.c:596
GPUNodeLink * GPU_uniform(const float *num)
GPUNodeLink * GPU_image_tiled(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser, eGPUSamplerState sampler_state)
eGPUMaterialStatus
Definition: GPU_material.h:113
@ GPU_MAT_QUEUED
Definition: GPU_material.h:116
@ GPU_MAT_FAILED
Definition: GPU_material.h:114
@ GPU_MAT_SUCCESS
Definition: GPU_material.h:117
@ GPU_MAT_CREATED
Definition: GPU_material.h:115
struct GPUUniformBuf * GPU_material_create_sss_profile_ubo(void)
Definition: gpu_material.c:494
struct GPUPass * GPU_material_get_pass(GPUMaterial *material)
Definition: gpu_material.c:186
void GPU_uniform_attr_list_free(GPUUniformAttrList *set)
void GPU_material_output_volume(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:511
eGPUMaterialFlag GPU_material_flag(const GPUMaterial *mat)
Definition: gpu_material.c:606
struct Material * GPU_material_get_material(GPUMaterial *material)
Definition: gpu_material.c:196
struct GPUUniformBuf * GPU_material_uniform_buffer_get(GPUMaterial *material)
Definition: gpu_material.c:201
struct GPUMaterialTexture GPUMaterialTexture
ListBase GPU_material_attributes(GPUMaterial *material)
Definition: gpu_material.c:216
eGPUType
Definition: GPU_material.h:45
@ GPU_ATTR
Definition: GPU_material.h:67
@ GPU_VEC2
Definition: GPU_material.h:50
@ GPU_MAT4
Definition: GPU_material.h:54
@ GPU_TEX1D_ARRAY
Definition: GPU_material.h:58
@ GPU_MAX_CONSTANT_DATA
Definition: GPU_material.h:55
@ GPU_TEX2D_ARRAY
Definition: GPU_material.h:60
@ GPU_TEX2D
Definition: GPU_material.h:59
@ GPU_VEC4
Definition: GPU_material.h:52
@ GPU_NONE
Definition: GPU_material.h:48
@ GPU_CLOSURE
Definition: GPU_material.h:64
@ GPU_VEC3
Definition: GPU_material.h:51
@ GPU_MAT3
Definition: GPU_material.h:53
@ GPU_TEX3D
Definition: GPU_material.h:61
@ GPU_FLOAT
Definition: GPU_material.h:49
void GPU_pass_cache_garbage_collect(void)
Definition: gpu_codegen.cc:756
GPUMaterial * GPU_material_from_nodetree_find(struct ListBase *gpumaterials, const void *engine_type, int options)
struct GPUUniformAttr GPUUniformAttr
struct GPUUniformBuf * GPU_material_sss_profile_get(GPUMaterial *material, int sample_len, struct GPUTexture **tex_profile)
Definition: gpu_material.c:455
void GPU_pass_cache_init(void)
Definition: gpu_codegen.cc:784
void GPU_material_uniform_buffer_create(GPUMaterial *material, ListBase *inputs)
Definition: gpu_material.c:206
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_material_has_volume_output(GPUMaterial *mat)
Definition: gpu_material.c:591
struct GPUNodeStack GPUNodeStack
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
struct GPUShader GPUShader
Definition: GPU_shader.h:20
struct GPUShaderCreateInfo GPUShaderCreateInfo
Definition: GPU_shader.h:18
eGPUSamplerState
Definition: GPU_texture.h:25
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
struct GPUUniformBuf GPUUniformBuf
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
CCL_NAMESPACE_BEGIN struct Options options
OperationNode * node
Scene scene
Material material
DEGForeachIDComponentCallback callback
SyclQueue void void * src
SyclQueue void void size_t num_bytes void
SyclQueue void * dest
bNodeTree * ntree
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
MutableSpan< float > radii
static bNodeSocketTemplate inputs[]
#define hash
Definition: noise.c:153
unsigned __int64 uint64_t
Definition: stdint.h:90
char * material_functions
Definition: GPU_material.h:132
GPUShaderCreateInfo * create_info
Definition: GPU_material.h:134
struct GPUMaterialAttribute * prev
Definition: GPU_material.h:274
eGPUDefaultValue default_value
Definition: GPU_material.h:279
struct GPUMaterialAttribute * next
Definition: GPU_material.h:274
struct GPUMaterialTexture * prev
Definition: GPU_material.h:291
struct GPUMaterialTexture * next
Definition: GPU_material.h:291
struct Image * ima
Definition: GPU_material.h:292
struct ImageUser iuser
Definition: GPU_material.h:293
char tiled_mapping_name[32]
Definition: GPU_material.h:297
struct GPUTexture ** colorband
Definition: GPU_material.h:295
struct GPUNodeLink * link
Definition: GPU_material.h:106
eGPUType type
Definition: GPU_material.h:104
float vec[4]
Definition: GPU_material.h:105
short sockettype
Definition: GPU_material.h:109
unsigned int count
Definition: GPU_material.h:321
unsigned int hash_code
Definition: GPU_material.h:321
struct GPUUniformAttr * next
Definition: GPU_material.h:306
struct GPUUniformAttr * prev
Definition: GPU_material.h:306
Definition: BKE_main.h:121