diff options
| -rw-r--r-- | source/slang/emit.cpp | 57 | ||||
| -rw-r--r-- | tests/bugs/vk-structured-buffer-load.hlsl | 2 | ||||
| -rw-r--r-- | tests/bugs/vk-structured-buffer-load.hlsl.glsl | 21 |
3 files changed, 74 insertions, 6 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 24d1ce56c..675d459e9 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3938,9 +3938,7 @@ struct EmitVisitor CASE_COMPARE(kIROp_Geq, Geq, >=); CASE_COMPARE(kIROp_Leq, Leq, <=); - CASE(kIROp_BitAnd, BitAnd, &); CASE(kIROp_BitXor, BitXor, ^); - CASE(kIROp_BitOr, BitOr, |); CASE(kIROp_And, And, &&); CASE(kIROp_Or, Or, ||); @@ -3989,6 +3987,7 @@ struct EmitVisitor emitIROperand(ctx, inst->getOperand(0), mode, rightSide(prec, outerPrec)); } break; + case kIROp_BitNot: { auto prec = kEOp_Prefix; @@ -4006,6 +4005,60 @@ struct EmitVisitor } break; + case kIROp_BitAnd: + { + auto prec = kEOp_BitAnd; + needClose = maybeEmitParens(outerPrec, prec); + + // TODO: handle a bitwise And of a vector of bools by casting to + // a uvec and performing the bitwise operation + + emitIROperand(ctx, inst->getOperand(0), mode, leftSide(outerPrec, prec)); + + // Are we targetting GLSL, and are both operands scalar bools? + // In that case convert the operation to a logical And + if (getTarget(ctx) == CodeGenTarget::GLSL + && as<IRBoolType>(inst->getOperand(0)->getDataType()) + && as<IRBoolType>(inst->getOperand(1)->getDataType())) + { + emit("&&"); + } + else + { + emit("&"); + } + + emitIROperand(ctx, inst->getOperand(1), mode, rightSide(outerPrec, prec)); + } + break; + + case kIROp_BitOr: + { + auto prec = kEOp_BitOr; + needClose = maybeEmitParens(outerPrec, prec); + + // TODO: handle a bitwise Or of a vector of bools by casting to + // a uvec and performing the bitwise operation + + emitIROperand(ctx, inst->getOperand(0), mode, leftSide(outerPrec, prec)); + + // Are we targetting GLSL, and are both operands scalar bools? + // In that case convert the operation to a logical Or + if (getTarget(ctx) == CodeGenTarget::GLSL + && as<IRBoolType>(inst->getOperand(0)->getDataType()) + && as<IRBoolType>(inst->getOperand(1)->getDataType())) + { + emit("||"); + } + else + { + emit("|"); + } + + emitIROperand(ctx, inst->getOperand(1), mode, rightSide(outerPrec, prec)); + } + break; + case kIROp_Load: { auto base = inst->getOperand(0); diff --git a/tests/bugs/vk-structured-buffer-load.hlsl b/tests/bugs/vk-structured-buffer-load.hlsl index a5f518f93..bd5d16882 100644 --- a/tests/bugs/vk-structured-buffer-load.hlsl +++ b/tests/bugs/vk-structured-buffer-load.hlsl @@ -28,6 +28,8 @@ void HitMain(inout RayHitInfoPacked RayData, BuiltInTriangleIntersectionAttribut if (use_rcp) RayData.PackedHitInfoA.y = rcp(offsfloat); + else if ((use_rcp > 0) & (offsfloat == 0.0)) + RayData.PackedHitInfoA.y = rsqrt(offsfloat + 1.0); else RayData.PackedHitInfoA.y = rsqrt(offsfloat); } diff --git a/tests/bugs/vk-structured-buffer-load.hlsl.glsl b/tests/bugs/vk-structured-buffer-load.hlsl.glsl index 206a25ef0..016e49b25 100644 --- a/tests/bugs/vk-structured-buffer-load.hlsl.glsl +++ b/tests/bugs/vk-structured-buffer-load.hlsl.glsl @@ -33,9 +33,9 @@ void main() float offsfloat_0 = ((gParamBlock_sbuf_0)._data[(int(uint(0)))]); + uint use_rcp_1 = use_rcp_0|uint(HitT_0 > 0.00000000000000000000); - - if(bool(use_rcp_0 | uint(HitT_0 > 0.00000000000000000000))) + if(bool(use_rcp_1)) { float _S4 = (1.0/((offsfloat_0))); @@ -45,9 +45,22 @@ void main() } else { - float _S5 = (inversesqrt((offsfloat_0))); - _S2.PackedHitInfoA_0.y = _S5; + if(use_rcp_1 > uint(0)&&offsfloat_0 == 0.00000000000000000000) + { + + float _S5 = (inversesqrt((offsfloat_0 + 1.00000000000000000000))); + + _S2.PackedHitInfoA_0.y = _S5; + + } + else + { + float _S6 = (inversesqrt((offsfloat_0))); + + _S2.PackedHitInfoA_0.y = _S6; + + } } |
