Code Monkey home page Code Monkey logo

Comments (2)

vincentisambart avatar vincentisambart commented on July 26, 2024

Based on the zulip conversation, and looking at the SPIRV-Cross and MoltenVK source code, I made up a quick and dirty change to fn dispatch() and rerun the app in the Xcode debugger. I was then told by Xcode that a framebuffer-only texture should not be used as the destination of a texture copy so I also fixed that, and with these 2 changes no more validation error in Xcode. Here's the diff:

diff --git a/piet-gpu-hal/src/metal.rs b/piet-gpu-hal/src/metal.rs
index e3157d4..0c3b1a1 100644
--- a/piet-gpu-hal/src/metal.rs
+++ b/piet-gpu-hal/src/metal.rs
@@ -136,6 +136,7 @@ impl MtlInstance {
             let () = msg_send![ns_view, setWantsLayer: YES];
             let bounds: CGRect = msg_send![ns_view, bounds];
             let () = msg_send![metal_layer, setFrame: bounds];
+            metal_layer.set_framebuffer_only(false);
 
             if !ns_window.is_null() {
                 let scale_factor: CGFloat = msg_send![ns_window, backingScaleFactor];
@@ -464,6 +465,13 @@ impl crate::backend::CmdBuf<MtlDevice> for CmdBuf {
             encoder.set_texture(img_ix, Some(&image.texture));
             img_ix += 1;
         }
+        const BUFFER_SIZE_BUFFER_INDEX: usize = 25;
+        let buffer_size_constants: [u32; 1] = [0];
+        encoder.set_bytes(
+            BUFFER_SIZE_BUFFER_INDEX as NSUInteger,
+            mem::size_of_val(&buffer_size_constants) as NSUInteger,
+            &buffer_size_constants as *const u32 as _,
+        );
         let workgroup_count = metal::MTLSize {
             width: workgroup_count.0 as u64,
             height: workgroup_count.1 as u64,

Note that even without validation error, on a M1 Mac you still get incorrect colors, so #154 still needs to be fixed.

In regards to the diff above, I'm pretty sure set_framebuffer_only(false) is needed (as I also needed it when investigating #154), at least with the current way the texture is handled.
Binding a buffer to 25 is also needed, but you might want to only do it in the pipelines that require it. And looking at MoltenVK it seems -[MTLComputeCommandEncoder setBytes:length:atIndex:] might not work on some old GPUs (though these GPUs might already not be supported by piet-gpu). Also I don't fully understand what that value is needed for, so is really 0 the correct value?

from vello.

vincentisambart avatar vincentisambart commented on July 26, 2024

With vello now using WGPU as a backend this is not relevant anymore.
And just in case I tried running the current winit example in the Xcode debugger and it did not trigger any assertions, so closing this.

from vello.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.