diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-09-03 14:36:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-03 14:36:55 -0400 |
| commit | b5b3a8d36c09631cbd4cf236c0280a314436748d (patch) | |
| tree | 2ae5a848815c9bcdd4006eaa2f81a8317f5df2a9 /tools | |
| parent | ce5fd43b0c9c60ad85e7c5a54161b37897640ea6 (diff) | |
CPU uniform entry point params (#1041)
* * Made entry point parameters a separate entry point
* Made CPUMemoryBinding work with entry point parameters/initialize constant buffers
* Added isCPUOnly to bindings, because entry point parameters do not layout like constant buffer
* entry-point-uniform.slang works on CPU
* EntryPointParams -> UniformEntryPointParams
Updated CPU documentation.
* Update cpu-target.md to removed completed issues.
* Only allocate CPU buffers if the size is > 0.
Small update to cpu-target doc.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/render-test/cpu-memory-binding.cpp | 131 | ||||
| -rw-r--r-- | tools/render-test/cpu-memory-binding.h | 8 | ||||
| -rw-r--r-- | tools/render-test/render-test-main.cpp | 8 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.cpp | 41 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.h | 5 | ||||
| -rw-r--r-- | tools/render-test/shader-renderer-util.cpp | 1 | ||||
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 4 |
7 files changed, 166 insertions, 32 deletions
diff --git a/tools/render-test/cpu-memory-binding.cpp b/tools/render-test/cpu-memory-binding.cpp index 0c54ac651..2b2fed167 100644 --- a/tools/render-test/cpu-memory-binding.cpp +++ b/tools/render-test/cpu-memory-binding.cpp @@ -42,46 +42,104 @@ CPUMemoryBinding::Buffer CPUMemoryBinding::_allocateBuffer(size_t size, const vo return buffer; } -SlangResult CPUMemoryBinding::init(slang::ShaderReflection* reflection) +SlangResult CPUMemoryBinding::init(slang::ShaderReflection* reflection, int entryPointIndex) { m_reflection = reflection; m_rootBuffer = Buffer(); m_allBuffers.clear(); m_arena.deallocateAll(); + + { + size_t globalConstantBuffer = reflection->getGlobalConstantBufferSize(); - size_t globalConstantBuffer = reflection->getGlobalConstantBufferSize(); + size_t rootSizeInBytes = 0; + const int parameterCount = reflection->getParameterCount(); + for (int i = 0; i < parameterCount; ++i) + { + auto parameter = reflection->getParameterByIndex(i); - size_t rootSizeInBytes = 0; - const int parameterCount = reflection->getParameterCount(); - for (int i = 0; i < parameterCount; ++i) - { - auto parameter = reflection->getParameterByIndex(i); + auto offset = parameter->getOffset(); - auto offset = parameter->getOffset(); + auto typeLayout = parameter->getTypeLayout(); + auto sizeInBytes = typeLayout->getSize(); - auto typeLayout = parameter->getTypeLayout(); - auto sizeInBytes = typeLayout->getSize(); + size_t endOffset = offset + sizeInBytes; - size_t endOffset = offset + sizeInBytes; + rootSizeInBytes = (endOffset > rootSizeInBytes) ? endOffset : rootSizeInBytes; + } + SLANG_ASSERT(rootSizeInBytes == globalConstantBuffer); - rootSizeInBytes = (endOffset > rootSizeInBytes) ? endOffset : rootSizeInBytes; - } - SLANG_ASSERT(rootSizeInBytes == globalConstantBuffer); + if (rootSizeInBytes) + { + // Allocate the 'root' buffer + m_rootBuffer = _allocateBuffer(rootSizeInBytes); + + // Create default empty constant buffers + uint8_t*const buffer = m_rootBuffer.m_data; + for (int i = 0; i < parameterCount; ++i) + { + auto parameter = reflection->getParameterByIndex(i); + auto offset = parameter->getOffset(); - // Allocate the root (0 is the root) - m_rootBuffer = _allocateBuffer(rootSizeInBytes); + auto typeLayout = parameter->getTypeLayout(); + Buffer paramBuffer; + SLANG_RETURN_ON_FAIL(_add(parameter, typeLayout, buffer + offset, paramBuffer)); + } + } + } { - uint8_t*const buffer = m_rootBuffer.m_data; - for (int i = 0; i < parameterCount; ++i) + auto entryPointCount = reflection->getEntryPointCount(); + if (entryPointIndex < 0 || entryPointIndex >= entryPointCount) { - auto parameter = reflection->getParameterByIndex(i); + SLANG_ASSERT(!"Entry point index out of range"); + return SLANG_FAIL; + } + + m_entryPoint = reflection->getEntryPointByIndex(entryPointIndex); + size_t entryPointParamsSizeInBytes = 0; + + const int parameterCount = int(m_entryPoint->getParameterCount()); + for (int i = 0 ; i < parameterCount; i++) + { + slang::VariableLayoutReflection* parameter = m_entryPoint->getParameterByIndex(i); + + // If has a semantic, then isn't uniform parameter + if (auto semanticName = parameter->getSemanticName()) + { + continue; + } + auto offset = parameter->getOffset(); auto typeLayout = parameter->getTypeLayout(); - Buffer paramBuffer; - SLANG_RETURN_ON_FAIL(_add(parameter, typeLayout, buffer + offset, paramBuffer)); + auto sizeInBytes = typeLayout->getSize(); + + size_t endOffset = offset + sizeInBytes; + entryPointParamsSizeInBytes = (endOffset > entryPointParamsSizeInBytes) ? endOffset : entryPointParamsSizeInBytes; + } + + if (entryPointParamsSizeInBytes) + { + m_entryPointBuffer = _allocateBuffer(entryPointParamsSizeInBytes); + + uint8_t*const buffer = m_entryPointBuffer.m_data; + for (int i = 0; i < parameterCount; ++i) + { + auto parameter = m_entryPoint->getParameterByIndex(i); + // If has a semantic, then isn't uniform parameter + if (auto semanticName = parameter->getSemanticName()) + { + continue; + } + + auto offset = parameter->getOffset(); + + auto typeLayout = parameter->getTypeLayout(); + Buffer paramBuffer; + SLANG_RETURN_ON_FAIL(_add(parameter, typeLayout, buffer + offset, paramBuffer)); + } } } @@ -158,17 +216,42 @@ slang::VariableLayoutReflection* CPUMemoryBinding::getParameterByName(const char return parameter; } } + return nullptr; } +slang::VariableLayoutReflection* CPUMemoryBinding::getEntryPointParameterByName(const char* name) +{ + const int parameterCount = int(m_entryPoint->getParameterCount()); + for (int i = 0; i < parameterCount; ++i) + { + auto parameter = m_entryPoint->getParameterByIndex(i); + // If has a semantic we will ignore + if (parameter->getSemanticName()) + { + continue; + } + if (strcmp(parameter->getName(), name) == 0) + { + return parameter; + } + } + return nullptr; +} + CPUMemoryBinding::Location CPUMemoryBinding::find(const char* name) { auto varLayout = getParameterByName(name); - if (varLayout == nullptr) + if (varLayout) { - return Location(); + return Location::make(varLayout->getTypeLayout(), m_rootBuffer.m_data + varLayout->getOffset()); } - return Location::make(varLayout->getTypeLayout(), m_rootBuffer.m_data + varLayout->getOffset()); + varLayout = getEntryPointParameterByName(name); + if (varLayout) + { + return Location::make(varLayout->getTypeLayout(), m_entryPointBuffer.m_data + varLayout->getOffset()); + } + return Location(); } CPUMemoryBinding::Location CPUMemoryBinding::Location::toField(const char* name) const diff --git a/tools/render-test/cpu-memory-binding.h b/tools/render-test/cpu-memory-binding.h index 9501c1d13..994dacacd 100644 --- a/tools/render-test/cpu-memory-binding.h +++ b/tools/render-test/cpu-memory-binding.h @@ -43,6 +43,8 @@ struct CPUMemoryBinding }; slang::VariableLayoutReflection* getParameterByName(const char* name); + slang::VariableLayoutReflection* getEntryPointParameterByName(const char* name); + Location find(const char* name); @@ -50,7 +52,7 @@ struct CPUMemoryBinding SlangResult setNewBuffer(const Location& location, const void* initialData, size_t sizeInBytes, Buffer& outBuffer); SlangResult setObject(const Location& location, void* object); SlangResult setInplace(const Location& location, const void* data, size_t sizeInBytes); - SlangResult init(slang::ShaderReflection* reflection); + SlangResult init(slang::ShaderReflection* reflection, int entryPointIndex); CPUMemoryBinding(); Buffer _allocateBuffer(size_t size); @@ -61,11 +63,15 @@ struct CPUMemoryBinding Slang::MemoryArena m_arena; ///< Storage for buffers Buffer m_rootBuffer; + Buffer m_entryPointBuffer; slang::ShaderReflection* m_reflection; // All buffers Slang::List<Buffer> m_allBuffers; + + slang::EntryPointReflection* m_entryPoint; + int m_entryPointIndex; }; } // renderer_test diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp index ef3613240..440ba9c82 100644 --- a/tools/render-test/render-test-main.cpp +++ b/tools/render-test/render-test-main.cpp @@ -294,6 +294,7 @@ static SlangResult _compile(SlangSession* session, const String& sourcePath, Opt // Parse the layout layout.parse(sourceText.getBuffer()); + layout.updateForTarget(input.target); // Setup SourceInfo ShaderCompileRequest::SourceInfo sourceInfo; @@ -420,7 +421,7 @@ static SlangResult _doCPUCompute(SlangSession* session, const String& sourcePath auto request = output.compileOutput.request; struct UniformState; - typedef void(*Func)(CPPPrelude::ComputeVaryingInput* varyingInput, UniformState* uniformState); + typedef void(*Func)(CPPPrelude::ComputeVaryingInput* varyingInput, CPPPrelude::UniformEntryPointParams* params, UniformState* uniformState); auto reflection = (slang::ShaderReflection*) spGetReflection(request); @@ -442,7 +443,7 @@ static SlangResult _doCPUCompute(SlangSession* session, const String& sourcePath } CPUMemoryBinding binding; - binding.init(reflection); + SLANG_RETURN_ON_FAIL(binding.init(reflection, 0)); List<CPUMemoryBinding::Buffer> buffers; @@ -645,6 +646,7 @@ static SlangResult _doCPUCompute(SlangSession* session, const String& sourcePath { UniformState* uniformState = (UniformState*)binding.m_rootBuffer.m_data; + CPPPrelude::UniformEntryPointParams* params = (CPPPrelude::UniformEntryPointParams*)binding.m_entryPointBuffer.m_data; CPPPrelude::ComputeVaryingInput varying; varying.groupID = {}; @@ -659,7 +661,7 @@ static SlangResult _doCPUCompute(SlangSession* session, const String& sourcePath { varying.groupThreadID.x = x; - func(&varying, uniformState); + func(&varying, params, uniformState); } } } diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp index a59f30a24..810e31c2c 100644 --- a/tools/render-test/shader-input-layout.cpp +++ b/tools/render-test/shader-input-layout.cpp @@ -22,6 +22,40 @@ namespace renderer_test return -1; } + static bool _isCPUTarget(SlangCompileTarget target) + { + switch (target) + { + case SLANG_C_SOURCE: + case SLANG_CPP_SOURCE: + case SLANG_EXECUTABLE: + case SLANG_SHARED_LIBRARY: + case SLANG_HOST_CALLABLE: + { + return true; + } + default: return false; + } + } + + void ShaderInputLayout::updateForTarget(SlangCompileTarget target) + { + if (!_isCPUTarget(target)) + { + int count = int(entries.getCount()); + for (int i = 0; i < count; ++i) + { + auto& entry = entries[i]; + if (entry.isCPUOnly) + { + entries.removeAt(i); + i--; + count--; + } + } + } + } + void ShaderInputLayout::parse(const char * source) { entries.clear(); @@ -257,7 +291,12 @@ namespace renderer_test parser.Read(":"); while (!parser.IsEnd()) { - if (parser.LookAhead("dxbinding")) + if (parser.LookAhead("isCPUOnly")) + { + entry.isCPUOnly = true; + parser.ReadToken(); + } + else if (parser.LookAhead("dxbinding")) { parser.ReadToken(); parser.Read("("); diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h index 0f11c4ad7..2a58bfd2c 100644 --- a/tools/render-test/shader-input-layout.h +++ b/tools/render-test/shader-input-layout.h @@ -59,6 +59,7 @@ public: InputBufferDesc bufferDesc; InputSamplerDesc samplerDesc; bool isOutput = false; + bool isCPUOnly = false; int hlslBinding = -1; Slang::List<int> glslBinding; @@ -85,7 +86,9 @@ public: Slang::Index findEntryIndexByName(const Slang::String& name) const; - void parse(const char * source); + void updateForTarget(SlangCompileTarget target); + + void parse(const char* source); }; void generateTextureDataRGB8(TextureData& output, const InputTextureDesc& desc); diff --git a/tools/render-test/shader-renderer-util.cpp b/tools/render-test/shader-renderer-util.cpp index e13958f50..55ef4a3dc 100644 --- a/tools/render-test/shader-renderer-util.cpp +++ b/tools/render-test/shader-renderer-util.cpp @@ -223,6 +223,7 @@ static RefPtr<SamplerState> _createSamplerState( for (Index i = 0; i < numEntries; i++) { const ShaderInputLayoutEntry& srcEntry = srcEntries[i]; + SLANG_ASSERT(srcEntry.isCPUOnly == false); const BindingStateImpl::RegisterRange registerSet = calcRegisterRange(renderer, srcEntry); if (!registerSet.isValid()) diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index ff80c7ec0..42072cc81 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -1162,7 +1162,7 @@ TestResult runCPUExecuteTest(TestContext* context, TestInput& input) CPPPrelude::RWStructuredBuffer<int> buffer; }; - typedef void (*Func)(CPPPrelude::ComputeVaryingInput* varyingInput, UniformState* uniformState); + typedef void (*Func)(CPPPrelude::ComputeVaryingInput* varyingInput, CPPPrelude::UniformEntryPointParams* params, UniformState* uniformState); Func runFunc = Func(func); int32_t data[4] = { 0, 0, 0, 0}; @@ -1175,7 +1175,7 @@ TestResult runCPUExecuteTest(TestContext* context, TestInput& input) for (Int i = 0; i < 4; ++i) { varyingInput.groupThreadID.x = uint32_t(i); - runFunc(&varyingInput, &state); + runFunc(&varyingInput, nullptr, &state); } SharedLibrary::unload(sharedLibrary); |
