Blender  V2.93
Functions | Variables
gpu_codegen.c File Reference
#include "MEM_guardedalloc.h"
#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
#include "BLI_ghash.h"
#include "BLI_hash_mm2a.h"
#include "BLI_link_utils.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "PIL_time.h"
#include "BKE_material.h"
#include "GPU_capabilities.h"
#include "GPU_material.h"
#include "GPU_shader.h"
#include "GPU_uniform_buffer.h"
#include "GPU_vertex_format.h"
#include "BLI_sys_types.h"
#include "gpu_codegen.h"
#include "gpu_material_library.h"
#include "gpu_node_graph.h"
#include <stdarg.h>
#include <string.h>

Go to the source code of this file.

Functions

static uint32_t gpu_pass_hash (const char *frag_gen, const char *defs, ListBase *attributes)
 
static GPUPassgpu_pass_cache_lookup (uint32_t hash)
 
static GPUPassgpu_pass_cache_resolve_collision (GPUPass *pass, const char *vert, const char *geom, const char *frag, const char *defs, uint32_t hash)
 
static void codegen_convert_datatype (DynStr *ds, int from, int to, const char *tmp, int id)
 
static void codegen_print_datatype (DynStr *ds, const eGPUType type, float *data)
 
static const char * gpu_builtin_name (eGPUBuiltin builtin)
 
static void codegen_set_unique_ids (GPUNodeGraph *graph)
 
static int codegen_process_uniforms_functions (GPUMaterial *material, DynStr *ds, GPUNodeGraph *graph)
 
static void codegen_declare_tmps (DynStr *ds, GPUNodeGraph *graph)
 
static void codegen_call_functions (DynStr *ds, GPUNodeGraph *graph)
 
static void codegen_final_output (DynStr *ds, GPUOutput *finaloutput)
 
static char * code_generate_fragment (GPUMaterial *material, GPUNodeGraph *graph, const char *interface_str)
 
static const char * attr_prefix_get (CustomDataType type)
 
static char * code_generate_interface (GPUNodeGraph *graph, int builtins)
 
static char * code_generate_vertex (GPUNodeGraph *graph, const char *interface_str, const char *vert_code, int builtins)
 
static char * code_generate_geometry (GPUNodeGraph *graph, const char *interface_str, const char *geom_code, int builtins)
 
GPUShaderGPU_pass_shader_get (GPUPass *pass)
 
static bool gpu_pass_is_valid (GPUPass *pass)
 
GPUPassGPU_generate_pass (GPUMaterial *material, GPUNodeGraph *graph, const char *vert_code, const char *geom_code, const char *frag_lib, const char *defines)
 
static int count_active_texture_sampler (GPUShader *shader, char *source)
 
static bool gpu_pass_shader_validate (GPUPass *pass, GPUShader *shader)
 
bool GPU_pass_compile (GPUPass *pass, const char *shname)
 
void GPU_pass_release (GPUPass *pass)
 
static void gpu_pass_free (GPUPass *pass)
 
void GPU_pass_cache_garbage_collect (void)
 
void GPU_pass_cache_init (void)
 
void GPU_pass_cache_free (void)
 
void gpu_codegen_init (void)
 
void gpu_codegen_exit (void)
 

Variables

char datatoc_gpu_shader_codegen_lib_glsl []
 
char datatoc_gpu_shader_common_obinfos_lib_glsl []
 
static GPUPasspass_cache = NULL
 
static SpinLock pass_cache_spin
 

Detailed Description

Convert material node-trees to GLSL.

Definition in file gpu_codegen.c.

Function Documentation

◆ attr_prefix_get()

static const char* attr_prefix_get ( CustomDataType  type)
static

Definition at line 644 of file gpu_codegen.c.

References BLI_assert, CD_AUTO_FROM_NAME, CD_MCOL, CD_MTFACE, CD_ORCO, CD_PROP_COLOR, CD_TANGENT, and type.

Referenced by code_generate_vertex().

◆ code_generate_fragment()

static char* code_generate_fragment ( GPUMaterial material,
GPUNodeGraph graph,
const char *  interface_str 
)
static

◆ code_generate_geometry()

static char* code_generate_geometry ( GPUNodeGraph graph,
const char *  interface_str,
const char *  geom_code,
int  builtins 
)
static

◆ code_generate_interface()

static char* code_generate_interface ( GPUNodeGraph graph,
int  builtins 
)
static

◆ code_generate_vertex()

static char* code_generate_vertex ( GPUNodeGraph graph,
const char *  interface_str,
const char *  vert_code,
int  builtins 
)
static

◆ codegen_call_functions()

static void codegen_call_functions ( DynStr ds,
GPUNodeGraph graph 
)
static

◆ codegen_convert_datatype()

static void codegen_convert_datatype ( DynStr ds,
int  from,
int  to,
const char *  tmp,
int  id 
)
static

◆ codegen_declare_tmps()

static void codegen_declare_tmps ( DynStr ds,
GPUNodeGraph graph 
)
static

◆ codegen_final_output()

static void codegen_final_output ( DynStr ds,
GPUOutput finaloutput 
)
static

Definition at line 514 of file gpu_codegen.c.

References BLI_dynstr_appendf(), and GPUOutput::id.

Referenced by code_generate_fragment().

◆ codegen_print_datatype()

static void codegen_print_datatype ( DynStr ds,
const eGPUType  type,
float data 
)
static

◆ codegen_process_uniforms_functions()

static int codegen_process_uniforms_functions ( GPUMaterial material,
DynStr ds,
GPUNodeGraph graph 
)
static

◆ codegen_set_unique_ids()

static void codegen_set_unique_ids ( GPUNodeGraph graph)
static

Definition at line 280 of file gpu_codegen.c.

References graph, LISTBASE_FOREACH, node, and output.

Referenced by code_generate_fragment().

◆ count_active_texture_sampler()

static int count_active_texture_sampler ( GPUShader shader,
char *  source 
)
static

◆ gpu_builtin_name()

static const char* gpu_builtin_name ( eGPUBuiltin  builtin)
static

◆ gpu_codegen_exit()

void gpu_codegen_exit ( void  )

Definition at line 1120 of file gpu_codegen.c.

References BKE_material_defaults_free_gpu(), and GPU_shader_free_builtin_shaders().

Referenced by GPU_exit().

◆ gpu_codegen_init()

void gpu_codegen_init ( void  )

Definition at line 1116 of file gpu_codegen.c.

Referenced by GPU_init().

◆ GPU_generate_pass()

GPUPass* GPU_generate_pass ( GPUMaterial material,
GPUNodeGraph graph,
const char *  vert_code,
const char *  geom_code,
const char *  frag_lib,
const char *  defines 
)

◆ GPU_pass_cache_free()

void GPU_pass_cache_free ( void  )

◆ GPU_pass_cache_garbage_collect()

void GPU_pass_cache_garbage_collect ( void  )

◆ GPU_pass_cache_init()

void GPU_pass_cache_init ( void  )

Definition at line 1096 of file gpu_codegen.c.

References BLI_spin_init(), and pass_cache_spin.

Referenced by WM_init_opengl().

◆ gpu_pass_cache_lookup()

static GPUPass* gpu_pass_cache_lookup ( uint32_t  hash)
static

Definition at line 89 of file gpu_codegen.c.

References BLI_spin_lock(), BLI_spin_unlock(), hash, GPUPass::next, NULL, pass_cache, and pass_cache_spin.

Referenced by GPU_generate_pass().

◆ gpu_pass_cache_resolve_collision()

static GPUPass* gpu_pass_cache_resolve_collision ( GPUPass pass,
const char *  vert,
const char *  geom,
const char *  frag,
const char *  defs,
uint32_t  hash 
)
static

◆ GPU_pass_compile()

bool GPU_pass_compile ( GPUPass pass,
const char *  shname 
)

◆ gpu_pass_free()

static void gpu_pass_free ( GPUPass pass)
static

◆ gpu_pass_hash()

static uint32_t gpu_pass_hash ( const char *  frag_gen,
const char *  defs,
ListBase attributes 
)
static

◆ gpu_pass_is_valid()

static bool gpu_pass_is_valid ( GPUPass pass)
static

Definition at line 833 of file gpu_codegen.c.

References GPUPass::compiled, NULL, and GPUPass::shader.

Referenced by GPU_generate_pass().

◆ GPU_pass_release()

void GPU_pass_release ( GPUPass pass)

Definition at line 1049 of file gpu_codegen.c.

References BLI_assert, and GPUPass::refcount.

Referenced by GPU_material_compile(), and gpu_material_free_single().

◆ GPU_pass_shader_get()

GPUShader* GPU_pass_shader_get ( GPUPass pass)

◆ gpu_pass_shader_validate()

static bool gpu_pass_shader_validate ( GPUPass pass,
GPUShader shader 
)
static

Variable Documentation

◆ datatoc_gpu_shader_codegen_lib_glsl

char datatoc_gpu_shader_codegen_lib_glsl[]
extern

◆ datatoc_gpu_shader_common_obinfos_lib_glsl

char datatoc_gpu_shader_common_obinfos_lib_glsl[]
extern

◆ pass_cache

GPUPass* pass_cache = NULL
static

Internal shader cache: This prevent the shader recompilation / stall when using undo/redo AND also allows for GPUPass reuse if the Shader code is the same for 2 different Materials. Unused GPUPasses are free by Garbage collection.

Definition at line 69 of file gpu_codegen.c.

Referenced by GPU_generate_pass(), GPU_pass_cache_free(), GPU_pass_cache_garbage_collect(), and gpu_pass_cache_lookup().

◆ pass_cache_spin

SpinLock pass_cache_spin
static