diff options
28 files changed, 356 insertions, 69 deletions
@@ -1861,6 +1861,8 @@ extern "C" SLANG_SCALAR_TYPE_UINT8, SLANG_SCALAR_TYPE_INT16, SLANG_SCALAR_TYPE_UINT16, + SLANG_SCALAR_TYPE_INTPTR, + SLANG_SCALAR_TYPE_UINTPTR }; #ifndef SLANG_RESOURCE_SHAPE diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 39ba67d6a..5d4b57543 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -8,6 +8,9 @@ typedef double float64_t; typedef int int32_t; typedef uint uint32_t; +typedef uintptr_t size_t; +typedef uintptr_t usize_t +typedef intptr_t ssize_t; // Modifier for variables that must resolve to compile-time constants // as part of translation. @@ -229,6 +232,7 @@ ${{{{ case BaseType::Int16: case BaseType::Int: case BaseType::Int64: + case BaseType::IntPtr: }}}} , __BuiltinSignedArithmeticType ${{{{ @@ -237,6 +241,7 @@ ${{{{ case BaseType::UInt16: case BaseType::UInt: case BaseType::UInt64: + case BaseType::UIntPtr: }}}} , __BuiltinArithmeticType , __BuiltinIntegerType @@ -456,6 +461,26 @@ extension int64_t static const int64_t minValue = -0x8000000000000000LL; } +extension intptr_t +{ + __generic<T> + __intrinsic_op($(kIROp_Construct)) + __init(Ptr<T> ptr); + static const intptr_t maxValue = $(SLANG_PROCESSOR_X86_64?"0x7FFFFFFFFFFFFFFFz":"0x7FFFFFFFz"); + static const intptr_t minValue = $(SLANG_PROCESSOR_X86_64?"0x8000000000000000z":"0x80000000z"); + static const int size = $(SLANG_PROCESSOR_X86_64?"8":"4"); +} + +extension uintptr_t +{ + __generic<T> + __intrinsic_op($(kIROp_Construct)) + __init(Ptr<T> ptr); + static const uintptr_t maxValue = $(SLANG_PROCESSOR_X86_64?"0xFFFFFFFFFFFFFFFFz":"0xFFFFFFFFz"); + static const uintptr_t minValue = 0z; + static const int size = $(SLANG_PROCESSOR_X86_64?"8":"4"); +} + __generic<T> __magic_type(OutType) __intrinsic_type($(kIROp_OutType)) @@ -2300,7 +2325,9 @@ bool operator!=(E left, E right); interface IComparable { - int compareTo(This other); + bool equals(This other); + bool lessThan(This other); + bool lessThanOrEquals(This other); } interface IArithmetic : IComparable @@ -2340,37 +2367,37 @@ __generic<T : IComparable> [__unsafeForceInlineEarly] bool operator<(T v0, T v1) { - return v0.compareTo(v1) < 0; + return v0.lessThan(v1); } __generic<T : IComparable> [__unsafeForceInlineEarly] bool operator>(T v0, T v1) { - return v0.compareTo(v1) > 0; + return v1.lessThan(v0); } __generic<T : IComparable> [__unsafeForceInlineEarly] bool operator ==(T v0, T v1) { - return v0.compareTo(v1) == 0; + return v0.equals(v1); } __generic<T : IComparable> [__unsafeForceInlineEarly] bool operator >=(T v0, T v1) { - return v0.compareTo(v1) >= 0; + return v1.lessThanOrEquals(v1); } __generic<T : IComparable> [__unsafeForceInlineEarly] bool operator <=(T v0, T v1) { - return v0.compareTo(v1) <= 0; + return v0.lessThanOrEquals(v1); } __generic<T : IComparable> [__unsafeForceInlineEarly] bool operator !=(T v0, T v1) { - return v0.compareTo(v1) != 0; + return !v0.equals(v1); } __generic<T : IArithmetic> @@ -2451,7 +2478,9 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) }}}} extension $(kBaseTypes[tt].name) : IInteger { - [__unsafeForceInlineEarly] int compareTo(This other){return this-other;} + [__unsafeForceInlineEarly] bool equals(This other){return this==other;} + [__unsafeForceInlineEarly] bool lessThan(This other){return this<other;} + [__unsafeForceInlineEarly] bool lessThanOrEquals(This other){return this<=other;} [__unsafeForceInlineEarly] This add(This other) { return __add(this, other); } [__unsafeForceInlineEarly] This sub(This other) { return __sub(this, other); } [__unsafeForceInlineEarly] This mul(This other) { return __mul(this, other); } @@ -2477,12 +2506,9 @@ ${{{{ extension $(kBaseTypes[tt].name) : IFloat { - [__unsafeForceInlineEarly] static int __sign(This val) - { - return int(__leq(This(0),val)) - int(__leq(val,This(0))); - } - - [__unsafeForceInlineEarly] int compareTo(This other) { return __sign(this-other); } + [__unsafeForceInlineEarly] bool lessThan(This other) { return this < other; } + [__unsafeForceInlineEarly] bool lessThanOrEquals(This other) { return this <= other; } + [__unsafeForceInlineEarly] bool equals(This other) { return this == other; } [__unsafeForceInlineEarly] This add(This other) { return __add(this, other); } [__unsafeForceInlineEarly] This sub(This other) { return __sub(this, other); } [__unsafeForceInlineEarly] This mul(This other) { return __mul(this, other); } diff --git a/source/slang/slang-ast-builder.h b/source/slang/slang-ast-builder.h index 788257fa0..3023e274d 100644 --- a/source/slang/slang-ast-builder.h +++ b/source/slang/slang-ast-builder.h @@ -269,8 +269,10 @@ public: SLANG_FORCE_INLINE Type* getDoubleType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Double)]; } SLANG_FORCE_INLINE Type* getIntType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Int)]; } SLANG_FORCE_INLINE Type* getInt64Type() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Int64)]; } + SLANG_FORCE_INLINE Type* getIntPtrType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::IntPtr)]; } SLANG_FORCE_INLINE Type* getUIntType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::UInt)]; } SLANG_FORCE_INLINE Type* getUInt64Type() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::UInt64)]; } + SLANG_FORCE_INLINE Type* getUIntPtrType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::UIntPtr)]; } SLANG_FORCE_INLINE Type* getVoidType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Void)]; } /// Get a builtin type by the BaseType diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 125f0cb08..660e28802 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -1096,10 +1096,12 @@ namespace Slang case BaseType::Int16: case BaseType::Int: case BaseType::Int64: + case BaseType::IntPtr: case BaseType::UInt8: case BaseType::UInt16: case BaseType::UInt: case BaseType::UInt64: + case BaseType::UIntPtr: break; default: getSink()->diagnose(varDecl, Diagnostics::staticConstRequirementMustBeIntOrBool); @@ -3620,16 +3622,28 @@ namespace Slang case BaseType::UInt16: return (value >= 0 && value <= std::numeric_limits<uint16_t>::max()) || (value == -1); case BaseType::UInt: +#if SLANG_PTR_IS_32 + case BaseType::UIntPtr: +#endif return (value >= 0 && value <= std::numeric_limits<uint32_t>::max()) || (value == -1); case BaseType::UInt64: +#if SLANG_PTR_IS_64 + case BaseType::UIntPtr: +#endif return true; case BaseType::Int8: return value >= std::numeric_limits<int8_t>::min() && value <= std::numeric_limits<int8_t>::max(); case BaseType::Int16: return value >= std::numeric_limits<int16_t>::min() && value <= std::numeric_limits<int16_t>::max(); case BaseType::Int: +#if SLANG_PTR_IS_32 + case BaseType::IntPtr: +#endif return value >= std::numeric_limits<int32_t>::min() && value <= std::numeric_limits<int32_t>::max(); case BaseType::Int64: +#if SLANG_PTR_IS_64 + case BaseType::IntPtr: +#endif return value >= std::numeric_limits<int64_t>::min() && value <= std::numeric_limits<int64_t>::max(); default: return false; diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index b988fac60..2987fecee 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -1009,6 +1009,10 @@ namespace Slang case BaseType::Int16: case BaseType::UInt8: case BaseType::Int8: + case BaseType::UIntPtr: + case BaseType::IntPtr: + case BaseType::Int64: + case BaseType::UInt64: resultValue = constArgVals[0]; break; default: diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 7a7951ba1..734471fd0 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -215,11 +215,13 @@ void CLikeSourceEmitter::emitSimpleType(IRType* type) case kIROp_Int16Type: return UnownedStringSlice("int16_t"); case kIROp_IntType: return UnownedStringSlice("int"); case kIROp_Int64Type: return UnownedStringSlice("int64_t"); + case kIROp_IntPtrType: return UnownedStringSlice("intptr_t"); case kIROp_UInt8Type: return UnownedStringSlice("uint8_t"); case kIROp_UInt16Type: return UnownedStringSlice("uint16_t"); case kIROp_UIntType: return UnownedStringSlice("uint"); case kIROp_UInt64Type: return UnownedStringSlice("uint64_t"); + case kIROp_UIntPtrType: return UnownedStringSlice("uintptr_t"); case kIROp_HalfType: return UnownedStringSlice("half"); @@ -959,6 +961,33 @@ void CLikeSourceEmitter::emitSimpleValueImpl(IRInst* inst) m_writer->emit("ULL"); break; } + case BaseType::IntPtr: + { +#if SLANG_PTR_IS_64 + m_writer->emit("int64_t("); + m_writer->emitInt64(int64_t(litInst->value.intVal)); + m_writer->emit(")"); +#else + m_writer->emit("int("); + m_writer->emit(int(litInst->value.intVal)); + m_writer->emit(")"); +#endif + break; + } + case BaseType::UIntPtr: + { +#if SLANG_PTR_IS_64 + m_writer->emit("uint64_t("); + m_writer->emitUInt64(uint64_t(litInst->value.intVal)); + m_writer->emit(")"); +#else + m_writer->emit("uint("); + m_writer->emit(UInt(uint32_t(litInst->value.intVal))); + m_writer->emit(")"); +#endif + break; + } + } } else diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp index 9c1573bf8..bc145dca1 100644 --- a/source/slang/slang-emit-cpp.cpp +++ b/source/slang/slang-emit-cpp.cpp @@ -97,6 +97,8 @@ static IROp _getTypeStyle(IROp op) case kIROp_UIntType: case kIROp_Int64Type: case kIROp_UInt64Type: + case kIROp_IntPtrType: + case kIROp_UIntPtrType: { // All int like return kIROp_IntType; @@ -131,6 +133,11 @@ static IROp _getCType(IROp op) // Promote all these to Int return kIROp_IntType; } + case kIROp_IntPtrType: + case kIROp_UIntPtrType: + { + return kIROp_IntPtrType; + } case kIROp_Int64Type: case kIROp_UInt64Type: { @@ -165,6 +172,8 @@ static UnownedStringSlice _getCTypeVecPostFix(IROp op) case kIROp_FloatType: return UnownedStringSlice::fromLiteral("F"); case kIROp_Int64Type: return UnownedStringSlice::fromLiteral("I64"); case kIROp_DoubleType: return UnownedStringSlice::fromLiteral("F64"); + case kIROp_IntPtrType: return UnownedStringSlice::fromLiteral(""); + case kIROp_UIntPtrType: return UnownedStringSlice::fromLiteral(""); default: return UnownedStringSlice::fromLiteral("?"); } } @@ -207,11 +216,13 @@ static bool _isCppOrCudaTarget(CodeGenTarget target) case kIROp_Int16Type: return UnownedStringSlice("int16_t"); case kIROp_IntType: return UnownedStringSlice("int32_t"); case kIROp_Int64Type: return UnownedStringSlice("int64_t"); + case kIROp_IntPtrType: return UnownedStringSlice("intptr_t"); case kIROp_UInt8Type: return UnownedStringSlice("uint8_t"); case kIROp_UInt16Type: return UnownedStringSlice("uint16_t"); case kIROp_UIntType: return UnownedStringSlice("uint32_t"); case kIROp_UInt64Type: return UnownedStringSlice("uint64_t"); + case kIROp_UIntPtrType: return UnownedStringSlice("uintptr_t"); // Not clear just yet how we should handle half... we want all processing as float probly, but when reading/writing to memory converting diff --git a/source/slang/slang-emit-cuda.cpp b/source/slang/slang-emit-cuda.cpp index eda30b956..7c712d2c5 100644 --- a/source/slang/slang-emit-cuda.cpp +++ b/source/slang/slang-emit-cuda.cpp @@ -53,11 +53,13 @@ UnownedStringSlice CUDASourceEmitter::getBuiltinTypeName(IROp op) case kIROp_Int16Type: return UnownedStringSlice("short"); case kIROp_IntType: return UnownedStringSlice("int"); case kIROp_Int64Type: return UnownedStringSlice("longlong"); + case kIROp_IntPtrType: return UnownedStringSlice("intptr_t"); case kIROp_UInt8Type: return UnownedStringSlice("uchar"); case kIROp_UInt16Type: return UnownedStringSlice("ushort"); case kIROp_UIntType: return UnownedStringSlice("uint"); case kIROp_UInt64Type: return UnownedStringSlice("ulonglong"); + case kIROp_UIntPtrType: return UnownedStringSlice("uintptr_t"); case kIROp_HalfType: { diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index b0c10fdc2..0fd4ac69c 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -465,9 +465,11 @@ void GLSLSourceEmitter::_emitGLSLImageFormatModifier(IRInst* var, IRTextureType* case BaseType::Int8: m_writer->emit("8i"); break; case BaseType::Int16: m_writer->emit("16i"); break; case BaseType::Int64: m_writer->emit("64i"); break; + case BaseType::IntPtr: m_writer->emit("64i"); break; case BaseType::UInt8: m_writer->emit("8ui"); break; case BaseType::UInt16: m_writer->emit("16ui"); break; case BaseType::UInt64: m_writer->emit("64ui"); break; + case BaseType::UIntPtr: m_writer->emit("64ui"); break; // TODO: Here are formats that are available in GLSL, // but that are not handled by the above cases. @@ -662,10 +664,20 @@ void GLSLSourceEmitter::_emitGLSLTypePrefix(IRType* type, bool promoteHalfToFloa case kIROp_Int8Type: m_writer->emit("i8"); break; case kIROp_Int16Type: m_writer->emit("i16"); break; case kIROp_IntType: m_writer->emit("i"); break; - case kIROp_Int64Type: + case kIROp_Int64Type: + { + _requireBaseType(BaseType::Int64); + m_writer->emit("i64"); + break; + } + case kIROp_IntPtrType: { +#if SLANG_PTR_IS_64 _requireBaseType(BaseType::Int64); m_writer->emit("i64"); +#else + m_writer->emit("i"); +#endif break; } @@ -679,7 +691,16 @@ void GLSLSourceEmitter::_emitGLSLTypePrefix(IRType* type, bool promoteHalfToFloa m_writer->emit("u64"); break; } - + case kIROp_UIntPtrType: + { +#if SLANG_PTR_IS_64 + _requireBaseType(BaseType::Int64); + m_writer->emit("u64"); +#else + m_writer->emit("u"); +#endif + break; + } case kIROp_BoolType: m_writer->emit("b"); break; case kIROp_HalfType: @@ -817,12 +838,14 @@ void GLSLSourceEmitter::emitSimpleValueImpl(IRInst* inst) m_writer->emit("U"); return; } + case BaseType::IntPtr: case BaseType::Int64: { m_writer->emitInt64(int64_t(litInst->value.intVal)); m_writer->emit("L"); return; } + case BaseType::UIntPtr: case BaseType::UInt64: { SLANG_COMPILE_TIME_ASSERT(sizeof(litInst->value.intVal) >= sizeof(uint64_t)); @@ -1909,6 +1932,26 @@ void GLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) m_writer->emit(getDefaultBuiltinTypeName(type->getOp())); return; } + case kIROp_IntPtrType: + { +#if SLANG_PTR_IS_64 + _requireBaseType(BaseType::Int64); + m_writer->emit("int64_t"); +#else + m_writer->emit("int"); +#endif + return; + } + case kIROp_UIntPtrType: + { +#if SLANG_PTR_IS_64 + _requireBaseType(BaseType::UInt64); + m_writer->emit("uint64_t"); +#else + m_writer->emit("uint"); +#endif + return; + } case kIROp_VoidType: case kIROp_BoolType: case kIROp_Int8Type: diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 48fe86fff..20fcc5bed 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -467,10 +467,12 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu case BaseType::Int16: case BaseType::Int: case BaseType::Int64: + case BaseType::IntPtr: case BaseType::UInt8: case BaseType::UInt16: case BaseType::UInt: case BaseType::UInt64: + case BaseType::UIntPtr: case BaseType::Bool: // Because the intermediate type will always // be an integer type, we can convert to @@ -809,11 +811,26 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) case kIROp_DoubleType: case kIROp_Int16Type: case kIROp_UInt16Type: - { case kIROp_HalfType: + { m_writer->emit(getDefaultBuiltinTypeName(type->getOp())); return; } +#if SLANG_PTR_IS_64 + case kIROp_IntPtrType: + m_writer->emit("int64_t"); + return; + case kIROp_UIntPtrType: + m_writer->emit("uint64_t"); + return; +#else + case kIROp_IntPtrType: + m_writer->emit("int"); + return; + case kIROp_UIntPtrType: + m_writer->emit("uint"); + return; +#endif case kIROp_StructType: m_writer->emit(getName(type)); return; @@ -856,7 +873,7 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) case kIROp_NativeStringType: case kIROp_StringType: { - m_writer->emit("int"); + m_writer->emit("string"); return; } default: break; diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index fa0d92512..96ba89c55 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -708,7 +708,14 @@ struct SPIRVEmitContext return result; SpvWord valWord; memcpy(&valWord, &val, sizeof(SpvWord)); - if (type->getOp() == kIROp_Int64Type || type->getOp() == kIROp_UInt64Type) + switch (type->getOp()) + { + case kIROp_Int64Type: + case kIROp_UInt64Type: +#if SLANG_PTR_IS_64 + case kIROp_PtrType: + case kIROp_UIntPtrType: +#endif { SpvWord valHighWord; memcpy(&valHighWord, (char*)(&val) + 4, sizeof(SpvWord)); @@ -720,8 +727,9 @@ struct SPIRVEmitContext kResultID, valWord, valHighWord); + break; } - else + default: { result = emitInst( getSection(SpvLogicalSectionID::Constants), @@ -730,6 +738,8 @@ struct SPIRVEmitContext type, kResultID, valWord); + break; + } } m_spvIntConstants[key] = result; return result; @@ -1722,6 +1732,8 @@ struct SPIRVEmitContext { case BaseType::Int64: case BaseType::UInt64: + case BaseType::IntPtr: + case BaseType::UIntPtr: return emitInst( getSection(SpvLogicalSectionID::Constants), inst, diff --git a/source/slang/slang-glsl-extension-tracker.cpp b/source/slang/slang-glsl-extension-tracker.cpp index 8c3549fe9..4cd2b4a3c 100644 --- a/source/slang/slang-glsl-extension-tracker.cpp +++ b/source/slang/slang-glsl-extension-tracker.cpp @@ -65,7 +65,16 @@ void GLSLExtensionTracker::requireBaseTypeExtension(BaseType baseType) case BaseType::Int64: { requireExtension(UnownedStringSlice::fromLiteral("GL_EXT_shader_explicit_arithmetic_types_int64")); - m_hasBaseTypeFlags |= _getFlag(BaseType::UInt64) | _getFlag(BaseType::Int64); + m_hasBaseTypeFlags |= _getFlag(BaseType::UInt64) | _getFlag(BaseType::Int64) | _getFlag(BaseType::IntPtr) | _getFlag(BaseType::UIntPtr); + break; + } + case BaseType::IntPtr: + case BaseType::UIntPtr: + { +#if SLANG_PTR_IS_64 + requireExtension(UnownedStringSlice::fromLiteral("GL_EXT_shader_explicit_arithmetic_types_int64")); + m_hasBaseTypeFlags |= _getFlag(BaseType::UInt64) | _getFlag(BaseType::Int64) | _getFlag(BaseType::IntPtr) | _getFlag(BaseType::UIntPtr); +#endif break; } } diff --git a/source/slang/slang-intrinsic-expand.cpp b/source/slang/slang-intrinsic-expand.cpp index b494e71e1..48186b94a 100644 --- a/source/slang/slang-intrinsic-expand.cpp +++ b/source/slang/slang-intrinsic-expand.cpp @@ -71,7 +71,9 @@ static BaseType _getBaseTypeFromScalarType(SlangScalarType type) case SLANG_SCALAR_TYPE_INT16: return BaseType::Int16; case SLANG_SCALAR_TYPE_UINT16: return BaseType::UInt16; case SLANG_SCALAR_TYPE_INT64: return BaseType::Int64; + case SLANG_SCALAR_TYPE_INTPTR: return BaseType::IntPtr; case SLANG_SCALAR_TYPE_UINT64: return BaseType::UInt64; + case SLANG_SCALAR_TYPE_UINTPTR: return BaseType::UIntPtr; case SLANG_SCALAR_TYPE_INT8: return BaseType::Int8; case SLANG_SCALAR_TYPE_UINT8: return BaseType::UInt8; case SLANG_SCALAR_TYPE_FLOAT16: return BaseType::Half; diff --git a/source/slang/slang-ir-any-value-marshalling.cpp b/source/slang/slang-ir-any-value-marshalling.cpp index f1a1982c2..446d8faf0 100644 --- a/source/slang/slang-ir-any-value-marshalling.cpp +++ b/source/slang/slang-ir-any-value-marshalling.cpp @@ -136,6 +136,8 @@ namespace Slang case kIROp_UInt16Type: case kIROp_HalfType: case kIROp_BoolType: + case kIROp_IntPtrType: + case kIROp_UIntPtrType: context->marshalBasicType(builder, dataType, concreteTypedVar); break; case kIROp_VectorType: @@ -239,6 +241,9 @@ namespace Slang case kIROp_IntType: case kIROp_FloatType: case kIROp_BoolType: +#if SLANG_PTR_IS_32 + case kIROp_IntPtrType: +#endif { ensureOffsetAt4ByteBoundary(); if (fieldOffset < static_cast<uint32_t>(anyValInfo->fieldKeys.getCount())) @@ -255,6 +260,9 @@ namespace Slang break; } case kIROp_UIntType: +#if SLANG_PTR_IS_32 + case kIROp_UIntPtrType: +#endif { ensureOffsetAt4ByteBoundary(); if (fieldOffset < static_cast<uint32_t>(anyValInfo->fieldKeys.getCount())) @@ -313,6 +321,10 @@ namespace Slang case kIROp_UInt64Type: case kIROp_Int64Type: case kIROp_DoubleType: +#if SLANG_PTR_IS_64 + case kIROp_UIntPtrType: + case kIROp_IntPtrType: +#endif SLANG_UNIMPLEMENTED_X("AnyValue type packing for non 32-bit elements"); break; default: diff --git a/source/slang/slang-ir-lower-bit-cast.cpp b/source/slang/slang-ir-lower-bit-cast.cpp index d895f1e28..e7a4b661b 100644 --- a/source/slang/slang-ir-lower-bit-cast.cpp +++ b/source/slang/slang-ir-lower-bit-cast.cpp @@ -168,6 +168,10 @@ struct BitCastLoweringContext case kIROp_UIntType: case kIROp_FloatType: case kIROp_BoolType: +#if SLANG_PTR_IS_32 + case kIROp_IntPtrType: + case kIROp_UIntPtrType: +#endif { auto object = extractValueAtOffset(builder, targetReq, src, offset, 4); return builder.emitBitCast(type, object); @@ -176,6 +180,10 @@ struct BitCastLoweringContext case kIROp_DoubleType: case kIROp_Int64Type: case kIROp_UInt64Type: +#if SLANG_PTR_IS_64 + case kIROp_IntPtrType: + case kIROp_UIntPtrType: +#endif case kIROp_RawPointerType: { auto low = extractValueAtOffset(builder, targetReq, src, offset, 4); diff --git a/source/slang/slang-ir-lower-result-type.cpp b/source/slang/slang-ir-lower-result-type.cpp index 21e046849..07124d0d6 100644 --- a/source/slang/slang-ir-lower-result-type.cpp +++ b/source/slang/slang-ir-lower-result-type.cpp @@ -103,10 +103,12 @@ namespace Slang case kIROp_Int16Type: case kIROp_IntType: case kIROp_Int64Type: + case kIROp_IntPtrType: case kIROp_UInt8Type: case kIROp_UInt16Type: case kIROp_UIntType: case kIROp_UInt64Type: + case kIROp_UIntPtrType: break; default: SLANG_ASSERT_FAILURE("error type is not lowered to an integer type."); diff --git a/source/slang/slang-ir-sccp.cpp b/source/slang/slang-ir-sccp.cpp index e724d0d88..0bee2565c 100644 --- a/source/slang/slang-ir-sccp.cpp +++ b/source/slang/slang-ir-sccp.cpp @@ -303,6 +303,8 @@ struct SCCPContext case kIROp_UInt16Type: case kIROp_UIntType: case kIROp_UInt64Type: + case kIROp_IntPtrType: + case kIROp_UIntPtrType: switch (irConstant->getOp()) { case kIROp_FloatLit: @@ -368,10 +370,12 @@ struct SCCPContext case kIROp_Int16Type: case kIROp_IntType: case kIROp_Int64Type: + case kIROp_IntPtrType: case kIROp_UInt8Type: case kIROp_UInt16Type: case kIROp_UIntType: case kIROp_UInt64Type: + case kIROp_UIntPtrType: resultVal = getBuilder()->getIntValue(type, (IRIntegerValue)0); break; @@ -413,6 +417,8 @@ struct SCCPContext case kIROp_UInt16Type: case kIROp_UIntType: case kIROp_UInt64Type: + case kIROp_IntPtrType: + case kIROp_UIntPtrType: case kIROp_BoolType: resultVal = getBuilder()->getIntValue(type, intFunc(c0->value.intVal, c1->value.intVal)); break; @@ -447,10 +453,12 @@ struct SCCPContext case kIROp_Int16Type: case kIROp_IntType: case kIROp_Int64Type: + case kIROp_IntPtrType: case kIROp_UInt8Type: case kIROp_UInt16Type: case kIROp_UIntType: case kIROp_UInt64Type: + case kIROp_UIntPtrType: case kIROp_BoolType: resultVal = getBuilder()->getIntValue(type, intFunc(c0->value.intVal, c1->value.intVal)); @@ -476,10 +484,12 @@ struct SCCPContext case kIROp_Int16Type: case kIROp_IntType: case kIROp_Int64Type: + case kIROp_IntPtrType: case kIROp_UInt8Type: case kIROp_UInt16Type: case kIROp_UIntType: case kIROp_UInt64Type: + case kIROp_UIntPtrType: case kIROp_BoolType: resultVal = getBuilder()->getIntValue(type, intFunc(c0->value.intVal)); @@ -511,10 +521,12 @@ struct SCCPContext case kIROp_Int16Type: case kIROp_IntType: case kIROp_Int64Type: + case kIROp_IntPtrType: case kIROp_UInt8Type: case kIROp_UInt16Type: case kIROp_UIntType: case kIROp_UInt64Type: + case kIROp_UIntPtrType: case kIROp_BoolType: resultVal = getBuilder()->getBoolValue(intFunc(c0->value.intVal, c1->value.intVal)); @@ -680,10 +692,12 @@ struct SCCPContext case kIROp_Int16Type: case kIROp_IntType: case kIROp_Int64Type: + case kIROp_IntPtrType: case kIROp_UInt8Type: case kIROp_UInt16Type: case kIROp_UIntType: case kIROp_UInt64Type: + case kIROp_UIntPtrType: resultVal = getBuilder()->getIntValue(type, -c0->value.intVal); break; case kIROp_FloatType: @@ -708,10 +722,18 @@ struct SCCPContext { case kIROp_Int64Type: case kIROp_UInt64Type: +#if SLANG_PTR_IS_64 + case kIROp_IntPtrType: + case kIROp_UIntPtrType: +#endif resultVal = getBuilder()->getIntValue(type, c0->value.intVal); break; case kIROp_IntType: case kIROp_UIntType: +#if SLANG_PTR_IS_32 + case kIROp_IntPtrType: + case kIROp_UIntPtrType: +#endif { float val = (float)c0->value.floatVal; uint32_t intVal = (uint32_t)FloatAsInt(val); diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 221abe2b8..90f8208b2 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -3185,6 +3185,8 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo> case BaseType::UInt16: case BaseType::UInt: case BaseType::UInt64: + case BaseType::UIntPtr: + case BaseType::IntPtr: return LoweredValInfo::simple(getBuilder()->getIntValue(type, 0)); case BaseType::Half: diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp index c15402fbb..11c72b182 100644 --- a/source/slang/slang-mangle.cpp +++ b/source/slang/slang-mangle.cpp @@ -172,6 +172,8 @@ namespace Slang case BaseType::Half: emitRaw(context, "h"); break; case BaseType::Float: emitRaw(context, "f"); break; case BaseType::Double: emitRaw(context, "d"); break; + case BaseType::UIntPtr: emitRaw(context, "up"); break; + case BaseType::IntPtr: emitRaw(context, "ip"); break; break; default: diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 77a2319d2..55b6afd6a 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -5502,6 +5502,7 @@ namespace Slang int lCount = 0; int uCount = 0; + int zCount = 0; int unknownCount = 0; while(suffixCursor < suffixEnd) { @@ -5515,6 +5516,10 @@ namespace Slang uCount++; break; + case 'z': case 'Z': + zCount++; + break; + default: unknownCount++; break; @@ -5527,25 +5532,33 @@ namespace Slang suffixBaseType = BaseType::Void; } // `u` or `ul` suffix -> `uint` - else if(uCount == 1 && (lCount <= 1)) + else if(uCount == 1 && (lCount <= 1) && zCount == 0) { suffixBaseType = BaseType::UInt; } // `l` suffix on integer -> `int` (== `long`) - else if(lCount == 1 && !uCount) + else if(lCount == 1 && !uCount && zCount == 0) { suffixBaseType = BaseType::Int; } // `ull` suffix -> `uint64_t` - else if(uCount == 1 && lCount == 2) + else if(uCount == 1 && lCount == 2 && zCount == 0) { suffixBaseType = BaseType::UInt64; } // `ll` suffix -> `int64_t` - else if(uCount == 0 && lCount == 2) + else if(uCount == 0 && lCount == 2 && zCount == 0) { suffixBaseType = BaseType::Int64; } + else if (uCount == 0 && zCount == 1) + { + suffixBaseType = BaseType::IntPtr; + } + else if (uCount == 1 && zCount == 1) + { + suffixBaseType = BaseType::UIntPtr; + } // TODO: do we need suffixes for smaller integer types? else { diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index ac952d2eb..6df9eea46 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -97,6 +97,8 @@ namespace Slang { "int16_t", BaseType::Int16, SINT_MASK, kBaseTypeConversionKind_Signed, kBaseTypeConversionRank_Int16}, { "int", BaseType::Int, SINT_MASK, kBaseTypeConversionKind_Signed, kBaseTypeConversionRank_Int32}, { "int64_t", BaseType::Int64, SINT_MASK, kBaseTypeConversionKind_Signed, kBaseTypeConversionRank_Int64}, + { "intptr_t", BaseType::IntPtr, SINT_MASK, kBaseTypeConversionKind_Signed, kBaseTypeConversionRank_IntPtr}, + { "half", BaseType::Half, FLOAT_MASK, kBaseTypeConversionKind_Float, kBaseTypeConversionRank_Int16}, { "float", BaseType::Float, FLOAT_MASK, kBaseTypeConversionKind_Float, kBaseTypeConversionRank_Int32}, @@ -106,6 +108,8 @@ namespace Slang { "uint16_t", BaseType::UInt16, UINT_MASK, kBaseTypeConversionKind_Unsigned, kBaseTypeConversionRank_Int16}, { "uint", BaseType::UInt, UINT_MASK, kBaseTypeConversionKind_Unsigned, kBaseTypeConversionRank_Int32}, { "uint64_t", BaseType::UInt64, UINT_MASK, kBaseTypeConversionKind_Unsigned, kBaseTypeConversionRank_Int64}, + { "uintptr_t", BaseType::UIntPtr, UINT_MASK, kBaseTypeConversionKind_Unsigned, kBaseTypeConversionRank_IntPtr}, + }; // Given two base types, we need to be able to compute the cost of converting between them. diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index 5a32f6566..c77aadd68 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -82,11 +82,13 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl case BaseType::Int16: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2); case BaseType::Int: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4); case BaseType::Int64: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8,8); + case BaseType::IntPtr: return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(intptr_t), sizeof(intptr_t)); case BaseType::UInt8: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 1,1); case BaseType::UInt16: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2); case BaseType::UInt: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4); case BaseType::UInt64: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8,8); + case BaseType::UIntPtr: return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(intptr_t), sizeof(intptr_t)); case BaseType::Half: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2); case BaseType::Float: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4); diff --git a/source/slang/slang-type-system-shared.h b/source/slang/slang-type-system-shared.h index a0b8f45a8..2e824e0a0 100644 --- a/source/slang/slang-type-system-shared.h +++ b/source/slang/slang-type-system-shared.h @@ -20,6 +20,8 @@ namespace Slang X(Float) \ X(Double) \ X(Char) \ + X(IntPtr) \ + X(UIntPtr) \ /* end */ enum class BaseType diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index b68dbc14a..f2668b995 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -79,6 +79,8 @@ namespace Slang { { uint8_t(sizeof(float)), BaseTypeInfo::Flag::FloatingPoint , uint8_t(BaseType::Float) }, { uint8_t(sizeof(double)), BaseTypeInfo::Flag::FloatingPoint , uint8_t(BaseType::Double) }, { uint8_t(sizeof(char)), BaseTypeInfo::Flag::Signed | BaseTypeInfo::Flag::Integer , uint8_t(BaseType::Char) }, + { uint8_t(sizeof(intptr_t)), BaseTypeInfo::Flag::Signed | BaseTypeInfo::Flag::Integer , uint8_t(BaseType::IntPtr) }, + { uint8_t(sizeof(uintptr_t)), BaseTypeInfo::Flag::Integer , uint8_t(BaseType::UIntPtr) }, }; /* static */bool BaseTypeInfo::check() @@ -111,6 +113,9 @@ namespace Slang { case BaseType::Half: return UnownedStringSlice::fromLiteral("half"); case BaseType::Float: return UnownedStringSlice::fromLiteral("float"); case BaseType::Double: return UnownedStringSlice::fromLiteral("double"); + case BaseType::Char: return UnownedStringSlice::fromLiteral("char"); + case BaseType::IntPtr: return UnownedStringSlice::fromLiteral("intptr_t"); + case BaseType::UIntPtr: return UnownedStringSlice::fromLiteral("uintptr_t"); default: { SLANG_ASSERT(!"Unknown basic type"); diff --git a/tests/diagnostics/bad-operator-call.slang.expected b/tests/diagnostics/bad-operator-call.slang.expected index e7dc23739..14d1b858f 100644 --- a/tests/diagnostics/bad-operator-call.slang.expected +++ b/tests/diagnostics/bad-operator-call.slang.expected @@ -3,36 +3,38 @@ standard error = { tests/diagnostics/bad-operator-call.slang(18): error 39999: no overload for '+=' applicable to arguments of type (int, S) a += b; ^~ -core.meta.slang(1940): note 39999: candidate: __unsafeForceInlineEarly func +=<T, R:int, C:int>(out matrix<T,R,C>, T) -> matrix<T,R,C> -core.meta.slang(1932): note 39999: candidate: __unsafeForceInlineEarly func +=<T, R:int, C:int>(out matrix<T,R,C>, matrix<T,R,C>) -> matrix<T,R,C> -core.meta.slang(1924): note 39999: candidate: __unsafeForceInlineEarly func +=<T, N:int>(out vector<T,N>, T) -> vector<T,N> -core.meta.slang(1916): note 39999: candidate: __unsafeForceInlineEarly func +=<T, N:int>(out vector<T,N>, vector<T,N>) -> vector<T,N> -core.meta.slang(1908): note 39999: candidate: __unsafeForceInlineEarly func +=<T>(out T, T) -> T +core.meta.slang(2219): note 39999: candidate: __unsafeForceInlineEarly func +=<T, R:int, C:int>(out matrix<T,R,C>, T) -> matrix<T,R,C> +core.meta.slang(2211): note 39999: candidate: __unsafeForceInlineEarly func +=<T, R:int, C:int>(out matrix<T,R,C>, matrix<T,R,C>) -> matrix<T,R,C> +core.meta.slang(2203): note 39999: candidate: __unsafeForceInlineEarly func +=<T, N:int>(out vector<T,N>, T) -> vector<T,N> +core.meta.slang(2195): note 39999: candidate: __unsafeForceInlineEarly func +=<T, N:int>(out vector<T,N>, vector<T,N>) -> vector<T,N> +core.meta.slang(2187): note 39999: candidate: __unsafeForceInlineEarly func +=<T>(out T, T) -> T tests/diagnostics/bad-operator-call.slang(20): error 39999: no overload for '+' applicable to arguments of type (int, S) a = a + b; ^ -core.meta.slang(1746): note 39999: candidate: __intrinsic_op func +(uint64_t, uint64_t) -> uint64_t -core.meta.slang(1739): note 39999: candidate: __intrinsic_op func +(uint, uint) -> uint -core.meta.slang(1732): note 39999: candidate: __intrinsic_op func +(uint16_t, uint16_t) -> uint16_t -core.meta.slang(1725): note 39999: candidate: __intrinsic_op func +(uint8_t, uint8_t) -> uint8_t -core.meta.slang(1718): note 39999: candidate: __intrinsic_op func +(double, double) -> double -core.meta.slang(1711): note 39999: candidate: __intrinsic_op func +(float, float) -> float -core.meta.slang(1704): note 39999: candidate: __intrinsic_op func +(half, half) -> half -core.meta.slang(1697): note 39999: candidate: __intrinsic_op func +(int64_t, int64_t) -> int64_t -core.meta.slang(1690): note 39999: candidate: __intrinsic_op func +(int, int) -> int -core.meta.slang(1683): note 39999: candidate: __intrinsic_op func +(int16_t, int16_t) -> int16_t -tests/diagnostics/bad-operator-call.slang(20): note 39999: 1 more overload candidates +core.meta.slang(2045): note 39999: candidate: __intrinsic_op func +(uintptr_t, uintptr_t) -> uintptr_t +core.meta.slang(2037): note 39999: candidate: __intrinsic_op func +(uint64_t, uint64_t) -> uint64_t +core.meta.slang(2029): note 39999: candidate: __intrinsic_op func +(uint, uint) -> uint +core.meta.slang(2021): note 39999: candidate: __intrinsic_op func +(uint16_t, uint16_t) -> uint16_t +core.meta.slang(2013): note 39999: candidate: __intrinsic_op func +(uint8_t, uint8_t) -> uint8_t +core.meta.slang(2005): note 39999: candidate: __intrinsic_op func +(double, double) -> double +core.meta.slang(1997): note 39999: candidate: __intrinsic_op func +(float, float) -> float +core.meta.slang(1989): note 39999: candidate: __intrinsic_op func +(half, half) -> half +core.meta.slang(1981): note 39999: candidate: __intrinsic_op func +(intptr_t, intptr_t) -> intptr_t +core.meta.slang(1973): note 39999: candidate: __intrinsic_op func +(int64_t, int64_t) -> int64_t +tests/diagnostics/bad-operator-call.slang(20): note 39999: 3 more overload candidates tests/diagnostics/bad-operator-call.slang(22): error 39999: no overload for '~' applicable to arguments of type (S) a = ~b; ^ -core.meta.slang(1632): note 39999: candidate: __prefix __intrinsic_op func ~(uint64_t) -> uint64_t -core.meta.slang(1629): note 39999: candidate: __prefix __intrinsic_op func ~(uint) -> uint -core.meta.slang(1626): note 39999: candidate: __prefix __intrinsic_op func ~(uint16_t) -> uint16_t -core.meta.slang(1623): note 39999: candidate: __prefix __intrinsic_op func ~(uint8_t) -> uint8_t -core.meta.slang(1620): note 39999: candidate: __prefix __intrinsic_op func ~(int64_t) -> int64_t -core.meta.slang(1617): note 39999: candidate: __prefix __intrinsic_op func ~(int) -> int -core.meta.slang(1614): note 39999: candidate: __prefix __intrinsic_op func ~(int16_t) -> int16_t -core.meta.slang(1611): note 39999: candidate: __prefix __intrinsic_op func ~(int8_t) -> int8_t +core.meta.slang(1914): note 39999: candidate: __prefix __intrinsic_op func ~(uintptr_t) -> uintptr_t +core.meta.slang(1910): note 39999: candidate: __prefix __intrinsic_op func ~(uint64_t) -> uint64_t +core.meta.slang(1906): note 39999: candidate: __prefix __intrinsic_op func ~(uint) -> uint +core.meta.slang(1902): note 39999: candidate: __prefix __intrinsic_op func ~(uint16_t) -> uint16_t +core.meta.slang(1898): note 39999: candidate: __prefix __intrinsic_op func ~(uint8_t) -> uint8_t +core.meta.slang(1894): note 39999: candidate: __prefix __intrinsic_op func ~(intptr_t) -> intptr_t +core.meta.slang(1890): note 39999: candidate: __prefix __intrinsic_op func ~(int64_t) -> int64_t +core.meta.slang(1886): note 39999: candidate: __prefix __intrinsic_op func ~(int) -> int +core.meta.slang(1882): note 39999: candidate: __prefix __intrinsic_op func ~(int16_t) -> int16_t +core.meta.slang(1878): note 39999: candidate: __prefix __intrinsic_op func ~(int8_t) -> int8_t tests/diagnostics/bad-operator-call.slang(27): error 30047: argument passed to parameter '0' must be l-value. a += c; ^ @@ -40,25 +42,25 @@ tests/diagnostics/bad-operator-call.slang(27): note 30048: argument was implicit tests/diagnostics/bad-operator-call.slang(31): error 39999: no overload for '+=' applicable to arguments of type (vector<float,3>, vector<int,4>) d += c; ^~ -core.meta.slang(1940): note 39999: candidate: __unsafeForceInlineEarly func +=<T, R:int, C:int>(out matrix<T,R,C>, T) -> matrix<T,R,C> -core.meta.slang(1932): note 39999: candidate: __unsafeForceInlineEarly func +=<T, R:int, C:int>(out matrix<T,R,C>, matrix<T,R,C>) -> matrix<T,R,C> -core.meta.slang(1924): note 39999: candidate: __unsafeForceInlineEarly func +=<T, N:int>(out vector<T,N>, T) -> vector<T,N> -core.meta.slang(1916): note 39999: candidate: __unsafeForceInlineEarly func +=<T, N:int>(out vector<T,N>, vector<T,N>) -> vector<T,N> -core.meta.slang(1908): note 39999: candidate: __unsafeForceInlineEarly func +=<T>(out T, T) -> T +core.meta.slang(2219): note 39999: candidate: __unsafeForceInlineEarly func +=<T, R:int, C:int>(out matrix<T,R,C>, T) -> matrix<T,R,C> +core.meta.slang(2211): note 39999: candidate: __unsafeForceInlineEarly func +=<T, R:int, C:int>(out matrix<T,R,C>, matrix<T,R,C>) -> matrix<T,R,C> +core.meta.slang(2203): note 39999: candidate: __unsafeForceInlineEarly func +=<T, N:int>(out vector<T,N>, T) -> vector<T,N> +core.meta.slang(2195): note 39999: candidate: __unsafeForceInlineEarly func +=<T, N:int>(out vector<T,N>, vector<T,N>) -> vector<T,N> +core.meta.slang(2187): note 39999: candidate: __unsafeForceInlineEarly func +=<T>(out T, T) -> T tests/diagnostics/bad-operator-call.slang(33): error 39999: no overload for '+' applicable to arguments of type (vector<int,4>, vector<float,3>) d = c + d; ^ -core.meta.slang(1751): note 39999: candidate: __intrinsic_op func +<4>(vector<uint64_t,4>, uint64_t) -> vector<uint64_t,4> -core.meta.slang(1749): note 39999: candidate: __intrinsic_op func +<3>(uint64_t, vector<uint64_t,3>) -> vector<uint64_t,3> -core.meta.slang(1746): note 39999: candidate: __intrinsic_op func +(uint64_t, uint64_t) -> uint64_t -core.meta.slang(1744): note 39999: candidate: __intrinsic_op func +<4>(vector<uint,4>, uint) -> vector<uint,4> -core.meta.slang(1742): note 39999: candidate: __intrinsic_op func +<3>(uint, vector<uint,3>) -> vector<uint,3> -core.meta.slang(1739): note 39999: candidate: __intrinsic_op func +(uint, uint) -> uint -core.meta.slang(1737): note 39999: candidate: __intrinsic_op func +<4>(vector<uint16_t,4>, uint16_t) -> vector<uint16_t,4> -core.meta.slang(1735): note 39999: candidate: __intrinsic_op func +<3>(uint16_t, vector<uint16_t,3>) -> vector<uint16_t,3> -core.meta.slang(1732): note 39999: candidate: __intrinsic_op func +(uint16_t, uint16_t) -> uint16_t -core.meta.slang(1730): note 39999: candidate: __intrinsic_op func +<4>(vector<uint8_t,4>, uint8_t) -> vector<uint8_t,4> -tests/diagnostics/bad-operator-call.slang(33): note 39999: 23 more overload candidates +core.meta.slang(2051): note 39999: candidate: __intrinsic_op func +<4>(vector<uintptr_t,4>, uintptr_t) -> vector<uintptr_t,4> +core.meta.slang(2049): note 39999: candidate: __intrinsic_op func +<3>(uintptr_t, vector<uintptr_t,3>) -> vector<uintptr_t,3> +core.meta.slang(2045): note 39999: candidate: __intrinsic_op func +(uintptr_t, uintptr_t) -> uintptr_t +core.meta.slang(2043): note 39999: candidate: __intrinsic_op func +<4>(vector<uint64_t,4>, uint64_t) -> vector<uint64_t,4> +core.meta.slang(2041): note 39999: candidate: __intrinsic_op func +<3>(uint64_t, vector<uint64_t,3>) -> vector<uint64_t,3> +core.meta.slang(2037): note 39999: candidate: __intrinsic_op func +(uint64_t, uint64_t) -> uint64_t +core.meta.slang(2035): note 39999: candidate: __intrinsic_op func +<4>(vector<uint,4>, uint) -> vector<uint,4> +core.meta.slang(2033): note 39999: candidate: __intrinsic_op func +<3>(uint, vector<uint,3>) -> vector<uint,3> +core.meta.slang(2029): note 39999: candidate: __intrinsic_op func +(uint, uint) -> uint +core.meta.slang(2027): note 39999: candidate: __intrinsic_op func +<4>(vector<uint16_t,4>, uint16_t) -> vector<uint16_t,4> +tests/diagnostics/bad-operator-call.slang(33): note 39999: 29 more overload candidates } standard output = { } diff --git a/tests/language-feature/types/intptr.slang b/tests/language-feature/types/intptr.slang new file mode 100644 index 000000000..ea626adad --- /dev/null +++ b/tests/language-feature/types/intptr.slang @@ -0,0 +1,37 @@ +// intptr.slang + +// Test pointer-sized integer types. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -cpu -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +__target_intrinsic(cpp, "sizeof(intptr_t)") +intptr_t getNativeIntPtrSize(); + +__generic<T> +__target_intrinsic(cpp, "sizeof($0)") +intptr_t getSizeOf(T val); + +intptr_t getIntPtrVal() { return 0z; } + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + let expectedSize = getNativeIntPtrSize(); + intptr_t a = 0z; + var actualSize = getSizeOf(getIntPtrVal()); + int testResult = 1; + if (expectedSize != actualSize) + { + testResult = 0; + } + uintptr_t b = 0uz; + actualSize = getSizeOf(b); + if (expectedSize != actualSize) + { + testResult = 0; + } + outputBuffer[dispatchThreadID.x] = testResult; +} diff --git a/tests/language-feature/types/intptr.slang.expected.txt b/tests/language-feature/types/intptr.slang.expected.txt new file mode 100644 index 000000000..56a6051ca --- /dev/null +++ b/tests/language-feature/types/intptr.slang.expected.txt @@ -0,0 +1 @@ +1
\ No newline at end of file diff --git a/tools/gfx/gfx.slang b/tools/gfx/gfx.slang index 02e31fad2..d57b746db 100644 --- a/tools/gfx/gfx.slang +++ b/tools/gfx/gfx.slang @@ -4,13 +4,13 @@ namespace gfx { typedef slang.Result Result; -typedef int64_t Int; -typedef uint64_t UInt; +typedef intptr_t Int; +typedef uintptr_t UInt; typedef uint64_t DeviceAddress; typedef int GfxIndex; typedef int GfxCount; -typedef uint64_t Size; -typedef uint64_t Offset; +typedef intptr_t Size; +typedef intptr_t Offset; const uint64_t kTimeoutInfinite = 0xFFFFFFFFFFFFFFFF; |
