Merge pull request #801 from amdrexu/bugfix

HLSL: Fix an issue of frexp().
This commit is contained in:
John Kessenich
2017-03-29 10:04:30 -06:00
committed by GitHub
11 changed files with 10037 additions and 9638 deletions

View File

@@ -4618,6 +4618,9 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv::
spv::Id typeId0 = 0;
if (consumedOperands > 0)
typeId0 = builder.getTypeId(operands[0]);
spv::Id typeId1 = 0;
if (consumedOperands > 1)
typeId1 = builder.getTypeId(operands[1]);
spv::Id frexpIntType = 0;
switch (op) {
@@ -4739,13 +4742,22 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv::
libCall = spv::GLSLstd450Fma;
break;
case glslang::EOpFrexp:
libCall = spv::GLSLstd450FrexpStruct;
if (builder.getNumComponents(operands[0]) == 1)
frexpIntType = builder.makeIntegerType(32, true);
else
frexpIntType = builder.makeVectorType(builder.makeIntegerType(32, true), builder.getNumComponents(operands[0]));
typeId = builder.makeStructResultType(typeId0, frexpIntType);
consumedOperands = 1;
{
libCall = spv::GLSLstd450FrexpStruct;
assert(builder.isPointerType(typeId1));
typeId1 = builder.getContainedTypeId(typeId1);
#ifdef AMD_EXTENSIONS
int width = builder.getScalarTypeWidth(typeId1);
#else
int width = 32;
#endif
if (builder.getNumComponents(operands[0]) == 1)
frexpIntType = builder.makeIntegerType(width, true);
else
frexpIntType = builder.makeVectorType(builder.makeIntegerType(width, true), builder.getNumComponents(operands[0]));
typeId = builder.makeStructResultType(typeId0, frexpIntType);
consumedOperands = 1;
}
break;
case glslang::EOpLdexp:
libCall = spv::GLSLstd450Ldexp;
@@ -4853,9 +4865,18 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv::
builder.createStore(builder.createCompositeExtract(id, typeId0, 1), operands[2]);
break;
case glslang::EOpFrexp:
assert(operands.size() == 2);
builder.createStore(builder.createCompositeExtract(id, frexpIntType, 1), operands[1]);
id = builder.createCompositeExtract(id, typeId0, 0);
{
assert(operands.size() == 2);
if (builder.isFloatType(builder.getScalarTypeId(typeId1))) {
// "exp" is floating-point type (from HLSL intrinsic)
spv::Id member1 = builder.createCompositeExtract(id, frexpIntType, 1);
member1 = builder.createUnaryOp(spv::OpConvertSToF, typeId1, member1);
builder.createStore(member1, operands[1]);
} else
// "exp" is integer type (from GLSL built-in function)
builder.createStore(builder.createCompositeExtract(id, frexpIntType, 1), operands[1]);
id = builder.createCompositeExtract(id, typeId0, 0);
}
break;
default:
break;