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/render-test/cpu-memory-binding.cpp | |
| 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/render-test/cpu-memory-binding.cpp')
| -rw-r--r-- | tools/render-test/cpu-memory-binding.cpp | 131 |
1 files changed, 107 insertions, 24 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 |
