diff options
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_context.cc | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_context_private.hh | 8 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader.cc | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader_create_info.hh | 52 |
4 files changed, 67 insertions, 0 deletions
diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc index e29b0d5801d..bcc418169b7 100644 --- a/source/blender/gpu/intern/gpu_context.cc +++ b/source/blender/gpu/intern/gpu_context.cc @@ -56,11 +56,15 @@ static void gpu_backend_discard(); namespace blender::gpu { +int Context::context_counter = 0; Context::Context() { thread_ = pthread_self(); is_active_ = false; matrix_state = GPU_matrix_state_create(); + + context_id = Context::context_counter; + Context::context_counter++; } Context::~Context() diff --git a/source/blender/gpu/intern/gpu_context_private.hh b/source/blender/gpu/intern/gpu_context_private.hh index f823a92893c..2217e5262ed 100644 --- a/source/blender/gpu/intern/gpu_context_private.hh +++ b/source/blender/gpu/intern/gpu_context_private.hh @@ -48,6 +48,14 @@ class Context { DebugStack debug_stack; + /* GPUContext counter used to assign a unique ID to each GPUContext. + * NOTE(Metal): This is required by the Metal Backend, as a bug exists in the global OS shader + * cache wherein compilation of identical source from two distinct threads can result in an + * invalid cache collision, result in a broken shader object. Appending the unique context ID + * onto compiled sources ensures the source hashes are different. */ + static int context_counter; + int context_id = 0; + protected: /** Thread on which this context is active. */ pthread_t thread_; diff --git a/source/blender/gpu/intern/gpu_shader.cc b/source/blender/gpu/intern/gpu_shader.cc index 2d1b3dc2dca..4d059ae495e 100644 --- a/source/blender/gpu/intern/gpu_shader.cc +++ b/source/blender/gpu/intern/gpu_shader.cc @@ -95,6 +95,9 @@ static void standard_defines(Vector<const char *> &sources) case GPU_BACKEND_OPENGL: sources.append("#define GPU_OPENGL\n"); break; + case GPU_BACKEND_METAL: + sources.append("#define GPU_METAL\n"); + break; default: BLI_assert(false && "Invalid GPU Backend Type"); break; diff --git a/source/blender/gpu/intern/gpu_shader_create_info.hh b/source/blender/gpu/intern/gpu_shader_create_info.hh index 8236e669288..3884c067c83 100644 --- a/source/blender/gpu/intern/gpu_shader_create_info.hh +++ b/source/blender/gpu/intern/gpu_shader_create_info.hh @@ -32,6 +32,7 @@ namespace blender::gpu::shader { #endif enum class Type { + /* Types supported natively across all GPU backends. */ FLOAT = 0, VEC2, VEC3, @@ -47,6 +48,21 @@ enum class Type { IVEC3, IVEC4, BOOL, + /* Additionally supported types to enable data optimisation and native + * support in some GPUBackends. + * NOTE: These types must be representable in all APIs. E.g. VEC3_101010I2 is aliased as vec3 in + * the GL backend, as implicit type conversions from packed normal attribute data to vec3 is + * supported. UCHAR/CHAR types are natively supported in Metal and can be used to avoid + * additional data conversions for GPU_COMP_U8 vertex attributes. */ + VEC3_101010I2, + UCHAR, + UCHAR2, + UCHAR3, + UCHAR4, + CHAR, + CHAR2, + CHAR3, + CHAR4 }; /* All of these functions is a bit out of place */ @@ -86,6 +102,40 @@ static inline std::ostream &operator<<(std::ostream &stream, const Type type) return stream << "mat3"; case Type::MAT4: return stream << "mat4"; + case Type::VEC3_101010I2: + return stream << "vec3_1010102_Inorm"; + case Type::UCHAR: + return stream << "uchar"; + case Type::UCHAR2: + return stream << "uchar2"; + case Type::UCHAR3: + return stream << "uchar3"; + case Type::UCHAR4: + return stream << "uchar4"; + case Type::CHAR: + return stream << "char"; + case Type::CHAR2: + return stream << "char2"; + case Type::CHAR3: + return stream << "char3"; + case Type::CHAR4: + return stream << "char4"; + case Type::INT: + return stream << "int"; + case Type::IVEC2: + return stream << "ivec2"; + case Type::IVEC3: + return stream << "ivec3"; + case Type::IVEC4: + return stream << "ivec4"; + case Type::UINT: + return stream << "uint"; + case Type::UVEC2: + return stream << "uvec2"; + case Type::UVEC3: + return stream << "uvec3"; + case Type::UVEC4: + return stream << "uvec4"; default: BLI_assert(0); return stream; @@ -228,6 +278,8 @@ enum class PrimitiveOut { POINTS = 0, LINE_STRIP, TRIANGLE_STRIP, + LINES, + TRIANGLES, }; struct StageInterfaceInfo { |