Add basic namespace to internal macros.

Some projects build SPIRV-Cross as a single translation unit
and this causes a lot of warnings because the same macro is redeclared
multiple times in the different backends. This make sure that each
backend has its own namespace for internal macros.
This commit is contained in:
Hans-Kristian Arntzen 2018-06-28 22:57:52 +02:00
parent d67e586b2e
commit f1752e58e1
3 changed files with 218 additions and 218 deletions

View File

@ -2500,48 +2500,48 @@ string CompilerGLSL::constant_op_expression(const SPIRConstantOp &cop)
op = type_to_glsl_constructor(type);
break;
#define BOP(opname, x) \
#define GLSL_BOP(opname, x) \
case Op##opname: \
binary = true; \
op = x; \
break
#define UOP(opname, x) \
#define GLSL_UOP(opname, x) \
case Op##opname: \
unary = true; \
op = x; \
break
UOP(SNegate, "-");
UOP(Not, "~");
BOP(IAdd, "+");
BOP(ISub, "-");
BOP(IMul, "*");
BOP(SDiv, "/");
BOP(UDiv, "/");
BOP(UMod, "%");
BOP(SMod, "%");
BOP(ShiftRightLogical, ">>");
BOP(ShiftRightArithmetic, ">>");
BOP(ShiftLeftLogical, "<<");
BOP(BitwiseOr, "|");
BOP(BitwiseXor, "^");
BOP(BitwiseAnd, "&");
BOP(LogicalOr, "||");
BOP(LogicalAnd, "&&");
UOP(LogicalNot, "!");
BOP(LogicalEqual, "==");
BOP(LogicalNotEqual, "!=");
BOP(IEqual, "==");
BOP(INotEqual, "!=");
BOP(ULessThan, "<");
BOP(SLessThan, "<");
BOP(ULessThanEqual, "<=");
BOP(SLessThanEqual, "<=");
BOP(UGreaterThan, ">");
BOP(SGreaterThan, ">");
BOP(UGreaterThanEqual, ">=");
BOP(SGreaterThanEqual, ">=");
GLSL_UOP(SNegate, "-");
GLSL_UOP(Not, "~");
GLSL_BOP(IAdd, "+");
GLSL_BOP(ISub, "-");
GLSL_BOP(IMul, "*");
GLSL_BOP(SDiv, "/");
GLSL_BOP(UDiv, "/");
GLSL_BOP(UMod, "%");
GLSL_BOP(SMod, "%");
GLSL_BOP(ShiftRightLogical, ">>");
GLSL_BOP(ShiftRightArithmetic, ">>");
GLSL_BOP(ShiftLeftLogical, "<<");
GLSL_BOP(BitwiseOr, "|");
GLSL_BOP(BitwiseXor, "^");
GLSL_BOP(BitwiseAnd, "&");
GLSL_BOP(LogicalOr, "||");
GLSL_BOP(LogicalAnd, "&&");
GLSL_UOP(LogicalNot, "!");
GLSL_BOP(LogicalEqual, "==");
GLSL_BOP(LogicalNotEqual, "!=");
GLSL_BOP(IEqual, "==");
GLSL_BOP(INotEqual, "!=");
GLSL_BOP(ULessThan, "<");
GLSL_BOP(SLessThan, "<");
GLSL_BOP(ULessThanEqual, "<=");
GLSL_BOP(SLessThanEqual, "<=");
GLSL_BOP(UGreaterThan, ">");
GLSL_BOP(SGreaterThan, ">");
GLSL_BOP(UGreaterThanEqual, ">=");
GLSL_BOP(SGreaterThanEqual, ">=");
case OpSelect:
{
@ -2620,8 +2620,8 @@ string CompilerGLSL::constant_op_expression(const SPIRConstantOp &cop)
break;
}
#undef BOP
#undef UOP
#undef GLSL_BOP
#undef GLSL_UOP
if (binary)
{
if (cop.arguments.size() < 2)
@ -4810,7 +4810,7 @@ void CompilerGLSL::emit_subgroup_op(const Instruction &i)
break;
// clang-format off
#define GROUP_OP(op, glsl_op) \
#define GLSL_GROUP_OP(op, glsl_op) \
case OpGroupNonUniform##op: \
{ \
auto operation = static_cast<GroupOperation>(ops[3]); \
@ -4826,20 +4826,20 @@ case OpGroupNonUniform##op: \
SPIRV_CROSS_THROW("Invalid group operation."); \
break; \
}
GROUP_OP(FAdd, Add)
GROUP_OP(FMul, Mul)
GROUP_OP(FMin, Min)
GROUP_OP(FMax, Max)
GROUP_OP(IAdd, Add)
GROUP_OP(IMul, Mul)
GROUP_OP(SMin, Min)
GROUP_OP(SMax, Max)
GROUP_OP(UMin, Min)
GROUP_OP(UMax, Max)
GROUP_OP(BitwiseAnd, And)
GROUP_OP(BitwiseOr, Or)
GROUP_OP(BitwiseXor, Xor)
#undef GROUP_OP
GLSL_GROUP_OP(FAdd, Add)
GLSL_GROUP_OP(FMul, Mul)
GLSL_GROUP_OP(FMin, Min)
GLSL_GROUP_OP(FMax, Max)
GLSL_GROUP_OP(IAdd, Add)
GLSL_GROUP_OP(IMul, Mul)
GLSL_GROUP_OP(SMin, Min)
GLSL_GROUP_OP(SMax, Max)
GLSL_GROUP_OP(UMin, Min)
GLSL_GROUP_OP(UMax, Max)
GLSL_GROUP_OP(BitwiseAnd, And)
GLSL_GROUP_OP(BitwiseOr, Or)
GLSL_GROUP_OP(BitwiseXor, Xor)
#undef GLSL_GROUP_OP
// clang-format on
case OpGroupNonUniformQuadSwap:
@ -6082,17 +6082,17 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
auto opcode = static_cast<Op>(instruction.op);
uint32_t length = instruction.length;
#define BOP(op) emit_binary_op(ops[0], ops[1], ops[2], ops[3], #op)
#define BOP_CAST(op, type) \
#define GLSL_BOP(op) emit_binary_op(ops[0], ops[1], ops[2], ops[3], #op)
#define GLSL_BOP_CAST(op, type) \
emit_binary_op_cast(ops[0], ops[1], ops[2], ops[3], #op, type, glsl_opcode_is_sign_invariant(opcode))
#define UOP(op) emit_unary_op(ops[0], ops[1], ops[2], #op)
#define QFOP(op) emit_quaternary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], ops[5], #op)
#define TFOP(op) emit_trinary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], #op)
#define BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define BFOP_CAST(op, type) \
#define GLSL_UOP(op) emit_unary_op(ops[0], ops[1], ops[2], #op)
#define GLSL_QFOP(op) emit_quaternary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], ops[5], #op)
#define GLSL_TFOP(op) emit_trinary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], #op)
#define GLSL_BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define GLSL_BFOP_CAST(op, type) \
emit_binary_func_op_cast(ops[0], ops[1], ops[2], ops[3], #op, type, glsl_opcode_is_sign_invariant(opcode))
#define BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define UFOP(op) emit_unary_func_op(ops[0], ops[1], ops[2], #op)
#define GLSL_BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define GLSL_UFOP(op) emit_unary_func_op(ops[0], ops[1], ops[2], #op)
switch (opcode)
{
@ -6625,45 +6625,45 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
// ALU
case OpIsNan:
UFOP(isnan);
GLSL_UFOP(isnan);
break;
case OpIsInf:
UFOP(isinf);
GLSL_UFOP(isinf);
break;
case OpSNegate:
case OpFNegate:
UOP(-);
GLSL_UOP(-);
break;
case OpIAdd:
{
// For simple arith ops, prefer the output type if there's a mismatch to avoid extra bitcasts.
auto type = get<SPIRType>(ops[0]).basetype;
BOP_CAST(+, type);
GLSL_BOP_CAST(+, type);
break;
}
case OpFAdd:
BOP(+);
GLSL_BOP(+);
break;
case OpISub:
{
auto type = get<SPIRType>(ops[0]).basetype;
BOP_CAST(-, type);
GLSL_BOP_CAST(-, type);
break;
}
case OpFSub:
BOP(-);
GLSL_BOP(-);
break;
case OpIMul:
{
auto type = get<SPIRType>(ops[0]).basetype;
BOP_CAST(*, type);
GLSL_BOP_CAST(*, type);
break;
}
@ -6679,7 +6679,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
e->need_transpose = true;
}
else
BOP(*);
GLSL_BOP(*);
break;
}
@ -6687,19 +6687,19 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
case OpMatrixTimesScalar:
case OpVectorTimesScalar:
case OpMatrixTimesMatrix:
BOP(*);
GLSL_BOP(*);
break;
case OpOuterProduct:
BFOP(outerProduct);
GLSL_BFOP(outerProduct);
break;
case OpDot:
BFOP(dot);
GLSL_BFOP(dot);
break;
case OpTranspose:
UFOP(transpose);
GLSL_UFOP(transpose);
break;
case OpSRem:
@ -6721,67 +6721,67 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
}
case OpSDiv:
BOP_CAST(/, SPIRType::Int);
GLSL_BOP_CAST(/, SPIRType::Int);
break;
case OpUDiv:
BOP_CAST(/, SPIRType::UInt);
GLSL_BOP_CAST(/, SPIRType::UInt);
break;
case OpFDiv:
BOP(/);
GLSL_BOP(/);
break;
case OpShiftRightLogical:
BOP_CAST(>>, SPIRType::UInt);
GLSL_BOP_CAST(>>, SPIRType::UInt);
break;
case OpShiftRightArithmetic:
BOP_CAST(>>, SPIRType::Int);
GLSL_BOP_CAST(>>, SPIRType::Int);
break;
case OpShiftLeftLogical:
{
auto type = get<SPIRType>(ops[0]).basetype;
BOP_CAST(<<, type);
GLSL_BOP_CAST(<<, type);
break;
}
case OpBitwiseOr:
{
auto type = get<SPIRType>(ops[0]).basetype;
BOP_CAST(|, type);
GLSL_BOP_CAST(|, type);
break;
}
case OpBitwiseXor:
{
auto type = get<SPIRType>(ops[0]).basetype;
BOP_CAST(^, type);
GLSL_BOP_CAST(^, type);
break;
}
case OpBitwiseAnd:
{
auto type = get<SPIRType>(ops[0]).basetype;
BOP_CAST(&, type);
GLSL_BOP_CAST(&, type);
break;
}
case OpNot:
UOP(~);
GLSL_UOP(~);
break;
case OpUMod:
BOP_CAST(%, SPIRType::UInt);
GLSL_BOP_CAST(%, SPIRType::UInt);
break;
case OpSMod:
BOP_CAST(%, SPIRType::Int);
GLSL_BOP_CAST(%, SPIRType::Int);
break;
case OpFMod:
BFOP(mod);
GLSL_BFOP(mod);
break;
case OpFRem:
@ -6808,11 +6808,11 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
// Relational
case OpAny:
UFOP(any);
GLSL_UFOP(any);
break;
case OpAll:
UFOP(all);
GLSL_UFOP(all);
break;
case OpSelect:
@ -6829,7 +6829,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
if (type.vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "||");
else
BOP(||);
GLSL_BOP(||);
break;
}
@ -6843,7 +6843,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
if (type.vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "&&");
else
BOP(&&);
GLSL_BOP(&&);
break;
}
@ -6851,18 +6851,18 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
auto &type = get<SPIRType>(ops[0]);
if (type.vecsize > 1)
UFOP(not);
GLSL_UFOP(not);
else
UOP(!);
GLSL_UOP(!);
break;
}
case OpIEqual:
{
if (expression_type(ops[2]).vecsize > 1)
BFOP_CAST(equal, SPIRType::Int);
GLSL_BFOP_CAST(equal, SPIRType::Int);
else
BOP_CAST(==, SPIRType::Int);
GLSL_BOP_CAST(==, SPIRType::Int);
break;
}
@ -6870,18 +6870,18 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
case OpFOrdEqual:
{
if (expression_type(ops[2]).vecsize > 1)
BFOP(equal);
GLSL_BFOP(equal);
else
BOP(==);
GLSL_BOP(==);
break;
}
case OpINotEqual:
{
if (expression_type(ops[2]).vecsize > 1)
BFOP_CAST(notEqual, SPIRType::Int);
GLSL_BFOP_CAST(notEqual, SPIRType::Int);
else
BOP_CAST(!=, SPIRType::Int);
GLSL_BOP_CAST(!=, SPIRType::Int);
break;
}
@ -6889,9 +6889,9 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
case OpFOrdNotEqual:
{
if (expression_type(ops[2]).vecsize > 1)
BFOP(notEqual);
GLSL_BFOP(notEqual);
else
BOP(!=);
GLSL_BOP(!=);
break;
}
@ -6900,18 +6900,18 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
auto type = opcode == OpUGreaterThan ? SPIRType::UInt : SPIRType::Int;
if (expression_type(ops[2]).vecsize > 1)
BFOP_CAST(greaterThan, type);
GLSL_BFOP_CAST(greaterThan, type);
else
BOP_CAST(>, type);
GLSL_BOP_CAST(>, type);
break;
}
case OpFOrdGreaterThan:
{
if (expression_type(ops[2]).vecsize > 1)
BFOP(greaterThan);
GLSL_BFOP(greaterThan);
else
BOP(>);
GLSL_BOP(>);
break;
}
@ -6920,18 +6920,18 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
auto type = opcode == OpUGreaterThanEqual ? SPIRType::UInt : SPIRType::Int;
if (expression_type(ops[2]).vecsize > 1)
BFOP_CAST(greaterThanEqual, type);
GLSL_BFOP_CAST(greaterThanEqual, type);
else
BOP_CAST(>=, type);
GLSL_BOP_CAST(>=, type);
break;
}
case OpFOrdGreaterThanEqual:
{
if (expression_type(ops[2]).vecsize > 1)
BFOP(greaterThanEqual);
GLSL_BFOP(greaterThanEqual);
else
BOP(>=);
GLSL_BOP(>=);
break;
}
@ -6940,18 +6940,18 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
auto type = opcode == OpULessThan ? SPIRType::UInt : SPIRType::Int;
if (expression_type(ops[2]).vecsize > 1)
BFOP_CAST(lessThan, type);
GLSL_BFOP_CAST(lessThan, type);
else
BOP_CAST(<, type);
GLSL_BOP_CAST(<, type);
break;
}
case OpFOrdLessThan:
{
if (expression_type(ops[2]).vecsize > 1)
BFOP(lessThan);
GLSL_BFOP(lessThan);
else
BOP(<);
GLSL_BOP(<);
break;
}
@ -6960,18 +6960,18 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
auto type = opcode == OpULessThanEqual ? SPIRType::UInt : SPIRType::Int;
if (expression_type(ops[2]).vecsize > 1)
BFOP_CAST(lessThanEqual, type);
GLSL_BFOP_CAST(lessThanEqual, type);
else
BOP_CAST(<=, type);
GLSL_BOP_CAST(<=, type);
break;
}
case OpFOrdLessThanEqual:
{
if (expression_type(ops[2]).vecsize > 1)
BFOP(lessThanEqual);
GLSL_BFOP(lessThanEqual);
else
BOP(<=);
GLSL_BOP(<=);
break;
}
@ -7045,21 +7045,21 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
// Derivatives
case OpDPdx:
UFOP(dFdx);
GLSL_UFOP(dFdx);
if (is_legacy_es())
require_extension_internal("GL_OES_standard_derivatives");
register_control_dependent_expression(ops[1]);
break;
case OpDPdy:
UFOP(dFdy);
GLSL_UFOP(dFdy);
if (is_legacy_es())
require_extension_internal("GL_OES_standard_derivatives");
register_control_dependent_expression(ops[1]);
break;
case OpDPdxFine:
UFOP(dFdxFine);
GLSL_UFOP(dFdxFine);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
@ -7070,7 +7070,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
break;
case OpDPdyFine:
UFOP(dFdyFine);
GLSL_UFOP(dFdyFine);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
@ -7085,14 +7085,14 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
}
UFOP(dFdxCoarse);
GLSL_UFOP(dFdxCoarse);
if (options.version < 450)
require_extension_internal("GL_ARB_derivative_control");
register_control_dependent_expression(ops[1]);
break;
case OpDPdyCoarse:
UFOP(dFdyCoarse);
GLSL_UFOP(dFdyCoarse);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
@ -7103,14 +7103,14 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
break;
case OpFwidth:
UFOP(fwidth);
GLSL_UFOP(fwidth);
if (is_legacy_es())
require_extension_internal("GL_OES_standard_derivatives");
register_control_dependent_expression(ops[1]);
break;
case OpFwidthCoarse:
UFOP(fwidthCoarse);
GLSL_UFOP(fwidthCoarse);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
@ -7121,7 +7121,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
break;
case OpFwidthFine:
UFOP(fwidthFine);
GLSL_UFOP(fwidthFine);
if (options.es)
{
SPIRV_CROSS_THROW("GL_ARB_derivative_control is unavailable in OpenGL ES.");
@ -7134,21 +7134,21 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
// Bitfield
case OpBitFieldInsert:
// TODO: The signedness of inputs is strict in GLSL, but not in SPIR-V, bitcast if necessary.
QFOP(bitfieldInsert);
GLSL_QFOP(bitfieldInsert);
break;
case OpBitFieldSExtract:
case OpBitFieldUExtract:
// TODO: The signedness of inputs is strict in GLSL, but not in SPIR-V, bitcast if necessary.
TFOP(bitfieldExtract);
GLSL_TFOP(bitfieldExtract);
break;
case OpBitReverse:
UFOP(bitfieldReverse);
GLSL_UFOP(bitfieldReverse);
break;
case OpBitCount:
UFOP(bitCount);
GLSL_UFOP(bitCount);
break;
// Atomics
@ -7185,7 +7185,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
flush_all_atomic_capable_variables();
// FIXME: Image?
// OpAtomicLoad seems to only be relevant for atomic counters.
UFOP(atomicCounter);
GLSL_UFOP(atomicCounter);
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
@ -7195,7 +7195,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
case OpAtomicIIncrement:
forced_temporaries.insert(ops[1]);
// FIXME: Image?
UFOP(atomicCounterIncrement);
GLSL_UFOP(atomicCounterIncrement);
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
@ -7203,7 +7203,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
case OpAtomicIDecrement:
forced_temporaries.insert(ops[1]);
// FIXME: Image?
UFOP(atomicCounterDecrement);
GLSL_UFOP(atomicCounterDecrement);
flush_all_atomic_capable_variables();
register_read(ops[1], ops[2], should_forward(ops[2]));
break;
@ -7334,12 +7334,12 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
{
require_extension_internal("GL_ARB_texture_query_lod");
// For some reason, the ARB spec is all-caps.
BFOP(textureQueryLOD);
GLSL_BFOP(textureQueryLOD);
}
else if (options.es)
SPIRV_CROSS_THROW("textureQueryLod not supported in ES profile.");
else
BFOP(textureQueryLod);
GLSL_BFOP(textureQueryLod);
register_control_dependent_expression(ops[1]);
break;
}

View File

@ -3766,7 +3766,7 @@ void CompilerHLSL::emit_subgroup_op(const Instruction &i)
}
// clang-format off
#define GROUP_OP(op, hlsl_op, supports_scan) \
#define HLSL_GROUP_OP(op, hlsl_op, supports_scan) \
case OpGroupNonUniform##op: \
{ \
auto operation = static_cast<GroupOperation>(ops[3]); \
@ -3786,20 +3786,20 @@ case OpGroupNonUniform##op: \
SPIRV_CROSS_THROW("Invalid group operation."); \
break; \
}
GROUP_OP(FAdd, Sum, true)
GROUP_OP(FMul, Product, true)
GROUP_OP(FMin, Min, false)
GROUP_OP(FMax, Max, false)
GROUP_OP(IAdd, Sum, true)
GROUP_OP(IMul, Product, true)
GROUP_OP(SMin, Min, false)
GROUP_OP(SMax, Max, false)
GROUP_OP(UMin, Min, false)
GROUP_OP(UMax, Max, false)
GROUP_OP(BitwiseAnd, BitAnd, false)
GROUP_OP(BitwiseOr, BitOr, false)
GROUP_OP(BitwiseXor, BitXor, false)
#undef GROUP_OP
HLSL_GROUP_OP(FAdd, Sum, true)
HLSL_GROUP_OP(FMul, Product, true)
HLSL_GROUP_OP(FMin, Min, false)
HLSL_GROUP_OP(FMax, Max, false)
HLSL_GROUP_OP(IAdd, Sum, true)
HLSL_GROUP_OP(IMul, Product, true)
HLSL_GROUP_OP(SMin, Min, false)
HLSL_GROUP_OP(SMax, Max, false)
HLSL_GROUP_OP(UMin, Min, false)
HLSL_GROUP_OP(UMax, Max, false)
HLSL_GROUP_OP(BitwiseAnd, BitAnd, false)
HLSL_GROUP_OP(BitwiseOr, BitOr, false)
HLSL_GROUP_OP(BitwiseXor, BitXor, false)
#undef HLSL_GROUP_OP
// clang-format on
case OpGroupNonUniformQuadSwap:
@ -3834,17 +3834,17 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
auto ops = stream(instruction);
auto opcode = static_cast<Op>(instruction.op);
#define BOP(op) emit_binary_op(ops[0], ops[1], ops[2], ops[3], #op)
#define BOP_CAST(op, type) \
#define HLSL_BOP(op) emit_binary_op(ops[0], ops[1], ops[2], ops[3], #op)
#define HLSL_BOP_CAST(op, type) \
emit_binary_op_cast(ops[0], ops[1], ops[2], ops[3], #op, type, hlsl_opcode_is_sign_invariant(opcode))
#define UOP(op) emit_unary_op(ops[0], ops[1], ops[2], #op)
#define QFOP(op) emit_quaternary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], ops[5], #op)
#define TFOP(op) emit_trinary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], #op)
#define BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define BFOP_CAST(op, type) \
#define HLSL_UOP(op) emit_unary_op(ops[0], ops[1], ops[2], #op)
#define HLSL_QFOP(op) emit_quaternary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], ops[5], #op)
#define HLSL_TFOP(op) emit_trinary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], #op)
#define HLSL_BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define HLSL_BFOP_CAST(op, type) \
emit_binary_func_op_cast(ops[0], ops[1], ops[2], ops[3], #op, type, hlsl_opcode_is_sign_invariant(opcode))
#define BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define UFOP(op) emit_unary_func_op(ops[0], ops[1], ops[2], #op)
#define HLSL_BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define HLSL_UFOP(op) emit_unary_func_op(ops[0], ops[1], ops[2], #op)
switch (opcode)
{
@ -3913,39 +3913,39 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
}
case OpDPdx:
UFOP(ddx);
HLSL_UFOP(ddx);
register_control_dependent_expression(ops[1]);
break;
case OpDPdy:
UFOP(ddy);
HLSL_UFOP(ddy);
register_control_dependent_expression(ops[1]);
break;
case OpDPdxFine:
UFOP(ddx_fine);
HLSL_UFOP(ddx_fine);
register_control_dependent_expression(ops[1]);
break;
case OpDPdyFine:
UFOP(ddy_fine);
HLSL_UFOP(ddy_fine);
register_control_dependent_expression(ops[1]);
break;
case OpDPdxCoarse:
UFOP(ddx_coarse);
HLSL_UFOP(ddx_coarse);
register_control_dependent_expression(ops[1]);
break;
case OpDPdyCoarse:
UFOP(ddy_coarse);
HLSL_UFOP(ddy_coarse);
register_control_dependent_expression(ops[1]);
break;
case OpFwidth:
case OpFwidthCoarse:
case OpFwidthFine:
UFOP(fwidth);
HLSL_UFOP(fwidth);
register_control_dependent_expression(ops[1]);
break;
@ -3958,7 +3958,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (type.vecsize > 1)
emit_unrolled_unary_op(result_type, id, ops[2], "!");
else
UOP(!);
HLSL_UOP(!);
break;
}
@ -3970,7 +3970,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "==");
else
BOP_CAST(==, SPIRType::Int);
HLSL_BOP_CAST(==, SPIRType::Int);
break;
}
@ -3983,7 +3983,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "==");
else
BOP(==);
HLSL_BOP(==);
break;
}
@ -3995,7 +3995,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "!=");
else
BOP_CAST(!=, SPIRType::Int);
HLSL_BOP_CAST(!=, SPIRType::Int);
break;
}
@ -4008,7 +4008,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "!=");
else
BOP(!=);
HLSL_BOP(!=);
break;
}
@ -4022,7 +4022,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], ">");
else
BOP_CAST(>, type);
HLSL_BOP_CAST(>, type);
break;
}
@ -4034,7 +4034,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], ">");
else
BOP(>);
HLSL_BOP(>);
break;
}
@ -4048,7 +4048,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], ">=");
else
BOP_CAST(>=, type);
HLSL_BOP_CAST(>=, type);
break;
}
@ -4060,7 +4060,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], ">=");
else
BOP(>=);
HLSL_BOP(>=);
break;
}
@ -4074,7 +4074,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "<");
else
BOP_CAST(<, type);
HLSL_BOP_CAST(<, type);
break;
}
@ -4086,7 +4086,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "<");
else
BOP(<);
HLSL_BOP(<);
break;
}
@ -4100,7 +4100,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "<=");
else
BOP_CAST(<=, type);
HLSL_BOP_CAST(<=, type);
break;
}
@ -4112,7 +4112,7 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
if (expression_type(ops[2]).vecsize > 1)
emit_unrolled_binary_op(result_type, id, ops[2], ops[3], "<=");
else
BOP(<=);
HLSL_BOP(<=);
break;
}
@ -4417,18 +4417,18 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction)
}
if (opcode == OpBitFieldSExtract)
TFOP(SPIRV_Cross_bitfieldSExtract);
HLSL_TFOP(SPIRV_Cross_bitfieldSExtract);
else
TFOP(SPIRV_Cross_bitfieldUExtract);
HLSL_TFOP(SPIRV_Cross_bitfieldUExtract);
break;
}
case OpBitCount:
UFOP(countbits);
HLSL_UFOP(countbits);
break;
case OpBitReverse:
UFOP(reversebits);
HLSL_UFOP(reversebits);
break;
default:

View File

@ -1543,16 +1543,16 @@ void CompilerMSL::emit_specialization_constants()
void CompilerMSL::emit_instruction(const Instruction &instruction)
{
#define BOP(op) emit_binary_op(ops[0], ops[1], ops[2], ops[3], #op)
#define BOP_CAST(op, type) \
#define MSL_BOP(op) emit_binary_op(ops[0], ops[1], ops[2], ops[3], #op)
#define MSL_BOP_CAST(op, type) \
emit_binary_op_cast(ops[0], ops[1], ops[2], ops[3], #op, type, opcode_is_sign_invariant(opcode))
#define UOP(op) emit_unary_op(ops[0], ops[1], ops[2], #op)
#define QFOP(op) emit_quaternary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], ops[5], #op)
#define TFOP(op) emit_trinary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], #op)
#define BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define BFOP_CAST(op, type) \
#define MSL_UOP(op) emit_unary_op(ops[0], ops[1], ops[2], #op)
#define MSL_QFOP(op) emit_quaternary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], ops[5], #op)
#define MSL_TFOP(op) emit_trinary_func_op(ops[0], ops[1], ops[2], ops[3], ops[4], #op)
#define MSL_BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
#define MSL_BFOP_CAST(op, type) \
emit_binary_func_op_cast(ops[0], ops[1], ops[2], ops[3], #op, type, opcode_is_sign_invariant(opcode))
#define UFOP(op) emit_unary_func_op(ops[0], ops[1], ops[2], #op)
#define MSL_UFOP(op) emit_unary_func_op(ops[0], ops[1], ops[2], #op)
auto ops = stream(instruction);
auto opcode = static_cast<Op>(instruction.op);
@ -1564,81 +1564,81 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
case OpIEqual:
case OpLogicalEqual:
case OpFOrdEqual:
BOP(==);
MSL_BOP(==);
break;
case OpINotEqual:
case OpLogicalNotEqual:
case OpFOrdNotEqual:
BOP(!=);
MSL_BOP(!=);
break;
case OpUGreaterThan:
case OpSGreaterThan:
case OpFOrdGreaterThan:
BOP(>);
MSL_BOP(>);
break;
case OpUGreaterThanEqual:
case OpSGreaterThanEqual:
case OpFOrdGreaterThanEqual:
BOP(>=);
MSL_BOP(>=);
break;
case OpULessThan:
case OpSLessThan:
case OpFOrdLessThan:
BOP(<);
MSL_BOP(<);
break;
case OpULessThanEqual:
case OpSLessThanEqual:
case OpFOrdLessThanEqual:
BOP(<=);
MSL_BOP(<=);
break;
// Derivatives
case OpDPdx:
case OpDPdxFine:
case OpDPdxCoarse:
UFOP(dfdx);
MSL_UFOP(dfdx);
register_control_dependent_expression(ops[1]);
break;
case OpDPdy:
case OpDPdyFine:
case OpDPdyCoarse:
UFOP(dfdy);
MSL_UFOP(dfdy);
register_control_dependent_expression(ops[1]);
break;
case OpFwidth:
case OpFwidthCoarse:
case OpFwidthFine:
UFOP(fwidth);
MSL_UFOP(fwidth);
register_control_dependent_expression(ops[1]);
break;
// Bitfield
case OpBitFieldInsert:
QFOP(insert_bits);
MSL_QFOP(insert_bits);
break;
case OpBitFieldSExtract:
case OpBitFieldUExtract:
TFOP(extract_bits);
MSL_TFOP(extract_bits);
break;
case OpBitReverse:
UFOP(reverse_bits);
MSL_UFOP(reverse_bits);
break;
case OpBitCount:
UFOP(popcount);
MSL_UFOP(popcount);
break;
case OpFRem:
BFOP(fmod);
MSL_BFOP(fmod);
break;
// Atomics
@ -1691,7 +1691,7 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
break;
}
#define AFMOImpl(op, valsrc) \
#define MSL_AFMO_IMPL(op, valsrc) \
do \
{ \
uint32_t result_type = ops[0]; \
@ -1702,45 +1702,45 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
emit_atomic_func_op(result_type, id, "atomic_fetch_" #op "_explicit", mem_sem, mem_sem, false, ptr, val); \
} while (false)
#define AFMO(op) AFMOImpl(op, ops[5])
#define AFMIO(op) AFMOImpl(op, 1)
#define MSL_AFMO(op) MSL_AFMO_IMPL(op, ops[5])
#define MSL_AFMIO(op) MSL_AFMO_IMPL(op, 1)
case OpAtomicIIncrement:
AFMIO(add);
MSL_AFMIO(add);
break;
case OpAtomicIDecrement:
AFMIO(sub);
MSL_AFMIO(sub);
break;
case OpAtomicIAdd:
AFMO(add);
MSL_AFMO(add);
break;
case OpAtomicISub:
AFMO(sub);
MSL_AFMO(sub);
break;
case OpAtomicSMin:
case OpAtomicUMin:
AFMO(min);
MSL_AFMO(min);
break;
case OpAtomicSMax:
case OpAtomicUMax:
AFMO(max);
MSL_AFMO(max);
break;
case OpAtomicAnd:
AFMO(and);
MSL_AFMO(and);
break;
case OpAtomicOr:
AFMO(or);
MSL_AFMO(or);
break;
case OpAtomicXor:
AFMO(xor);
MSL_AFMO(xor);
break;
// Images
@ -1864,7 +1864,7 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
break;
}
#define ImgQry(qrytype) \
#define MSL_ImgQry(qrytype) \
do \
{ \
uint32_t rslt_type_id = ops[0]; \
@ -1877,11 +1877,11 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
} while (false)
case OpImageQueryLevels:
ImgQry(mip_levels);
MSL_ImgQry(mip_levels);
break;
case OpImageQuerySamples:
ImgQry(samples);
MSL_ImgQry(samples);
break;
// Casting
@ -1963,7 +1963,7 @@ void CompilerMSL::emit_instruction(const Instruction &instruction)
e->need_transpose = true;
}
else
BOP(*);
MSL_BOP(*);
break;
}