diff options
| -rw-r--r-- | docs/cpu-target.md | 19 | ||||
| -rw-r--r-- | tests/compute/parameter-block.slang | 5 | ||||
| -rw-r--r-- | tools/render-test/cpu-memory-binding.cpp | 12 |
3 files changed, 21 insertions, 15 deletions
diff --git a/docs/cpu-target.md b/docs/cpu-target.md index 9aaeef2e3..d4ef6ddd8 100644 --- a/docs/cpu-target.md +++ b/docs/cpu-target.md @@ -19,7 +19,6 @@ These limitations apply to Slang transpiling to C++. * Atomics are not supported * Complex resource types (such as Texture2d) are work in progress * Out of bounds access to resources has undefined behavior -* ParameterBlocks are not currently supported For current C++ source output, the compiler needs to support partial specialization. @@ -61,7 +60,7 @@ In order to be able to use the Slang code on CPU, there needs to be binding via If a binary target is requested, the binary contents will be returned in a ISlangBlob just like for other targets. To use the CPU binary typically it must be saved as file and then potentially marked for execution by the OS before executing. It may be possible to load shared libraries or dlls from memory - but is a non standard feature, that requires unusual work arounds. -Under the covers when Slang is used to generate a binary via a C/C++ compiler, it must do so through the file system. Currently this means that the source (say generated by Slang) and the binary (produced by the C/C++ compiler) must all be files. To make this work Slang uses temporary files. The reasoning for hiding this mechanism - and not return filenames, is so that in the future when binaries are produced directly (for example with LLVM), nothing will need to change. +Under the covers when Slang is used to generate a binary via a C/C++ compiler, it must do so through the file system. Currently this means that the source (say generated by Slang) and the binary (produced by the C/C++ compiler) must all be files. To make this work Slang uses temporary files. The reasoning for hiding this mechanism - and for example not return filenames, is so that in the future when binaries are produced directly (for example with LLVM), nothing will need to change. Executing CPU Code ================== @@ -133,17 +132,26 @@ struct UniformState Notice that of the entry point parameters `dispatchThreadID` is not part of UniformEntryPointParams and this is because it is not uniform. -ConstantBuffers will become pointers to the type they hold (as `thing3` is in the above structure). +`ConstantBuffer` and `ParameterBlock` will become pointers to the type they hold (as `thing3` is in the above structure). -StructuredBuffer/RWStructuredBuffer/ByteAddressBuffer/RWByteAddressBuffer become in effect (where in ByteAddressBuffers T is uint32_t). +`StructuredBuffer<T>`,`RWStructuredBuffer<T>` become ``` T* data; size_t count; ``` +`ByteAddressBuffer`, `RWByteAddressBuffer` become + +``` + uint32_t* data; + size_t sizeInBytes; +``` + Resource types become pointers to interfaces that implement their features. For example `Texture2D` become a pointer to a `ITexture2D` interface that has to be implemented in client side code. Similarly SamplerState and SamplerComparisonState become `ISamplerState` and `ISamplerComparisonState`. +The actual definitions for the interfaces for resource types, and types are specified in 'slang-cpp-types.h' in the `prelude` directory. + The code that sets up the prelude for the test infrastucture and command line usage can be found in ```TestToolUtil::setSessionDefaultPrelude```. ## Prelude @@ -163,7 +171,7 @@ For the Slang prelude this is split into the following files... * 'prelude/slang-cpp-types.h' - The 'built in types' * 'slang.h' - Slang header is used for majority of compiler based definitions -For a client application - as long as the requirements of the generated code are met, the prelude can be implemented by whatever mechanism is appropriate for the client . For example the implementation could be replaced with another implementation, or the prelude could contain all of the required text for compilation. Setting the prelude text can be achieved with the method on the global session... +For a client application - as long as the requirements of the generated code are met, the prelude can be implemented by whatever mechanism is appropriate for the client. For example the implementation could be replaced with another implementation, or the prelude could contain all of the required text for compilation. Setting the prelude text can be achieved with the method on the global session... ``` /** Set the 'prelude' for generated code for a 'downstream compiler'. @@ -240,7 +248,6 @@ TODO # Main * Complete support (in terms of interfaces) for 'complex' resource types - such as Texture -* Parameter block support (the difficulty is around layout) * Output of header files * Output multiple entry points diff --git a/tests/compute/parameter-block.slang b/tests/compute/parameter-block.slang index c409fe22d..8c1675405 100644 --- a/tests/compute/parameter-block.slang +++ b/tests/compute/parameter-block.slang @@ -1,7 +1,8 @@ //TEST(compute):COMPARE_COMPUTE: +//TEST(compute):COMPARE_COMPUTE:-cpu -//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out -//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):dxbinding(1),glbinding(1) +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out,name=block0.buffer +//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):dxbinding(1),glbinding(1),name=block1.buffer // Ensure that Slang `ParameterBlock` type is lowered // to HLSL in the fashion that we expect. diff --git a/tools/render-test/cpu-memory-binding.cpp b/tools/render-test/cpu-memory-binding.cpp index 612c2fc57..c2d853aa8 100644 --- a/tools/render-test/cpu-memory-binding.cpp +++ b/tools/render-test/cpu-memory-binding.cpp @@ -183,6 +183,7 @@ SlangResult CPUMemoryBinding::_add(slang::VariableLayoutReflection* varLayout, s } break; } + case slang::TypeReflection::Kind::ParameterBlock: case slang::TypeReflection::Kind::ConstantBuffer: { SLANG_ASSERT(typeLayout->getSize() == sizeof(void*)); @@ -269,7 +270,8 @@ CPUMemoryBinding::Location CPUMemoryBinding::Location::toField(const char* name) // Strip constantBuffer wrapping { const auto kind = typeLayout->getKind(); - if (kind == slang::TypeReflection::Kind::ConstantBuffer) + if (kind == slang::TypeReflection::Kind::ConstantBuffer || + kind == slang::TypeReflection::Kind::ParameterBlock) { // Follow the pointer cur = *(uint8_t**)cur; @@ -344,6 +346,7 @@ SlangResult CPUMemoryBinding::setBufferContents(const Location& location, const const auto kind = typeLayout->getKind(); switch (kind) { + case slang::TypeReflection::Kind::ParameterBlock: case slang::TypeReflection::Kind::ConstantBuffer: { typeLayout = typeLayout->getElementTypeLayout(); @@ -373,6 +376,7 @@ SlangResult CPUMemoryBinding::setNewBuffer(const Location& location, const void* const auto kind = typeLayout->getKind(); switch (kind) { + case slang::TypeReflection::Kind::ParameterBlock: case slang::TypeReflection::Kind::ConstantBuffer: { // All should be allocated (!) @@ -441,12 +445,6 @@ SlangResult CPUMemoryBinding::setObject(const Location& location, void* object) default: break; - case slang::TypeReflection::Kind::ParameterBlock: - { - auto elementTypeLayout = typeLayout->getElementTypeLayout(); - SLANG_UNUSED(elementTypeLayout); - break; - } case slang::TypeReflection::Kind::TextureBuffer: { auto elementTypeLayout = typeLayout->getElementTypeLayout(); |
