diff options
| author | Yong He <yonghe@outlook.com> | 2019-01-23 21:51:34 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-23 21:51:34 -0800 |
| commit | 968d7b4084fd2e8561b7d5e65f359b05dc3d7c78 (patch) | |
| tree | 855214769ce6a79ddca31853f06bc82fc82c060e | |
| parent | 935b629448fedc187243bfe88d4149bf30d89c05 (diff) | |
| parent | a4261598be7e3229a6280002eaced96d8cb3ced6 (diff) | |
Merge pull request #793 from csyonghe/yong-fix
Fix handling of GLSL sign function
| -rw-r--r-- | source/slang/emit.cpp | 21 | ||||
| -rw-r--r-- | tests/cross-compile/sign.slang | 13 | ||||
| -rw-r--r-- | tests/cross-compile/sign.slang.glsl | 17 | ||||
| -rw-r--r-- | tests/cross-compile/sign.slang.hlsl | 6 |
4 files changed, 55 insertions, 2 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 0aebf6153..914aea7fd 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3488,7 +3488,23 @@ struct EmitVisitor emit("."); operandIndex++; } - + // fixing issue #602 for GLSL sign function: https://github.com/shader-slang/slang/issues/602 + bool glslSignFix = ctx->shared->target == CodeGenTarget::GLSL && name == "sign"; + if (glslSignFix) + { + if (auto vectorType = as<IRVectorType>(inst->getDataType())) + { + emit("ivec"); + emit(as<IRConstant>(vectorType->getElementCount())->value.intVal); + emit("("); + } + else if (auto scalarType = as<IRBasicType>(inst->getDataType())) + { + emit("int("); + } + else + glslSignFix = false; + } emit(name); emit("("); bool first = true; @@ -3499,7 +3515,8 @@ struct EmitVisitor first = false; } emit(")"); - + if (glslSignFix) + emit(")"); maybeCloseParens(needClose); } diff --git a/tests/cross-compile/sign.slang b/tests/cross-compile/sign.slang new file mode 100644 index 000000000..17a51d93d --- /dev/null +++ b/tests/cross-compile/sign.slang @@ -0,0 +1,13 @@ +// sign.slang + +//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage fragment +//TEST:CROSS_COMPILE:-target dxil-assembly -entry main -stage fragment -profile sm_6_0 + +// Test cross compilation of the sign function + +float4 main() : SV_Target +{ + float4 s = sign(float4(1.5, 1.0, -1.5, -1.0)); + return s; +} + diff --git a/tests/cross-compile/sign.slang.glsl b/tests/cross-compile/sign.slang.glsl new file mode 100644 index 000000000..7a3a37c51 --- /dev/null +++ b/tests/cross-compile/sign.slang.glsl @@ -0,0 +1,17 @@ +//TEST_IGNORE_FILE: +#version 450 +layout(row_major) uniform; +layout(row_major) buffer; + +#line 8 0 +layout(location = 0) +out vec4 _S1; + + +#line 8 +void main() +{ + ivec4 _S2 = ivec4(sign(vec4(1.50000000000000000000, 1.00000000000000000000, -1.50000000000000000000, -1.00000000000000000000))); + _S1 = vec4(_S2); + return; +}
\ No newline at end of file diff --git a/tests/cross-compile/sign.slang.hlsl b/tests/cross-compile/sign.slang.hlsl new file mode 100644 index 000000000..d7016dde7 --- /dev/null +++ b/tests/cross-compile/sign.slang.hlsl @@ -0,0 +1,6 @@ +//TEST_IGNORE_FILE: +float4 main() : SV_Target +{ + float4 s = sign(float4(1.5, 1.0, -1.5, -1.0)); + return s; +}
\ No newline at end of file |
