From ca527efb9f84b228b0799dda11e9b2b3a20b40a5 Mon Sep 17 00:00:00 2001 From: Jason Fielder Date: Mon, 14 Aug 2023 15:56:12 +0200 Subject: [PATCH] Metal: Ensure MTLBatch uses context bound shader Previously the shader associated with a batch was assigned separately. This meant on occasion, the incorrect shader was used with the Metal backend. Updating the shader fetch to use the context bound shader instead of the batch shader member as per OpenGL/Vulkan backends. Also include state change check to be consistent with OpenGL. Authored by Apple: Michael Parkin-White Co-authored-by: Michael Parkin-White Pull Request: https://projects.blender.org/blender/blender/pulls/111112 --- source/blender/gpu/metal/mtl_batch.mm | 4 ++-- source/blender/gpu/metal/mtl_state.mm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/gpu/metal/mtl_batch.mm b/source/blender/gpu/metal/mtl_batch.mm index 94433438235..cc2b7f5fb09 100644 --- a/source/blender/gpu/metal/mtl_batch.mm +++ b/source/blender/gpu/metal/mtl_batch.mm @@ -418,8 +418,8 @@ id MTLBatch::bind(uint v_count) return nil; } - /* Verify Shader. */ - active_shader_ = (shader) ? static_cast(unwrap(shader)) : nullptr; + /* Fetch bound shader from context. */ + active_shader_ = static_cast(ctx->shader); if (active_shader_ == nullptr || !active_shader_->is_valid()) { /* Skip drawing if there is no valid Metal shader. diff --git a/source/blender/gpu/metal/mtl_state.mm b/source/blender/gpu/metal/mtl_state.mm index fc8798a2a16..9e95b859687 100644 --- a/source/blender/gpu/metal/mtl_state.mm +++ b/source/blender/gpu/metal/mtl_state.mm @@ -143,7 +143,7 @@ void MTLStateManager::set_mutable_state(const GPUStateMutable &state) pipeline_state.dirty_flags |= MTL_PIPELINE_STATE_PSO_FLAG; } - if (changed.depth_range[0] != 0 || changed.depth_range[1] != 0) { + if (float_as_uint(changed.depth_range[0]) != 0 || float_as_uint(changed.depth_range[1]) != 0) { /* TODO remove, should modify the projection matrix instead. */ mtl_depth_range(state.depth_range[0], state.depth_range[1]); }