Slow texture sampling in a fragment shader using Vulkan

I am making an SSAO shader with a kernel size of 64.

SSAO fragment shader:

const int kernelSize = 64;
for (int i = 0; i < kernelSize; i++) {
        //Get sample position
        vec3 s = tbn * ubo.kernel[i].xyz;
        s = s * radius + origin;
        vec4 offset = vec4(s, 1.0);
        offset = ubo.projection * offset;
        offset.xy /= offset.w;
        offset.xy = offset.xy * 0.5 + 0.5;
        float sampleDepth = texture(samplerposition, offset.xy).z;
        float rangeCheck = abs(origin.z - sampleDepth) < radius ? 1.0 : 0.0;
        occlusion += (sampleDepth >= s.z ? 1.0 : 0.0) * rangeCheck;
    }

The sampling texture has a format VK_FORMAT_R16G16B16A16_SFLOATand is loaded with a flag VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT.

I am using a laptop with an nvidia K1100M graphics card. If I run the code in renderdoc, this shader will take 114 ms . And if I change kernelSizeto 1, it takes 1 ms .

Is this texture fetch normal? Or maybe I created something somewhere?

Like the layout transition did not go through, so the texture is in VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMALinstead VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.

+4
source share
2 answers

, , , , , , . 10- , . SSAO .

. 4 16- , . Blitting the depth 16- 4x.

+4

, , . Vertex .

: SSAO, . 1. AO , . . 2. , AO Map . .

: OpenGL ES , .

+1

Source: https://habr.com/ru/post/1651276/


All Articles