From a8669ade5cb3add8b9ce08e2c3bd96e93190bca8 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 17 Jan 2020 09:15:06 -0500 Subject: Slang -> CUDA kernel runs correctly in test infrastructure (#1167) * First pass at BindLocation. * Added BindSet::init - for initializing with two input constant buffers. Needs better name, and perhaps should be another class. * Fix handling of constant buffer stripping. Improved initialization. * Trying to generalize BindLocation a little more. Split out CPULikeBindRoot. * More work to make BindLocation et al work with non uniform bindings. * Added parsing to a location. * WIP: Trying to get CPU working with BindLocation. * Describe problem of knowing the type of the reference point in the binding table. * More ideas on getBindings fix. * Remove BindSet as member of BindLocation. * Added BindLocation::Invalid * Made BindLocation able to be key in hash * Use BindLocation for bindings on BindingSet. * Added cuda and nvrtc categories to test infrastructure. Disabled CUDA synthetic tests by default. Fixed such that all tests now produce something in BindLocation style. * Use m_userIndex instead of m_userData on Resource. Move the binding setup out of cpu-compute-util (as no longer CPU specific) * Removed CPUBinding - used BindLocation/BindSet instead. Fixed some bugs around indexOf around uniform indirection. * Renamed BindSet::Resource -> BindSet::Value. * Document BindLocation. * Fixes for Clang/GCC Improve invariant requirement handling when constructing from BindPoints. * WIP: First attempt to run CUDA kernel. * Fix some issues around doing CUDA kernel launch. * Fix issues around use of cudaMemCpy . * Better cuda runtime error checking mechanism. * Fixed bug in passing parameters to cuda kernel launch. Simplified initialisation of context. * WIP: Fix CUDA runtime issues. * Add explicit CUDA synchronize so failures don't appear on implicit ones. * Fix problem emitting non shared variable on CUDA. * Fix some typos in CUDA layout. Use just a pointer for now for CUDA StucturedBuffer. * Arg order for CUDA launch was wrong. * First compute kernel runs on CUDA. --- tools/render-test/shader-input-layout.cpp | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'tools/render-test/shader-input-layout.cpp') diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp index 5ae35b90d..ee4f5fc2c 100644 --- a/tools/render-test/shader-input-layout.cpp +++ b/tools/render-test/shader-input-layout.cpp @@ -1,3 +1,6 @@ +// Stop warnings from Visual Studio +#define _CRT_SECURE_NO_WARNINGS 1 + #include "shader-input-layout.h" #include "core/slang-token-reader.h" @@ -676,6 +679,61 @@ namespace renderer_test return SLANG_OK; } + /* static */void ShaderInputLayout::getValueBuffers(const Slang::List& entries, const BindSet& bindSet, List& outBuffers) + { + outBuffers.setCount(entries.getCount()); + + for (Index i = 0; i< outBuffers.getCount(); ++i) + { + outBuffers[i] = nullptr; + } + + const auto& values = bindSet.getValues(); + for (BindSet::Value* value : values) + { + if (value->m_userIndex >= 0) + { + outBuffers[value->m_userIndex] = value; + } + } + } + + + /* static */SlangResult ShaderInputLayout::writeBindings(const ShaderInputLayout& layout, const List& buffers, const String& fileName) + { + FILE * f = fopen(fileName.getBuffer(), "wb"); + if (!f) + { + return SLANG_FAIL; + } + + const auto& entries = layout.entries; + + for (int i = 0; i < entries.getCount(); ++i) + { + const auto& entry = entries[i]; + if (entry.isOutput) + { + BindSet::Value* buffer = buffers[i]; + + unsigned int* ptr = (unsigned int*)buffer->m_data; + + const int size = int(entry.bufferData.getCount()); + // Must be the same size or less than allocated buffer + SLANG_ASSERT(size * sizeof(unsigned int) <= buffer->m_sizeInBytes); + + for (int i = 0; i < size; ++i) + { + unsigned int v = ptr[i]; + + fprintf(f, "%X\n", v); + } + } + } + fclose(f); + return SLANG_OK; + } + void generateTextureData(TextureData& output, const InputTextureDesc& desc) { switch (desc.format) -- cgit v1.2.3