Group Group Group Group Group Group Group Group Group

Issue in Chapter 21

This post is helpful to understand syntax

Continuing the discussion from Chapter 21 Shader Attributes:

But at this stage, when “Build and Run” I have this bug

**2020-05-23 18:17:03.344388+0200 Raytracing[18963:2774266] Metal GPU Frame Capture Enabled**

**2020-05-23 18:17:03.344670+0200 Raytracing[18963:2774266] Metal API Validation Enabled**

**validateComputeFunctionArguments:834: failed assertion `Compute Function(accumulatedKernel): Shader uses texture(t[1]) as read-write, but hardware does not support read-write texture of this pixel format.'**

**(lldb)**

Any clue?

:sob: I was almost reaching the end … so

Ho, and of course, I have the issue also with the “Final” project
:scream:

what GPU are you running your code on?

MacBook Pro (13-inch, 2018, Four Thunderbolt 3 Ports)
Enabled with
Intel Iris Plus Graphics 655 1536 Mo :fearful:

And by the way : thank you for writing this book. Very instructing so far :slight_smile:

1 Like

So

I made some googling with “hardware compatibility” in mind and in search text fields

I found this thread: https://forums.developer.apple.com/thread/123657
From there I applied the suggested workaround which consist of:

In Shaders.metal, a revisited kernel function:

kernel void accumulatedKernel(constant Uniforms &uniforms,
                              texture2d<float> rendTex,
                              texture2d<float, access::read> t,
                              texture2d<float, access::write> tout, //<<<<<<< added
                              uint2 tid [[thread_position_in_grid]])
{
    if (tid.x < uniforms.width & tid.y < uniforms.height) {
        float3 color = rendTex.read(tid).xyz ;
        if (uniforms.frameIndex > 0) {
            float3 prevColor = t.read(tid).xyz ;
            prevColor *= uniforms.frameIndex ;
            color += prevColor ;
            color /= (uniforms.frameIndex + 1);
        }
        tout.write(float4(color, 1), tid); //<<<<<<< changed
    }

and in Renderer.swift under

// MARK: accumulation
computerEncoder?.setTexture(accumulationTarget, index: 1)
computerEncoder?.setTexture(accumulationTarget, index: 2) //FIXME: My own addition inspired by https://forums.developer.apple.com/thread/123657
computerEncoder?.setComputePipelineState(accumulatedPipeline)


}

and so far, I have a black screen (which is what I expected :partying_face:)