diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-04-17 16:59:03 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-17 16:59:03 -0400 |
| commit | 00389a127af8db18a3ec8fe7ad2dd114a65ac024 (patch) | |
| tree | 7fa57f2f30a399f03a7967a8534eb212744de5cc /tools/render-test/slang-support.cpp | |
| parent | 15bff9162530113b426664eb0c1deb7ea9e3a90d (diff) | |
Feature/renderer binding (#489)
* Dx12 rendering works in test framework.
* Turn on dx12 render tests.
* First pass at Resource and TextureResource/BufferResource types.
* Fix bug in Dx11 impl for BufferResource.
* Dx12 supports TextureResource and binds using TextureResource type, and all tests pass.
* Added TextureBuffer::Size type to make handling mips a little simpler.
* Small improvements to Dx12 constant buffer binding
Removed k prefix on an enum
* First pass impl of dx11 createTextureResource
Added setDefaults to TextureResource::Desc and BufferResource::Desc to simplify setup
accessFlags -> cpuAccessFlags
desc -> srcDesc
* Split out generateTextureResource - can produce the texture using createTextureResource on the Renderer.
* Added support for read mapping to Dx11
accessFlags -> cpuAccessFlags
First pass at using TextureResource/BufferResource on Dx11
Some tests fail with this checkin
* TextureResource working on all tests on dx11.
* Construct ResourceBuffers on Dx11 and Dx12 using utility function createInputBufferResource.
* First pass at OpenGl TextureResource
* Small fixes to dx12 and dx11 setup.
Gl working working using BufferResource and TextureResource
* Tidy up around the compareSampler - looks like the previous test was incorrect.
* Small documentation /naming improvements.
* Fix some more small documentation issues.
Diffstat (limited to 'tools/render-test/slang-support.cpp')
| -rw-r--r-- | tools/render-test/slang-support.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp index aa097bb44..d45ce55a4 100644 --- a/tools/render-test/slang-support.cpp +++ b/tools/render-test/slang-support.cpp @@ -172,5 +172,125 @@ ShaderCompiler* createSlangShaderCompiler( return result; } +SlangResult generateTextureResource(const InputTextureDesc& inputDesc, int bindFlags, Renderer* renderer, Slang::RefPtr<TextureResource>& textureOut) +{ + using namespace Slang; + + TextureData texData; + generateTextureData(texData, inputDesc); + + TextureResource::Desc textureResourceDesc; + textureResourceDesc.init(); + + textureResourceDesc.format = Format::RGBA_Unorm_UInt8; + textureResourceDesc.numMipLevels = texData.mipLevels; + textureResourceDesc.arraySize = inputDesc.arrayLength; + textureResourceDesc.bindFlags = bindFlags; + + // It's the same size in all dimensions + Resource::Type type = Resource::Type::Unknown; + switch (inputDesc.dimension) + { + case 1: + { + type = Resource::Type::Texture1D; + textureResourceDesc.size.init(inputDesc.size); + break; + } + case 2: + { + type = inputDesc.isCube ? Resource::Type::TextureCube : Resource::Type::Texture2D; + textureResourceDesc.size.init(inputDesc.size, inputDesc.size); + break; + } + case 3: + { + type = Resource::Type::Texture3D; + textureResourceDesc.size.init(inputDesc.size, inputDesc.size, inputDesc.size); + break; + } + } + + const int effectiveArraySize = textureResourceDesc.calcEffectiveArraySize(type); + const int numSubResources = textureResourceDesc.calcNumSubResources(type); + + Resource::Usage initialUsage = Resource::Usage::GenericRead; + TextureResource::Data initData; + + List<ptrdiff_t> mipRowStrides; + mipRowStrides.SetSize(textureResourceDesc.numMipLevels); + List<const void*> subResources; + subResources.SetSize(numSubResources); + + // Set up the src row strides + for (int i = 0; i < textureResourceDesc.numMipLevels; i++) + { + const int mipWidth = TextureResource::calcMipSize(textureResourceDesc.size.width, i); + mipRowStrides[i] = mipWidth * sizeof(uint32_t); + } + + // Set up pointers the the data + { + int subResourceIndex = 0; + const int numGen = int(texData.dataBuffer.Count()); + for (int i = 0; i < numSubResources; i++) + { + subResources[i] = texData.dataBuffer[subResourceIndex].Buffer(); + // Wrap around + subResourceIndex = (subResourceIndex + 1 >= numGen) ? 0 : (subResourceIndex + 1); + } + } + + initData.mipRowStrides = mipRowStrides.Buffer(); + initData.numMips = textureResourceDesc.numMipLevels; + initData.numSubResources = numSubResources; + initData.subResources = subResources.Buffer(); + + textureOut = renderer->createTextureResource(type, Resource::Usage::GenericRead, textureResourceDesc, &initData); + + return textureOut ? SLANG_OK : SLANG_FAIL; +} + +SlangResult createInputBufferResource(const InputBufferDesc& inputDesc, bool isOutput, size_t bufferSize, const void* initData, Renderer* renderer, Slang::RefPtr<BufferResource>& bufferOut) +{ + using namespace Slang; + + Resource::Usage initialUsage = Resource::Usage::GenericRead; + + BufferResource::Desc srcDesc; + srcDesc.init(bufferSize); + + int bindFlags = 0; + if (inputDesc.type == InputBufferType::ConstantBuffer) + { + bindFlags |= Resource::BindFlag::ConstantBuffer; + srcDesc.cpuAccessFlags |= Resource::AccessFlag::Write; + initialUsage = Resource::Usage::ConstantBuffer; + } + else + { + bindFlags |= Resource::BindFlag::UnorderedAccess | Resource::BindFlag::PixelShaderResource | Resource::BindFlag::NonPixelShaderResource; + srcDesc.elementSize = inputDesc.stride; + initialUsage = Resource::Usage::UnorderedAccess; + } + + if (isOutput) + { + srcDesc.cpuAccessFlags |= Resource::AccessFlag::Read; + } + + srcDesc.bindFlags = bindFlags; + + RefPtr<BufferResource> bufferResource = renderer->createBufferResource(initialUsage, srcDesc, initData); + if (!bufferResource) + { + return SLANG_FAIL; + } + + bufferOut = bufferResource; + return SLANG_OK; +} + + } // renderer_test |
