summaryrefslogtreecommitdiffstats
path: root/tools/render-test/slang-support.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-04-19 17:47:04 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2018-04-19 14:47:04 -0700
commit4c751df1680c30fac0369171a9b8dd4bb5bb5b9f (patch)
treeafde05a4cefd2b203add6b6ea8b94722d9734e11 /tools/render-test/slang-support.cpp
parentcbedf01cc53b848dfcc086f04098ef438121a7c7 (diff)
Separation of Binding/Resource construction on Renderer interface (#508)
* 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. * First pass testing out construction of binding resources external to Renderer implementation. * Moved some BindingState::Desc types to BindingState to make easier to use. * First pass of binding using BindingState::Desc for Dx11. * First pass at binding with dx12. * Fixed issues around separating dx12 binding from ShaderInputLayout * First pass at OpenGl state binding. * BindingState::Desc::Binding::Type -> BindingType * Use Buffer to manage life of vk resources. Construction of buffers handled by createBufferResource (BindingState doesn't have specialized logic) * Remove InputLayout types from binding so can create a binding independent of it. * Added upload buffer to BufferResource - could be used for write mapping. * m_samplers -> m_samplerDescs. First pass at Vk binding with BindingState::Desc. Small tidy/doc improvements. * First pass with binding all taking place through BindingState::Desc. All tests pass. * Removed support for creating BindingState from ShaderInputLayout * Remove serializeOutput from Renderer interface and all implementations. Implement map/unmap on vulkan Implement serializeBindingOutput which uses map/unmap and BindingState::Desc to write result. * Make implementation of BindingState use the BindingState::Desc for much of state - only hold api specific in BindingDetail per implementation. * Use Glsl binding on vulkan (was using hlsl). * BindingState::Desc::Binding -> BindingState::Binding. Made possible by impls using 'BindingDetail' for their specific needs. * Fix compile problems on win32. * Fix a typo in name createBindingSetDesc -> createBindingStateDesc
Diffstat (limited to 'tools/render-test/slang-support.cpp')
-rw-r--r--tools/render-test/slang-support.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index d45ce55a4..a9079b52c 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -1,5 +1,7 @@
// slang-support.cpp
+#define _CRT_SECURE_NO_WARNINGS 1
+
#include "slang-support.h"
#include <assert.h>
@@ -291,6 +293,136 @@ SlangResult createInputBufferResource(const InputBufferDesc& inputDesc, bool isO
return SLANG_OK;
}
+static BindingState::SamplerDesc _calcSamplerDesc(const InputSamplerDesc& srcDesc)
+{
+ BindingState::SamplerDesc dstDesc;
+ dstDesc.isCompareSampler = srcDesc.isCompareSampler;
+ return dstDesc;
+}
+
+SlangResult createBindingStateDesc(ShaderInputLayoutEntry* srcEntries, int numEntries, Renderer* renderer, BindingState::Desc& descOut)
+{
+ using namespace Slang;
+
+ const int textureBindFlags = Resource::BindFlag::NonPixelShaderResource | Resource::BindFlag::PixelShaderResource;
+
+ descOut.clear();
+ for (int i = 0; i < numEntries; i++)
+ {
+ const ShaderInputLayoutEntry& srcEntry = srcEntries[i];
+
+ BindingState::RegisterDesc registerDesc;
+ registerDesc.registerSets[int(BindingState::ShaderStyle::Hlsl)] = descOut.addRegisterSet(srcEntry.hlslBinding);
+ registerDesc.registerSets[int(BindingState::ShaderStyle::Glsl)] = descOut.addRegisterSet(srcEntry.glslBinding.Buffer(), int(srcEntry.glslBinding.Count()));
+
+ switch (srcEntry.type)
+ {
+ case ShaderInputType::Buffer:
+ {
+ const InputBufferDesc& srcBuffer = srcEntry.bufferDesc;
+
+ const size_t bufferSize = srcEntry.bufferData.Count() * sizeof(uint32_t);
+
+ RefPtr<BufferResource> bufferResource;
+ SLANG_RETURN_ON_FAIL(createInputBufferResource(srcEntry.bufferDesc, srcEntry.isOutput, bufferSize, srcEntry.bufferData.Buffer(), renderer, bufferResource));
+
+ descOut.addBufferResource(bufferResource, registerDesc);
+ break;
+ }
+ case ShaderInputType::CombinedTextureSampler:
+ {
+ RefPtr<TextureResource> texture;
+ SLANG_RETURN_ON_FAIL(generateTextureResource(srcEntry.textureDesc, textureBindFlags, renderer, texture));
+ descOut.addCombinedTextureSampler(texture, _calcSamplerDesc(srcEntry.samplerDesc), registerDesc);
+ break;
+ }
+ case ShaderInputType::Texture:
+ {
+ RefPtr<TextureResource> texture;
+ SLANG_RETURN_ON_FAIL(generateTextureResource(srcEntry.textureDesc, textureBindFlags, renderer, texture));
+
+ descOut.addTextureResource(texture, registerDesc);
+ break;
+ }
+ case ShaderInputType::Sampler:
+ {
+ descOut.addSampler(_calcSamplerDesc(srcEntry.samplerDesc), registerDesc);
+ break;
+ }
+ default:
+ {
+ assert(!"Unhandled type");
+ return SLANG_FAIL;
+ }
+ }
+ }
+
+ return SLANG_OK;
+}
+
+SlangResult createBindingStateDesc(const ShaderInputLayout& layout, Renderer* renderer, BindingState::Desc& descOut)
+{
+ SLANG_RETURN_ON_FAIL(createBindingStateDesc(layout.entries.Buffer(), int(layout.entries.Count()), renderer, descOut));
+ descOut.m_numRenderTargets = layout.numRenderTargets;
+
+ return SLANG_OK;
+}
+
+SlangResult serializeBindingOutput(const ShaderInputLayout& layout, BindingState* bindingState, Renderer* renderer, const char* fileName)
+{
+ // Submit the work
+ renderer->submitGpuWork();
+ // Wait until everything is complete
+ renderer->waitForGpu();
+
+ FILE * f = fopen(fileName, "wb");
+ if (!f)
+ {
+ return SLANG_FAIL;
+ }
+
+ const BindingState::Desc& bindingStateDesc = bindingState->getDesc();
+ // Must be the same amount of entries
+ assert(bindingStateDesc.m_bindings.Count() == layout.entries.Count());
+
+ const int numBindings = int(bindingStateDesc.m_bindings.Count());
+
+ for (int i = 0; i < numBindings; ++i)
+ {
+ const auto& layoutBinding = layout.entries[i];
+ const auto& binding = bindingStateDesc.m_bindings[i];
+
+ if (layoutBinding.isOutput)
+ {
+ if (binding.resource && binding.resource->isBuffer())
+ {
+ BufferResource* bufferResource = static_cast<BufferResource*>(binding.resource.Ptr());
+ const size_t bufferSize = bufferResource->getDesc().sizeInBytes;
+
+ unsigned int* ptr = (unsigned int*)renderer->map(bufferResource, MapFlavor::HostRead);
+ if (!ptr)
+ {
+ fclose(f);
+ return SLANG_FAIL;
+ }
+
+ const int size = int(bufferSize / sizeof(unsigned int));
+ for (int i = 0; i < size; ++i)
+ {
+ fprintf(f, "%X\n", ptr[i]);
+ }
+ renderer->unmap(bufferResource);
+ }
+ else
+ {
+ printf("invalid output type at %d.\n", i);
+ }
+ }
+ }
+ fclose(f);
+
+ return SLANG_OK;
+}
} // renderer_test