为什么在代码和环境中使用 cs_5_0 时会出现错误 "X3666 cs_4_0 does not support types UAVs"?
Why error "X3666 cs_4_0 does not support types UAVs", when using cs_5_0 in code and environment?
我正在尝试通过复制此视频中的示例来编译计算着色器。
我在编译时收到以下错误消息:
Error X3666 cs_4_0 does not support typed UAVs
这个错误是从哪里来的?配置为cs_5_0(VS2019中代码an)。这是代码的编译部分。
HRESULT DirectCompute::CreateShaders()
{
HRESULT hr = S_OK;
ID3DBlob* CS, * csError;
hr = D3DCompileFromFile(L"ComputeShader.hlsl", NULL, NULL, "main", "cs_5_0", NULL, NULL,
&CS, &csError);
if (csError) {
MessageBox(NULL, L"Failed compiling computer shader", L"Error", MB_OK);
csError->Release();
}
hr = device->CreateComputeShader(
CS->GetBufferPointer(),
CS->GetBufferSize(),
NULL,
pComputeShader.GetAddressOf());
context->CSSetShader(pComputeShader.Get(), NULL, 0);
context->CSSetConstantBuffers(0, 1, pConstantBuffer.GetAddressOf());
ID3D11ShaderResourceView* aSRViews[2] = { pBufferA_SRV.Get(), pBufferB_SRV.Get() };
context->CSSetShaderResources(0, 2, aSRViews);
ID3D11UnorderedAccessView* aUAViews[1] = { pBufferOut_UAV.Get() };
context->CSSetUnorderedAccessViews(0, 1, aUAViews, NULL);
context->Dispatch(matB_width, matA_height, 1);
ID3D11ShaderResourceView* aSRViewsNULL[1] = { NULL };
context->CSSetShaderResources(0, 1, aSRViewsNULL);
ID3D11UnorderedAccessView* aUAViewsNULL[1] = { NULL };
context->CSSetUnorderedAccessViews(0, 1, aUAViewsNULL, NULL);
return hr;
}
如果移除着色器中的 RWBuffer 引用,则不会出错。
cbuffer SampleCB: register(b0)
{
uint WidthA;
uint HeightA;
uint WidthB;
uint HeightB;
uint WidthOut;
uint HeightOut;
};
struct SimpleBufType
{
float val;
};
StructuredBuffer<SimpleBufType> MatrixA : register(t0);
Buffer<float> MatrixB: register(t1);
RWBuffer<float> Output : register(u0); //compiles if this is removed (as well as the output below)
[numthreads(1, 1, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
if (DTid.x < WidthB && DTid.y < HeightA)
{
float sum = 0;
for (uint i = 0; i != WidthA; i++)
{
uint addrA = DTid.y * WidthA + i;
uint addrB = DTid.x + i * WidthB;
sum += MatrixA[addrA].val * MatrixB[addrB];
}
Output[DTid.y * WidthOut + DTid.x] = sum;
}
}
Visual Studio 配置正确 我相信,我可以在另一个程序中使用 shaders 5.0。
知道是什么导致了错误吗?如何确保 ComputeShader 被定义为 cs_5_0 着色器?
将 RWBuffer
换成 RWStructuredBuffer
并且有效
仍在寻找有关错误消息的指示以及导致 RWBuffer 问题的原因。
我正在尝试通过复制此视频中的示例来编译计算着色器。
我在编译时收到以下错误消息:
Error X3666 cs_4_0 does not support typed UAVs
这个错误是从哪里来的?配置为cs_5_0(VS2019中代码an)。这是代码的编译部分。
HRESULT DirectCompute::CreateShaders()
{
HRESULT hr = S_OK;
ID3DBlob* CS, * csError;
hr = D3DCompileFromFile(L"ComputeShader.hlsl", NULL, NULL, "main", "cs_5_0", NULL, NULL,
&CS, &csError);
if (csError) {
MessageBox(NULL, L"Failed compiling computer shader", L"Error", MB_OK);
csError->Release();
}
hr = device->CreateComputeShader(
CS->GetBufferPointer(),
CS->GetBufferSize(),
NULL,
pComputeShader.GetAddressOf());
context->CSSetShader(pComputeShader.Get(), NULL, 0);
context->CSSetConstantBuffers(0, 1, pConstantBuffer.GetAddressOf());
ID3D11ShaderResourceView* aSRViews[2] = { pBufferA_SRV.Get(), pBufferB_SRV.Get() };
context->CSSetShaderResources(0, 2, aSRViews);
ID3D11UnorderedAccessView* aUAViews[1] = { pBufferOut_UAV.Get() };
context->CSSetUnorderedAccessViews(0, 1, aUAViews, NULL);
context->Dispatch(matB_width, matA_height, 1);
ID3D11ShaderResourceView* aSRViewsNULL[1] = { NULL };
context->CSSetShaderResources(0, 1, aSRViewsNULL);
ID3D11UnorderedAccessView* aUAViewsNULL[1] = { NULL };
context->CSSetUnorderedAccessViews(0, 1, aUAViewsNULL, NULL);
return hr;
}
如果移除着色器中的 RWBuffer 引用,则不会出错。
cbuffer SampleCB: register(b0)
{
uint WidthA;
uint HeightA;
uint WidthB;
uint HeightB;
uint WidthOut;
uint HeightOut;
};
struct SimpleBufType
{
float val;
};
StructuredBuffer<SimpleBufType> MatrixA : register(t0);
Buffer<float> MatrixB: register(t1);
RWBuffer<float> Output : register(u0); //compiles if this is removed (as well as the output below)
[numthreads(1, 1, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
if (DTid.x < WidthB && DTid.y < HeightA)
{
float sum = 0;
for (uint i = 0; i != WidthA; i++)
{
uint addrA = DTid.y * WidthA + i;
uint addrB = DTid.x + i * WidthB;
sum += MatrixA[addrA].val * MatrixB[addrB];
}
Output[DTid.y * WidthOut + DTid.x] = sum;
}
}
Visual Studio 配置正确 我相信,我可以在另一个程序中使用 shaders 5.0。
知道是什么导致了错误吗?如何确保 ComputeShader 被定义为 cs_5_0 着色器?
将 RWBuffer
换成 RWStructuredBuffer
并且有效
仍在寻找有关错误消息的指示以及导致 RWBuffer 问题的原因。