diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-29 14:49:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 14:49:26 +0800 |
| commit | f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch) | |
| tree | ea1d61342cd29368e19135000ec2948813096205 /tools/gfx/d3d12/d3d12-resource-views.cpp | |
| parent | a729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff) | |
format
* format
* Minor test fixes
* enable checking cpp format in ci
Diffstat (limited to 'tools/gfx/d3d12/d3d12-resource-views.cpp')
| -rw-r--r-- | tools/gfx/d3d12/d3d12-resource-views.cpp | 177 |
1 files changed, 90 insertions, 87 deletions
diff --git a/tools/gfx/d3d12/d3d12-resource-views.cpp b/tools/gfx/d3d12/d3d12-resource-views.cpp index b156f6ab6..a760caef8 100644 --- a/tools/gfx/d3d12/d3d12-resource-views.cpp +++ b/tools/gfx/d3d12/d3d12-resource-views.cpp @@ -1,5 +1,6 @@ // d3d12-resource-views.cpp #include "d3d12-resource-views.h" + #include "d3d12-device.h" namespace gfx @@ -34,104 +35,106 @@ SlangResult createD3D12BufferDescriptor( const auto counterResourceImpl = static_cast<BufferResourceImpl*>(counterBuffer); uint64_t offset = desc.bufferRange.offset; - uint64_t size = desc.bufferRange.size == 0 ? buffer->getDesc()->sizeInBytes - offset : desc.bufferRange.size; + uint64_t size = desc.bufferRange.size == 0 ? buffer->getDesc()->sizeInBytes - offset + : desc.bufferRange.size; switch (desc.type) { - default: - return SLANG_FAIL; + default: return SLANG_FAIL; case IResourceView::Type::UnorderedAccess: - { - D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {}; - uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; - uavDesc.Format = D3DUtil::getMapFormat(desc.format); - if (bufferStride) - { - uavDesc.Buffer.FirstElement = offset / bufferStride; - uavDesc.Buffer.NumElements = UINT(size / bufferStride); - uavDesc.Buffer.StructureByteStride = bufferStride; - } - else if (desc.format == Format::Unknown) - { - uavDesc.Format = DXGI_FORMAT_R32_TYPELESS; - uavDesc.Buffer.FirstElement = offset / 4; - uavDesc.Buffer.NumElements = UINT(size / 4); - uavDesc.Buffer.Flags |= D3D12_BUFFER_UAV_FLAG_RAW; - } - else { - FormatInfo sizeInfo; - gfxGetFormatInfo(desc.format, &sizeInfo); - assert(sizeInfo.pixelsPerBlock == 1); - uavDesc.Buffer.FirstElement = offset / sizeInfo.blockSizeInBytes; - uavDesc.Buffer.NumElements = UINT(size / sizeInfo.blockSizeInBytes); + D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {}; + uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER; + uavDesc.Format = D3DUtil::getMapFormat(desc.format); + if (bufferStride) + { + uavDesc.Buffer.FirstElement = offset / bufferStride; + uavDesc.Buffer.NumElements = UINT(size / bufferStride); + uavDesc.Buffer.StructureByteStride = bufferStride; + } + else if (desc.format == Format::Unknown) + { + uavDesc.Format = DXGI_FORMAT_R32_TYPELESS; + uavDesc.Buffer.FirstElement = offset / 4; + uavDesc.Buffer.NumElements = UINT(size / 4); + uavDesc.Buffer.Flags |= D3D12_BUFFER_UAV_FLAG_RAW; + } + else + { + FormatInfo sizeInfo; + gfxGetFormatInfo(desc.format, &sizeInfo); + assert(sizeInfo.pixelsPerBlock == 1); + uavDesc.Buffer.FirstElement = offset / sizeInfo.blockSizeInBytes; + uavDesc.Buffer.NumElements = UINT(size / sizeInfo.blockSizeInBytes); + } + + if (size >= (1ull << 32) - 8) + { + // D3D12 does not support view descriptors that has size near 4GB. + // We will not create actual SRV/UAVs for such large buffers. + // However, a buffer this large can still be bound as root parameter. + // So instead of failing, we quietly ignore descriptor creation. + outDescriptor->cpuHandle.ptr = 0; + } + else + { + SLANG_RETURN_ON_FAIL(descriptorHeap->allocate(outDescriptor)); + device->m_device->CreateUnorderedAccessView( + resourceImpl->m_resource, + counterResourceImpl ? counterResourceImpl->m_resource.getResource() : nullptr, + &uavDesc, + outDescriptor->cpuHandle); + } } - - if (size >= (1ull << 32) - 8) - { - // D3D12 does not support view descriptors that has size near 4GB. - // We will not create actual SRV/UAVs for such large buffers. - // However, a buffer this large can still be bound as root parameter. - // So instead of failing, we quietly ignore descriptor creation. - outDescriptor->cpuHandle.ptr = 0; - } - else - { - SLANG_RETURN_ON_FAIL(descriptorHeap->allocate(outDescriptor)); - device->m_device->CreateUnorderedAccessView( - resourceImpl->m_resource, - counterResourceImpl ? counterResourceImpl->m_resource.getResource() : nullptr, - &uavDesc, - outDescriptor->cpuHandle); - } - } - break; + break; case IResourceView::Type::ShaderResource: - { - D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; - srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; - srvDesc.Format = D3DUtil::getMapFormat(desc.format); - srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; - if (bufferStride) - { - srvDesc.Buffer.FirstElement = offset / bufferStride; - srvDesc.Buffer.NumElements = UINT(size / bufferStride); - srvDesc.Buffer.StructureByteStride = bufferStride; - } - else if (desc.format == Format::Unknown) { - srvDesc.Format = DXGI_FORMAT_R32_TYPELESS; - srvDesc.Buffer.FirstElement = offset / 4; - srvDesc.Buffer.NumElements = UINT(size / 4); - srvDesc.Buffer.Flags |= D3D12_BUFFER_SRV_FLAG_RAW; + D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; + srvDesc.Format = D3DUtil::getMapFormat(desc.format); + srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + if (bufferStride) + { + srvDesc.Buffer.FirstElement = offset / bufferStride; + srvDesc.Buffer.NumElements = UINT(size / bufferStride); + srvDesc.Buffer.StructureByteStride = bufferStride; + } + else if (desc.format == Format::Unknown) + { + srvDesc.Format = DXGI_FORMAT_R32_TYPELESS; + srvDesc.Buffer.FirstElement = offset / 4; + srvDesc.Buffer.NumElements = UINT(size / 4); + srvDesc.Buffer.Flags |= D3D12_BUFFER_SRV_FLAG_RAW; + } + else + { + FormatInfo sizeInfo; + gfxGetFormatInfo(desc.format, &sizeInfo); + assert(sizeInfo.pixelsPerBlock == 1); + srvDesc.Buffer.FirstElement = offset / sizeInfo.blockSizeInBytes; + srvDesc.Buffer.NumElements = UINT(size / sizeInfo.blockSizeInBytes); + } + + if (size >= (1ull << 32) - 8) + { + // D3D12 does not support view descriptors that has size near 4GB. + // We will not create actual SRV/UAVs for such large buffers. + // However, a buffer this large can still be bound as root parameter. + // So instead of failing, we quietly ignore descriptor creation. + outDescriptor->cpuHandle.ptr = 0; + } + else + { + SLANG_RETURN_ON_FAIL(descriptorHeap->allocate(outDescriptor)); + device->m_device->CreateShaderResourceView( + resourceImpl->m_resource, + &srvDesc, + outDescriptor->cpuHandle); + } } - else - { - FormatInfo sizeInfo; - gfxGetFormatInfo(desc.format, &sizeInfo); - assert(sizeInfo.pixelsPerBlock == 1); - srvDesc.Buffer.FirstElement = offset / sizeInfo.blockSizeInBytes; - srvDesc.Buffer.NumElements = UINT(size / sizeInfo.blockSizeInBytes); - } - - if (size >= (1ull << 32) - 8) - { - // D3D12 does not support view descriptors that has size near 4GB. - // We will not create actual SRV/UAVs for such large buffers. - // However, a buffer this large can still be bound as root parameter. - // So instead of failing, we quietly ignore descriptor creation. - outDescriptor->cpuHandle.ptr = 0; - } - else - { - SLANG_RETURN_ON_FAIL(descriptorHeap->allocate(outDescriptor)); - device->m_device->CreateShaderResourceView( - resourceImpl->m_resource, &srvDesc, outDescriptor->cpuHandle); - } - } - break; + break; } return SLANG_OK; } |
