summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-cpp.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-08-08 17:23:03 -0400
committerGitHub <noreply@github.com>2019-08-08 17:23:03 -0400
commit41247c3942210df33b9e3dd733eafb23573a4f2f (patch)
treea49a88e680078bd379fe183cf826d49d7f935737 /source/slang/slang-emit-cpp.h
parentc1cc93dd962a6db6c839341f11d2654cf0e62e37 (diff)
WIP: Preliminary Slang -> C++ code generation (#1009)
* Expanded prelude for some other resource types. Disable C++ output for ParameterGroup. * WIP: Layout for CPU. * Fixes to CPU layout. * WIP: The uniform is output, but the variable definition is not. * WIP: Entry point parameters to global scope in C++. Handling of resource types (in so far as outputting) * Some discussion of ABI and different input types. * WIP: More C++ support around resource types. * WIP: Split up variables into different structures on emit. * WIP: Emitting C++ with wrapping up of 'Context' * WIP: C++ code has access to semantic values. Wrap in struct so can use method calls to pass shared state. Disable legalizeResourceTypes and legalizeExistentialTypeLayout * Fix structured buffer layout for CPU. * Remove testing/handling of global uniforms on CPU path. Typo fix. Changed CPU tests to use new CPU calling convention. * Check globals are working. Initalize context to zero globals. * Order the global parameters for C++ ouput by their layout. Note - that layout isn't quite working correctly because the StructuredBuffer<int> the int seems to be consuming uniform space. * Work around for reflection not having all data needed for layout ordering for C++ code. * Output constant buffers as pointers. * Entry point parameters accessed through pointer to struct. * WIP: Layout for CPU is reasonable for test case. * Only output 'f' after float literal if type marks as a float. * Cast construction works on C++. * Made IntrinsicOp::ConvertConstruct to make intent clearer. * C++ handling construction from scalar. Handle access of a scalar with .x. Check default initialization. * Comment about need for split of kIROp_construct. Release build works. * Added support from constructVectorFromScalar to C/C++ target. * Handling of in/out in C/C++. * First pass documentation CPU support. * Improvements to C++/C slang code generation documentation. * Small doc change to include need for mechansim to specify cpp compiler path. * Better handling of swizzling - allow swizzling a scalar into a vector.
Diffstat (limited to 'source/slang/slang-emit-cpp.h')
-rw-r--r--source/slang/slang-emit-cpp.h38
1 files changed, 37 insertions, 1 deletions
diff --git a/source/slang/slang-emit-cpp.h b/source/slang/slang-emit-cpp.h
index ea793ee95..4280bdc80 100644
--- a/source/slang/slang-emit-cpp.h
+++ b/source/slang/slang-emit-cpp.h
@@ -10,6 +10,24 @@
namespace Slang
{
+/* TODO(JS): Note that there are multiple methods to handle 'construction' operations. That is because 'construct' is used as a kind of
+generic 'construction' for built in types including vectors and matrices.
+
+For the moment the cpp emit code, determines what kind of construct is needed, and has special handling for ConstructConvert and
+ConstructFromScalar.
+
+That currently we do not see constructVectorFromScalar - for example when we do...
+
+int2 fromScalar = 1;
+
+This appears as a construction from an int.
+
+That the better thing to do would be that there were IR instructions for the specific types of construction. I suppose there is a question
+about whether there should be separate instructions for vector/matrix, or emit code should just use the destination type. In practice I think
+it's fine that there isn't an instruction separating vector/matrix. That being the case I guess we arguably don't need constructVectorFromScalar,
+just constructXXXFromScalar. Would be good if there was a suitable name to encompass vector/matrix.
+*/
+
#define SLANG_CPP_INTRINSIC_OP(x) \
x(Invalid, "", -1) \
x(Init, "", -1) \
@@ -93,7 +111,10 @@ namespace Slang
\
x(AsFloat, "asfloat", 1) \
x(AsInt, "asint", 1) \
- x(AsUInt, "asuint", 1)
+ x(AsUInt, "asuint", 1) \
+ \
+ x(ConstructConvert, "", 1) \
+ x(ConstructFromScalar, "", 1)
class CPPSourceEmitter: public CLikeSourceEmitter
@@ -181,6 +202,13 @@ protected:
virtual void emitVectorTypeNameImpl(IRType* elementType, IRIntegerValue elementCount) SLANG_OVERRIDE;
virtual bool tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOuterPrec) SLANG_OVERRIDE;
virtual void emitPreprocessorDirectivesImpl() SLANG_OVERRIDE;
+ virtual void emitSimpleValueImpl(IRInst* value) SLANG_OVERRIDE;
+ virtual void emitModuleImpl(IRModule* module) SLANG_OVERRIDE;
+ virtual void emitSimpleFuncImpl(IRFunc* func) SLANG_OVERRIDE;
+ virtual void emitOperandImpl(IRInst* inst, EmitOpInfo const& outerPrec) SLANG_OVERRIDE;
+ virtual void emitParamTypeImpl(IRType* type, String const& name) SLANG_OVERRIDE;
+
+ virtual bool tryEmitGlobalParamImpl(IRGlobalParam* varDecl, IRType* varType) SLANG_OVERRIDE;
void emitIntrinsicCallExpr(IRCall* inst, IRFunc* func, EmitOpInfo const& inOuterPrec);
@@ -194,9 +222,13 @@ protected:
void _emitLengthDefinition(const UnownedStringSlice& funcName, const SpecializedIntrinsic& specOp);
void _emitNormalizeDefinition(const UnownedStringSlice& funcName, const SpecializedIntrinsic& specOp);
void _emitReflectDefinition(const UnownedStringSlice& funcName, const SpecializedIntrinsic& specOp);
+ void _emitConstructConvertDefinition(const UnownedStringSlice& funcName, const SpecializedIntrinsic& specOp);
+ void _emitConstructFromScalarDefinition(const UnownedStringSlice& funcName, const SpecializedIntrinsic& specOp);
void _emitSignature(const UnownedStringSlice& funcName, const SpecializedIntrinsic& specOp);
+ void _emitInOutParamType(IRType* type, String const& name, IRType* valueType);
+
UnownedStringSlice _getAndEmitSpecializedOperationDefinition(IntrinsicOp op, IRType*const* argTypes, Int argCount, IRType* retType);
static TypeDimension _getTypeDimension(IRType* type, bool vecSwap);
@@ -216,6 +248,10 @@ protected:
UnownedStringSlice _getTypeName(IRType* type);
StringSlicePool::Handle _calcTypeName(IRType* type);
+ SlangResult _calcTypeName(IRType* type, CodeGenTarget target, StringBuilder& out);
+
+ SlangResult _calcTextureTypeName(IRTextureTypeBase* texType, StringBuilder& outName);
+
Dictionary<SpecializedIntrinsic, StringSlicePool::Handle> m_intrinsicNameMap;
Dictionary<IRType*, StringSlicePool::Handle> m_typeNameMap;