Commit e5a80727 by John Kessenich Committed by GitHub

Merge pull request #349 from steve-lunarg/intrinsics

HLSL: Add lerp, fix sincos ret, add ret type tests, non-square mats, tx semantics
parents 22bca551 4624a02e
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -32,6 +32,7 @@ float VertexShaderFunction(float inF0, float inF1, float inF2, uint inU0, uint i ...@@ -32,6 +32,7 @@ float VertexShaderFunction(float inF0, float inF1, float inF2, uint inU0, uint i
isinf(inF0); isinf(inF0);
isnan(inF0); isnan(inF0);
ldexp(inF0, inF1); ldexp(inF0, inF1);
lerp(inF0, inF1, inF2);
log(inF0); log(inF0);
log10(inF0); log10(inF0);
log2(inF0); log2(inF0);
...@@ -102,6 +103,7 @@ float2 VertexShaderFunction(float2 inF0, float2 inF1, float2 inF2, uint2 inU0, u ...@@ -102,6 +103,7 @@ float2 VertexShaderFunction(float2 inF0, float2 inF1, float2 inF2, uint2 inU0, u
isinf(inF0); isinf(inF0);
isnan(inF0); isnan(inF0);
ldexp(inF0, inF1); ldexp(inF0, inF1);
lerp(inF0, inF1, inF2);
length(inF0); length(inF0);
log(inF0); log(inF0);
log10(inF0); log10(inF0);
...@@ -172,6 +174,7 @@ float3 VertexShaderFunction(float3 inF0, float3 inF1, float3 inF2, uint3 inU0, u ...@@ -172,6 +174,7 @@ float3 VertexShaderFunction(float3 inF0, float3 inF1, float3 inF2, uint3 inU0, u
isinf(inF0); isinf(inF0);
isnan(inF0); isnan(inF0);
ldexp(inF0, inF1); ldexp(inF0, inF1);
lerp(inF0, inF1, inF2);
length(inF0); length(inF0);
log(inF0); log(inF0);
log10(inF0); log10(inF0);
...@@ -242,6 +245,7 @@ float4 VertexShaderFunction(float4 inF0, float4 inF1, float4 inF2, uint4 inU0, u ...@@ -242,6 +245,7 @@ float4 VertexShaderFunction(float4 inF0, float4 inF1, float4 inF2, uint4 inU0, u
isinf(inF0); isinf(inF0);
isnan(inF0); isnan(inF0);
ldexp(inF0, inF1); ldexp(inF0, inF1);
lerp(inF0, inF1, inF2);
length(inF0); length(inF0);
log(inF0); log(inF0);
log10(inF0); log10(inF0);
...@@ -303,6 +307,7 @@ float4 VertexShaderFunction(float4 inF0, float4 inF1, float4 inF2, uint4 inU0, u ...@@ -303,6 +307,7 @@ float4 VertexShaderFunction(float4 inF0, float4 inF1, float4 inF2, uint4 inU0, u
frac(inF0); \ frac(inF0); \
frexp(inF0, inF1); \ frexp(inF0, inF1); \
ldexp(inF0, inF1); \ ldexp(inF0, inF1); \
lerp(inF0, inF1, inF2); \
log(inF0); \ log(inF0); \
log10(inF0); \ log10(inF0); \
log2(inF0); \ log2(inF0); \
...@@ -386,3 +391,29 @@ void TestGenMul(float inF0, float inF1, ...@@ -386,3 +391,29 @@ void TestGenMul(float inF0, float inF1,
{ {
TESTGENMUL(float, float4, float4x4); TESTGENMUL(float, float4, float4x4);
} }
// Test some non-square mats
void TestGenMul(float inF0, float inF1,
float2 inFV2, float3 inFV3,
float2x3 inFM2x3, float3x2 inFM3x2,
float3x3 inFM3x3, float3x4 inFM3x4,
float2x4 inFM2x4)
{
float r00 = mul(inF0, inF1); // S=S*S
float2 r01 = mul(inFV2, inF0); // V=V*S
float3 r02 = mul(inFV3, inF0); // V=V*S
float2 r03 = mul(inF0, inFV2); // V=S*V
float3 r04 = mul(inF0, inFV3); // V=S*V
float r05 = mul(inFV2, inFV2); // S=V*V
float r06 = mul(inFV3, inFV3); // S=V*V
float3 r07 = mul(inFV2, inFM2x3); // V=V*M (return V dim is Mcols)
float2 r08 = mul(inFV3, inFM3x2); // V=V*M (return V dim is Mcols)
float2 r09 = mul(inFM2x3, inFV3); // V=M*V (return V dim is Mrows)
float3 r10 = mul(inFM3x2, inFV2); // V=M*V (return V dim is Mrows)
float2x3 r11 = mul(inFM2x3, inF0);
float3x2 r12 = mul(inFM3x2, inF0);
float2x2 r13 = mul(inFM2x3, inFM3x2);
float2x3 r14 = mul(inFM2x3, inFM3x3);
float2x4 r15 = mul(inFM2x3, inFM3x4);
float3x4 r16 = mul(inFM3x2, inFM2x4);
}
...@@ -523,6 +523,7 @@ enum TOperator { ...@@ -523,6 +523,7 @@ enum TOperator {
EOpF32tof16, // HLSL conversion: half of a PackHalf2x16 EOpF32tof16, // HLSL conversion: half of a PackHalf2x16
EOpF16tof32, // HLSL conversion: half of an UnpackHalf2x16 EOpF16tof32, // HLSL conversion: half of an UnpackHalf2x16
EOpLit, // HLSL lighting coefficient vector EOpLit, // HLSL lighting coefficient vector
EOpTextureBias, // HLSL texture bias: will be lowered to EOpTexture
}; };
class TIntermTraverser; class TIntermTraverser;
......
...@@ -799,6 +799,68 @@ TOperator HlslParseContext::mapAtomicOp(const TSourceLoc& loc, TOperator op, boo ...@@ -799,6 +799,68 @@ TOperator HlslParseContext::mapAtomicOp(const TSourceLoc& loc, TOperator op, boo
} }
} }
//
// Change texture parameters to match AST & SPIR-V semantics
//
void HlslParseContext::textureParameters(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
{
if (!node || !node->getAsOperator())
return;
const TOperator op = node->getAsOperator()->getOp();
const TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
switch (op) {
case EOpTexture:
{
// Texture with ddx & ddy is really gradient form
if (argAggregate->getSequence().size() == 4) {
node->getAsAggregate()->setOperator(EOpTextureGrad);
break;
}
break;
}
case EOpTextureBias:
{
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped(); // sampler
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped(); // coord
// HLSL puts bias in W component of coordinate. We extract it and add it to
// the argument list, instead
TIntermTyped* w = intermediate.addConstantUnion(3, loc, true);
TIntermTyped* bias = intermediate.addIndex(EOpIndexDirect, arg1, w, loc);
TOperator constructOp = EOpNull;
switch (arg0->getType().getSampler().dim) {
case Esd1D: constructOp = EOpConstructFloat; break; // 1D
case Esd2D: constructOp = EOpConstructVec2; break; // 2D
case Esd3D: constructOp = EOpConstructVec3; break; // 3D
case EsdCube: constructOp = EOpConstructVec3; break; // also 3D
default: break;
}
TIntermAggregate* constructCoord = new TIntermAggregate(constructOp);
constructCoord->getSequence().push_back(arg1);
constructCoord->setLoc(loc);
TIntermAggregate* tex = new TIntermAggregate(EOpTexture);
tex->getSequence().push_back(arg0); // sampler
tex->getSequence().push_back(constructCoord); // coordinate
tex->getSequence().push_back(bias); // bias
tex->setLoc(loc);
node = tex;
break;
}
default:
break; // most pass through unchanged
}
}
//
// Optionally decompose intrinsics to AST opcodes. // Optionally decompose intrinsics to AST opcodes.
// //
void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments) void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
...@@ -875,6 +937,7 @@ void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*& ...@@ -875,6 +937,7 @@ void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*&
compoundStatement = intermediate.growAggregate(compoundStatement, cosAssign); compoundStatement = intermediate.growAggregate(compoundStatement, cosAssign);
compoundStatement->setOperator(EOpSequence); compoundStatement->setOperator(EOpSequence);
compoundStatement->setLoc(loc); compoundStatement->setLoc(loc);
compoundStatement->setType(TType(EbtVoid));
node = compoundStatement; node = compoundStatement;
...@@ -1222,6 +1285,7 @@ TIntermTyped* HlslParseContext::handleFunctionCall(const TSourceLoc& loc, TFunct ...@@ -1222,6 +1285,7 @@ TIntermTyped* HlslParseContext::handleFunctionCall(const TSourceLoc& loc, TFunct
} }
decomposeIntrinsic(loc, result, arguments); decomposeIntrinsic(loc, result, arguments);
textureParameters(loc, result, arguments);
} }
} }
......
...@@ -87,6 +87,7 @@ public: ...@@ -87,6 +87,7 @@ public:
void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg); void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg);
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermNode*); TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermNode*);
void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments); void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void textureParameters(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*); TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*);
void addInputArgumentConversions(const TFunction&, TIntermNode*&) const; void addInputArgumentConversions(const TFunction&, TIntermNode*&) const;
TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const; TIntermTyped* addOutputArgumentConversions(const TFunction&, TIntermAggregate&) const;
......
...@@ -54,6 +54,9 @@ public: ...@@ -54,6 +54,9 @@ public:
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable); void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable);
void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources); void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources);
private:
void createMatTimesMat();
}; };
} // end namespace glslang } // end namespace glslang
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment