diff --git a/source/blender/gpu/intern/gpu_shader_dependency.cc b/source/blender/gpu/intern/gpu_shader_dependency.cc index d5e9e945514..2583b66247d 100644 --- a/source/blender/gpu/intern/gpu_shader_dependency.cc +++ b/source/blender/gpu/intern/gpu_shader_dependency.cc @@ -104,6 +104,7 @@ struct GPUSource { if (filename.endswith(".h") || filename.endswith(".hh")) { enum_preprocess(); quote_preprocess(); + small_types_check(); } else { if (source.find("'") != StringRef::not_found) { @@ -236,6 +237,45 @@ struct GPUSource { source = processed_source.c_str(); } + /** + * Assert not small types are present inside shader shared files. + */ + void small_types_check() + { +#ifndef NDEBUG + auto check_type = [&](StringRefNull type_str) { + int64_t cursor = -1; + while (true) { + cursor = find_keyword(source, type_str, cursor + 1); + if (cursor == -1) { + break; + } + print_error(source, cursor, "small types are forbidden in shader interfaces"); + } + }; + check_type("char "); + check_type("char2 "); + check_type("char3 "); + check_type("char4 "); + check_type("uchar "); + check_type("uchar2 "); + check_type("uchar3 "); + check_type("uchar4 "); + check_type("short "); + check_type("short2 "); + check_type("short3 "); + check_type("short4 "); + check_type("ushort "); + check_type("ushort2 "); + check_type("ushort3 "); + check_type("ushort4 "); + check_type("half "); + check_type("half2 "); + check_type("half3 "); + check_type("half4 "); +#endif + } + /** * Transform C,C++ enum declaration into GLSL compatible defines and constants: * diff --git a/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl b/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl index c579a7e84b0..9b5b6f667ae 100644 --- a/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl +++ b/source/blender/gpu/shaders/opengl/glsl_shader_defines.glsl @@ -36,6 +36,32 @@ #define float3x4 mat3x4 #define float4x4 mat4x4 +/* Small types are unavailable in GLSL (or badly supported), promote them to bigger type. */ +#define char int +#define char2 int2 +#define char3 int3 +#define char4 int4 +#define short int +#define short2 int2 +#define short3 int3 +#define short4 int4 +#define uchar uint +#define uchar2 uint2 +#define uchar3 uint3 +#define uchar4 uint4 +#define ushort uint +#define ushort2 uint2 +#define ushort3 uint3 +#define ushort4 uint4 +#define half float +#define half2 float2 +#define half3 float3 +#define half4 float4 + +/* Aliases for supported fixed width types. */ +#define int32_t int +#define uint32_t uint + /* Fast store variant macro. In GLSL this is the same as imageStore, but assumes no bounds * checking. */ #define imageStoreFast imageStore