Add HLSL memory barrier intrinsics, fix dst, add lit & EvaluateAttributeSnapped
This commit is contained in:
@@ -967,6 +967,7 @@ void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*&
|
||||
dst->getSequence().push_back(handleBinaryMath(loc, "mul", EOpMul, src0y, src1y));
|
||||
dst->getSequence().push_back(src0z);
|
||||
dst->getSequence().push_back(src1w);
|
||||
dst->setType(TType(EbtFloat, EvqTemporary, 4));
|
||||
dst->setLoc(loc);
|
||||
node = dst;
|
||||
|
||||
@@ -1028,6 +1029,90 @@ void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*&
|
||||
break;
|
||||
}
|
||||
|
||||
case EOpEvaluateAttributeSnapped:
|
||||
{
|
||||
// SPIR-V InterpolateAtOffset uses float vec2 offset in pixels
|
||||
// HLSL uses int2 offset on a 16x16 grid in [-8..7] on x & y:
|
||||
// iU = (iU<<28)>>28
|
||||
// fU = ((float)iU)/16
|
||||
// Targets might handle this natively, in which case they can disable
|
||||
// decompositions.
|
||||
|
||||
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // value
|
||||
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // offset
|
||||
|
||||
TIntermTyped* i28 = intermediate.addConstantUnion(28, loc, true);
|
||||
TIntermTyped* iU = handleBinaryMath(loc, ">>", EOpRightShift,
|
||||
handleBinaryMath(loc, "<<", EOpLeftShift, arg1, i28),
|
||||
i28);
|
||||
|
||||
TIntermTyped* recip16 = intermediate.addConstantUnion((1.0/16.0), EbtFloat, loc, true);
|
||||
TIntermTyped* floatOffset = handleBinaryMath(loc, "mul", EOpMul,
|
||||
intermediate.addConversion(EOpConstructFloat,
|
||||
TType(EbtFloat, EvqTemporary, 2), iU),
|
||||
recip16);
|
||||
|
||||
TIntermAggregate* interp = new TIntermAggregate(EOpInterpolateAtOffset);
|
||||
interp->getSequence().push_back(arg0);
|
||||
interp->getSequence().push_back(floatOffset);
|
||||
interp->setLoc(loc);
|
||||
interp->setType(arg0->getType());
|
||||
interp->getWritableType().getQualifier().makeTemporary();
|
||||
|
||||
node = interp;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EOpLit:
|
||||
{
|
||||
TIntermTyped* n_dot_l = argAggregate->getSequence()[0]->getAsTyped();
|
||||
TIntermTyped* n_dot_h = argAggregate->getSequence()[1]->getAsTyped();
|
||||
TIntermTyped* m = argAggregate->getSequence()[2]->getAsTyped();
|
||||
|
||||
TIntermAggregate* dst = new TIntermAggregate(EOpConstructVec4);
|
||||
|
||||
// Ambient
|
||||
dst->getSequence().push_back(intermediate.addConstantUnion(1.0, EbtFloat, loc, true));
|
||||
|
||||
// Diffuse:
|
||||
TIntermTyped* zero = intermediate.addConstantUnion(0.0, EbtFloat, loc, true);
|
||||
TIntermAggregate* diffuse = new TIntermAggregate(EOpMax);
|
||||
diffuse->getSequence().push_back(n_dot_l);
|
||||
diffuse->getSequence().push_back(zero);
|
||||
diffuse->setLoc(loc);
|
||||
diffuse->setType(TType(EbtFloat));
|
||||
dst->getSequence().push_back(diffuse);
|
||||
|
||||
// Specular:
|
||||
TIntermAggregate* min_ndot = new TIntermAggregate(EOpMin);
|
||||
min_ndot->getSequence().push_back(n_dot_l);
|
||||
min_ndot->getSequence().push_back(n_dot_h);
|
||||
min_ndot->setLoc(loc);
|
||||
min_ndot->setType(TType(EbtFloat));
|
||||
|
||||
TIntermTyped* compare = handleBinaryMath(loc, "<", EOpLessThan, min_ndot, zero);
|
||||
TIntermTyped* n_dot_h_m = handleBinaryMath(loc, "mul", EOpMul, n_dot_h, m); // n_dot_h * m
|
||||
|
||||
dst->getSequence().push_back(intermediate.addSelection(compare, zero, n_dot_h_m, loc));
|
||||
|
||||
// One:
|
||||
dst->getSequence().push_back(intermediate.addConstantUnion(1.0, EbtFloat, loc, true));
|
||||
|
||||
dst->setLoc(loc);
|
||||
dst->setType(TType(EbtFloat, EvqTemporary, 4));
|
||||
node = dst;
|
||||
break;
|
||||
}
|
||||
|
||||
case EOpF16tof32:
|
||||
case EOpF32tof16:
|
||||
{
|
||||
// Temporary until decomposition is available.
|
||||
error(loc, "unimplemented intrinsic: handle natively", "f32tof16", "");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break; // most pass through unchanged
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ void TBuiltInParseablesHlsl::initialize(int version, EProfile profile, const Spv
|
||||
// { "errorf", "-", "-", "", "", EShLangAll }, TODO: varargs
|
||||
{ "EvaluateAttributeAtCentroid", nullptr, nullptr, "SVM", "F", EShLangFragmentMask },
|
||||
{ "EvaluateAttributeAtSample", nullptr, nullptr, "SVM,S", "F,U", EShLangFragmentMask },
|
||||
{ "EvaluateAttributeSnapped", nullptr, nullptr, "SVM,V2", "F,F", EShLangFragmentMask },
|
||||
{ "EvaluateAttributeSnapped", nullptr, nullptr, "SVM,V2", "F,I", EShLangFragmentMask },
|
||||
{ "exp", nullptr, nullptr, "SVM", "F", EShLangAll },
|
||||
{ "exp2", nullptr, nullptr, "SVM", "F", EShLangAll },
|
||||
{ "f16tof32", nullptr, "F", "SV", "U", EShLangAll },
|
||||
@@ -519,8 +519,8 @@ void TBuiltInParseablesHlsl::identifyBuiltIns(int version, EProfile profile, con
|
||||
symbolTable.relateToOperator("abs", EOpAbs);
|
||||
symbolTable.relateToOperator("acos", EOpAcos);
|
||||
symbolTable.relateToOperator("all", EOpAll);
|
||||
// symbolTable.relateToOperator("AllMemoryBarrier");
|
||||
// symbolTable.relateToOperator("AllMemoryBarrierWithGroupSync");
|
||||
symbolTable.relateToOperator("AllMemoryBarrier", EOpMemoryBarrier);
|
||||
symbolTable.relateToOperator("AllMemoryBarrierWithGroupSync", EOpAllMemoryBarrierWithGroupSync);
|
||||
symbolTable.relateToOperator("any", EOpAny);
|
||||
symbolTable.relateToOperator("asdouble", EOpUint64BitsToDouble);
|
||||
symbolTable.relateToOperator("asfloat", EOpIntBitsToFloat);
|
||||
@@ -546,19 +546,19 @@ void TBuiltInParseablesHlsl::identifyBuiltIns(int version, EProfile profile, con
|
||||
symbolTable.relateToOperator("ddy_fine", EOpDPdyFine);
|
||||
symbolTable.relateToOperator("degrees", EOpDegrees);
|
||||
symbolTable.relateToOperator("determinant", EOpDeterminant);
|
||||
// symbolTable.relateToOperator("DeviceMemoryBarrier");
|
||||
// symbolTable.relateToOperator("DeviceMemoryBarrierWithGroupSync");
|
||||
symbolTable.relateToOperator("DeviceMemoryBarrier", EOpGroupMemoryBarrier); // == ScopeDevice+CrossWorkGroup
|
||||
symbolTable.relateToOperator("DeviceMemoryBarrierWithGroupSync", EOpGroupMemoryBarrierWithGroupSync); // ...
|
||||
symbolTable.relateToOperator("distance", EOpDistance);
|
||||
symbolTable.relateToOperator("dot", EOpDot);
|
||||
symbolTable.relateToOperator("dst", EOpDst);
|
||||
// symbolTable.relateToOperator("errorf");
|
||||
// symbolTable.relateToOperator("errorf", EOpErrorf);
|
||||
symbolTable.relateToOperator("EvaluateAttributeAtCentroid", EOpInterpolateAtCentroid);
|
||||
symbolTable.relateToOperator("EvaluateAttributeAtSample", EOpInterpolateAtSample);
|
||||
// symbolTable.relateToOperator("EvaluateAttributeSnapped"); // TODO: hsnflr positions. new op?
|
||||
symbolTable.relateToOperator("EvaluateAttributeSnapped", EOpEvaluateAttributeSnapped);
|
||||
symbolTable.relateToOperator("exp", EOpExp);
|
||||
symbolTable.relateToOperator("exp2", EOpExp2);
|
||||
// symbolTable.relateToOperator("f16tof32");
|
||||
// symbolTable.relateToOperator("f32tof16");
|
||||
symbolTable.relateToOperator("f16tof32", EOpF16tof32);
|
||||
symbolTable.relateToOperator("f32tof16", EOpF32tof16);
|
||||
symbolTable.relateToOperator("faceforward", EOpFaceForward);
|
||||
symbolTable.relateToOperator("firstbithigh", EOpFindMSB);
|
||||
symbolTable.relateToOperator("firstbitlow", EOpFindLSB);
|
||||
@@ -570,8 +570,8 @@ void TBuiltInParseablesHlsl::identifyBuiltIns(int version, EProfile profile, con
|
||||
symbolTable.relateToOperator("fwidth", EOpFwidth);
|
||||
// symbolTable.relateToOperator("GetRenderTargetSampleCount");
|
||||
// symbolTable.relateToOperator("GetRenderTargetSamplePosition");
|
||||
// symbolTable.relateToOperator("GroupMemoryBarrier");
|
||||
// symbolTable.relateToOperator("GroupMemoryBarrierWithGroupSync");
|
||||
symbolTable.relateToOperator("GroupMemoryBarrier", EOpWorkgroupMemoryBarrier);
|
||||
symbolTable.relateToOperator("GroupMemoryBarrierWithGroupSync", EOpWorkgroupMemoryBarrierWithGroupSync);
|
||||
symbolTable.relateToOperator("InterlockedAdd", EOpInterlockedAdd);
|
||||
symbolTable.relateToOperator("InterlockedAnd", EOpInterlockedAnd);
|
||||
symbolTable.relateToOperator("InterlockedCompareExchange", EOpInterlockedCompareExchange);
|
||||
@@ -586,7 +586,7 @@ void TBuiltInParseablesHlsl::identifyBuiltIns(int version, EProfile profile, con
|
||||
symbolTable.relateToOperator("isnan", EOpIsNan);
|
||||
symbolTable.relateToOperator("ldexp", EOpLdexp);
|
||||
symbolTable.relateToOperator("length", EOpLength);
|
||||
// symbolTable.relateToOperator("lit");
|
||||
symbolTable.relateToOperator("lit", EOpLit);
|
||||
symbolTable.relateToOperator("log", EOpLog);
|
||||
symbolTable.relateToOperator("log10", EOpLog10);
|
||||
symbolTable.relateToOperator("log2", EOpLog2);
|
||||
@@ -599,7 +599,7 @@ void TBuiltInParseablesHlsl::identifyBuiltIns(int version, EProfile profile, con
|
||||
// symbolTable.relateToOperator("noise", EOpNoise); // TODO: check return type
|
||||
symbolTable.relateToOperator("normalize", EOpNormalize);
|
||||
symbolTable.relateToOperator("pow", EOpPow);
|
||||
// symbolTable.relateToOperator("printf");
|
||||
// symbolTable.relateToOperator("printf", EOpPrintf);
|
||||
// symbolTable.relateToOperator("Process2DQuadTessFactorsAvg");
|
||||
// symbolTable.relateToOperator("Process2DQuadTessFactorsMax");
|
||||
// symbolTable.relateToOperator("Process2DQuadTessFactorsMin");
|
||||
|
||||
Reference in New Issue
Block a user