c++ - 为什么在代码和环境中使用 cs_5_0 时出现错误“X3666 cs_4_0 不支持无人机类型”?
问题描述
我正在尝试通过复制此视频中的示例来编译计算着色器。
我在编译时收到以下错误消息:
Error X3666 cs_4_0 does not support typed UAVs
这个错误来自哪里?配置为 cs_5_0(在 VS2019 中的代码中)。这是代码的编译部分。
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 配置正确,我可以在另一个程序中使用着色器 5.0。
知道是什么导致了错误吗?如何确保将 ComputeShader 定义为 cs_5_0 着色器?
解决方案
切换了RWBuffer
forRWStructuredBuffer
并且可以正常工作
仍在寻找有关错误消息的指示以及导致 RWBuffer 问题的原因。
推荐阅读
- iframe - iframe 元素在 Windows 浏览器上显示视频正常,但在 IOS 上不显示
- asp.net - Google Chrome 不显示来自 asp.net 页面的 PDF
- java - 通过 GUI 插入 jButton 事件时由 netbeans 自动编码生成的多个错误
- java - 修复 int 转换并为类添加返回
- maven - JUnit - 除了@Test 注释之外的所有注释都有效
- mongodb - 替换 mongo db 中的文档不会更新时间戳。架构级别有什么替代方案吗?
- r - 保留带有前导零数字的站标识符
- laravel - 约束急切加载的关系以及嵌套关系 - Laravel 8
- c++ - R - 在 linux redhat 发行版上安装 processx 包时,仅在 C99 模式下允许“for”循环初始声明
- azure-data-factory-2 - ADF 数据流源 - SQL Server 不可选