简体   繁体   English

使用 DirectCompute 更改 ID3D11Texture2D

[英]Changing ID3D11Texture2D with DirectCompute

I do video editing.我做视频编辑。 I want to try using DirectCompute, but there are difficulties with the start.我想尝试使用 DirectCompute,但是一开始有困难。

Can anyone help with a simple example?谁能帮忙举个简单的例子? There is an ID3D11Texture2D texture in the format DXGI_FORMAT_R8G8B8A8_UNORM or DXGI_FORMAT_R16G16B16A16_FLOAT.格式为 DXGI_FORMAT_R8G8B8A8_UNORM 或 DXGI_FORMAT_R16G16B16A16_FLOAT 的 ID3D11Texture2D 纹理。 It needs to be processed with a DirectCompute shader.它需要使用 DirectCompute 着色器进行处理。 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 .但这需要让 VS 图形诊断工作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在visual studio菜单>debug >Graphics >Start Graphics Degugging

It will show you the state of the input textures/buffers and output textures/buffers (after the shader call).它将显示输入纹理/缓冲区的 state 和 output 纹理/缓冲区(在着色器调用之后)。

Just write write to the texture with float4(1, 0, 0, 1);只需使用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).并查看调试器,看看你是蓝色还是红色(使用DXGI_FORMAT_R8G8B8A8_UNORM它将是红色的)。

Here's some hlsl code you can play around with.这是一些您可以使用的 hlsl 代码。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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