From 047daae9300c8a94d28383cf992ce00e3ad2da1e Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 9 Sep 2019 13:54:31 -0400 Subject: CPU compute testing on non windows targets (#1045) * WIP: Refactor of CPUCompute and stand alone cpu-render-test * Fix compilation on CygWin. * Make CPU compute tests run on non windows targets. * Check that C/C++ compiler is available for CPU compute. * Fix some tabbing issues. * Add -fPIC on gfx * Use dxcompiler_47.dll from slang-binaries on windows. * make https for git module slang-binaries * Fix comment in premake5.lua around d3dcompiler_47.dll * Add resources to the CPUComputeUtil::Context to keep in scope. * Fixes problem compiling on cygwin where dx12 is included in build of gfx lib. --- tools/render-test/cpu-render-test-main.cpp | 99 ++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tools/render-test/cpu-render-test-main.cpp (limited to 'tools/render-test/cpu-render-test-main.cpp') diff --git a/tools/render-test/cpu-render-test-main.cpp b/tools/render-test/cpu-render-test-main.cpp new file mode 100644 index 000000000..d754f9359 --- /dev/null +++ b/tools/render-test/cpu-render-test-main.cpp @@ -0,0 +1,99 @@ +// cpu-render-test-main.cpp + +#include "options.h" + +#include "slang-support.h" + +#include "../source/core/slang-io.h" + +#include "shader-input-layout.h" +#include +#include + +#include "../../source/core/slang-test-tool-util.h" + +#include "cpu-compute-util.h" + +SLANG_TEST_TOOL_API SlangResult innerMain(Slang::StdWriters* stdWriters, SlangSession* session, int argcIn, const char*const* argvIn) +{ + using namespace renderer_test; + using namespace Slang; + + StdWriters::setSingleton(stdWriters); + + // Parse command-line options + SLANG_RETURN_ON_FAIL(parseOptions(argcIn, argvIn, StdWriters::getError())); + + // Declare window pointer before renderer, such that window is released after renderer + RefPtr window; + // Renderer is constructed (later) using the window + Slang::RefPtr renderer; + + ShaderCompilerUtil::Input input; + + input.profile = ""; + input.target = SLANG_TARGET_NONE; + input.args = &gOptions.slangArgs[0]; + input.argCount = gOptions.slangArgCount; + + SlangSourceLanguage nativeLanguage = SLANG_SOURCE_LANGUAGE_UNKNOWN; + SlangPassThrough slangPassThrough = SLANG_PASS_THROUGH_NONE; + char const* profileName = ""; + switch (gOptions.rendererType) + { + case RendererType::CPU: + input.target = SLANG_HOST_CALLABLE; + input.profile = ""; + nativeLanguage = SLANG_SOURCE_LANGUAGE_CPP; + slangPassThrough = SLANG_PASS_THROUGH_GENERIC_C_CPP; + break; + default: + fprintf(stderr, "error: unexpected\n"); + return SLANG_FAIL; + } + + switch (gOptions.inputLanguageID) + { + case Options::InputLanguageID::Slang: + input.sourceLanguage = SLANG_SOURCE_LANGUAGE_SLANG; + input.passThrough = SLANG_PASS_THROUGH_NONE; + break; + + case Options::InputLanguageID::Native: + input.sourceLanguage = nativeLanguage; + input.passThrough = slangPassThrough; + break; + + default: + break; + } + + // Use the profile name set on options if set + input.profile = gOptions.profileName ? gOptions.profileName : input.profile; + + { + ShaderCompilerUtil::OutputAndLayout compilationAndLayout; + SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(session, gOptions.sourcePath, gOptions.shaderType, input, compilationAndLayout)); + + CPUComputeUtil::Context context; + SLANG_RETURN_ON_FAIL(CPUComputeUtil::calcBindings(compilationAndLayout, context)); + SLANG_RETURN_ON_FAIL(CPUComputeUtil::execute(compilationAndLayout, context)); + + // Dump everything out that was written + return CPUComputeUtil::writeBindings(compilationAndLayout.layout, context.buffers, gOptions.outputPath); + } +} + +int main(int argc, char** argv) +{ + using namespace Slang; + SlangSession* session = spCreateSession(nullptr); + + TestToolUtil::setSessionDefaultPrelude(argv[0], session); + auto stdWriters = StdWriters::initDefaultSingleton(); + SlangResult res = innerMain(stdWriters, session, argc, argv); + spDestroySession(session); + + return (int)TestToolUtil::getReturnCode(res); +} + -- cgit v1.2.3