我做视频编辑。我想尝试使用DirectCompute,但是开始时有一些困难。
有人能帮我举个简单的例子吗?ID3D11Texture2D纹理以DXGI_FORMAT_R8G8B8A8_UNORM或DXGI_FORMAT_R16G16B16A16_FLOAT格式存在。它需要处理一个DirectCompute着色器。有必要反演所有颜色值,并将结果写入相同的纹理。这有可能吗?
发布于 2022-08-31 05:55:38
最好的做法是通过跟踪和错误。但这需要获得VS图形诊断工作的https://learn.microsoft.com/en-us/visualstudio/debugger/graphics/getting-started-with-visual-studio-graphics-diagnostics?view=vs-2022。在visual菜单>debug >Graphics >Start Graphics Degugging
中
它将显示输入纹理/缓冲区和输出纹理/缓冲区的状态(在着色器调用之后)。
只需使用float4(1, 0, 0, 1);
写入纹理,并在调试器中查看是否得到蓝色或红色(使用DXGI_FORMAT_R8G8B8A8_UNORM
时,它将为红色)。
这里有一些hlsl代码可以用来玩。
RWTexture2D<unorm float4> ReadWriteTexture: register(u0); // Bind with UAV slot 0
Texture2D<unorm float4> ReadOnlyTexture: register(t0); // Bind with SRV slot 0
[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);
}
您将需要将无序访问视图绑定到它命令写入到纹理的计算管道。
deviceContext->CSSetUnorderedAccessViews(...);
deviceContext->Dispatch(1, TEXTURE_HEIGHT, 1);
https://stackoverflow.com/questions/73545882
复制相似问题