diff options
| author | Qubaef <52603374+Qubaef@users.noreply.github.com> | 2022-09-16 06:55:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-15 21:55:54 -0700 |
| commit | 53db0e9e126cb26ffb505e1bf02cc64f00cc9855 (patch) | |
| tree | eb2b3adb828e154bfd1b7c6084e8e496b21a555e | |
| parent | a5d3bec25d70f23da1e79cd7773981ff34593611 (diff) | |
Add support for GL_EXT_debug_printf extension to slang (#2399)
| -rw-r--r-- | source/slang/core.meta.slang | 2 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 29 | ||||
| -rw-r--r-- | source/slang/slang-emit-glsl.cpp | 44 | ||||
| -rw-r--r-- | source/slang/slang-emit-hlsl.cpp | 20 |
4 files changed, 63 insertions, 32 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 82783c0b6..4f2597756 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -2300,7 +2300,7 @@ T reinterpret(U value); // Specialized function /// Given a string returns an integer hash of that string. -__intrinsic_op +__intrinsic_op($(kIROp_GetStringHash)) int getStringHash(String string); /// Use will produce a syntax error in downstream compiler diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index b2f6fa06b..151105896 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -2736,8 +2736,35 @@ matrix<T,N,M> pow(matrix<T,N,M> x, matrix<T,N,M> y) } // Output message +__target_intrinsic(hlsl) +__glsl_extension(GL_EXT_debug_printf) +__target_intrinsic(glsl, "debugPrintfEXT($0)") +void printf(NativeString format); + +__target_intrinsic(hlsl) +__glsl_extension(GL_EXT_debug_printf) +__target_intrinsic(glsl, "debugPrintfEXT($0, $1)") +void printf<T0>(NativeString format, T0 arg0); + +__target_intrinsic(hlsl) +__glsl_extension(GL_EXT_debug_printf) +__target_intrinsic(glsl, "debugPrintfEXT($0, $1, $2)") +void printf<T0, T1>(NativeString format, T0 arg0, T1 arg1); -// void printf( string format, ... ); +__target_intrinsic(hlsl) +__glsl_extension(GL_EXT_debug_printf) +__target_intrinsic(glsl, "debugPrintfEXT($0, $1, $2, $3)") +void printf<T0, T1, T2>(NativeString format, T0 arg0, T1 arg1, T2 arg2); + +__target_intrinsic(hlsl) +__glsl_extension(GL_EXT_debug_printf) +__target_intrinsic(glsl, "debugPrintfEXT($0, $1, $2, $3, $4)") +void printf<T0, T1, T2, T3>(NativeString format, T0 arg0, T1 arg1, T2 arg2, T3 arg3); + +__target_intrinsic(hlsl) +__glsl_extension(GL_EXT_debug_printf) +__target_intrinsic(glsl, "debugPrintfEXT($0, $1, $2, $3, $4, $5)") +void printf<T0, T1, T2, T3, T4>(NativeString format, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4); // Tessellation factor fixup routines diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 0fd4ac69c..48dcd21f7 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -38,7 +38,7 @@ SlangResult GLSLSourceEmitter::init() case Stage::Miss: case Stage::RayGeneration: { - _requireRayTracing(); + _requireRayTracing(); break; } default: break; @@ -448,7 +448,7 @@ void GLSLSourceEmitter::_emitGLSLImageFormatModifier(IRInst* var, IRTextureType* // inference (e.g., to specify r11fg11fb10f). m_writer->emit("rgba"); - //Emit("rgb"); + //Emit("rgb"); break; } @@ -784,7 +784,7 @@ void GLSLSourceEmitter::_emitSpecialFloatImpl(IRType* type, const char* valueExp m_writer->emit(")"); } -void GLSLSourceEmitter::emitSimpleValueImpl(IRInst* inst) +void GLSLSourceEmitter::emitSimpleValueImpl(IRInst* inst) { switch (inst->getOp()) { @@ -797,8 +797,8 @@ void GLSLSourceEmitter::emitSimpleValueImpl(IRInst* inst) { switch (type->getBaseType()) { - default: - + default: + case BaseType::Int8: { emitType(type); @@ -856,7 +856,7 @@ void GLSLSourceEmitter::emitSimpleValueImpl(IRInst* inst) } } - break; + break; } case kIROp_FloatLit: { @@ -988,7 +988,7 @@ void GLSLSourceEmitter::emitEntryPointAttributesImpl(IRFunc* irFunc, IREntryPoin case kIROp_HLSLLineStreamType: m_writer->emit("layout(line_strip) out;\n"); break; case kIROp_HLSLTriangleStreamType: m_writer->emit("layout(triangle_strip) out;\n"); break; default: SLANG_ASSERT(!"Unknown stream out type"); - } + } } } break; @@ -1652,19 +1652,21 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu case kIROp_StringLit: { - IRStringLit* lit = cast<IRStringLit>(inst); - const UnownedStringSlice slice = lit->getStringSlice(); - m_writer->emit(int32_t(getStableHashCode32(slice.begin(), slice.getLength()))); + const auto handler = StringEscapeUtil::getHandler(StringEscapeUtil::Style::Slang); + + StringBuilder buf; + const UnownedStringSlice slice = as<IRStringLit>(inst)->getStringSlice(); + StringEscapeUtil::appendQuoted(handler, slice, buf); + + m_writer->emit(buf); + return true; } case kIROp_GetStringHash: { - // On GLSL target, the `String` type is just an `int` - // that is the hash of the string, so we can emit - // the first operand to `getStringHash` directly. - // - EmitOpInfo outerPrec = inOuterPrec; - emitOperand(inst->getOperand(0), outerPrec); + const UnownedStringSlice slice = as<IRStringLit>(inst->getOperand(0))->getStringSlice(); + m_writer->emit(static_cast<int32_t>(getStableHashCode32(slice.begin(), slice.getLength()))); + return true; } case kIROp_ImageLoad: @@ -1771,7 +1773,7 @@ static Index _getGLSLVersion(ProfileVersion profile) { switch (profile) { -#define CASE(TAG, VALUE) case ProfileVersion::TAG: return VALUE; +#define CASE(TAG, VALUE) case ProfileVersion::TAG: return VALUE; CASE(GLSL_110, 110); CASE(GLSL_120, 120); CASE(GLSL_130, 130); @@ -1960,7 +1962,7 @@ void GLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) case kIROp_UInt8Type: case kIROp_UInt16Type: case kIROp_UIntType: - case kIROp_FloatType: + case kIROp_FloatType: case kIROp_DoubleType: { _requireBaseType(cast<IRBasicType>(type)->getBaseType()); @@ -2011,9 +2013,9 @@ void GLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) return; } case kIROp_NativeStringType: - case kIROp_StringType: + case kIROp_StringType: { - m_writer->emit("int"); + m_writer->emit("int"); return; } default: break; @@ -2135,7 +2137,7 @@ void GLSLSourceEmitter::emitRateQualifiersImpl(IRRate* rate) if (as<IRConstExprRate>(rate)) { m_writer->emit("const "); - + } else if (as<IRGroupSharedRate>(rate)) { diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 20fcc5bed..2ffcd6c10 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -539,19 +539,21 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu } case kIROp_StringLit: { - IRStringLit* lit = cast<IRStringLit>(inst); - UnownedStringSlice slice = lit->getStringSlice(); - m_writer->emit(int32_t(getStableHashCode32(slice.begin(), slice.getLength()))); + const auto handler = StringEscapeUtil::getHandler(StringEscapeUtil::Style::Slang); + + StringBuilder buf; + const UnownedStringSlice slice = as<IRStringLit>(inst)->getStringSlice(); + StringEscapeUtil::appendQuoted(handler, slice, buf); + + m_writer->emit(buf); + return true; } case kIROp_GetStringHash: { - // On GLSL target, the `String` type is just an `int` - // that is the hash of the string, so we can emit - // the first operand to `getStringHash` directly. - // - EmitOpInfo outerPrec = inOuterPrec; - emitOperand(inst->getOperand(0), outerPrec); + const UnownedStringSlice slice = as<IRStringLit>(inst->getOperand(0))->getStringSlice(); + m_writer->emit(static_cast<int32_t>(getStableHashCode32(slice.begin(), slice.getLength()))); + return true; } case kIROp_ByteAddressBufferLoad: |
