summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-04-25 15:00:36 -0400
committerGitHub <noreply@github.com>2019-04-25 15:00:36 -0400
commitb5ca6352416995b5edd358623a6ae5db38d5e634 (patch)
tree8fa30243c974a18565756956f77045e034a7524d
parentc84e7c0fa526de51f380227a6667f723af36aea2 (diff)
Feature/uint int definition (#954)
* * Moved CPU determination macros to slang.h * Determine SlangUInt/SlangInt from the pointer width (determined from CPU macros) * Removed the UnambiguousInt and UnambigousUInt types - as a previous fragile work around * Removed UInt/Int definition from smart-pointer.h as now in common.h * * Remove ambiguity for PrettyWriter and ints * Improve comment around SlangInt/UInt * More fixes around ambiguity with PrettyWriter and integral types. * Disable VK on OSX. * Force CI to rebuild as spurious error.
-rw-r--r--docs/building.md2
-rw-r--r--premake5.lua5
-rw-r--r--slang.h98
-rw-r--r--source/core/common.h6
-rw-r--r--source/core/core.vcxproj1
-rw-r--r--source/core/core.vcxproj.filters3
-rw-r--r--source/core/slang-byte-encode-util.h2
-rw-r--r--source/core/slang-cpu-defines.h102
-rw-r--r--source/core/smart-pointer.h4
-rw-r--r--source/slang/ir.cpp3
-rw-r--r--source/slang/mangle.cpp4
-rw-r--r--source/slang/reflection.h8
-rw-r--r--source/slang/type-layout.h3
-rw-r--r--tools/gfx/render.h6
-rw-r--r--tools/slang-reflection-test/slang-reflection-test-main.cpp33
15 files changed, 137 insertions, 143 deletions
diff --git a/docs/building.md b/docs/building.md
index c4b8fc521..528df814d 100644
--- a/docs/building.md
+++ b/docs/building.md
@@ -1,6 +1,6 @@
# Building Slang From Source
-## Get the Source Code
+## Get the Source Code
Clone [this](https://github.com/shader-slang/slang) repository, and then run:
diff --git a/premake5.lua b/premake5.lua
index d939400d0..e6c0ea069 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -538,6 +538,11 @@ tool "gfx"
removefiles { "tools/gfx/circular-resource-heap-d3d12.cpp", "tools/gfx/d3d-util.cpp", "tools/gfx/descriptor-heap-d3d12.cpp", "tools/gfx/render-d3d11.cpp", "tools/gfx/render-d3d12.cpp", "tools/gfx/render-gl.cpp", "tools/gfx/resource-d3d12.cpp", "tools/gfx/render-vk.cpp", "tools/gfx/vk-swap-chain.cpp", "tools/gfx/window.cpp" }
end
+ -- Remove VK from OSX gfx build
+ if os.target() == "macosx" then
+ removefiles { "tools/gfx/render-vk.cpp", "tools/gfx/vk-device-queue.cpp", "tools/gfx/vk-api.cpp", "tools/gfx/vk-module.cpp", "tools/gfx/vk-swap-chain.cpp", "tools/gfx/vk-util.cpp" }
+ end
+
--
-- The `slangc` command-line application is just a very thin wrapper
-- around the Slang dynamic library, so its build is extermely simple.
diff --git a/slang.h b/slang.h
index 7dc9501f0..3582e8092 100644
--- a/slang.h
+++ b/slang.h
@@ -344,6 +344,91 @@ convention for interface methods.
#endif // __cplusplus
+/* Macros for detecting processor */
+#if defined(_M_ARM) || defined(__ARM_EABI__)
+// This is special case for nVidia tegra
+# define SLANG_PROCESSOR_ARM 1
+#elif defined(__i386__) || defined(_M_IX86)
+# define SLANG_PROCESSOR_X86 1
+#elif defined(_M_AMD64) || defined(_M_X64) || defined(__amd64) || defined(__x86_64)
+# define SLANG_PROCESSOR_X86_64 1
+#elif defined(_PPC_) || defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC)
+# if defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(__64BIT__) || defined(_LP64) || defined(__LP64__)
+# define SLANG_PROCESSOR_POWER_PC_64 1
+# else
+# define SLANG_PROCESSOR_POWER_PC 1
+# endif
+#elif defined(__arm__)
+# define SLANG_PROCESSOR_ARM 1
+#elif defined(__aarch64__)
+# define SLANG_PROCESSOR_ARM_64 1
+#endif
+
+#ifndef SLANG_PROCESSOR_ARM
+# define SLANG_PROCESSOR_ARM 0
+#endif
+
+#ifndef SLANG_PROCESSOR_ARM_64
+# define SLANG_PROCESSOR_ARM_64 0
+#endif
+
+#ifndef SLANG_PROCESSOR_X86
+# define SLANG_PROCESSOR_X86 0
+#endif
+
+#ifndef SLANG_PROCESSOR_X86_64
+# define SLANG_PROCESSOR_X86_64 0
+#endif
+
+#ifndef SLANG_PROCESSOR_POWER_PC
+# define SLANG_PROCESSOR_POWER_PC 0
+#endif
+
+#ifndef SLANG_PROCESSOR_POWER_PC_64
+# define SLANG_PROCESSOR_POWER_PC_64 0
+#endif
+
+// Processor families
+
+#define SLANG_PROCESSOR_FAMILY_X86 (SLANG_PROCESSOR_X86_64 | SLANG_PROCESSOR_X86)
+#define SLANG_PROCESSOR_FAMILY_ARM (SLANG_PROCESSOR_ARM | SLANG_PROCESSOR_ARM_64)
+#define SLANG_PROCESSOR_FAMILY_POWER_PC (SLANG_PROCESSOR_POWER_PC_64 | SLANG_PROCESSOR_POWER_PC)
+
+// Pointer size
+#define SLANG_PTR_IS_64 (SLANG_PROCESSOR_ARM_64 | SLANG_PROCESSOR_X86_64 | SLANG_PROCESSOR_POWER_PC_64)
+#define SLANG_PTR_IS_32 (SLANG_PTR_IS_64 ^ 1)
+
+// Processor features
+#if SLANG_PROCESSOR_FAMILY_X86
+# define SLANG_LITTLE_ENDIAN 1
+# define SLANG_UNALIGNED_ACCESS 1
+#elif SLANG_PROCESSOR_FAMILY_ARM
+# if defined(__ARMEB__)
+# define SLANG_BIG_ENDIAN 1
+# else
+# define SLANG_LITTLE_ENDIAN 1
+# endif
+#elif SLANG_PROCESSOR_FAMILY_POWER_PC
+# define SLANG_BIG_ENDIAN 1
+#endif
+
+#ifndef SLANG_LITTLE_ENDIAN
+# define SLANG_LITTLE_ENDIAN 0
+#endif
+
+#ifndef SLANG_BIG_ENDIAN
+# define SLANG_BIG_ENDIAN 0
+#endif
+
+#ifndef SLANG_UNALIGNED_ACCESS
+# define SLANG_UNALIGNED_ACCESS 0
+#endif
+
+// One endianess must be set
+#if ((SLANG_BIG_ENDIAN | SLANG_LITTLE_ENDIAN) == 0)
+# error "Couldn't determine endianess"
+#endif
+
#ifndef SLANG_NO_INTTYPES
#include <inttypes.h>
#endif // ! SLANG_NO_INTTYPES
@@ -365,8 +450,17 @@ extern "C"
*/
typedef uint32_t SlangUInt32;
- typedef intptr_t SlangInt;
- typedef uintptr_t SlangUInt;
+
+ // Use SLANG_PTR_ macros to determine SlangInt/SlangUInt types.
+ // This is used over say using size_t/ptrdiff_t/intptr_t/uintptr_t, because on some targets, these types are distinct from
+ // their uint_t/int_t equivalents and so produce ambiguity with function overloading.
+#if SLANG_PTR_IS_64
+ typedef int64_t SlangInt;
+ typedef uint64_t SlangUInt;
+#else
+ typedef int32_t SlangInt;
+ typedef uint32_t SlangUInt;
+#endif
typedef bool SlangBool;
diff --git a/source/core/common.h b/source/core/common.h
index 5aa7b7737..ba7cd9836 100644
--- a/source/core/common.h
+++ b/source/core/common.h
@@ -1,6 +1,8 @@
#ifndef CORE_LIB_COMMON_H
#define CORE_LIB_COMMON_H
+#include "../../slang.h"
+
#include <cstdint>
#ifdef __GNUC__
@@ -19,6 +21,10 @@ namespace Slang
typedef int64_t Int64;
typedef uint64_t UInt64;
+ // Define
+ typedef SlangUInt UInt;
+ typedef SlangInt Int;
+
// typedef unsigned short Word;
typedef intptr_t PtrInt;
diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj
index b89e2acff..4b730f028 100644
--- a/source/core/core.vcxproj
+++ b/source/core/core.vcxproj
@@ -183,7 +183,6 @@
<ClInclude Include="platform.h" />
<ClInclude Include="secure-crt.h" />
<ClInclude Include="slang-byte-encode-util.h" />
- <ClInclude Include="slang-cpu-defines.h" />
<ClInclude Include="slang-free-list.h" />
<ClInclude Include="slang-io.h" />
<ClInclude Include="slang-math.h" />
diff --git a/source/core/core.vcxproj.filters b/source/core/core.vcxproj.filters
index 2faaa7137..e0341df7a 100644
--- a/source/core/core.vcxproj.filters
+++ b/source/core/core.vcxproj.filters
@@ -48,9 +48,6 @@
<ClInclude Include="slang-byte-encode-util.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="slang-cpu-defines.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="slang-free-list.h">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/source/core/slang-byte-encode-util.h b/source/core/slang-byte-encode-util.h
index 77ddc2f65..5936cae60 100644
--- a/source/core/slang-byte-encode-util.h
+++ b/source/core/slang-byte-encode-util.h
@@ -3,8 +3,6 @@
#include "list.h"
-#include "slang-cpu-defines.h"
-
namespace Slang {
struct ByteEncodeUtil
diff --git a/source/core/slang-cpu-defines.h b/source/core/slang-cpu-defines.h
deleted file mode 100644
index 5ad1ecf88..000000000
--- a/source/core/slang-cpu-defines.h
+++ /dev/null
@@ -1,102 +0,0 @@
-#ifndef SLANG_CPU_DEFINES_H
-#define SLANG_CPU_DEFINES_H
-
-/* Macros for detecting processor */
-#if defined(_M_ARM) || defined(__ARM_EABI__)
-// This is special case for nVidia tegra
-# define SLANG_PROCESSOR_ARM 1
-#elif defined(__i386__) || defined(_M_IX86)
-# define SLANG_PROCESSOR_X86 1
-#elif defined(_M_AMD64) || defined(_M_X64) || defined(__amd64) || defined(__x86_64)
-# define SLANG_PROCESSOR_X86_64 1
-#elif defined(_PPC_) || defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC)
-# if defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(__64BIT__) || defined(_LP64) || defined(__LP64__)
-# define SLANG_PROCESSOR_POWER_PC_64 1
-# else
-# define SLANG_PROCESSOR_POWER_PC 1
-# endif
-#elif defined(__arm__)
-# define SLANG_PROCESSOR_ARM 1
-#elif defined(__aarch64__)
-# define SLANG_PROCESSOR_ARM_64 1
-#endif
-
-#ifndef SLANG_PROCESSOR_ARM
-# define SLANG_PROCESSOR_ARM 0
-#endif
-
-#ifndef SLANG_PROCESSOR_ARM_64
-# define SLANG_PROCESSOR_ARM_64 0
-#endif
-
-#ifndef SLANG_PROCESSOR_X86
-# define SLANG_PROCESSOR_X86 0
-#endif
-
-#ifndef SLANG_PROCESSOR_X86_64
-# define SLANG_PROCESSOR_X86_64 0
-#endif
-
-#ifndef SLANG_PROCESSOR_POWER_PC
-# define SLANG_PROCESSOR_POWER_PC 0
-#endif
-
-#ifndef SLANG_PROCESSOR_POWER_PC_64
-# define SLANG_PROCESSOR_POWER_PC_64 0
-#endif
-
-// Processor families
-
-#define SLANG_PROCESSOR_FAMILY_X86 (SLANG_PROCESSOR_X86_64 | SLANG_PROCESSOR_X86)
-#define SLANG_PROCESSOR_FAMILY_ARM (SLANG_PROCESSOR_ARM | SLANG_PROCESSOR_ARM_64)
-#define SLANG_PROCESSOR_FAMILY_POWER_PC (SLANG_PROCESSOR_POWER_PC_64 | SLANG_PROCESSOR_POWER_PC)
-
-#define SLANG_PTR_IS_64 (SLANG_PROCESSOR_ARM_64 | SLANG_PROCESSOR_X86_64 | SLANG_PROCESSOR_POWER_PC_64)
-#define SLANG_PTR_IS_32 (SLANG_PTR_IS_64 ^ 1)
-
-// TODO: This isn't great. The problem is UInt maps to size_t, and on some targets (like OSX)
-// size_t is distinct from any other integral type. So that creates an ambiguity
-// Really we want to modify the StringBuilder and elsewhere to handle the case when it is known it can't unambiguously coerce
-namespace Slang {
-#ifdef SLANG_PTR_IS_64
-typedef UInt64 UnambigousUInt;
-typedef Int64 UnambiguousInt;
-#else
-typedef UInt32 UnambigousUInt;
-typedef Int32 UnambiguousInt;
-#endif
-} // namespace Slang
-
-// Processor features
-#if SLANG_PROCESSOR_FAMILY_X86
-# define SLANG_LITTLE_ENDIAN 1
-# define SLANG_UNALIGNED_ACCESS 1
-#elif SLANG_PROCESSOR_FAMILY_ARM
-# if defined(__ARMEB__)
-# define SLANG_BIG_ENDIAN 1
-# else
-# define SLANG_LITTLE_ENDIAN 1
-# endif
-#elif SLANG_PROCESSOR_FAMILY_POWER_PC
-# define SLANG_BIG_ENDIAN 1
-#endif
-
-#ifndef SLANG_LITTLE_ENDIAN
-# define SLANG_LITTLE_ENDIAN 0
-#endif
-
-#ifndef SLANG_BIG_ENDIAN
-# define SLANG_BIG_ENDIAN 0
-#endif
-
-#ifndef SLANG_UNALIGNED_ACCESS
-# define SLANG_UNALIGNED_ACCESS 0
-#endif
-
-// One endianess must be set
-#if ((SLANG_BIG_ENDIAN | SLANG_LITTLE_ENDIAN) == 0)
-# error "Couldn't determine endianess"
-#endif
-
-
-#endif // SLANG_CPU_DEFINES_H \ No newline at end of file
diff --git a/source/core/smart-pointer.h b/source/core/smart-pointer.h
index 0b03deb8f..8ce67e384 100644
--- a/source/core/smart-pointer.h
+++ b/source/core/smart-pointer.h
@@ -11,10 +11,6 @@
namespace Slang
{
- // TODO: Need to centralize these typedefs
- typedef uintptr_t UInt;
- typedef intptr_t Int;
-
// Base class for all reference-counted objects
class RefObject
{
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp
index 3f6f8e0a3..43ec09abb 100644
--- a/source/slang/ir.cpp
+++ b/source/slang/ir.cpp
@@ -3,7 +3,6 @@
#include "ir-insts.h"
#include "../core/basic.h"
-#include "../core/slang-cpu-defines.h"
#include "mangle.h"
@@ -3008,7 +3007,7 @@ namespace Slang
IRDumpContext* context,
UInt val)
{
- context->builder->append(UnambigousUInt(val));
+ context->builder->append(val);
}
*/
diff --git a/source/slang/mangle.cpp b/source/slang/mangle.cpp
index a61e4e666..61fa709b1 100644
--- a/source/slang/mangle.cpp
+++ b/source/slang/mangle.cpp
@@ -3,8 +3,6 @@
#include "name.h"
#include "syntax.h"
-#include "../core/slang-cpu-defines.h"
-
namespace Slang
{
struct ManglingContext
@@ -23,7 +21,7 @@ namespace Slang
ManglingContext* context,
UInt value)
{
- context->sb.append(UnambigousUInt(value));
+ context->sb.append(value);
}
void emit(
diff --git a/source/slang/reflection.h b/source/slang/reflection.h
index 6c0b39564..09f02d8dd 100644
--- a/source/slang/reflection.h
+++ b/source/slang/reflection.h
@@ -8,14 +8,6 @@
namespace Slang {
-// TODO(tfoley): Need to move these somewhere universal
-
-typedef intptr_t Int;
-typedef int64_t Int64;
-
-typedef uintptr_t UInt;
-typedef uint64_t UInt64;
-
class ProgramLayout;
class TypeLayout;
diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h
index 5ac9229b4..f0c09f371 100644
--- a/source/slang/type-layout.h
+++ b/source/slang/type-layout.h
@@ -10,9 +10,6 @@
namespace Slang {
-typedef intptr_t Int;
-typedef uintptr_t UInt;
-
// Forward declarations
enum class BaseType;
diff --git a/tools/gfx/render.h b/tools/gfx/render.h
index eebeaa170..c95652cd0 100644
--- a/tools/gfx/render.h
+++ b/tools/gfx/render.h
@@ -13,6 +13,8 @@
#include "../../source/core/list.h"
#include "../../source/core/dictionary.h"
+#include "../../slang.h"
+
namespace gfx {
using Slang::RefObject;
@@ -25,8 +27,8 @@ using Slang::List;
typedef SlangResult Result;
// Had to move here, because Options needs types defined here
-typedef intptr_t Int;
-typedef uintptr_t UInt;
+typedef SlangInt Int;
+typedef SlangUInt UInt;
// pre declare types
class Surface;
diff --git a/tools/slang-reflection-test/slang-reflection-test-main.cpp b/tools/slang-reflection-test/slang-reflection-test-main.cpp
index 636b16a1b..a327f1960 100644
--- a/tools/slang-reflection-test/slang-reflection-test-main.cpp
+++ b/tools/slang-reflection-test/slang-reflection-test-main.cpp
@@ -77,18 +77,31 @@ static void write(PrettyWriter& writer, char const* text, size_t length = 0)
}
}
-static void write(PrettyWriter& writer, SlangUInt val)
+static void write(PrettyWriter& writer, uint64_t val)
{
adjust(writer);
Slang::StdWriters::getOut().print("%llu", (unsigned long long)val);
}
-static void write(PrettyWriter& writer, int val)
+static void write(PrettyWriter& writer, int64_t val)
{
adjust(writer);
- Slang::StdWriters::getOut().print("%d", val);
+ Slang::StdWriters::getOut().print("%ll", (long long)val);
}
+static void write(PrettyWriter& writer, int32_t val)
+{
+ adjust(writer);
+ Slang::StdWriters::getOut().print("%d", int(val));
+}
+
+static void write(PrettyWriter& writer, uint32_t val)
+{
+ adjust(writer);
+ Slang::StdWriters::getOut().print("%u", (unsigned int)val);
+}
+
+
static void write(PrettyWriter& writer, float val)
{
adjust(writer);
@@ -248,7 +261,7 @@ static void emitReflectionVarBindingInfoJSON(
{
write(writer, ",\n");
write(writer,"\"semanticIndex\": ");
- write(writer, semanticIndex);
+ write(writer, int(semanticIndex));
}
}
}
@@ -539,7 +552,7 @@ static void emitReflectionTypeInfoJSON(
write(writer, "\"kind\": \"vector\"");
write(writer, ",\n");
write(writer, "\"elementCount\": ");
- write(writer, type->getElementCount());
+ write(writer, int(type->getElementCount()));
write(writer, ",\n");
write(writer, "\"elementType\": ");
emitReflectionTypeJSON(
@@ -551,10 +564,10 @@ static void emitReflectionTypeInfoJSON(
write(writer, "\"kind\": \"matrix\"");
write(writer, ",\n");
write(writer, "\"rowCount\": ");
- write(writer, (SlangUInt)type->getRowCount());
+ write(writer, type->getRowCount());
write(writer, ",\n");
write(writer, "\"columnCount\": ");
- write(writer, (SlangUInt)type->getColumnCount());
+ write(writer, type->getColumnCount());
write(writer, ",\n");
write(writer, "\"elementType\": ");
emitReflectionTypeJSON(
@@ -568,7 +581,7 @@ static void emitReflectionTypeInfoJSON(
write(writer, "\"kind\": \"array\"");
write(writer, ",\n");
write(writer, "\"elementCount\": ");
- write(writer, arrayType->getElementCount());
+ write(writer, int(arrayType->getElementCount()));
write(writer, ",\n");
write(writer, "\"elementType\": ");
emitReflectionTypeJSON(writer, arrayType->getElementType());
@@ -628,7 +641,7 @@ static void emitReflectionTypeLayoutInfoJSON(
write(writer, "\"kind\": \"array\"");
write(writer, ",\n");
write(writer, "\"elementCount\": ");
- write(writer, arrayTypeLayout->getElementCount());
+ write(writer, int(arrayTypeLayout->getElementCount()));
write(writer, ",\n");
write(writer, "\"elementType\": ");
emitReflectionTypeLayoutJSON(
@@ -638,7 +651,7 @@ static void emitReflectionTypeLayoutInfoJSON(
{
write(writer, ",\n");
write(writer, "\"uniformStride\": ");
- write(writer, arrayTypeLayout->getElementStride(SLANG_PARAMETER_CATEGORY_UNIFORM));
+ write(writer, int(arrayTypeLayout->getElementStride(SLANG_PARAMETER_CATEGORY_UNIFORM)));
}
}
break;