简体   繁体   中英

Changing ID3D11Texture2D with DirectCompute

I do video editing. I want to try using DirectCompute, but there are difficulties with the start.

Can anyone help with a simple example? There is an ID3D11Texture2D texture in the format DXGI_FORMAT_R8G8B8A8_UNORM or DXGI_FORMAT_R16G16B16A16_FLOAT. It needs to be processed with a DirectCompute shader. It is necessary to invert all color values and write the result to the same texture. Is this even possible?

The best thing to is proceed by trail and error. But this requires the getting VS graphics Diagnostics working https://docs.microsoft.com/en-us/visualstudio/debugger/graphics/getting-started-with-visual-studio-graphics-diagnostics?view=vs-2022 . In visual studio menu >debug >Graphics >Start Graphics Degugging

It will show you the state of the input textures/buffers and output textures/buffers (after the shader call).

Just write write to the texture with float4(1, 0, 0, 1);and look in the debugger to see if you get blue or red (with DXGI_FORMAT_R8G8B8A8_UNORM it will be red).

Here's some hlsl code you can play around with.

RWTexture2D<unorm float4> ReadWriteTexture: register(u0); // Bind with UAV
Texture2D<unorm float4> ReadOnlyTexture: register(t0); // Bind with SRV

[numthreads(TEXTURE_WIDTH, 1, 1)]
void main(uint3 pos : SV_DispatchThreadID)
{
    float4 rgba = readWriteTexture[uint2(pos.x, pos.y)] ;
    //float4 rgba = readOnlyTexture[uint2(pos.x, pos.y)] ;
    float red = 1 - rgba.x;
    float green = 1 - rgba.y;
    float blue = 1 - rgba.z;
    readWriteTexture[uint2(pos.x, pos.y)] = float4(red, green, blue, 1); 
}

You will need to bind a Unordered access view to the compute pipeline it order to write to the texture.

deviceContext->CSSetUnorderedAccessViews(...);
deviceContext->Dispatch(1, TEXTURE_HEIGHT, 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM