Blender  V2.93
Variables
gpu_shader.cc File Reference
#include "MEM_guardedalloc.h"
#include "BLI_dynstr.h"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
#include "BKE_appdir.h"
#include "BKE_global.h"
#include "DNA_space_types.h"
#include "GPU_capabilities.h"
#include "GPU_matrix.h"
#include "GPU_platform.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
#include "GPU_uniform_buffer.h"
#include "gpu_backend.hh"
#include "gpu_context_private.hh"
#include "gpu_shader_private.hh"
#include "CLG_log.h"

Go to the source code of this file.

Functions

Creation / Destruction
static void standard_defines (Vector< const char * > &sources)
 
GPUShaderGPU_shader_create_ex (const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const eGPUShaderTFBType tf_type, const char **tf_names, const int tf_count, const char *shname)
 
void GPU_shader_free (GPUShader *shader)
 
Creation utils
GPUShaderGPU_shader_create (const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const char *shname)
 
GPUShaderGPU_shader_create_from_python (const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines)
 
static const char * string_join_array_maybe_alloc (const char **str_arr, bool *r_is_alloc)
 
struct GPUShaderGPU_shader_create_from_arrays_impl (const struct GPU_ShaderCreateFromArray_Params *params, const char *func, int line)
 
Binding
void GPU_shader_bind (GPUShader *gpu_shader)
 
void GPU_shader_unbind (void)
 
Transform feedback

TODO(fclem): Should be replaced by compute shaders.

bool GPU_shader_transform_feedback_enable (GPUShader *shader, GPUVertBuf *vertbuf)
 
void GPU_shader_transform_feedback_disable (GPUShader *shader)
 
Uniforms / Resource location
int GPU_shader_get_uniform (GPUShader *shader, const char *name)
 
int GPU_shader_get_builtin_uniform (GPUShader *shader, int builtin)
 
int GPU_shader_get_builtin_block (GPUShader *shader, int builtin)
 
int GPU_shader_get_uniform_block (GPUShader *shader, const char *name)
 
int GPU_shader_get_uniform_block_binding (GPUShader *shader, const char *name)
 
int GPU_shader_get_texture_binding (GPUShader *shader, const char *name)
 
int GPU_shader_get_attribute (GPUShader *shader, const char *name)
 
Getters
int GPU_shader_get_program (GPUShader *shader)
 
Uniforms setters
void GPU_shader_uniform_vector (GPUShader *shader, int loc, int len, int arraysize, const float *value)
 
void GPU_shader_uniform_vector_int (GPUShader *shader, int loc, int len, int arraysize, const int *value)
 
void GPU_shader_uniform_int (GPUShader *shader, int location, int value)
 
void GPU_shader_uniform_float (GPUShader *shader, int location, float value)
 
void GPU_shader_uniform_1i (GPUShader *sh, const char *name, int value)
 
void GPU_shader_uniform_1b (GPUShader *sh, const char *name, bool value)
 
void GPU_shader_uniform_2f (GPUShader *sh, const char *name, float x, float y)
 
void GPU_shader_uniform_3f (GPUShader *sh, const char *name, float x, float y, float z)
 
void GPU_shader_uniform_4f (GPUShader *sh, const char *name, float x, float y, float z, float w)
 
void GPU_shader_uniform_1f (GPUShader *sh, const char *name, float value)
 
void GPU_shader_uniform_2fv (GPUShader *sh, const char *name, const float data[2])
 
void GPU_shader_uniform_3fv (GPUShader *sh, const char *name, const float data[3])
 
void GPU_shader_uniform_4fv (GPUShader *sh, const char *name, const float data[4])
 
void GPU_shader_uniform_mat4 (GPUShader *sh, const char *name, const float data[4][4])
 
void GPU_shader_uniform_2fv_array (GPUShader *sh, const char *name, int len, const float(*val)[2])
 
void GPU_shader_uniform_4fv_array (GPUShader *sh, const char *name, int len, const float(*val)[4])
 

Variables

char datatoc_gpu_shader_colorspace_lib_glsl []
 
static CLG_LogRef LOG = {"gpu.shader"}
 

sRGB Rendering Workaround

The viewport overlay frame-buffer is sRGB and will expect shaders to output display referred Linear colors. But other frame-buffers (i.e: the area frame-buffers) are not sRGB and require the shader output color to be in sRGB space (assumed display encoded color-space as the time of writing). For this reason we have a uniform to switch the transform on and off depending on the current frame-buffer color-space.

static int g_shader_builtin_srgb_transform = 0
 
static bool g_shader_builtin_srgb_is_dirty = false
 
static bool gpu_shader_srgb_uniform_dirty_get ()
 
void GPU_shader_set_srgb_uniform (GPUShader *shader)
 
void GPU_shader_set_framebuffer_srgb_target (int use_srgb_to_linear)
 

Function Documentation

◆ GPU_shader_bind()

void GPU_shader_bind ( GPUShader gpu_shader)

◆ GPU_shader_create()

GPUShader* GPU_shader_create ( const char *  vertcode,
const char *  fragcode,
const char *  geomcode,
const char *  libcode,
const char *  defines,
const char *  shname 
)

◆ GPU_shader_create_ex()

GPUShader* GPU_shader_create_ex ( const char *  vertcode,
const char *  fragcode,
const char *  geomcode,
const char *  libcode,
const char *  defines,
const eGPUShaderTFBType  tf_type,
const char **  tf_names,
const int  tf_count,
const char *  shname 
)

◆ GPU_shader_create_from_arrays_impl()

struct GPUShader* GPU_shader_create_from_arrays_impl ( const struct GPU_ShaderCreateFromArray_Params params,
const char *  func,
int  line 
)

Use via GPU_shader_create_from_arrays macro (avoids passing in param).

Similar to DRW_shader_create_with_lib with the ability to include libs for each type of shader.

It has the advantage that each item can be conditionally included without having to build the string inline, then free it.

Parameters
paramsNULL terminated arrays of strings.

Example:

.vert = (const char *[]){shader_lib_glsl, shader_vert_glsl, NULL},
.geom = (const char *[]){shader_geom_glsl, NULL},
.frag = (const char *[]){shader_frag_glsl, NULL},
.defs = (const char *[]){"#define DEFINE\n", test ? "#define OTHER_DEFINE\n" : "", NULL},
});
#define GPU_shader_create_from_arrays(...)
Definition: GPU_shader.h:69

Definition at line 461 of file gpu_shader.cc.

References ARRAY_SIZE, BLI_snprintf(), GPU_shader_create(), MEM_freeN, params, str, and string_join_array_maybe_alloc().

◆ GPU_shader_create_from_python()

GPUShader* GPU_shader_create_from_python ( const char *  vertcode,
const char *  fragcode,
const char *  geomcode,
const char *  libcode,
const char *  defines 
)

◆ GPU_shader_free()

void GPU_shader_free ( GPUShader shader)

◆ GPU_shader_get_attribute()

int GPU_shader_get_attribute ( GPUShader shader,
const char *  name 
)

Definition at line 592 of file gpu_shader.cc.

References blender::gpu::ShaderInput::location.

Referenced by pygpu_shader_attr_from_name().

◆ GPU_shader_get_builtin_block()

int GPU_shader_get_builtin_block ( GPUShader shader,
int  builtin 
)

Definition at line 564 of file gpu_shader.cc.

References blender::gpu::ShaderInterface::ubo_builtin().

Referenced by drw_shgroup_init().

◆ GPU_shader_get_builtin_uniform()

int GPU_shader_get_builtin_uniform ( GPUShader shader,
int  builtin 
)

◆ GPU_shader_get_program()

int GPU_shader_get_program ( GPUShader shader)

Definition at line 606 of file gpu_shader.cc.

References shader(), and blender::gpu::unwrap().

Referenced by pygpu_shader_program_get().

◆ GPU_shader_get_texture_binding()

int GPU_shader_get_texture_binding ( GPUShader shader,
const char *  name 
)

◆ GPU_shader_get_uniform()

int GPU_shader_get_uniform ( GPUShader shader,
const char *  name 
)

◆ GPU_shader_get_uniform_block()

int GPU_shader_get_uniform_block ( GPUShader shader,
const char *  name 
)

◆ GPU_shader_get_uniform_block_binding()

int GPU_shader_get_uniform_block_binding ( GPUShader shader,
const char *  name 
)

◆ GPU_shader_set_framebuffer_srgb_target()

void GPU_shader_set_framebuffer_srgb_target ( int  use_srgb_to_linear)

◆ GPU_shader_set_srgb_uniform()

void GPU_shader_set_srgb_uniform ( GPUShader shader)

◆ gpu_shader_srgb_uniform_dirty_get()

static bool gpu_shader_srgb_uniform_dirty_get ( void  )
static

Definition at line 726 of file gpu_shader.cc.

References g_shader_builtin_srgb_is_dirty.

Referenced by GPU_shader_bind().

◆ GPU_shader_transform_feedback_disable()

void GPU_shader_transform_feedback_disable ( GPUShader shader)

Definition at line 540 of file gpu_shader.cc.

References shader(), and blender::gpu::unwrap().

Referenced by draw_shgroup().

◆ GPU_shader_transform_feedback_enable()

bool GPU_shader_transform_feedback_enable ( GPUShader shader,
GPUVertBuf vertbuf 
)

Definition at line 535 of file gpu_shader.cc.

References shader(), and blender::gpu::unwrap().

Referenced by draw_update_uniforms().

◆ GPU_shader_unbind()

void GPU_shader_unbind ( void  )

◆ GPU_shader_uniform_1b()

void GPU_shader_uniform_1b ( GPUShader sh,
const char *  name,
bool  value 
)

Definition at line 645 of file gpu_shader.cc.

References GPU_shader_uniform_1i().

◆ GPU_shader_uniform_1f()

void GPU_shader_uniform_1f ( GPUShader sh,
const char *  name,
float  value 
)

Definition at line 668 of file gpu_shader.cc.

References GPU_shader_get_uniform(), and GPU_shader_uniform_float().

Referenced by createGPUShader(), and immUniform1f().

◆ GPU_shader_uniform_1i()

void GPU_shader_uniform_1i ( GPUShader sh,
const char *  name,
int  value 
)

◆ GPU_shader_uniform_2f()

void GPU_shader_uniform_2f ( GPUShader sh,
const char *  name,
float  x,
float  y 
)

Definition at line 650 of file gpu_shader.cc.

References data, GPU_shader_uniform_2fv(), x, and y.

Referenced by immUniform2f().

◆ GPU_shader_uniform_2fv()

void GPU_shader_uniform_2fv ( GPUShader sh,
const char *  name,
const float  data[2] 
)

Definition at line 674 of file gpu_shader.cc.

References data, GPU_shader_get_uniform(), and GPU_shader_uniform_vector().

Referenced by GPU_shader_uniform_2f(), and immUniform2fv().

◆ GPU_shader_uniform_2fv_array()

void GPU_shader_uniform_2fv_array ( GPUShader sh,
const char *  name,
int  len,
const float(*)  val[2] 
)

Definition at line 698 of file gpu_shader.cc.

References GPU_shader_get_uniform(), GPU_shader_uniform_vector(), and len.

◆ GPU_shader_uniform_3f()

void GPU_shader_uniform_3f ( GPUShader sh,
const char *  name,
float  x,
float  y,
float  z 
)

Definition at line 656 of file gpu_shader.cc.

References data, GPU_shader_uniform_3fv(), x, y, and z.

Referenced by createGPUShader(), and immUniform3f().

◆ GPU_shader_uniform_3fv()

void GPU_shader_uniform_3fv ( GPUShader sh,
const char *  name,
const float  data[3] 
)

Definition at line 680 of file gpu_shader.cc.

References data, GPU_shader_get_uniform(), and GPU_shader_uniform_vector().

Referenced by GPU_shader_uniform_3f(), and immUniform3fv().

◆ GPU_shader_uniform_4f()

void GPU_shader_uniform_4f ( GPUShader sh,
const char *  name,
float  x,
float  y,
float  z,
float  w 
)

Definition at line 662 of file gpu_shader.cc.

References data, GPU_shader_uniform_4fv(), w(), x, y, and z.

Referenced by button2d_draw_intern(), and immUniform4f().

◆ GPU_shader_uniform_4fv()

void GPU_shader_uniform_4fv ( GPUShader sh,
const char *  name,
const float  data[4] 
)

Definition at line 686 of file gpu_shader.cc.

References data, GPU_shader_get_uniform(), and GPU_shader_uniform_vector().

Referenced by GPU_shader_uniform_4f(), and immUniform4fv().

◆ GPU_shader_uniform_4fv_array()

void GPU_shader_uniform_4fv_array ( GPUShader sh,
const char *  name,
int  len,
const float(*)  val[4] 
)

Definition at line 704 of file gpu_shader.cc.

References GPU_shader_get_uniform(), GPU_shader_uniform_vector(), and len.

Referenced by immUniformArray4fv().

◆ GPU_shader_uniform_float()

void GPU_shader_uniform_float ( GPUShader shader,
int  location,
float  value 
)

Definition at line 634 of file gpu_shader.cc.

References GPU_shader_uniform_vector(), and shader().

Referenced by GPU_shader_uniform_1f().

◆ GPU_shader_uniform_int()

void GPU_shader_uniform_int ( GPUShader shader,
int  location,
int  value 
)

◆ GPU_shader_uniform_mat4()

void GPU_shader_uniform_mat4 ( GPUShader sh,
const char *  name,
const float  data[4][4] 
)

Definition at line 692 of file gpu_shader.cc.

References data, GPU_shader_get_uniform(), and GPU_shader_uniform_vector().

Referenced by immUniformMatrix4fv().

◆ GPU_shader_uniform_vector()

void GPU_shader_uniform_vector ( GPUShader shader,
int  loc,
int  len,
int  arraysize,
const float value 
)

◆ GPU_shader_uniform_vector_int()

void GPU_shader_uniform_vector_int ( GPUShader shader,
int  loc,
int  len,
int  arraysize,
const int *  value 
)

◆ standard_defines()

static void standard_defines ( Vector< const char * > &  sources)
static

◆ string_join_array_maybe_alloc()

static const char* string_join_array_maybe_alloc ( const char **  str_arr,
bool *  r_is_alloc 
)
static

Definition at line 416 of file gpu_shader.cc.

References BLI_string_join_arrayN().

Referenced by GPU_shader_create_from_arrays_impl().

Variable Documentation

◆ datatoc_gpu_shader_colorspace_lib_glsl

char datatoc_gpu_shader_colorspace_lib_glsl[]

Definition at line 53 of file gpu_shader.cc.

Referenced by GPU_shader_create_from_python().

◆ g_shader_builtin_srgb_is_dirty

bool g_shader_builtin_srgb_is_dirty = false
static

◆ g_shader_builtin_srgb_transform

int g_shader_builtin_srgb_transform = 0
static

◆ LOG

CLG_LogRef LOG = {"gpu.shader"}
static

Definition at line 55 of file gpu_shader.cc.

Referenced by blender::gpu::Shader::print_log().