diff --git a/source/blender/gpu/metal/mtl_shader_generator.mm b/source/blender/gpu/metal/mtl_shader_generator.mm index 9621cf3db69..73792bd1ff7 100644 --- a/source/blender/gpu/metal/mtl_shader_generator.mm +++ b/source/blender/gpu/metal/mtl_shader_generator.mm @@ -3113,6 +3113,14 @@ std::string MSLGeneratorInterface::generate_msl_fragment_input_population() << this->vertex_output_varyings[0].name << ";" << std::endl; } + /* Assign default gl_FragDepth. + * If gl_FragDepth is used, it should default to the original depth value. Resolves #107159 where + * overlay_wireframe_frag may not write to gl_FragDepth. */ + if (this->uses_gl_FragDepth) { + out << "\t" << shader_stage_inst_name << ".gl_FragDepth = " << shader_stage_inst_name + << ".gl_FragCoord.z;" << std::endl; + } + /* NOTE: We will only assign to the intersection of the vertex output and fragment input. * Fragment input represents varying variables which are declared (but are not necessarily * used). The Vertex out defines the set which is passed into the fragment shader, which diff --git a/source/blender/gpu/metal/mtl_texture.mm b/source/blender/gpu/metal/mtl_texture.mm index 37a289af705..bf88495b90b 100644 --- a/source/blender/gpu/metal/mtl_texture.mm +++ b/source/blender/gpu/metal/mtl_texture.mm @@ -1551,7 +1551,7 @@ void gpu::MTLTexture::read_internal(int mip, MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); cs.bind_pso(pso); cs.bind_compute_bytes(¶ms, sizeof(params), 0); - cs.bind_compute_buffer(destination_buffer, 0, 1); + cs.bind_compute_buffer(destination_buffer, 0, 1, true); cs.bind_compute_texture(read_texture, 0); [compute_encoder dispatchThreads:MTLSizeMake(width, height, 1) /* Width, Height, Layer */ threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; @@ -1601,7 +1601,7 @@ void gpu::MTLTexture::read_internal(int mip, MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); cs.bind_pso(pso); cs.bind_compute_bytes(¶ms, sizeof(params), 0); - cs.bind_compute_buffer(destination_buffer, 0, 1); + cs.bind_compute_buffer(destination_buffer, 0, 1, true); cs.bind_compute_texture(read_texture, 0); [compute_encoder dispatchThreads:MTLSizeMake(width, height, depth) /* Width, Height, Layer */