GPU: Add support for small types
This implement the design of #118961. - Add aliases in GLSL since theses types are not supported. - Add detection mechanism that prevents usage inside shader shared code. Check is only done in debug build to avoid slowing down application startup. Pull Request: https://projects.blender.org/blender/blender/pulls/119226
This commit is contained in:
committed by
Clément Foucault
parent
7ba8087ac8
commit
b8e726a158
@@ -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:
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user