Blender V5.0
GPU_shader_shared_utils.hh File Reference
#include "BLI_assert.h"
#include "BLI_sys_types.h"
#include <math.h>
#include "BLI_math_matrix_types.hh"
#include "BLI_math_vector_types.hh"

Go to the source code of this file.

Macros

#define GPU_THREAD   error_not_in_a_shader_question_mark

Typedefs

using bool32_t = int32_t
using packed_float3 = blender::float3
using packed_int3 = blender::int3
using packed_uint3 = blender::uint3
using float2
using float4
using int2
using int4
using uint2
using uint4
using float3
using int3
using uint3
using float2x2
using float4x2
using float2x4
using float3x4
using float4x4

Detailed Description

Glue definition to make shared declaration of struct & functions work in both C / C++ and GLSL. We use the same vector and matrix types as Blender C++. Some math functions are defined to use the float version to match the GLSL syntax. This file can be used for C & C++ code and the syntax used should follow the same rules. Some preprocessing is done by the GPU back-end to make it GLSL compatible.

IMPORTANT:

  • Always use u suffix for enum values. GLSL do not support implicit cast.
  • Define all values. This is in order to simplify custom pre-processor code.
  • (C++ only) Always use uint32_t as underlying type (enum MyEnum : uint32_t).
  • (C only) do NOT use the enum type inside UBO/SSBO structs and use uint instead.
  • Use float suffix by default for float literals to avoid double promotion in C++.
  • Pack one float or int after a vec3/ivec3 to fulfill alignment rules.

NOTE: Due to alignment restriction and buggy drivers, do not try to use mat3 inside structs. NOTE: (UBO only) Do not use arrays of float. They are padded to arrays of vec4 and are not worth it. This does not apply to SSBO.

IMPORTANT: Do not forget to align mat4, vec3 and vec4 to 16 bytes, and vec2 to 8 bytes.

NOTE: You can use bool type using bool32_t a int boolean type matching the GLSL type.

Definition in file GPU_shader_shared_utils.hh.

Macro Definition Documentation

◆ GPU_THREAD

#define GPU_THREAD   error_not_in_a_shader_question_mark

Definition at line 124 of file GPU_shader_shared_utils.hh.

Typedef Documentation

◆ bool32_t

using bool32_t = int32_t

Definition at line 83 of file GPU_shader_shared_utils.hh.

◆ float2

Definition at line 618 of file BLI_math_vector_types.hh.

◆ float2x2

Definition at line 1004 of file BLI_math_matrix_types.hh.

◆ float2x4

Definition at line 1006 of file BLI_math_matrix_types.hh.

◆ float3

IMPORTANT: Do not use in shared struct. Use packed_(float/int/uint)3 instead. Here for static functions usage only.

Definition at line 619 of file BLI_math_vector_types.hh.

◆ float3x4

Definition at line 1009 of file BLI_math_matrix_types.hh.

◆ float4

Definition at line 620 of file BLI_math_vector_types.hh.

◆ float4x2

Definition at line 1010 of file BLI_math_matrix_types.hh.

◆ float4x4

Definition at line 1012 of file BLI_math_matrix_types.hh.

◆ int2

Definition at line 601 of file BLI_math_vector_types.hh.

◆ int3

Definition at line 602 of file BLI_math_vector_types.hh.

◆ int4

Definition at line 603 of file BLI_math_vector_types.hh.

◆ packed_float3

using packed_float3 = blender::float3

Packed types are needed for MSL which have different alignment rules for float3.

Definition at line 100 of file GPU_shader_shared_utils.hh.

◆ packed_int3

using packed_int3 = blender::int3

Definition at line 101 of file GPU_shader_shared_utils.hh.

◆ packed_uint3

using packed_uint3 = blender::uint3

Definition at line 102 of file GPU_shader_shared_utils.hh.

◆ uint2

Definition at line 605 of file BLI_math_vector_types.hh.

◆ uint3

Definition at line 606 of file BLI_math_vector_types.hh.

◆ uint4

Definition at line 607 of file BLI_math_vector_types.hh.