我想创建staging Texture3D并将其绑定到无序访问视图以使用DirectCompute执行某些计算,然后使用CPU读取它们。不幸的是,在使用以下描述创建Texture3D时出现错误:
Texture3DDescription desc = new Texture3DDescription()
{
BindFlags = BindFlags.UnorderedAccess,
CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write,
Depth = sunAngleIterations,
Format = SharpDX.DXGI.Format.R32G32B32_Float,
Height = viewAngleIterations,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Staging,
Width = heightIterations
};
texture = new Texture3D(device, desc);
抛出的异常是:
{HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: Parameter jest niepoprawny.}
这里有什么想法吗?
答案 0 :(得分:3)
暂存纹理无法绑定到着色器管道,因此您需要首先创建一个默认纹理(也不是所有卡都支持3个通道,所以我也改变了格式,尝试采样3个通道纹理可能无法正常工作或让你的司机崩溃)
Texture3DDescription desc = new Texture3DDescription()
{
BindFlags = BindFlags.UnorderedAccess,
CpuAccessFlags = CpuAccessFlags.None,
Depth = sunAngleIterations,
Format = SharpDX.DXGI.Format.R32G32B32A32_Float,
Height = viewAngleIterations,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
Width = heightIterations
};
texture = new Texture3D(device, desc);
然后执行计算并使用分段纹理来检索数据:
Texture3DDescription stagingdesc = new Texture3DDescription()
{
BindFlags = BindFlags.None,
CpuAccessFlags = CpuAccessFlags.Read,
Depth = sunAngleIterations,
Format = SharpDX.DXGI.Format.R32G32B32A32_Float,
Height = viewAngleIterations,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Staging,
Width = heightIterations
};
stagingtexture = new Texture3D(device, stagingdesc);
然后您需要使用deviceContext.CopyResource将默认rexture的内容复制到您的登台纹理。
完成后,您可以使用deviceContext.MapSubresource(带有读取标志)来访问纹理数据。