D3D12:无法创建尺寸超25000的一维缓冲区/纹理?求解决办法
光线追踪Shader中创建大尺寸float数组UAV的问题
我理论上的需求很简单,但实践中无法实现:希望在光线追踪Shader中对动态大小的float数组进行读写操作,我认为应将其声明为UAV。我尝试将其声明为RWTexture1D<float>和RWBuffer<float>,但指定约100k的尺寸时均报错,提示维度过大,其中RWBuffer<float>似乎限制为25k,RWTexture1D<float>限制为16384。
编辑1:相关代码与报错
以下是创建UAV的代码:
D3D12_UNORDERED_ACCESS_VIEW_DESC unordered_access_view_desc{}; unordered_access_view_desc.Buffer.NumElements = 100000; unordered_access_view_desc.Format = DXGI_FORMAT_R32_FLOAT; unordered_access_view_desc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; d3d.device->CreateUnorderedAccessView(resource, nullptr, &unordered_access_view_desc, handle);
报错信息:
The Dimensions of the View are invalid due to at least one of the following conditions. Assuming this Format (0x29, R32_FLOAT), FirstElement (value = 0) must be between 0 and the maximum offset of the Buffer, 24999, inclusively.
我无法理解:若改用DXGI_FORMAT_R32G32B32A32_FLOAT格式,设置Buffer.NumElements = 25000,内存占用量是相同的。但即便用这种取巧方式,真的无法创建尺寸>25000的一维数组吗?就连简单的512x512二维纹理都有262144个值,难道我必须创建二维纹理并重新索引吗?
编辑2:CreateBuffer与CreateCommittedResource代码
以下是创建Buffer的相关代码:
D3D12_HEAP_PROPERTIES heapDesc = {}; heapDesc.Type = D3D12_HEAP_TYPE_DEFAULT; heapDesc.CreationNodeMask = 1; heapDesc.VisibleNodeMask = 1; D3D12_RESOURCE_DESC resourceDesc = {}; resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; resourceDesc.Height = 1; resourceDesc.DepthOrArraySize = 1; resourceDesc.MipLevels = 1; resourceDesc.Format = DXGI_FORMAT_UNKNOWN; resourceDesc.SampleDesc.Count = 1; resourceDesc.SampleDesc.Quality = 0; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; resourceDesc.Width = /* ... */; resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; device->CreateCommittedResource(&heapDesc, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(&myresource));
以及另一处CreateCommittedResource的代码:
D3D12_HEAP_PROPERTIES const DefaultHeapProperties = { D3D12_HEAP_TYPE_DEFAULT, D3D12_CPU_PAGE_PROPERTY_UNKNOWN, D3D12_MEMORY_POOL_UNKNOWN, 0, 0 }; D3D12_RESOURCE_DESC resource_desc{}; resource_desc.DepthOrArraySize = 1; resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; //resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; resource_desc.Format = DXGI_FORMAT_UNKNOWN; //resource_desc.Format = DXGI_FORMAT_R32_FLOAT; resource_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; resource_desc.Width = static_cast<UINT64>(resources.raytracingData.bootstrap_sample_count); resource_desc.Height = 1; //resource_desc.Width = /* ... */; resource_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; resource_desc.MipLevels = 1; resource_desc.SampleDesc.Count = 1; device->CreateCommittedResource(&DefaultHeapProperties, D3D12_HEAP_FLAG_NONE, &resource_desc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(&myresource));
内容的提问来源于stack exchange,提问作者0xbadf00d
相关产品推荐
相关产品推荐

