summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-04 15:19:48 -0500
committerGitHub <noreply@github.com>2020-02-04 15:19:48 -0500
commit17c6c6044965629a3ae7e8ef004cc0b2ca657c55 (patch)
tree5b78004808354b32d09ba13c0ec4e32a44f345ab /source/core
parentb415760d7f166eaad7fa27daa09edc9a8964c37e (diff)
CUDA/C++ backend improvements (#1198)
* WIP with vector float test. * vector-float test working. * Fixed remaing tests broken with init changes. * Improve 64bit-type-support.md * Disable tests broken on CI system for Dx. * WIP: Make type available for comparison. * Moved type conversion into TypeTextUtil. * Add text/type conversions from DownstreamCompiler to TypeTextUtil. * Allow compaison taking into account type. * Removed quantize in vector-float.slang test.
Diffstat (limited to 'source/core')
-rw-r--r--source/core/core.vcxproj2
-rw-r--r--source/core/core.vcxproj.filters6
-rw-r--r--source/core/slang-downstream-compiler.cpp105
-rw-r--r--source/core/slang-downstream-compiler.h11
-rw-r--r--source/core/slang-type-text-util.cpp165
-rw-r--r--source/core/slang-type-text-util.h38
-rw-r--r--source/core/slang-writer.cpp5
-rw-r--r--source/core/slang-writer.h1
8 files changed, 220 insertions, 113 deletions
diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj
index b10bcc683..fe3d45f1b 100644
--- a/source/core/core.vcxproj
+++ b/source/core/core.vcxproj
@@ -207,6 +207,7 @@
<ClInclude Include="slang-test-tool-util.h" />
<ClInclude Include="slang-text-io.h" />
<ClInclude Include="slang-token-reader.h" />
+ <ClInclude Include="slang-type-text-util.h" />
<ClInclude Include="slang-type-traits.h" />
<ClInclude Include="slang-uint-set.h" />
<ClInclude Include="slang-visual-studio-compiler-util.h" />
@@ -238,6 +239,7 @@
<ClCompile Include="slang-test-tool-util.cpp" />
<ClCompile Include="slang-text-io.cpp" />
<ClCompile Include="slang-token-reader.cpp" />
+ <ClCompile Include="slang-type-text-util.cpp" />
<ClCompile Include="slang-uint-set.cpp" />
<ClCompile Include="slang-visual-studio-compiler-util.cpp" />
<ClCompile Include="slang-writer.cpp" />
diff --git a/source/core/core.vcxproj.filters b/source/core/core.vcxproj.filters
index b296b23af..aeac70769 100644
--- a/source/core/core.vcxproj.filters
+++ b/source/core/core.vcxproj.filters
@@ -120,6 +120,9 @@
<ClInclude Include="slang-token-reader.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="slang-type-text-util.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="slang-type-traits.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -209,6 +212,9 @@
<ClCompile Include="slang-token-reader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="slang-type-text-util.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="slang-uint-set.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/source/core/slang-downstream-compiler.cpp b/source/core/slang-downstream-compiler.cpp
index 2f0cff1a9..0a40092ea 100644
--- a/source/core/slang-downstream-compiler.cpp
+++ b/source/core/slang-downstream-compiler.cpp
@@ -5,6 +5,8 @@
#include "../../slang-com-helper.h"
#include "slang-string-util.h"
+#include "slang-type-text-util.h"
+
#include "slang-io.h"
#include "slang-shared-library.h"
#include "slang-blob.h"
@@ -47,7 +49,7 @@ static DownstreamCompiler::Infos _calcInfos()
void DownstreamCompiler::Desc::appendAsText(StringBuilder& out) const
{
- out << getCompilerTypeAsText(type);
+ out << TypeTextUtil::asHumanText(type);
// Append the version if there is a version
if (majorVersion || minorVersion)
@@ -74,21 +76,6 @@ void DownstreamCompiler::Desc::appendAsText(StringBuilder& out) const
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DownstreamCompiler !!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
-/* static */UnownedStringSlice DownstreamCompiler::getCompilerTypeAsText(SlangPassThrough type)
-{
- switch (type)
- {
- default:
- case SLANG_PASS_THROUGH_NONE: return UnownedStringSlice::fromLiteral("Unknown");
- case SLANG_PASS_THROUGH_VISUAL_STUDIO: return UnownedStringSlice::fromLiteral("Visual Studio");
- case SLANG_PASS_THROUGH_GCC: return UnownedStringSlice::fromLiteral("GCC");
- case SLANG_PASS_THROUGH_CLANG: return UnownedStringSlice::fromLiteral("Clang");
- case SLANG_PASS_THROUGH_NVRTC: return UnownedStringSlice::fromLiteral("NVRTC");
- case SLANG_PASS_THROUGH_FXC: return UnownedStringSlice::fromLiteral("fxc");
- case SLANG_PASS_THROUGH_DXC: return UnownedStringSlice::fromLiteral("dxc");
- case SLANG_PASS_THROUGH_GLSLANG: return UnownedStringSlice::fromLiteral("glslang");
- }
-}
/* static */bool DownstreamCompiler::canCompile(SlangPassThrough compiler, SlangSourceLanguage sourceLanguage)
{
@@ -96,92 +83,6 @@ void DownstreamCompiler::Desc::appendAsText(StringBuilder& out) const
return (info.sourceLanguageFlags & (SourceLanguageFlags(1) << int(sourceLanguage))) != 0;
}
-/* static */SlangSourceLanguage DownstreamCompiler::getSourceLanguageFromName(const UnownedStringSlice& text)
-{
- if (text == "c" || text == "C")
- {
- return SLANG_SOURCE_LANGUAGE_C;
- }
- else if (text == "cpp" || text == "c++" || text == "C++" || text == "cxx")
- {
- return SLANG_SOURCE_LANGUAGE_CPP;
- }
- else if (text == "slang")
- {
- return SLANG_SOURCE_LANGUAGE_SLANG;
- }
- else if (text == "glsl")
- {
- return SLANG_SOURCE_LANGUAGE_GLSL;
- }
- else if (text == "hlsl")
- {
- return SLANG_SOURCE_LANGUAGE_HLSL;
- }
- else if (text == "cu" || text == "cuda")
- {
- return SLANG_SOURCE_LANGUAGE_CUDA;
- }
- return SLANG_SOURCE_LANGUAGE_UNKNOWN;
-}
-
-#define SLANG_PASS_THROUGH_TYPES(x) \
- x(none, NONE) \
- x(fxc, FXC) \
- x(dxc, DXC) \
- x(glslang, GLSLANG) \
- x(visualstudio, VISUAL_STUDIO) \
- x(clang, CLANG) \
- x(gcc, GCC) \
- x(genericcpp, GENERIC_C_CPP) \
- x(nvrtc, NVRTC)
-
-
-
-/* static */SlangPassThrough DownstreamCompiler::getPassThroughFromName(const UnownedStringSlice& slice)
-{
-#define SLANG_PASS_THROUGH_NAME_TO_TYPE(x, y) \
- if (slice == UnownedStringSlice::fromLiteral(#x)) return SLANG_PASS_THROUGH_##y;
-
- SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_NAME_TO_TYPE)
-
- // Other options
- if (slice == "c" || slice == "cpp")
- {
- return SLANG_PASS_THROUGH_GENERIC_C_CPP;
- }
- else if (slice == "vs")
- {
- return SLANG_PASS_THROUGH_VISUAL_STUDIO;
- }
-
- return SLANG_PASS_THROUGH_NONE;
-}
-
-/* static */SlangResult DownstreamCompiler::getPassThroughFromName(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough)
-{
- outPassThrough = getPassThroughFromName(slice);
- // It could be none on error - if it's not equal to "none" then it msut be an error
- if (outPassThrough == SLANG_PASS_THROUGH_NONE && slice != UnownedStringSlice::fromLiteral("none"))
- {
- return SLANG_FAIL;
- }
- return SLANG_OK;
-}
-
-/* static */UnownedStringSlice DownstreamCompiler::getPassThroughName(SlangPassThrough passThru)
-{
-#define SLANG_PASS_THROUGH_TYPE_TO_NAME(x, y) \
- case SLANG_PASS_THROUGH_##y: return UnownedStringSlice::fromLiteral(#x);
-
- switch (passThru)
- {
- SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_TYPE_TO_NAME)
- default: break;
- }
- return UnownedStringSlice::fromLiteral("unknown");
-}
-
/* static */SlangCompileTarget DownstreamCompiler::getCompileTarget(SlangSourceLanguage sourceLanguage)
{
switch (sourceLanguage)
diff --git a/source/core/slang-downstream-compiler.h b/source/core/slang-downstream-compiler.h
index a4238ce38..f9e33ed6c 100644
--- a/source/core/slang-downstream-compiler.h
+++ b/source/core/slang-downstream-compiler.h
@@ -280,22 +280,11 @@ public:
/// Some downstream compilers are backed by a shared library. This allows access to the shared library to access internal functions.
virtual ISlangSharedLibrary* getSharedLibrary() { return nullptr; }
- /// Return the compiler type as name
- static UnownedStringSlice getCompilerTypeAsText(SlangPassThrough type);
-
/// Get info for a compiler type
static const Info& getInfo(SlangPassThrough compiler) { return s_infos.infos[int(compiler)]; }
/// True if this compiler can compile the specified language
static bool canCompile(SlangPassThrough compiler, SlangSourceLanguage sourceLanguage);
- /// Given a source language name returns a source language. Name here is distinct from extension
- static SlangSourceLanguage getSourceLanguageFromName(const UnownedStringSlice& text);
- /// Given a name returns the pass through
- static SlangPassThrough getPassThroughFromName(const UnownedStringSlice& slice);
- static SlangResult getPassThroughFromName(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough);
- /// Get the compilers name
- static UnownedStringSlice getPassThroughName(SlangPassThrough passThru);
-
/// Given a source language return as the equivalent compile target
static SlangCompileTarget getCompileTarget(SlangSourceLanguage sourceLanguage);
diff --git a/source/core/slang-type-text-util.cpp b/source/core/slang-type-text-util.cpp
new file mode 100644
index 000000000..b9ccc4971
--- /dev/null
+++ b/source/core/slang-type-text-util.cpp
@@ -0,0 +1,165 @@
+
+#include "slang-type-text-util.h"
+
+
+namespace Slang
+{
+
+#define SLANG_SCALAR_TYPES(x) \
+ x(None, none) \
+ x(Void, void) \
+ x(Bool, bool) \
+ x(Float16, half) \
+ x(UInt32, uint32_t) \
+ x(Int32, int32_t) \
+ x(Int64, int64_t) \
+ x(UInt64, uint64_t) \
+ x(Float32, float) \
+ x(Float64, double)
+
+#define SLANG_PASS_THROUGH_TYPES(x) \
+ x(none, NONE) \
+ x(fxc, FXC) \
+ x(dxc, DXC) \
+ x(glslang, GLSLANG) \
+ x(visualstudio, VISUAL_STUDIO) \
+ x(clang, CLANG) \
+ x(gcc, GCC) \
+ x(genericcpp, GENERIC_C_CPP) \
+ x(nvrtc, NVRTC)
+
+namespace { // anonymous
+
+struct ScalarTypeInfo
+{
+ slang::TypeReflection::ScalarType type;
+ UnownedStringSlice text;
+};
+
+static const ScalarTypeInfo s_scalarTypeInfo[] =
+{
+ #define SLANG_SCALAR_TYPE_INFO(value, text) \
+ { slang::TypeReflection::ScalarType::value, UnownedStringSlice::fromLiteral(#text) },
+ SLANG_SCALAR_TYPES(SLANG_SCALAR_TYPE_INFO)
+};
+
+} // anonymous
+
+/* static */UnownedStringSlice TypeTextUtil::asText(slang::TypeReflection::ScalarType scalarType)
+{
+ typedef slang::TypeReflection::ScalarType ScalarType;
+ switch (scalarType)
+ {
+#define SLANG_SCALAR_TYPE_TO_TEXT(value, text) case ScalarType::value: return UnownedStringSlice::fromLiteral(#text);
+ SLANG_SCALAR_TYPES(SLANG_SCALAR_TYPE_TO_TEXT)
+ default: break;
+ }
+
+ return UnownedStringSlice();
+}
+
+/* static */slang::TypeReflection::ScalarType TypeTextUtil::asScalarType(const UnownedStringSlice& inText)
+{
+ for (Index i = 0; i < SLANG_COUNT_OF(s_scalarTypeInfo); ++i)
+ {
+ const auto& info = s_scalarTypeInfo[i];
+ if (info.text == inText)
+ {
+ return info.type;
+ }
+ }
+ return slang::TypeReflection::ScalarType::None;
+}
+
+/* static */UnownedStringSlice TypeTextUtil::asHumanText(SlangPassThrough type)
+{
+ switch (type)
+ {
+ default:
+ case SLANG_PASS_THROUGH_NONE: return UnownedStringSlice::fromLiteral("Unknown");
+ case SLANG_PASS_THROUGH_VISUAL_STUDIO: return UnownedStringSlice::fromLiteral("Visual Studio");
+ case SLANG_PASS_THROUGH_GCC: return UnownedStringSlice::fromLiteral("GCC");
+ case SLANG_PASS_THROUGH_CLANG: return UnownedStringSlice::fromLiteral("Clang");
+ case SLANG_PASS_THROUGH_NVRTC: return UnownedStringSlice::fromLiteral("NVRTC");
+ case SLANG_PASS_THROUGH_FXC: return UnownedStringSlice::fromLiteral("fxc");
+ case SLANG_PASS_THROUGH_DXC: return UnownedStringSlice::fromLiteral("dxc");
+ case SLANG_PASS_THROUGH_GLSLANG: return UnownedStringSlice::fromLiteral("glslang");
+ }
+}
+
+/* static */SlangSourceLanguage TypeTextUtil::asSourceLanguage(const UnownedStringSlice& text)
+{
+ if (text == "c" || text == "C")
+ {
+ return SLANG_SOURCE_LANGUAGE_C;
+ }
+ else if (text == "cpp" || text == "c++" || text == "C++" || text == "cxx")
+ {
+ return SLANG_SOURCE_LANGUAGE_CPP;
+ }
+ else if (text == "slang")
+ {
+ return SLANG_SOURCE_LANGUAGE_SLANG;
+ }
+ else if (text == "glsl")
+ {
+ return SLANG_SOURCE_LANGUAGE_GLSL;
+ }
+ else if (text == "hlsl")
+ {
+ return SLANG_SOURCE_LANGUAGE_HLSL;
+ }
+ else if (text == "cu" || text == "cuda")
+ {
+ return SLANG_SOURCE_LANGUAGE_CUDA;
+ }
+ return SLANG_SOURCE_LANGUAGE_UNKNOWN;
+}
+
+/* static */SlangPassThrough TypeTextUtil::asPassThrough(const UnownedStringSlice& slice)
+{
+#define SLANG_PASS_THROUGH_NAME_TO_TYPE(x, y) \
+ if (slice == UnownedStringSlice::fromLiteral(#x)) return SLANG_PASS_THROUGH_##y;
+
+ SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_NAME_TO_TYPE)
+
+ // Other options
+ if (slice == "c" || slice == "cpp")
+ {
+ return SLANG_PASS_THROUGH_GENERIC_C_CPP;
+ }
+ else if (slice == "vs")
+ {
+ return SLANG_PASS_THROUGH_VISUAL_STUDIO;
+ }
+
+ return SLANG_PASS_THROUGH_NONE;
+}
+
+/* static */SlangResult TypeTextUtil::asPassThrough(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough)
+{
+ outPassThrough = asPassThrough(slice);
+ // It could be none on error - if it's not equal to "none" then it must be an error
+ if (outPassThrough == SLANG_PASS_THROUGH_NONE && slice != UnownedStringSlice::fromLiteral("none"))
+ {
+ return SLANG_FAIL;
+ }
+ return SLANG_OK;
+}
+
+/* static */UnownedStringSlice TypeTextUtil::asText(SlangPassThrough passThru)
+{
+#define SLANG_PASS_THROUGH_TYPE_TO_NAME(x, y) \
+ case SLANG_PASS_THROUGH_##y: return UnownedStringSlice::fromLiteral(#x);
+
+ switch (passThru)
+ {
+ SLANG_PASS_THROUGH_TYPES(SLANG_PASS_THROUGH_TYPE_TO_NAME)
+ default: break;
+ }
+ return UnownedStringSlice::fromLiteral("unknown");
+}
+
+
+}
+
diff --git a/source/core/slang-type-text-util.h b/source/core/slang-type-text-util.h
new file mode 100644
index 000000000..73c1d9ef0
--- /dev/null
+++ b/source/core/slang-type-text-util.h
@@ -0,0 +1,38 @@
+#ifndef SLANG_CORE_TYPE_TEXT_UTIL_H
+#define SLANG_CORE_TYPE_TEXT_UTIL_H
+
+#include "../../slang.h"
+
+#include "slang-string.h"
+
+
+namespace Slang
+{
+
+/// Utility class to allow conversion of types (such as enums) to and from text types
+struct TypeTextUtil
+{
+
+ /// Get the scalar type as text.
+ static Slang::UnownedStringSlice asText(slang::TypeReflection::ScalarType scalarType);
+
+ // Converts text to scalar type. Returns 'none' if not determined
+ static slang::TypeReflection::ScalarType asScalarType(const Slang::UnownedStringSlice& text);
+
+ /// As human readable text
+ static UnownedStringSlice asHumanText(SlangPassThrough type);
+
+ /// Given a source language name returns a source language. Name here is distinct from extension
+ static SlangSourceLanguage asSourceLanguage(const UnownedStringSlice& text);
+
+ /// Given a name returns the pass through
+ static SlangPassThrough asPassThrough(const UnownedStringSlice& slice);
+ static SlangResult asPassThrough(const UnownedStringSlice& slice, SlangPassThrough& outPassThrough);
+
+ /// Get the compilers name
+ static UnownedStringSlice asText(SlangPassThrough passThru);
+};
+
+}
+
+#endif // SLANG_CORE_TYPE_TEXT_UTIL_H
diff --git a/source/core/slang-writer.cpp b/source/core/slang-writer.cpp
index 2f694aeec..0688bea6c 100644
--- a/source/core/slang-writer.cpp
+++ b/source/core/slang-writer.cpp
@@ -57,6 +57,11 @@ SlangResult WriterHelper::put(const char* text)
return m_writer->write(text, ::strlen(text));
}
+SlangResult WriterHelper::put(const UnownedStringSlice& text)
+{
+ return m_writer->write(text.begin(), text.size());
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!! BaseWriter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
ISlangUnknown* BaseWriter::getInterface(const Guid& guid)
diff --git a/source/core/slang-writer.h b/source/core/slang-writer.h
index 759644fde..380823b39 100644
--- a/source/core/slang-writer.h
+++ b/source/core/slang-writer.h
@@ -16,6 +16,7 @@ class WriterHelper
public:
SlangResult print(const char* format, ...);
SlangResult put(const char* text);
+ SlangResult put(const UnownedStringSlice& text);
SLANG_FORCE_INLINE SlangResult write(const char* chars, size_t numChars) { return m_writer->write(chars, numChars); }
SLANG_FORCE_INLINE void flush() { m_writer->flush(); }