Blender V4.3
gpu_codegen.cc File Reference
#include "MEM_guardedalloc.h"
#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
#include "BLI_ghash.h"
#include "BLI_hash_mm2a.hh"
#include "BLI_link_utils.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_threads.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "BKE_cryptomatte.hh"
#include "BKE_material.h"
#include "GPU_capabilities.hh"
#include "GPU_context.hh"
#include "GPU_material.hh"
#include "GPU_shader.hh"
#include "GPU_uniform_buffer.hh"
#include "GPU_vertex_format.hh"
#include "BLI_sys_types.h"
#include "BLI_vector.hh"
#include "gpu_codegen.hh"
#include "gpu_node_graph.hh"
#include "gpu_shader_create_info.hh"
#include "gpu_shader_dependency_private.hh"
#include <cstdarg>
#include <cstring>
#include <sstream>
#include <string>

Go to the source code of this file.

Classes

struct  GPUCodegenCreateInfo
 
struct  GPUCodegenCreateInfo::NameBuffer
 
struct  GPUPass
 
struct  GPUConstant
 
class  GPUCodegen
 

Functions

GPUPass
GPUPassGPU_generate_pass (GPUMaterial *material, GPUNodeGraph *graph, eGPUMaterialEngine engine, GPUCodegenCallbackFn finalize_source_cb, void *thunk, bool optimize_graph)
 
bool GPU_pass_should_optimize (GPUPass *pass)
 
Compilation
static int count_active_texture_sampler (GPUPass *pass, GPUShader *shader)
 
static bool gpu_pass_shader_validate (GPUPass *pass, GPUShader *shader)
 
GPUShaderCreateInfo * GPU_pass_begin_compilation (GPUPass *pass, const char *shname)
 
bool GPU_pass_finalize_compilation (GPUPass *pass, GPUShader *shader)
 
void GPU_pass_begin_async_compilation (GPUPass *pass, const char *shname)
 
bool GPU_pass_async_compilation_try_finalize (GPUPass *pass)
 
bool GPU_pass_compile (GPUPass *pass, const char *shname)
 
GPUShaderGPU_pass_shader_get (GPUPass *pass)
 
static void gpu_pass_free (GPUPass *pass)
 
void GPU_pass_acquire (GPUPass *pass)
 
void GPU_pass_release (GPUPass *pass)
 
void GPU_pass_cache_garbage_collect ()
 
void GPU_pass_cache_init ()
 
void GPU_pass_cache_free ()
 
Module
void gpu_codegen_init ()
 
void gpu_codegen_exit ()
 

Type > string conversion

#define SRC_NAME(io, list, link, type)   type
 
static std::ostream & operator<< (std::ostream &stream, const GPUInput *input)
 
static std::ostream & operator<< (std::ostream &stream, const GPUOutput *output)
 
static std::ostream & operator<< (std::ostream &stream, const GPUConstant *input)
 

GPUPass Cache

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.

static GPUPasspass_cache = nullptr
 
static SpinLock pass_cache_spin
 
static GPUPassgpu_pass_cache_lookup (eGPUMaterialEngine engine, uint32_t hash)
 
static void gpu_pass_cache_insert_after (GPUPass *node, GPUPass *pass)
 
static GPUPassgpu_pass_cache_resolve_collision (GPUPass *pass, GPUShaderCreateInfo *info, uint32_t hash)
 
static bool gpu_pass_is_valid (const GPUPass *pass)
 

Detailed Description

Convert material node-trees to GLSL.

Definition in file gpu_codegen.cc.

Macro Definition Documentation

◆ SRC_NAME

#define SRC_NAME ( io,
list,
link,
type )   type

Definition at line 199 of file gpu_codegen.cc.

Referenced by operator<<(), and operator<<().

Function Documentation

◆ count_active_texture_sampler()

static int count_active_texture_sampler ( GPUPass * pass,
GPUShader * shader )
static

Definition at line 831 of file gpu_codegen.cc.

References GPU_shader_get_uniform().

Referenced by gpu_pass_shader_validate().

◆ gpu_codegen_exit()

void gpu_codegen_exit ( )

Definition at line 1045 of file gpu_codegen.cc.

References BKE_material_defaults_free_gpu(), and GPU_shader_free_builtin_shaders().

Referenced by GPU_exit().

◆ gpu_codegen_init()

void gpu_codegen_init ( )

Definition at line 1043 of file gpu_codegen.cc.

Referenced by GPU_init().

◆ GPU_generate_pass()

◆ GPU_pass_acquire()

void GPU_pass_acquire ( GPUPass * pass)

Definition at line 976 of file gpu_codegen.cc.

References BLI_assert, BLI_spin_lock(), BLI_spin_unlock(), and pass_cache_spin.

Referenced by GPU_material_from_nodetree().

◆ GPU_pass_async_compilation_try_finalize()

bool GPU_pass_async_compilation_try_finalize ( GPUPass * pass)

NOTE: Unlike the non-async version, this one returns true when compilation has finalized, regardless if it succeeded or not. To check for success, see if GPU_pass_shader_get() != nullptr.

Definition at line 923 of file gpu_codegen.cc.

References BLI_assert, BLI_mutex_lock(), BLI_mutex_unlock(), GPU_pass_finalize_compilation(), GPU_shader_batch_finalize(), and GPU_shader_batch_is_ready().

Referenced by GPU_material_async_try_finalize().

◆ GPU_pass_begin_async_compilation()

void GPU_pass_begin_async_compilation ( GPUPass * pass,
const char * shname )

◆ GPU_pass_begin_compilation()

GPUShaderCreateInfo * GPU_pass_begin_compilation ( GPUPass * pass,
const char * shname )

Definition at line 873 of file gpu_codegen.cc.

Referenced by GPU_pass_begin_async_compilation(), and GPU_pass_compile().

◆ GPU_pass_cache_free()

void GPU_pass_cache_free ( )

◆ GPU_pass_cache_garbage_collect()

void GPU_pass_cache_garbage_collect ( )

◆ GPU_pass_cache_init()

void GPU_pass_cache_init ( )

Definition at line 1019 of file gpu_codegen.cc.

References BLI_spin_init(), and pass_cache_spin.

Referenced by WM_init_gpu().

◆ gpu_pass_cache_insert_after()

static void gpu_pass_cache_insert_after ( GPUPass * node,
GPUPass * pass )
static

◆ gpu_pass_cache_lookup()

static GPUPass * gpu_pass_cache_lookup ( eGPUMaterialEngine engine,
uint32_t hash )
static

Definition at line 132 of file gpu_codegen.cc.

References BLI_spin_lock(), BLI_spin_unlock(), hash, GPUPass::next, 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,
GPUShaderCreateInfo * info,
uint32_t hash )
static

Definition at line 163 of file gpu_codegen.cc.

References BLI_spin_lock(), BLI_spin_unlock(), GPUPass::engine, hash, and pass_cache_spin.

Referenced by GPU_generate_pass().

◆ GPU_pass_compile()

◆ GPU_pass_finalize_compilation()

bool GPU_pass_finalize_compilation ( GPUPass * pass,
GPUShader * shader )

◆ gpu_pass_free()

static void gpu_pass_free ( GPUPass * pass)
static

◆ gpu_pass_is_valid()

static bool gpu_pass_is_valid ( const GPUPass * pass)
static

Definition at line 182 of file gpu_codegen.cc.

Referenced by GPU_generate_pass().

◆ GPU_pass_release()

void GPU_pass_release ( GPUPass * pass)

◆ GPU_pass_shader_get()

◆ gpu_pass_shader_validate()

static bool gpu_pass_shader_validate ( GPUPass * pass,
GPUShader * shader )
static

◆ GPU_pass_should_optimize()

bool GPU_pass_should_optimize ( GPUPass * pass)

Definition at line 816 of file gpu_codegen.cc.

References GPU_backend_get_type(), and GPU_BACKEND_METAL.

Referenced by GPU_material_from_nodetree().

◆ operator<<() [1/3]

static std::ostream & operator<< ( std::ostream & stream,
const GPUConstant * input )
static

Definition at line 239 of file gpu_codegen.cc.

References SNPRINTF, and GPUInput::type.

◆ operator<<() [2/3]

◆ operator<<() [3/3]

static std::ostream & operator<< ( std::ostream & stream,
const GPUOutput * output )
static

Definition at line 230 of file gpu_codegen.cc.

References SRC_NAME.

Variable Documentation

◆ pass_cache

GPUPass* pass_cache = nullptr
static

◆ pass_cache_spin