Blender V4.3
GPU_shader_shared_utils.hh File Reference

Go to the source code of this file.

Typedefs

using bool32_t = int32_t
 
using packed_float3 = blender::float3
 
using packed_int3 = blender::int3
 
using packed_uint3 = blender::uint3
 

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 eMyEnum : 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.

Typedef Documentation

◆ bool32_t

using bool32_t = int32_t

Definition at line 61 of file GPU_shader_shared_utils.hh.

◆ packed_float3

using packed_float3 = blender::float3

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

Definition at line 78 of file GPU_shader_shared_utils.hh.

◆ packed_int3

using packed_int3 = blender::int3

Definition at line 79 of file GPU_shader_shared_utils.hh.

◆ packed_uint3

using packed_uint3 = blender::uint3

Definition at line 80 of file GPU_shader_shared_utils.hh.