New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy shaders for more than D2/D2Array in DX11 #2317

Open
fkaa opened this Issue Aug 12, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@fkaa
Copy link
Member

fkaa commented Aug 12, 2018

Currently copy operations between buffers and images are implemented in shaders/copy.hlsl with functions like:

ByteAddressBuffer   BufferCopySrc : register(t0);
RWByteAddressBuffer BufferCopyDst : register(u0);

Texture2DArray<uint4>   ImageCopySrc     : register(t0);
RWTexture2DArray<uint4> ImageCopyDstRgba : register(u0);

#define COPY_NUM_THREAD_X 8
#define COPY_NUM_THREAD_Y 8

// R8G8B8A8
[numthreads(COPY_NUM_THREAD_X, COPY_NUM_THREAD_Y, 1)]
void cs_copy_buffer_image2d_r8g8b8a8(uint3 dispatch_thread_id : SV_DispatchThreadID) {
    uint3 dst_idx = GetImageDst(dispatch_thread_id);
    if (dst_idx.x >= BufferImageCopies.ImageSize.x || dst_idx.y >= BufferImageCopies.ImageSize.y) {
        return;
    }

    uint src_idx = GetBufferSrc32(dispatch_thread_id);

    ImageCopyDstRgba[dst_idx] = Uint32ToUint8x4(BufferCopySrc.Load(src_idx));
}

[numthreads(COPY_NUM_THREAD_X, COPY_NUM_THREAD_Y, 1)]
void cs_copy_image2d_r8g8b8a8_buffer(uint3 dispatch_thread_id : SV_DispatchThreadID) {
    uint3 src_idx = GetImageSrc(dispatch_thread_id);
    if (src_idx.x >= BufferImageCopies.ImageSize.x || src_idx.y >= BufferImageCopies.ImageSize.y) {
        return;
    }

    uint dst_idx = GetBufferDst32(dispatch_thread_id);

    BufferCopyDst.Store(dst_idx, Uint8x4ToUint32(ImageCopySrc[src_idx]));
}

Trying to copy to/from textures with dimension types will spit out errors. Repeating roughly the same code snippet over and over again for the other dimensions (with different thread group count) should be trivial, but doesn't sound very pleasant..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment