diff options
| author | Simon Kallweit <64953474+skallweitNV@users.noreply.github.com> | 2024-09-19 17:16:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-19 23:16:48 +0800 |
| commit | 3861be7ce5bd3ffc1bc60f2c3f7f41647145d575 (patch) | |
| tree | b473120fa3745c6b33f2d5f7e3df17b45a6412be /tools/render-test/shader-renderer-util.cpp | |
| parent | fe71eafcb6e11a420ab537f257e6b8971d31d9de (diff) | |
refactor render test to use latest slang-rhi (#5119)
* refactor render test to use latest slang-rhi
* update slang-rhi
* update slang-rhi
* update slang-rhi
* update slang-rhi
Diffstat (limited to 'tools/render-test/shader-renderer-util.cpp')
| -rw-r--r-- | tools/render-test/shader-renderer-util.cpp | 184 |
1 files changed, 72 insertions, 112 deletions
diff --git a/tools/render-test/shader-renderer-util.cpp b/tools/render-test/shader-renderer-util.cpp index c2f7583a7..5448979b4 100644 --- a/tools/render-test/shader-renderer-util.cpp +++ b/tools/render-test/shader-renderer-util.cpp @@ -13,49 +13,26 @@ inline int calcMipSize(int size, int level) return size > 0 ? size : 1; } -inline ITextureResource::Extents calcMipSize(ITextureResource::Extents size, int mipLevel) +inline Extents calcMipSize(Extents size, int mipLevel) { - ITextureResource::Extents rs; + Extents rs; rs.width = calcMipSize(size.width, mipLevel); rs.height = calcMipSize(size.height, mipLevel); rs.depth = calcMipSize(size.depth, mipLevel); return rs; } -/// Calculate the effective array size - in essence the amount if mip map sets needed. -/// In practice takes into account if the arraySize is 0 (it's not an array, but it will still have -/// at least one mip set) and if the type is a cubemap (multiplies the amount of mip sets by 6) -inline int calcEffectiveArraySize(const ITextureResource::Desc& desc) -{ - const int arrSize = (desc.arraySize > 0) ? desc.arraySize : 1; - - switch (desc.type) - { - case IResource::Type::Texture1D: // fallthru - case IResource::Type::Texture2D: - { - return arrSize; - } - case IResource::Type::TextureCube: - return arrSize * 6; - case IResource::Type::Texture3D: - return 1; - default: - return 0; - } -} - /// Given the type works out the maximum dimension size -inline int calcMaxDimension(ITextureResource::Extents size, IResource::Type type) +inline int calcMaxDimension(Extents size, TextureType type) { switch (type) { - case IResource::Type::Texture1D: + case TextureType::Texture1D: return size.width; - case IResource::Type::Texture3D: + case TextureType::Texture3D: return Math::Max(Math::Max(size.width, size.height), size.depth); - case IResource::Type::TextureCube: // fallthru - case IResource::Type::Texture2D: + case TextureType::TextureCube: // fallthru + case TextureType::Texture2D: { return Math::Max(size.width, size.height); } @@ -65,115 +42,103 @@ inline int calcMaxDimension(ITextureResource::Extents size, IResource::Type type } /// Given the type, calculates the number of mip maps. 0 on error -inline int calcNumMipLevels(IResource::Type type, ITextureResource::Extents size) +inline int calcNumMipLevels(TextureType type, Extents size) { const int maxDimensionSize = calcMaxDimension(size, type); return (maxDimensionSize > 0) ? (Math::Log2Floor(maxDimensionSize) + 1) : 0; } -/// Calculate the total number of sub resources. 0 on error. -inline int calcNumSubResources(const ITextureResource::Desc& desc) -{ - const int numMipMaps = - (desc.numMipLevels > 0) ? desc.numMipLevels : calcNumMipLevels(desc.type, desc.size); - const int arrSize = (desc.arraySize > 0) ? desc.arraySize : 1; - - switch (desc.type) - { - case IResource::Type::Texture1D: - case IResource::Type::Texture2D: - case IResource::Type::Texture3D: - { - return numMipMaps * arrSize; - } - case IResource::Type::TextureCube: - { - // There are 6 faces to a cubemap - return numMipMaps * arrSize * 6; - } - default: - return 0; - } -} - -/* static */ Result ShaderRendererUtil::generateTextureResource( +/* static */ Result ShaderRendererUtil::generateTexture( const InputTextureDesc& inputDesc, ResourceState defaultState, IDevice* device, - ComPtr<ITextureResource>& textureOut) + ComPtr<ITexture>& textureOut) { TextureData texData; generateTextureData(texData, inputDesc); - return createTextureResource(inputDesc, texData, defaultState, device, textureOut); + return createTexture(inputDesc, texData, defaultState, device, textureOut); } -/* static */ Result ShaderRendererUtil::createTextureResource( +/* static */ Result ShaderRendererUtil::createTexture( const InputTextureDesc& inputDesc, const TextureData& texData, ResourceState defaultState, IDevice* device, - ComPtr<ITextureResource>& textureOut) + ComPtr<ITexture>& textureOut) { - ITextureResource::Desc textureResourceDesc = {}; + TextureDesc textureDesc = {}; // Default to R8G8B8A8_UNORM const Format format = (inputDesc.format == Format::Unknown) ? Format::R8G8B8A8_UNORM : inputDesc.format; - textureResourceDesc.sampleDesc = ITextureResource::SampleDesc{inputDesc.sampleCount, 0}; - textureResourceDesc.format = format; - textureResourceDesc.numMipLevels = texData.m_mipLevels; - textureResourceDesc.arraySize = inputDesc.arrayLength; - textureResourceDesc.allowedStates = - ResourceStateSet(defaultState, ResourceState::CopyDestination, ResourceState::CopySource); - textureResourceDesc.defaultState = defaultState; + textureDesc.sampleCount = inputDesc.sampleCount; + textureDesc.format = format; + textureDesc.numMipLevels = texData.m_mipLevels; + textureDesc.arrayLength = inputDesc.arrayLength > 0 ? inputDesc.arrayLength : 1; + textureDesc.usage = TextureUsage::CopyDestination | TextureUsage::CopySource; + switch (defaultState) + { + case ResourceState::ShaderResource: + textureDesc.usage |= TextureUsage::ShaderResource; + break; + case ResourceState::UnorderedAccess: + textureDesc.usage |= TextureUsage::UnorderedAccess; + break; + default: + return SLANG_FAIL; + } + textureDesc.defaultState = defaultState; // It's the same size in all dimensions switch (inputDesc.dimension) { case 1: { - textureResourceDesc.type = IResource::Type::Texture1D; - textureResourceDesc.size.width = inputDesc.size; - textureResourceDesc.size.height = 1; - textureResourceDesc.size.depth = 1; + textureDesc.type = TextureType::Texture1D; + textureDesc.size.width = inputDesc.size; + textureDesc.size.height = 1; + textureDesc.size.depth = 1; break; } case 2: { - textureResourceDesc.type = inputDesc.isCube ? IResource::Type::TextureCube : IResource::Type::Texture2D; - textureResourceDesc.size.width = inputDesc.size; - textureResourceDesc.size.height = inputDesc.size; - textureResourceDesc.size.depth = 1; + textureDesc.type = inputDesc.isCube ? TextureType::TextureCube : TextureType::Texture2D; + textureDesc.size.width = inputDesc.size; + textureDesc.size.height = inputDesc.size; + textureDesc.size.depth = 1; break; } case 3: { - textureResourceDesc.type = IResource::Type::Texture3D; - textureResourceDesc.size.width = inputDesc.size; - textureResourceDesc.size.height = inputDesc.size; - textureResourceDesc.size.depth = inputDesc.size; + textureDesc.type = TextureType::Texture3D; + textureDesc.size.width = inputDesc.size; + textureDesc.size.height = inputDesc.size; + textureDesc.size.depth = inputDesc.size; break; } } - const int effectiveArraySize = calcEffectiveArraySize(textureResourceDesc); - const int numSubResources = calcNumSubResources(textureResourceDesc); + if (textureDesc.numMipLevels == 0) + { + textureDesc.numMipLevels = calcNumMipLevels(textureDesc.type, textureDesc.size); + } - List<ITextureResource::SubresourceData> initSubresources; + List<SubresourceData> initSubresources; + int arrayLayerCount = textureDesc.arrayLength * (textureDesc.type == TextureType::TextureCube ? 6 : 1); int subResourceCounter = 0; - for( int a = 0; a < effectiveArraySize; ++a ) + for( int a = 0; a < arrayLayerCount; ++a ) { - for( int m = 0; m < textureResourceDesc.numMipLevels; ++m ) + for( int m = 0; m < textureDesc.numMipLevels; ++m ) { int subResourceIndex = subResourceCounter++; - const int mipWidth = calcMipSize(textureResourceDesc.size.width, m); - const int mipHeight = calcMipSize(textureResourceDesc.size.height, m); + const int mipWidth = calcMipSize(textureDesc.size.width, m); + const int mipHeight = calcMipSize(textureDesc.size.height, m); auto strideY = mipWidth * sizeof(uint32_t); auto strideZ = mipHeight * strideY; - ITextureResource::SubresourceData subresourceData; + SubresourceData subresourceData; subresourceData.data = texData.m_slices[subResourceIndex].values; subresourceData.strideY = strideY; subresourceData.strideZ = strideZ; @@ -182,31 +147,26 @@ inline int calcNumSubResources(const ITextureResource::Desc& desc) } } - textureOut = device->createTextureResource(textureResourceDesc, initSubresources.getBuffer()); + textureOut = device->createTexture(textureDesc, initSubresources.getBuffer()); return textureOut ? SLANG_OK : SLANG_FAIL; } -/* static */ Result ShaderRendererUtil::createBufferResource( +/* static */ Result ShaderRendererUtil::createBuffer( const InputBufferDesc& inputDesc, size_t bufferSize, const void* initData, IDevice* device, - Slang::ComPtr<IBufferResource>& bufferOut) + Slang::ComPtr<IBuffer>& bufferOut) { - IBufferResource::Desc srcDesc; - srcDesc.type = IResource::Type::Buffer; - srcDesc.sizeInBytes = bufferSize; - srcDesc.format = inputDesc.format; - srcDesc.elementSize = inputDesc.stride; - srcDesc.defaultState = ResourceState::UnorderedAccess; - srcDesc.allowedStates = ResourceStateSet( - ResourceState::CopyDestination, - ResourceState::CopySource, - ResourceState::UnorderedAccess, - ResourceState::ShaderResource); - - ComPtr<IBufferResource> bufferResource = device->createBufferResource(srcDesc, initData); + BufferDesc bufferDesc; + bufferDesc.size = bufferSize; + bufferDesc.format = inputDesc.format; + bufferDesc.elementSize = inputDesc.stride; + bufferDesc.usage = BufferUsage::CopyDestination | BufferUsage::CopySource | BufferUsage::ShaderResource | BufferUsage::UnorderedAccess; + bufferDesc.defaultState = ResourceState::UnorderedAccess; + + ComPtr<IBuffer> bufferResource = device->createBuffer(bufferDesc, initData); if (!bufferResource) { return SLANG_FAIL; @@ -216,21 +176,21 @@ inline int calcNumSubResources(const ITextureResource::Desc& desc) return SLANG_OK; } -static ISamplerState::Desc _calcSamplerDesc(const InputSamplerDesc& srcDesc) +static SamplerDesc _calcSamplerDesc(const InputSamplerDesc& srcDesc) { - ISamplerState::Desc dstDesc; + SamplerDesc samplerDesc; if (srcDesc.isCompareSampler) { - dstDesc.reductionOp = TextureReductionOp::Comparison; - dstDesc.comparisonFunc = ComparisonFunc::Less; + samplerDesc.reductionOp = TextureReductionOp::Comparison; + samplerDesc.comparisonFunc = ComparisonFunc::Less; } - return dstDesc; + return samplerDesc; } -ComPtr<ISamplerState> _createSamplerState(IDevice* device, +ComPtr<ISampler> _createSampler(IDevice* device, const InputSamplerDesc& srcDesc) { - return device->createSamplerState(_calcSamplerDesc(srcDesc)); + return device->createSampler(_calcSamplerDesc(srcDesc)); } } // renderer_test |
