summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-platform.cpp15
-rw-r--r--source/core/slang-platform.h3
-rw-r--r--source/slang/core.meta.slang19
-rw-r--r--source/slang/core.meta.slang.h21
-rw-r--r--source/slang/slang-emit-c-like.cpp4
-rw-r--r--source/slang/slang-emit-cpp.cpp35
-rw-r--r--source/slang/slang-emit-cuda.cpp11
-rw-r--r--source/slang/slang-type-layout.cpp22
8 files changed, 93 insertions, 37 deletions
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp
index e735216f4..d02951e0b 100644
--- a/source/core/slang-platform.cpp
+++ b/source/core/slang-platform.cpp
@@ -1,4 +1,7 @@
// slang-platform.cpp
+
+#define _CRT_SECURE_NO_WARNINGS
+
#include "slang-platform.h"
#include "slang-common.h"
@@ -197,6 +200,18 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
#endif // _WIN32
+
+/* static */SlangResult PlatformUtil::getEnvironmentVariable(const UnownedStringSlice& name, StringBuilder& out)
+{
+ const char* value = getenv(String(name).getBuffer());
+ if (value)
+ {
+ out.append(value);
+ return SLANG_OK;
+ }
+ return SLANG_E_NOT_FOUND;
+}
+
/* static */PlatformKind PlatformUtil::getPlatformKind()
{
#if SLANG_WINRT
diff --git a/source/core/slang-platform.h b/source/core/slang-platform.h
index c3ad1c486..767e83c1d 100644
--- a/source/core/slang-platform.h
+++ b/source/core/slang-platform.h
@@ -128,6 +128,9 @@ namespace Slang
/// True if the kind is part of the family
static bool isFamily(PlatformFamily family, PlatformKind kind) { return (getPlatformFlags(family) & (PlatformFlags(1) << int(kind))) != 0; }
+ /// Given an environment name returns the set system variable.
+ /// Will return SLANG_E_NOT_FOUND if the variable is not set
+ static SlangResult getEnvironmentVariable(const UnownedStringSlice& name, StringBuilder& out);
};
#ifndef _MSC_VER
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang
index 80ff09ea8..58e6e287c 100644
--- a/source/slang/core.meta.slang
+++ b/source/slang/core.meta.slang
@@ -770,6 +770,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt)
sb << "$1";
}
sb << ")$z\")\n";
+
}
sb << "T Load(";
sb << "int" << loadCoordCount << " location";
@@ -887,6 +888,24 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt)
// `Sample()`
sb << "__target_intrinsic(glsl, \"$ctexture($p, $2)$z\")\n";
+
+ if( baseShape != TextureFlavor::Shape::ShapeCube )
+ {
+ sb << "__target_intrinsic(cuda, \"tex" << kBaseTextureTypes[tt].coordCount << "D<$S0>($0";
+ if (kBaseTextureTypes[tt].coordCount == 1)
+ {
+ sb << ", $2";
+ }
+ else
+ {
+ for (int i = 0; i < kBaseTextureTypes[tt].coordCount; ++i)
+ {
+ sb << ", ($2)." << char(i + 'x');
+ }
+ }
+ sb << ")\")\n";
+ }
+
sb << "T Sample(SamplerState s, ";
sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location);\n";
diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h
index 27811b588..201429700 100644
--- a/source/slang/core.meta.slang.h
+++ b/source/slang/core.meta.slang.h
@@ -791,6 +791,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt)
sb << "$1";
}
sb << ")$z\")\n";
+
}
sb << "T Load(";
sb << "int" << loadCoordCount << " location";
@@ -908,6 +909,24 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt)
// `Sample()`
sb << "__target_intrinsic(glsl, \"$ctexture($p, $2)$z\")\n";
+
+ if( baseShape != TextureFlavor::Shape::ShapeCube )
+ {
+ sb << "__target_intrinsic(cuda, \"tex" << kBaseTextureTypes[tt].coordCount << "D<$S0>($0";
+ if (kBaseTextureTypes[tt].coordCount == 1)
+ {
+ sb << ", $2";
+ }
+ else
+ {
+ for (int i = 0; i < kBaseTextureTypes[tt].coordCount; ++i)
+ {
+ sb << ", ($2)." << char(i + 'x');
+ }
+ }
+ sb << ")\")\n";
+ }
+
sb << "T Sample(SamplerState s, ";
sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location);\n";
@@ -1258,7 +1277,7 @@ for (auto op : binaryOps)
sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, " << rightType << " right);\n";
}
}
-SLANG_RAW("#line 1240 \"core.meta.slang\"")
+SLANG_RAW("#line 1259 \"core.meta.slang\"")
SLANG_RAW("\n")
SLANG_RAW("\n")
SLANG_RAW("// Specialized function\n")
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 10790567e..8e0c64d1a 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -1250,6 +1250,10 @@ void CLikeSourceEmitter::emitIntrinsicCallExprImpl(
SLANG_RELEASE_ASSERT(argCount > argIndex);
IRType* type = args[argIndex].get()->getDataType();
+ if (auto baseTextureType = as<IRTextureType>(type))
+ {
+ type = baseTextureType->getElementType();
+ }
IRBasicType* underlyingType = nullptr;
if (auto basicType = as<IRBasicType>(type))
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index 5ea3c72a2..759f980d3 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -1912,48 +1912,23 @@ void CPPSourceEmitter::emitIntrinsicCallExprImpl(
return;
}
- auto prec = getInfo(EmitOp::Postfix);
- needClose = maybeEmitParens(outerPrec, prec);
-
- if (name[0] == '.')
- {
- // Looks like a member function call
- emitOperand(args[0].get(), leftSide(outerPrec, prec));
- m_writer->emit(".");
-
- name = UnownedStringSlice(name.begin() + 1, name.end());
-
- args++;
- argCount--;
- }
- else
{
Op op = m_opLookup->getOpByName(name);
if (op != Op::Invalid)
{
-
+
// Work out the intrinsic used
HLSLIntrinsic intrinsic;
m_intrinsicSet.calcIntrinsic(op, inst->getDataType(), args, argCount, intrinsic);
HLSLIntrinsic* specOp = m_intrinsicSet.add(intrinsic);
-
+
emitCall(specOp, inst, args, int(argCount), inOuterPrec);
return;
}
}
-
- m_writer->emit(name);
- m_writer->emit("(");
- for (Index i = 0; i < argCount; ++i)
- {
- if (i != 0)
- {
- m_writer->emit(", ");
- }
- emitOperand(args[i].get(), getInfo(EmitOp::General));
- }
- m_writer->emit(")");
- maybeCloseParens(needClose);
+
+ // Use default impl (which will do intrinsic special macro expansion as necessary)
+ return Super::emitIntrinsicCallExprImpl(inst, targetIntrinsic, inOuterPrec);
}
bool CPPSourceEmitter::_tryEmitInstExprAsIntrinsic(IRInst* inst, const EmitOpInfo& inOuterPrec)
diff --git a/source/slang/slang-emit-cuda.cpp b/source/slang/slang-emit-cuda.cpp
index 93508813b..26d6eada0 100644
--- a/source/slang/slang-emit-cuda.cpp
+++ b/source/slang/slang-emit-cuda.cpp
@@ -89,6 +89,9 @@ SlangResult CUDASourceEmitter::_calcCUDATextureTypeName(IRTextureTypeBase* texTy
return SLANG_FAIL;
}
+ outName << "CUtexObject";
+
+#if 0
outName << "texture<";
outName << _getTypeName(texType->getElementType());
outName << ", ";
@@ -124,6 +127,7 @@ SlangResult CUDASourceEmitter::_calcCUDATextureTypeName(IRTextureTypeBase* texTy
}
outName << ">";
+#endif
return SLANG_OK;
}
@@ -312,6 +316,13 @@ SlangResult CUDASourceEmitter::calcTypeName(IRType* type, CodeGenTarget target,
}
}
+ switch (type->op)
+ {
+ case kIROp_SamplerStateType: out << "SamplerState"; return SLANG_OK;
+ case kIROp_SamplerComparisonStateType: out << "SamplerComparisonState"; return SLANG_OK;
+ default: break;
+ }
+
break;
}
}
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp
index 644f54a95..cf793b52d 100644
--- a/source/slang/slang-type-layout.cpp
+++ b/source/slang/slang-type-layout.cpp
@@ -735,25 +735,30 @@ struct CUDAObjectLayoutRulesImpl : CPUObjectLayoutRulesImpl
{
typedef CPUObjectLayoutRulesImpl Super;
+ // cuda.h defines a variety of handle types. We don't want to have to include cuda.h though - as it may not be available
+ // on a build target. So for we define this handle type, that matches cuda.h and is used for types that use this kind
+ // of opaque handle (as opposed to a pointer) such as CUsurfObject, CUtexObject
+ typedef unsigned long long ObjectHandle;
+
virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind) override
{
switch (kind)
{
case ShaderParameterKind::ConstantBuffer:
// It's a pointer to the actual uniform data
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*));
+ return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*));
case ShaderParameterKind::MutableTexture:
case ShaderParameterKind::TextureUniformBuffer:
case ShaderParameterKind::Texture:
// It's a pointer to a texture interface
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*));
+ return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(ObjectHandle), SLANG_ALIGN_OF(ObjectHandle));
case ShaderParameterKind::StructuredBuffer:
case ShaderParameterKind::MutableStructuredBuffer:
// TODO(JS): We are just storing as a pointer for now
// It's a ptr and a size of the amount of elements
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*));
+ return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*));
case ShaderParameterKind::RawBuffer:
case ShaderParameterKind::Buffer:
@@ -763,11 +768,16 @@ struct CUDAObjectLayoutRulesImpl : CPUObjectLayoutRulesImpl
// TODO(JS): We are storing as a pointer for now
// It's a pointer and a size in bytes
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*));
+ return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*));
case ShaderParameterKind::SamplerState:
- // It's a pointer
- return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*));
+ // In CUDA it seems that sampler states are combined into texture objects.
+ // So it's a binding issue to combine a sampler with a texture - and sampler are ignored
+ // For simplicity here though - we do create a variable and that variable takes up
+ // uniform binding space.
+ // TODO(JS): If we wanted to remove these variables we'd want to do it as a pass. The pass
+ // would presumably have to remove use of variables of this kind throughout IR.
+ return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*));
case ShaderParameterKind::TextureSampler:
case ShaderParameterKind::MutableTextureSampler: