Spec Constant Operations
authorqining <qining@google.com>
Mon, 21 Mar 2016 13:51:37 +0000 (09:51 -0400)
committerqining <qining@google.com>
Wed, 30 Mar 2016 20:18:26 +0000 (16:18 -0400)
commit135452061aca1346936aa7a28ebb138341052229
tree9ee0967d14e8dc67acba62a2ac9d7d1579c486db
parentc3869fee412a90c4eadea0bf936ab2530d2dff51
Spec Constant Operations

Approach:
Add a flag in `Builder` to indicate 'spec constant mode' and 'normal
mode'. When the builder is in 'normal mode', nothing changed. When the
builder is in 'spec constant mode', binary, unary and other instruction
creation rountines will be redirected to `createSpecConstantOp()` to
create instrution at module level with `OpSpecConstantOp <original
opcode> <operands>`.

'spec constant mode' should be enabled if and only if we are creating
spec constants. So a flager setter/recover guard is added when handling
binary/unary nodes in `createSpvConstantsFromConstSubTree()`.

Note when handling spec constants which are represented as ConstantUnion
Node, we should not use `OpSpecConstantOp` to initialize the composite
constant, so builder is set to 'normal mode'.

Tests:
Tests are added in Test/spv.specConstantOperations.vert, including:

1) Arithmetic, shift opeations for both scalar and composite type spec constants.
2) Size conversion from/to float and double for both scalar and vector.
3) Bitwise and/or/xor for both scalar and vector.
4) Unary negate/not for both scalar and vector.
5) Vector swizzles.
6) Comparisons for scalars.
7) == and != for composite type spec constants

Issues:
1) To implement == and != for composite type spec constants, the Spec needs
to allow OpAll, OpAny, OpFOrdEqual, OpFUnordEqual, OpOrdNotEqual,
OpFUnordNotEqual. Currently none of them are allowed in the Spec.
SPIRV/GlslangToSpv.cpp
SPIRV/SpvBuilder.cpp
SPIRV/SpvBuilder.h
Test/baseResults/spv.specConstantOperations.vert.out [new file with mode: 0644]
Test/spv.specConstantOperations.vert [new file with mode: 0644]
Test/test-spirv-list