Skip to content
Commits on Source (82)
  • GregF's avatar
    ADCE: Fix combinator initialization · 860b2ee5
    GregF authored
    The combinator initialization was only looking at the capabilities
    in the shader and not the inferred capabilities. Geometry and tessellation
    shaders were not setting the Shader capability which is inferred. So the
    combinator set was not initialized correctly causing problems for ADCE.
    860b2ee5
  • Alan Baker's avatar
    Registering a type now rebuilds it out of memory owned by the manager. · 87102277
    Alan Baker authored
    * Added TypeManager::RebuildType
     * rebuilds the type and its constituent types in terms of memory owned
     by the manager.
     * Used by TypeManager::RegisterType to properly allocate memory
    * Adding an unit test to expose the issue
    * Added some tests to provide coverage of RebuildType
    * Added an accessor to the target pointer for a forward pointer
    87102277
  • David Neto's avatar
    Update CHANGES · c452bfd0
    David Neto authored
    c452bfd0
  • David Neto's avatar
    Fix test inclusion when Effcee is absent · e7fafdaa
    David Neto authored
    e7fafdaa
  • David Neto's avatar
    Enable Visual Studio 2013 again · b1c9c4e8
    David Neto authored
    Disable use of Effcee and RE2 with MSVC compilers older than Visual
    Studio 2015 since RE2 doesn't support them.
    b1c9c4e8
  • Józef Kucia's avatar
    Build SPIRV-Tools as shared library · 30138975
    Józef Kucia authored
    Add pkg-config file for shared libraries
    
    Properly build SPIRV-Tools DLL
    
    Test C interface with shared library
    
    Set PATH to shared library file for c_interface_shared test
    
    Otherwise, the test won't find SPIRV-Tools-shared.dll.
    
    Do not use private functions when testing with shared library
    
    Make all symbols hidden by default for shared library target
    30138975
  • Andrey Tuganov's avatar
  • Andrey Tuganov's avatar
    Disable check which fails Vulkan CTS · a61e4c13
    Andrey Tuganov authored
    a61e4c13
  • Steven Perron's avatar
    Make use of the instruction folder. · 06cdb969
    Steven Perron authored
    Implementation of the simplification pass.
    
    - Create pass that calls the instruction folder on each instruction and
      propagate instructions that fold to a copy.  This will do copy
      propagation as well.
    
    - Did not use the propagator engine because I want to modify the instruction
      as we go along.
    
    - Change folding to not allocate new instructions, but make changes in
      place.  This change had a big impact on compile time.
    
    - Add simplification pass to the legalization passes in place of
      insert-extract elimination.
    
    - Added test cases for new folding rules.
    
    - Added tests for the simplification pass
    
    - Added a method to the CFG to apply a function to the basic blocks in
      reverse post order.
    
    Contributes to #1164.
    06cdb969
  • GregF's avatar
    ca4457b4
  • Alexander Johnston's avatar
    84ccd0b9
  • Steven Perron's avatar
    1a849ffb
  • Józef Kucia's avatar
    4e4a254b
  • David Neto's avatar
    Fix generation of Vim syntax file · 88685915
    David Neto authored
    88685915
  • Steven Perron's avatar
    Add folding of OpCompositeExtract and OpConstantComposite constant instructions. · 1d7b1423
    Steven Perron authored
    Create files for constant folding rules.
    
    Add the rules for OpConstantComposite and OpCompositeExtract.
    1d7b1423
  • Arseny Kapoulkine's avatar
    Fix spirv.h include to rely on include paths · 70bf3514
    Arseny Kapoulkine authored
    This is important when SPIRV-Headers are not checked out to external/
    folder and mirrors other places in the code where spirv.h is included.
    70bf3514
  • Steven Perron's avatar
    Avoid using the def-use manager during inlining. · 06b437de
    Steven Perron authored
    There seems to only be a single location where the def-use manager is
    used.  It is to get information about a type.  We can do that with the
    type manager instead.
    
    Fixes #1285
    06b437de
  • Diego Novillo's avatar
    Cleanup. Use proper #include guard. NFC. · 08699920
    Diego Novillo authored
    08699920
  • Alan Baker's avatar
    Fixes #1295. Mark undef values as varying in ccp. · 229ebc06
    Alan Baker authored
    * Undef now marked as varying in ccp
     * this prevents incorrect meet operations since phis were always not
     interesting
    * added a test to catch the bug
    229ebc06
  • Stephen McGroarty's avatar
    Initial support for loop unrolling. · dd8400e1
    Stephen McGroarty authored
    This patch adds initial support for loop unrolling in the form of a
    series of utility classes which perform the unrolling. The pass can
    be run with the command spirv-opt --loop-unroll. This will unroll
    loops within the module which have the unroll hint set. The unroller
    imposes a number of requirements on the loops it can unroll. These are
    documented in the comments for the LoopUtils::CanPerformUnroll method in
    loop_utils.h. Some of the restrictions will be lifted in future patches.
    dd8400e1
  • Steven Perron's avatar
    Fold binary floating point operators. · 6669d816
    Steven Perron authored
    Adds the floating rules for FAdd, FDiv, FMul, and FSub.
    
    Contributes to #1164.
    6669d816
  • Steven Perron's avatar
    Add id to name map · 0e9f2f94
    Steven Perron authored
    Adding a map from an id to it set of OpName and OpMemberName
    instructions.  This will be used in KillNameAndDecorates to kill the
    names for the ids that are being removed.
    
    In my test, the compile time for 50 shaders went from 1m57s to 55s.
    This was on linux using the release build.
    
    Fixes #1290.
    0e9f2f94
  • Arseny Kapoulkine's avatar
    Add folding of redundant OpSelect insns · 32a8e04c
    Arseny Kapoulkine authored
    We can fold OpSelect into one of the operands in two cases:
    
    - condition is constant
    - both results are the same
    
    Even if the original shader doesn't have either of these, if-conversion
    pass sometimes ends up generating instructions like
    
       %7127 = OpSelect %int %3220 %7058 %7058
    
    And this optimization cleans them up.
    32a8e04c
  • Lei Zhang's avatar
    Avoid using static unordered_map (#1304) · f3a10470
    Lei Zhang authored
    unordered_map is not POD. Using it as static may cause problems
    when operator new() and operator delete() is customized.
    
    Also changed some function signatures to use const char* instead
    of std::string, which will give caller the flexibility to avoid
    creating a std::string.
    f3a10470
  • David Neto's avatar
    Invoke cmake via CMAKE_COMMAND variable · d2c0fce3
    David Neto authored
    Need to do this in case cmake is not on the path.
    This should fix the Android NDK build, as in when building the NDK
    itself.
    d2c0fce3
  • Nerijus Baliūnas's avatar
    fix typo · 5d442fad
    Nerijus Baliūnas authored
    5d442fad
  • Lei Zhang's avatar
  • Steven Perron's avatar
    Get CCP to use the constant floating point rules. · 3756b387
    Steven Perron authored
    Fixes #1311
    3756b387
  • Steven Perron's avatar
    Simplify OpPhi instructions referencing unreachable continues · 50f307f8
    Steven Perron authored
    In dead branch elimination, we already recognize unreachable continue
    blocks, and update OpPhi instruction accordingly.  This change adds an
    extra check: if the head block has exactly 1 other incoming edge, then
    replace the OpPhi with the value from that edge.
    
    Fixes #1314.
    50f307f8
  • Arseny Kapoulkine's avatar
    Remove constants from constant manager in KillInst · 27d23a92
    Arseny Kapoulkine authored
    Registering a constant in constant manager establishes a relation
    between instruction that defined it and constant object. On complex
    shaders this could result in the constant definition getting removed as
    part of one of the DCE pass, and a subsequent simplification pass trying
    to use the defining instruction for the constant.
    
    To fix this, we now remove associated constant entries from constant
    manager when killing constant instructions; the constant object is still
    registered and can be remapped to a new instruction later.
    
    GetDefiningInstruction shouldn't ever return nullptr after this change
    so add an assertion to check for that.
    27d23a92
  • Arseny Kapoulkine's avatar
    Add constant folding rules for floating-point comparison · 10544136
    Arseny Kapoulkine authored
    This change handles all 6 regular comparison types in two variations,
    ordered (true if values are ordered *and* comparison is true) and
    unordered (true if values are unordered *or* comparison is true).
    
    Ordered comparison matches the default floating-point behavior on host
    but we use std::isnan to check ordering explicitly anyway.
    
    This change also slightly reworks the floating-point folding support
    code to make it possible to define a folding operation that returns
    boolean instead of floating point.
    
    These tests exhaustively test ordered/unordered comparisons for
    float/double.
    
    Since for NaN inputs the comparison result doesn't depend on the
    comparison function, we just test == and !=; NaN inputs result in true
    unordered comparisons and false ordered comparisons.
    10544136
  • Steven Perron's avatar
    Make better use of simplification pass · 04cd63e5
    Steven Perron authored
    The simplification pass works better after all of the dead branches are
    removed.  So swapping them around in the legalization passes.  Also
    adding the simplification pass to performance passes right after dead
    branch elimination.
    
    Added CCP to the legalization passes so we can propagate the constants
    into the branchs, and remove as many branches a possible.  CCP is
    designed to still get opportunities even if the branches are dead, so it
    is a good place for it.
    
    Fixes #1118
    04cd63e5
  • Andrew Woloszyn's avatar
    Removed warnings from hex_float.h · e543b195
    Andrew Woloszyn authored
    Bitcasting FloatProxy<->uint_type was hitting a warning
    with g++8.0.1. Replace bitcasts with new casting traits for FloatProxy.
    e543b195
  • Alan Baker's avatar
    Fixes #1300. Adding checks for bad CCP transitions and unsettled values · c3f34d8b
    Alan Baker authored
    * Now track propagation status and assert on bad statuses
     * Added helper methods to access instruction propagation status
    * Modified the phi meet operator to properly reflect the paper it is
    based on
    * Modified SSA edge addition so that all edge are added, but only on
    state changes
    * Fixed a bug in instruction simulation where interesting conditional
    branches would not mark the interesting edge as executed
     * Added a test to catch this bug
    * Added an ostream operator for SSAPropagator::PropStatus
    c3f34d8b
  • Steven Perron's avatar
    Fix folding insert feeding extract · 9d95a91a
    Steven Perron authored
    I mixed up two cases when folding an OpCompositeExtract that is feed by
    and OpCompositeInsert.  The specific cases are demonstracted in the new
    test.  I mixed up the conditions for the cases, and treated one like the
    other.
    
    Fixes #1323.
    9d95a91a
  • Lei Zhang's avatar
    Travis: require MacOS to build and test again · ac9ab0da
    Lei Zhang authored
    ac9ab0da
  • Diego Novillo's avatar
    Speed up Phi insertion. · 6c750501
    Diego Novillo authored
    On some shader code we have in our testsuite, Phi insertion is showing
    massive compile time slowdowns, particularly during destruction.  The
    specific shader I was looking at has about 600 variables to keep track
    of and around 3200 basic blocks.  The algorithm is currently O(var x
    blocks), which means maps with around 2M entries.  This was taking about
    8 minutes of compile time.
    
    This patch changes the tracking of stored variables to be more sparse.
    Instead of having every basic block contain all the tracked variables in
    the map, they now have only the variables actually stored in that block.
    
    This speeds up deallocation, which brings down compile time to about
    1m20s.
    
    Note that this is not the definite fix for this.  I will re-write Phi
    insertion to use a standard SSA rewriting algorithm
    (https://github.com/KhronosGroup/SPIRV-Tools/issues/893).
    
    This contributes to
    https://github.com/KhronosGroup/SPIRV-Tools/issues/1328.
    6c750501
  • Steven Perron's avatar
    Preserve analysies in the simplification pass · ec3bbf09
    Steven Perron authored
    Building the def-use chains is very expensive, so we do not want to
    invalidate them it if is not necessary.  At the moment, it seems like
    most optimizatoins are good at not invalidating the def-use chains, but
    simplification does.
    
    This PR get the simlification pass to keep the analysies valid.
    
    Contributes to #1328.
    ec3bbf09
  • Steven Perron's avatar
    Revert "Preserve analysies in the simplification pass" · fa3ac3cc
    Steven Perron authored
    This reverts commit ec3bbf09.
    fa3ac3cc
  • Arseny Kapoulkine's avatar
    Add folding for redundant add/sub/mul/div/mix operations · 309be423
    Arseny Kapoulkine authored
    This change implements instruction folding for arithmetic operations
    that are redundant, specifically:
    
      x + 0 = 0 + x = x
      x - 0 = x
      0 - x = -x
      x * 0 = 0 * x = 0
      x * 1 = 1 * x = x
      0 / x = 0
      x / 1 = x
      mix(a, b, 0) = a
      mix(a, b, 1) = b
    
    Cache ExtInst import id in feature manager
    
    This allows us to avoid string lookups during optimization; for now we
    just cache GLSL std450 import id but I can imagine caching more sets as
    they become utilized by the optimizer.
    
    Add tests for add/sub/mul/div/mix folding
    
    The tests cover scalar float/double cases, and some vector cases.
    
    Since most of the code for floating point folding is shared, the tests
    for vector folding are not as exhaustive as scalar.
    
    To test sub->negate folding I had to implement a custom fixture.
    309be423
  • Steven Perron's avatar
    Add Insert-extract elimination back into legalization passes. · c1b93663
    Steven Perron authored
    Fixes #1326.
    c1b93663
  • Steven Perron's avatar
    Reduce instruction create and deletion during inlining. · 51ecc731
    Steven Perron authored
    When inlining a function call the instructions in the same basic block
    as the call get cloned.  The clone is added to the set of new blocks
    containing the inlined code, and the original instructions are deleted.
    
    This PR will change this so that we simply move the instructions to the
    new blocks.  This saves on the creation and deletion of the
    instructions.
    
    Contributes to #1328.
    51ecc731
  • Alan Baker's avatar
    Fixes #1338. Handle OpConstantNull in branch/switch conditions · 01760d2f
    Alan Baker authored
    * No longer assume the branch/switch condition must be bool or int
    constants (respectively)
    * Added a couple unit tests for each case
    01760d2f
  • GregF's avatar
    Opt: Check for side-effects in DCEInst() · 46a9ec9d
    GregF authored
    This function now checks for side-effects before adding operand
    instructions to the dead instruction work list.
    
    Because this fix puts more pressure on IsCombinatorInstruction() to
    be correct, this commit adds all OpConstant* and OpType* instructions
    to combinator_ops_ set.
    
    Fixes #1341.
    46a9ec9d
  • Lei Zhang's avatar
    Appveyor: remove VS2015 configuration to reduce build time · 432dc404
    Lei Zhang authored
    We already have VS2013 and VS2017, which should be good guards.
    432dc404
  • Steven Perron's avatar
    Preserve analysies in the simplification pass · 3f19c203
    Steven Perron authored
    Fixes a bug at the same time.  In `UpdateDefUse`, if the definition
    already exists, we are not suppose to analyse it again.  When you do
    the entries for the definition are deleted, and we don't want that.
    The check for this was wrong.
    3f19c203
  • Steven Perron's avatar
    Clean up variables before sroa · 94af58a3
    Steven Perron authored
    In some shaders there are a lot of very large and deeply nested
    structures.  This creates a lot of work for scalar replacement.  Also,
    since commit ca4457b4 we have been very aggressive as rewriting
    variables.  This has causes a large increase in compile time in creating
    and then deleting the instructions.
    
    To help low the costs, I want to run a cleanup of some of the easy loads
    and stores to remove.  This reduces the number of symbols sroa has to
    work on.  It also reduces the amount of code the simplifier has to
    simplify because it was not generated by sroa.
    
    To confirm the improvement, I ran numbers on three different sets of
    shaders:
    
    Time to run --legalize-hlsl:
    
    Set #1: 55.89s -> 12.0s
    Set #2: 1m44s -> 1m40.5s
    Set #3: 6.8s -> 5.7s
    
    Time to run -O
    
    Set #1: 18.8s -> 10.9s
    Set #2: 5m44s -> 4m17s
    Set #3: 7.8s -> 7.8s
    
    Contributes to #1328.
    94af58a3
  • Stephen McGroarty's avatar
    Unroller support for multiple induction variables · e354984b
    Stephen McGroarty authored
    Support for multiple induction variables within a loop and support for
    loop condition operands <= and >=.
    e354984b
  • Victor Lomuller's avatar
    Add loop unswitch pass. · 3497a944
    Victor Lomuller authored
    It moves all conditional branching and switch whose conditions are loop
    invariant and uniform. Before performing the loop unswitch we check that
    the loop does not contain any instruction that would prevent it
    (barriers, group instructions etc.).
    3497a944
  • David Neto's avatar
    Update CHANGES · b08b94ec
    David Neto authored
    b08b94ec
  • Pierre Moreau's avatar
  • Pierre Moreau's avatar
  • Pierre Moreau's avatar
  • Stephen McGroarty's avatar
    Make IR builder use the type manager for constants · 20b8cdb7
    Stephen McGroarty authored
    This change makes the IR builder use the type manager to generate
    OpTypeInts when creating OpConstants. This avoids dangling references
    being stored by the created OpConstants.
    20b8cdb7
  • Alan Baker's avatar
    Merge arithmetic with non-trivial constant operands · 802cf053
    Alan Baker authored
    Adding basis of arithmetic merging
    
    * Refactored constant collection in ConstantManager
    * New rules:
     * consecutive negates
     * negate of arithmetic op with a constant
     * consecutive muls
     * reciprocal of div
    
    * Removed IRContext::CanFoldFloatingPoint
     * replaced by Instruction::IsFloatingPointFoldingAllowed
    * Fixed some bad tests
    * added some header comments
    
    Added PerformIntegerOperation
    
    * minor fixes to constants and tests
    * fixed IntMultiplyBy1 to work with 64 bit ints
    * added tests for integer mul merging
    
    Adding test for vector integer multiply merging
    
    Adding support for merging integer add and sub through negate
    
    * Added tests
    
    Adding rules to merge mult with preceding divide
    
    * Has a couple tests, but needs more
    * Added more comments
    
    Fixed bug in integer division folding
    
    * Will no longer merge through integer division if there would be a
    remainder in the division
    * Added a bunch more tests
    
    Adding rules to merge divide and multiply through divide
    
    * Improved comments
    * Added tests
    
    Adding rules to handle mul or div of a negation
    
    * Added tests
    
    Changes for review
    
    * Early exit if no constants are involved in more functions
    * fixed some comments
    * removed unused declaration
    * clarified some logic
    
    Adding new rules for add and subtract
    
    * Fold adds of adds, subtracts or negates
    * Fold subtracts of adds, subtracts or negates
    * Added tests
    802cf053
  • David Neto's avatar
    Consistently include latest spirv.h header file. · 0c134671
    David Neto authored
    Use indirection through latest_version_spirv.h
    
    Also, when generating enum tables, use the unified1 JSON grammar since
    it now has FragmentFullyCoveredEXT but the other JSON grammars don't.
    They are starting to fall behind.
    0c134671
  • Steven Perron's avatar
    Remove uses DCEInst and call ADCE · 2cb589cc
    Steven Perron authored
    The algorithm used in DCEInst to remove dead code is very slow.  It is
    fine if you only want to remove a small number of instructions, but, if
    you need to remove a large number of instructions, then the algorithm in
    ADCE is much faster.
    
    This PR removes the calls to DCEInst in the load-store removal passes
    and adds a pass of ADCE afterwards.
    
    A number of different iterations of the order of optimization, and I
    believe this is the best I could find.
    
    The results I have on 3 sets of shaders are:
    
    Legalization:
    
    Set 1: 5.39 -> 5.01
    Set 2: 13.98 -> 8.38
    Set 3: 98.00 -> 96.26
    
    Performance passes:
    
    Set 1: 6.90 -> 5.23
    Set 2: 10.11 -> 6.62
    Set 3: 253.69 -> 253.74
    
    Size reduction passes:
    
    Set 1: 7.16 -> 7.25
    Set 2: 17.17 -> 16.81
    Set 3: 112.06 -> 107.71
    
    Note that the third set's compile time is large because of the large
    number of basic blocks, not so much because of the number of
    instructions.  That is why we don't see much gain there.
    2cb589cc
  • Victor Lomuller's avatar
    90e1637c
  • Steven Perron's avatar
    Add more folding rules for vector shuffle. · 588f4fcc
    Steven Perron authored
    Adds rule to fold OpVectorShuffle with constant inputs.
    
    Adds rules to fold OpCompositeExtrac being fed by an OpVectorShuffle.
    588f4fcc
  • Alan Baker's avatar
    Fixes #1354. Do not merge integer division. · 9457cabb
    Alan Baker authored
    * Removes merging of div with a div or mul for integers
    * Updated tests
    9457cabb
  • GregF's avatar
    Opt: Add constant folding for FToI and IToF · bdaf8d56
    GregF authored
    bdaf8d56
  • Alan Baker's avatar
    Fixes #1357. Support null constants better in folding · ce5941a6
    Alan Baker authored
    * getFloatConstantKind() now handles OpConstantNull
    * PerformOperation() now handles OpConstantNull for vectors
    * Fixed some instances where we would attempt to merge a division by 0
    * added tests
    ce5941a6
  • Arseny Kapoulkine's avatar
    Vulkan BuiltIn variables can't have Location/Component decorations · 8b27ba83
    Arseny Kapoulkine authored
    As per Vulkan spec, BuiltIn variables can't have Location or Component
    decorations. On some drivers, these can lead to driver crashing when
    compiling the shader pipeline; for example, NVidia/AMD desktop drivers:
    https://github.com/KhronosGroup/glslang/issues/1182.
    
    This change adds validation and tests to catch this.
    8b27ba83
  • Alan Baker's avatar
    Fixes #1361. Mark all non-constant global values as varying in CCP · 82462576
    Alan Baker authored
    * Also mark function parameters as varying
    * Conservatively mark assignment instructions as varying if any input is
    varying after attempting to fold
    * Added a test to catch this case
    82462576
  • David Neto's avatar
    Update CHANGES · a7cec784
    David Neto authored
    a7cec784
  • Alan Baker's avatar
    Handles more cases of redundant selects · 52bceb35
    Alan Baker authored
    * Handles OpConstantNull and vector types
     * vector selects (except against a null) are converted to vector
     shuffles
    * Added tests
    52bceb35
  • David Neto's avatar
    Finalize v2018.1 · 6432a129
    David Neto authored
    6432a129
  • David Neto's avatar
    Start v2018.2 development · fe219216
    David Neto authored
    fe219216
  • David Neto's avatar
    Android.mk: Generate enum mappings from unified1 grammar · a942ff40
    David Neto authored
    Some tokens are only showing up in the unified1 grammar.
    So enum string mappings have to be generated from that grammar, not
    the grammar from the (deprecated) include/spirv/1.2 grammar.
    
    Example: capabilities FragmentFullyCovered, Float16ImageAMD
    a942ff40
  • Pierre Moreau's avatar
    6cd6e5eb
  • Steven Perron's avatar
    Avoid generating duplicate names when merging types · 9ba50e34
    Steven Perron authored
    The merging types we do not remove other information related to the
    types.  We simply leave it duplicated, and hope it is removed later.
    This is what happens with decorations.  They are removed in the next
    phase of remove duplicates.  However, for OpNames that is not the case.
    We end up with two different names for the same id, which does not make
    sense.
    
    The solution is to remove the names and decorations for the type being
    removed instead of rewriting them to refer to the other type.
    
    Note that it is possible that if the first type does not have a name,
    then the types will end up with no name.  That is fine because the names
    should not have any semantic significance anyway.
    
    The was identified in issue #1372, but this does not fix that issue.
    9ba50e34
  • David Neto's avatar
    Support SPV_GOOGLE_decorate_string and SPV_GOOGLE_hlsl_functionality1 · 5f69f751
    David Neto authored
    This commit add assembling, disassembling, and basic validation for two
    Google extensions to better support HLSL translation.
    5f69f751
  • Alan Baker's avatar
    Fixes #1376. Don't handle half folding gracefully. · 5f50e620
    Alan Baker authored
    * Added early returns to folding rules to prevent half attempts
    * Added some tests
    5f50e620
  • David Neto's avatar
    Support SPIR-V 1.3 and Vulkan 1.1 · 00fa3931
    David Neto authored
    The default target is SPIR-V 1.3.
    
    For example, spirv-as will generate a SPIR-V 1.3 binary by default.
    Use command line option "--target-env spv1.0" if you want to make a SPIR-V
    1.0 binary or validate against SPIR-V 1.0 rules.
    
    Example:
            # Generate a SPIR-V 1.0 binary instead of SPIR-V 1.3
    	spirv-as --target-env spv1.0 a.spvasm -o a.spv
    	spirv-as --target-env vulkan1.0 a.spvasm -o a.spv
    
            # Validate as SPIR-V 1.0.
    	spirv-val --target-env spv1.0 a.spv
            # Validate as Vulkan 1.0
    	spirv-val --target-env vulkan1.0 a.spv
    00fa3931
  • David Neto's avatar
    Update README for SPIR-V 1.3 · 01f32ee0
    David Neto authored
    01f32ee0
  • Andrey Tuganov's avatar
    AMD_gpu_shader_half_float enables float16 · 03b8a3fe
    Andrey Tuganov authored
    Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1375
    
    Hardcoded float16 feature enabling if extension
    SPV_AMD_gpu_shader_half_float is present.
    03b8a3fe
  • Alan Baker's avatar
    Fixes #1385. Grab correct input to calculate indices. · bc9cfee6
    Alan Baker authored
    * Added tests to catch the bug
    bc9cfee6
  • David Neto's avatar
    Update CHANGES · a0da44ef
    David Neto authored
    a0da44ef
  • David Neto's avatar
    Finalize v2018.2 · 8d8a7127
    David Neto authored
    8d8a7127
  • Timo Aaltonen's avatar
    c6119617
  • Timo Aaltonen's avatar
    bump the version · 47d2836d
    Timo Aaltonen authored
    47d2836d
  • Timo Aaltonen's avatar
    watch: fixed · 873a22f3
    Timo Aaltonen authored
    873a22f3
......@@ -8,7 +8,7 @@ version: "{build}"
# Put it first so we get its feedback first.
os:
- Visual Studio 2017
- Visual Studio 2015
- Visual Studio 2013
platform:
- x64
......@@ -33,7 +33,7 @@ clone_depth: 1
matrix:
fast_finish: true # Show final status immediately if a test fails.
exclude:
- os: Visual Studio 2015
- os: Visual Studio 2013
configuration: Debug
# scripts that run after cloning repository
......@@ -50,7 +50,7 @@ before_build:
- git clone --depth=1 https://github.com/google/effcee.git external/effcee
- git clone --depth=1 https://github.com/google/re2.git external/re2
# Set path and environment variables for the current Visual Studio version
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64)
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" (call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86_amd64)
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64)
build:
......@@ -59,7 +59,7 @@ build:
build_script:
- mkdir build && cd build
- cmake -GNinja -DSPIRV_BUILD_COMPRESSION=ON -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX=install ..
- cmake -GNinja -DSPIRV_BUILD_COMPRESSION=ON -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DCMAKE_INSTALL_PREFIX=install -DRE2_BUILD_TESTING=OFF ..
- ninja install
test_script:
......
......@@ -24,8 +24,6 @@ compiler:
- gcc
matrix:
allow_failures:
- os: osx
fast_finish: true
include:
# Additional build using Android NDK with android-cmake
......
......@@ -63,9 +63,10 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/cfg.cpp \
source/opt/cfg_cleanup_pass.cpp \
source/opt/ccp_pass.cpp \
source/opt/common_uniform_elim_pass.cpp \
source/opt/compact_ids_pass.cpp \
source/opt/composite.cpp \
source/opt/common_uniform_elim_pass.cpp \
source/opt/const_folding_rules.cpp \
source/opt/constants.cpp \
source/opt/dead_branch_elim_pass.cpp \
source/opt/dead_insert_elim_pass.cpp \
......@@ -92,12 +93,16 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/instruction_list.cpp \
source/opt/ir_context.cpp \
source/opt/ir_loader.cpp \
source/opt/licm_pass.cpp \
source/opt/local_access_chain_convert_pass.cpp \
source/opt/local_redundancy_elimination.cpp \
source/opt/local_single_block_elim_pass.cpp \
source/opt/local_single_store_elim_pass.cpp \
source/opt/local_ssa_elim_pass.cpp \
source/opt/loop_descriptor.cpp \
source/opt/loop_unroller.cpp \
source/opt/loop_unswitch_pass.cpp \
source/opt/loop_utils.cpp \
source/opt/mem_pass.cpp \
source/opt/merge_return_pass.cpp \
source/opt/module.cpp \
......@@ -111,6 +116,7 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/replace_invalid_opc.cpp \
source/opt/scalar_replacement_pass.cpp \
source/opt/set_spec_constant_default_value_pass.cpp \
source/opt/simplification_pass.cpp \
source/opt/strength_reduction_pass.cpp \
source/opt/strip_debug_info_pass.cpp \
source/opt/type_manager.cpp \
......@@ -120,10 +126,15 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/workaround1209.cpp
# Locations of grammar files.
#
# TODO(dneto): Build a single set of tables that embeds versioning differences on
# a per-item basis. That must happen before SPIR-V 1.4, etc.
# https://github.com/KhronosGroup/SPIRV-Tools/issues/1195
SPV_CORE10_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.0/spirv.core.grammar.json
SPV_CORE11_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.1/spirv.core.grammar.json
SPV_CORE12_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.2/spirv.core.grammar.json
SPV_CORELATEST_GRAMMAR=$(SPV_CORE12_GRAMMAR)
SPV_COREUNIFIED1_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/unified1/spirv.core.grammar.json
SPV_CORELATEST_GRAMMAR=$(SPV_COREUNIFIED1_GRAMMAR)
SPV_GLSL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.2/extinst.glsl.std.450.grammar.json
SPV_OPENCL_GRAMMAR=$(SPVHEADERS_LOCAL_PATH)/include/spirv/1.2/extinst.opencl.std.100.grammar.json
# TODO(dneto): I expect the DebugInfo grammar file to eventually migrate to SPIRV-Headers
......@@ -167,9 +178,26 @@ $(1)/core.insts-1.2.inc $(1)/operand.kinds-1.2.inc: \
--core-insts-output=$(1)/core.insts-1.2.inc \
--operand-kinds-output=$(1)/operand.kinds-1.2.inc
@echo "[$(TARGET_ARCH_ABI)] Grammar v1.2 : instructions & operands <= grammar JSON files"
$(LOCAL_PATH)/source/opcode.cpp: $(1)/core.insts-1.0.inc $(1)/core.insts-1.1.inc $(1)/core.insts-1.2.inc
$(LOCAL_PATH)/source/operand.cpp: $(1)/operand.kinds-1.0.inc $(1)/operand.kinds-1.1.inc $(1)/operand.kinds-1.2.inc
$(LOCAL_PATH)/source/ext_inst.cpp: $(1)/glsl.std.450.insts.inc $(1)/opencl.std.insts.inc
$(1)/core.insts-unified1.inc $(1)/operand.kinds-unified1.inc: \
$(LOCAL_PATH)/utils/generate_grammar_tables.py \
$(SPV_COREUNIFIED1_GRAMMAR) \
$(SPV_DEBUGINFO_GRAMMAR)
@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_grammar_tables.py \
--spirv-core-grammar=$(SPV_COREUNIFIED1_GRAMMAR) \
--extinst-debuginfo-grammar=$(SPV_DEBUGINFO_GRAMMAR) \
--core-insts-output=$(1)/core.insts-unified1.inc \
--operand-kinds-output=$(1)/operand.kinds-unified1.inc
@echo "[$(TARGET_ARCH_ABI)] Grammar v1.3 (from unified1) : instructions & operands <= grammar JSON files"
$(LOCAL_PATH)/source/opcode.cpp: $(1)/core.insts-1.0.inc $(1)/core.insts-1.1.inc $(1)/core.insts-1.2.inc $(1)/core.insts-unified1.inc
$(LOCAL_PATH)/source/operand.cpp: $(1)/operand.kinds-1.0.inc $(1)/operand.kinds-1.1.inc $(1)/operand.kinds-1.2.inc $(1)/operand.kinds-unified1.inc
$(LOCAL_PATH)/source/ext_inst.cpp: \
$(1)/glsl.std.450.insts.inc \
$(1)/opencl.std.insts.inc \
$(1)/debuginfo.insts.inc \
$(1)/spv-amd-gcn-shader.insts.inc \
$(1)/spv-amd-shader-ballot.insts.inc \
$(1)/spv-amd-shader-explicit-vertex-parameter.insts.inc \
$(1)/spv-amd-shader-trinary-minmax.insts.inc
endef
$(eval $(call gen_spvtools_grammar_tables,$(SPVTOOLS_OUT_PATH)))
......
Revision history for SPIRV-Tools
v2018.1-dev 2018-02-02
- Start v2018.1-dev
v2018.2 2018-03-07
- General:
- Support SPIR-V 1.3 and Vulkan 1.1.
- Default target environment is now SPIR-V 1.3. For command-line tools,
use the --target-env option to override the default. Examples:
# Generate a SPIR-V 1.0 binary instead of SPIR-V 1.3
spirv-as --target-env spv1.0 a.spvasm -o a.spv
spirv-as --target-env vulkan1.0 a.spvasm -o a.spv
# Validate as Vulkan 1.0
spirv-val --target-env vulkan1.0 a.spv
- Support SPV_GOOGLE_decorate_string and SPV_GOOGLE_hlsl_functionality1
- Fixes:
- Fix Android.mk build. Compilation was failing due to missing definitions of
SpvCapabilityFloat16ImageAMD and other enumerated values.
- Optimizer: Avoid generating duplicate names when merging types.
- #1375: Validator: SPV_AMD_gpu_shaer_half_float implicitly allows declaration
of the 16-bit floating point type.
- #1376: Optimizer: Avoid folding half-precision float.
v2018.1 2018-03-02
- General:
- Support Visual Studio 2013 again. (Continue support for VS 2015 and VS 2017.)
- Support building SPIRV-Tools as a shared library.
- Improve the HLSL legalization optimization recipe. #1311
- Optimizer:
- General speedups.
- Remove generic dead code elimination functionality from transforms:
--eliminate-local-single-block
--eliminate-local-single-store
--eliminate-local-multi-store
To recover the previous behaviour, a recipe using those transforms should now
also invoke the --eliminate-dead-code-aggressive transform.
- Improve folding, including coverage for floating point, OpSelect, and arithmetic
with non-trivial constant operands.
- Add loop-invariant code motion pass.
- Add loop-unrolling pass, for honouring unroll hits.
- Add loop-unswitch pass.
- Add instruction simplification pass.
- Aggressive dead code elimination: Understands capability hierarchy when finding
instructions it can eliminate (combinators). (PR #1268)
- CCP can now fold floating point arithmetic. #1311
- Validator:
- Validate barrier instructions.
- Check Vulkan-specific rules for atomics.
- Check Vulkan prohibition of Location or Component decorations on BuiltIn variables.
- Linker:
- Add --verify-ids option
- Add option to allow a resulting module to be partially linked.
- Handle OpModuleProcessed (instructions in SPIR-V layout section 7c)
- Fixes:
- #1265: Optimizer: Fix use-after free bug in if-conversion. (Fix object lifecycle bug
in type manager.)
- #1282: Fix new warnings found by GCC 8.0.1.
- #1285: Optimizer: Fix random failures during inlining. (Dangling references in DefUseManager)
- #1295: Optimizer: Fix incorrect handling of Phi nodes in CCP.
- #1300: Fix CCP: avoid bad CCP transitions and unsettled values.
- #1304: Avoid static-duration variables of class type (with constructors).
- #1323: Fix folding of an insert composite feeding a composite extract.
- #1339: Fix CCP: Handle OpConstantNull boolean values as conditions.
- #1341: DCEInst: Keep atomic instructions (and some others with side effects).
- #1354: Don't fold integer division.
- #1357: Support OpConstantNull in folding.
- #1361: CCP: Fix handling of non-constant module-scope values
v2018.0 2018-02-02
- General
......
......@@ -222,6 +222,7 @@ if (NOT "${SPIRV_SKIP_TESTS}")
endif()
set(SPIRV_LIBRARIES "-lSPIRV-Tools -lSPIRV-Tools-link -lSPIRV-Tools-opt")
set(SPIRV_SHARED_LIBRARIES "-lSPIRV-Tools-shared")
if(SPIRV_BUILD_COMPRESSION)
set(SPIRV_LIBRARIES "${SPIRV_LIBRARIES} -lSPIRV-Tools-comp")
endif(SPIRV_BUILD_COMPRESSION)
......@@ -229,19 +230,34 @@ endif(SPIRV_BUILD_COMPRESSION)
# Build pkg-config file
# Use a first-class target so it's regenerated when relevant files are updated.
add_custom_target(spirv-tools-pkg-config ALL
COMMAND cmake -DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES
COMMAND ${CMAKE_COMMAND}
-DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES
-DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/SPIRV-Tools.pc.in
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-DSPIRV_LIBRARIES=${SPIRV_LIBRARIES}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake
DEPENDS "CHANGES" "cmake/SPIRV-Tools.pc.in" "cmake/write_pkg_config.cmake")
add_custom_target(spirv-tools-shared-pkg-config ALL
COMMAND ${CMAKE_COMMAND}
-DCHANGES_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CHANGES
-DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/SPIRV-Tools-shared.pc.in
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools-shared.pc
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
-DSPIRV_SHARED_LIBRARIES=${SPIRV_SHARED_LIBRARIES}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/write_pkg_config.cmake
DEPENDS "CHANGES" "cmake/SPIRV-Tools-shared.pc.in" "cmake/write_pkg_config.cmake")
# Install pkg-config file
if (ENABLE_SPIRV_TOOLS_INSTALL)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools.pc
${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Tools-shared.pc
DESTINATION
${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
......@@ -22,7 +22,7 @@ SPIR-V is defined by the Khronos Group Inc.
See the [SPIR-V Registry][spirv-registry] for the SPIR-V specification,
headers, and XML registry.
## Verisoning SPIRV-Tools
## Versioning SPIRV-Tools
See [`CHANGES`](CHANGES) for a high level summary of recent changes, by version.
......@@ -43,7 +43,7 @@ version. An API call reports the software version as a C-style string.
### Assembler, binary parser, and disassembler
* Support for SPIR-V 1.0, 1.1, 1.2
* Support for SPIR-V 1.0, 1.1, 1.2, and 1.3
* Based on SPIR-V syntax described by JSON grammar files in the
[SPIRV-Headers](spirv-headers) repository.
* Support for extended instruction sets:
......
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: SPIRV-Tools
Description: Tools for SPIR-V
Version: @CURRENT_VERSION@
URL: https://github.com/KhronosGroup/SPIRV-Tools
Libs: -L${libdir} @SPIRV_SHARED_LIBRARIES@
Cflags: -I${includedir}
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/lib64
includedir=${prefix}/include
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: SPIRV-Tools
Description: Tools for SPIR-V
......
spirv-tools (2018.1~git9e19fc-1) UNRELEASED; urgency=medium
spirv-tools (2018.2-1) UNRELEASED; urgency=medium
* Initial release (Closes: #890553)
......
version=4
opts="filenamemangle="s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%spirv-tools-$1.tar.gz%" \
opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%spirv-tools-$1.tar.gz%" \
https://github.com/KhronosGroup/spirv-tools/tags \
(?:.*?/)?v?(\d[\d.]*)\.tar\.gz debian uupdate
......@@ -66,6 +66,15 @@ if (NOT ${SPIRV_SKIP_TESTS})
endforeach()
endif()
set(SPIRV_ENABLE_EFFCEE ON)
if (MSVC)
if (MSVC_VERSION LESS 1900)
message(STATUS "SPIRV-Tools: Need Visual Studio 2015 or later for Effcee and RE2")
set(SPIRV_ENABLE_EFFCEE OFF)
endif()
endif()
if (SPIRV_ENABLE_EFFCEE)
# Find Effcee and RE2, for testing.
# Optional for now, but eventually we'll make this required.
......@@ -103,6 +112,7 @@ if (NOT ${SPIRV_SKIP_TESTS})
endif()
endif()
# TODO(dneto): Eventually, require this.
endif()
if (TARGET effcee)
message(STATUS "SPIRV-Tools: Effcee is configured")
else()
......
......@@ -24,6 +24,24 @@ extern "C" {
#include <stddef.h>
#include <stdint.h>
#if defined(SPIRV_TOOLS_SHAREDLIB)
#if defined(_WIN32)
#if defined(SPIRV_TOOLS_IMPLEMENTATION)
#define SPIRV_TOOLS_EXPORT __declspec(dllexport)
#else
#define SPIRV_TOOLS_EXPORT __declspec(dllimport)
#endif
#else
#if defined(SPIRV_TOOLS_IMPLEMENTATION)
#define SPIRV_TOOLS_EXPORT __attribute__((visibility("default")))
#else
#define SPIRV_TOOLS_EXPORT
#endif
#endif
#else
#define SPIRV_TOOLS_EXPORT
#endif
// Helpers
#define SPV_BIT(shift) (1 << (shift))
......@@ -358,12 +376,12 @@ typedef const spv_validator_options_t* spv_const_validator_options;
// Returns the SPIRV-Tools software version as a null-terminated string.
// The contents of the underlying storage is valid for the remainder of
// the process.
const char* spvSoftwareVersionString();
SPIRV_TOOLS_EXPORT const char* spvSoftwareVersionString();
// Returns a null-terminated string containing the name of the project,
// the software version string, and commit details.
// The contents of the underlying storage is valid for the remainder of
// the process.
const char* spvSoftwareVersionDetailsString();
SPIRV_TOOLS_EXPORT const char* spvSoftwareVersionDetailsString();
// Certain target environments impose additional restrictions on SPIR-V, so it's
// often necessary to specify which one applies. SPV_ENV_UNIVERSAL means
......@@ -391,6 +409,8 @@ typedef enum {
// cl_khr_il_program, latest revision.
SPV_ENV_OPENCL_EMBEDDED_2_1, // OpenCL Embedded Profile 2.1 latest revision.
SPV_ENV_OPENCL_EMBEDDED_2_2, // OpenCL Embedded Profile 2.2 latest revision.
SPV_ENV_UNIVERSAL_1_3, // SPIR-V 1.3 latest revision, no other restrictions.
SPV_ENV_VULKAN_1_1, // Vulkan 1.0 latest revision.
} spv_target_env;
// SPIR-V Validator can be parameterized with the following Universal Limits.
......@@ -406,26 +426,27 @@ typedef enum {
} spv_validator_limit;
// Returns a string describing the given SPIR-V target environment.
const char* spvTargetEnvDescription(spv_target_env env);
SPIRV_TOOLS_EXPORT const char* spvTargetEnvDescription(spv_target_env env);
// Creates a context object. Returns null if env is invalid.
spv_context spvContextCreate(spv_target_env env);
SPIRV_TOOLS_EXPORT spv_context spvContextCreate(spv_target_env env);
// Destroys the given context object.
void spvContextDestroy(spv_context context);
SPIRV_TOOLS_EXPORT void spvContextDestroy(spv_context context);
// Creates a Validator options object with default options. Returns a valid
// options object. The object remains valid until it is passed into
// spvValidatorOptionsDestroy.
spv_validator_options spvValidatorOptionsCreate();
SPIRV_TOOLS_EXPORT spv_validator_options spvValidatorOptionsCreate();
// Destroys the given Validator options object.
void spvValidatorOptionsDestroy(spv_validator_options options);
SPIRV_TOOLS_EXPORT void spvValidatorOptionsDestroy(
spv_validator_options options);
// Records the maximum Universal Limit that is considered valid in the given
// Validator options object. <options> argument must be a valid options object.
void spvValidatorOptionsSetUniversalLimit(spv_validator_options options,
spv_validator_limit limit_type,
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetUniversalLimit(
spv_validator_options options, spv_validator_limit limit_type,
uint32_t limit);
// Record whether or not the validator should relax the rules on types for
......@@ -438,8 +459,8 @@ void spvValidatorOptionsSetUniversalLimit(spv_validator_options options,
//
// 2) the decorations that affect the memory layout are identical for both
// types. Other decorations are not relevant.
void spvValidatorOptionsSetRelaxStoreStruct(spv_validator_options options,
bool val);
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxStoreStruct(
spv_validator_options options, bool val);
// Records whether or not the validator should relax the rules on pointer usage
// in logical addressing mode.
......@@ -447,77 +468,79 @@ void spvValidatorOptionsSetRelaxStoreStruct(spv_validator_options options,
// When relaxed, it will allow the following usage cases of pointers:
// 1) OpVariable allocating an object whose type is a pointer type
// 2) OpReturnValue returning a pointer value
void spvValidatorOptionsSetRelaxLogicalPointer(spv_validator_options options,
bool val);
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxLogicalPointer(
spv_validator_options options, bool val);
// Encodes the given SPIR-V assembly text to its binary representation. The
// length parameter specifies the number of bytes for text. Encoded binary will
// be stored into *binary. Any error will be written into *diagnostic if
// diagnostic is non-null. The generated binary is independent of the context
// and may outlive it.
spv_result_t spvTextToBinary(const spv_const_context context, const char* text,
const size_t length, spv_binary* binary,
SPIRV_TOOLS_EXPORT spv_result_t spvTextToBinary(const spv_const_context context,
const char* text,
const size_t length,
spv_binary* binary,
spv_diagnostic* diagnostic);
// Encodes the given SPIR-V assembly text to its binary representation. Same as
// spvTextToBinary but with options. The options parameter is a bit field of
// spv_text_to_binary_options_t.
spv_result_t spvTextToBinaryWithOptions(const spv_const_context context,
const char* text, const size_t length,
const uint32_t options,
spv_binary* binary,
spv_diagnostic* diagnostic);
SPIRV_TOOLS_EXPORT spv_result_t spvTextToBinaryWithOptions(
const spv_const_context context, const char* text, const size_t length,
const uint32_t options, spv_binary* binary, spv_diagnostic* diagnostic);
// Frees an allocated text stream. This is a no-op if the text parameter
// is a null pointer.
void spvTextDestroy(spv_text text);
SPIRV_TOOLS_EXPORT void spvTextDestroy(spv_text text);
// Decodes the given SPIR-V binary representation to its assembly text. The
// word_count parameter specifies the number of words for binary. The options
// parameter is a bit field of spv_binary_to_text_options_t. Decoded text will
// be stored into *text. Any error will be written into *diagnostic if
// diagnostic is non-null.
spv_result_t spvBinaryToText(const spv_const_context context,
const uint32_t* binary, const size_t word_count,
const uint32_t options, spv_text* text,
SPIRV_TOOLS_EXPORT spv_result_t spvBinaryToText(const spv_const_context context,
const uint32_t* binary,
const size_t word_count,
const uint32_t options,
spv_text* text,
spv_diagnostic* diagnostic);
// Frees a binary stream from memory. This is a no-op if binary is a null
// pointer.
void spvBinaryDestroy(spv_binary binary);
SPIRV_TOOLS_EXPORT void spvBinaryDestroy(spv_binary binary);
// Validates a SPIR-V binary for correctness. Any errors will be written into
// *diagnostic if diagnostic is non-null.
spv_result_t spvValidate(const spv_const_context context,
SPIRV_TOOLS_EXPORT spv_result_t spvValidate(const spv_const_context context,
const spv_const_binary binary,
spv_diagnostic* diagnostic);
// Validates a SPIR-V binary for correctness. Uses the provided Validator
// options. Any errors will be written into *diagnostic if diagnostic is
// non-null.
spv_result_t spvValidateWithOptions(const spv_const_context context,
const spv_const_validator_options options,
const spv_const_binary binary,
spv_diagnostic* diagnostic);
SPIRV_TOOLS_EXPORT spv_result_t spvValidateWithOptions(
const spv_const_context context, const spv_const_validator_options options,
const spv_const_binary binary, spv_diagnostic* diagnostic);
// Validates a raw SPIR-V binary for correctness. Any errors will be written
// into *diagnostic if diagnostic is non-null.
spv_result_t spvValidateBinary(const spv_const_context context,
const uint32_t* words, const size_t num_words,
spv_diagnostic* diagnostic);
SPIRV_TOOLS_EXPORT spv_result_t
spvValidateBinary(const spv_const_context context, const uint32_t* words,
const size_t num_words, spv_diagnostic* diagnostic);
// Creates a diagnostic object. The position parameter specifies the location in
// the text/binary stream. The message parameter, copied into the diagnostic
// object, contains the error message to display.
spv_diagnostic spvDiagnosticCreate(const spv_position position,
const char* message);
SPIRV_TOOLS_EXPORT spv_diagnostic
spvDiagnosticCreate(const spv_position position, const char* message);
// Destroys a diagnostic object. This is a no-op if diagnostic is a null
// pointer.
void spvDiagnosticDestroy(spv_diagnostic diagnostic);
SPIRV_TOOLS_EXPORT void spvDiagnosticDestroy(spv_diagnostic diagnostic);
// Prints the diagnostic to stderr.
spv_result_t spvDiagnosticPrint(const spv_diagnostic diagnostic);
SPIRV_TOOLS_EXPORT spv_result_t
spvDiagnosticPrint(const spv_diagnostic diagnostic);
// The binary parser interface.
......@@ -550,11 +573,10 @@ typedef spv_result_t (*spv_parsed_instruction_fn_t)(
// also emits a diagnostic. If a callback returns anything other than
// SPV_SUCCESS, then that status code is returned, no further callbacks are
// issued, and no additional diagnostics are emitted.
spv_result_t spvBinaryParse(const spv_const_context context, void* user_data,
const uint32_t* words, const size_t num_words,
spv_parsed_header_fn_t parse_header,
spv_parsed_instruction_fn_t parse_instruction,
spv_diagnostic* diagnostic);
SPIRV_TOOLS_EXPORT spv_result_t spvBinaryParse(
const spv_const_context context, void* user_data, const uint32_t* words,
const size_t num_words, spv_parsed_header_fn_t parse_header,
spv_parsed_instruction_fn_t parse_instruction, spv_diagnostic* diagnostic);
#ifdef __cplusplus
}
......
......@@ -26,7 +26,10 @@ namespace spvtools {
class LinkerOptions {
public:
LinkerOptions() : create_library_(false), verify_ids_(false) {}
LinkerOptions()
: create_library_(false),
verify_ids_(false),
allow_partial_linkage_(false) {}
// Returns whether a library or an executable should be produced by the
// linking phase.
......@@ -50,9 +53,20 @@ class LinkerOptions {
// context.
void SetVerifyIds(bool verify_ids) { verify_ids_ = verify_ids; }
// Returns whether to allow for imported symbols to have no corresponding
// exported symbols
bool GetAllowPartialLinkage() const { return allow_partial_linkage_; }
// Sets whether to allow for imported symbols to have no corresponding
// exported symbols
void SetAllowPartialLinkage(bool allow_partial_linkage) {
allow_partial_linkage_ = allow_partial_linkage;
}
private:
bool create_library_;
bool verify_ids_;
bool allow_partial_linkage_;
};
// Links one or more SPIR-V modules into a new SPIR-V module. That is, combine
......
......@@ -463,6 +463,17 @@ Optimizer::PassToken CreateMergeReturnPass();
// same value, and remove the redundant ones.
Optimizer::PassToken CreateLocalRedundancyEliminationPass();
// Create LICM pass.
// This pass will look for invariant instructions inside loops and hoist them to
// the loops preheader.
Optimizer::PassToken CreateLoopInvariantCodeMotionPass();
// Creates a loop unswitch pass.
// This pass will look for loop independent branch conditions and move the
// condition out of the loop and version the loop based on the taken branch.
// Works best after LICM and local multi store elimination pass.
Optimizer::PassToken CreateLoopUnswitchPass();
// Create global value numbering pass.
// This pass will look for instructions where the same value is computed on all
// paths leading to the instruction. Those instructions are deleted.
......@@ -504,6 +515,17 @@ Optimizer::PassToken CreateIfConversionPass();
// current shader stage by constants. Has no effect on non-shader modules.
Optimizer::PassToken CreateReplaceInvalidOpcodePass();
// Creates a pass that simplifies instructions using the instruction folder.
Optimizer::PassToken CreateSimplificationPass();
// Create loop unroller pass.
// Creates a pass to unroll loops which have the "Unroll" loop control
// mask set. The loops must meet a specific criteria in order to be unrolled
// safely this criteria is checked before doing the unroll by the
// LoopUtils::CanPerformUnroll method. Any loop that does not meet the criteria
// won't be unrolled. See CanPerformUnroll LoopUtils.h for more information.
Optimizer::PassToken CreateLoopUnrollPass(bool fully_unroll, int factor = 0);
} // namespace spvtools
#endif // SPIRV_TOOLS_OPTIMIZER_HPP_
......@@ -66,7 +66,7 @@ macro(spvtools_vimsyntax VERSION CLVERSION)
add_custom_command(OUTPUT ${VIMSYNTAX_FILE}
COMMAND ${PYTHON_EXECUTABLE} ${VIMSYNTAX_PROCESSING_SCRIPT}
--spirv-core-grammar=${GRAMMAR_JSON_FILE}
--exinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
--extinst-debuginfo-grammar=${DEBUGINFO_GRAMMAR_JSON_FILE}
--extinst-glsl-grammar=${GLSL_GRAMMAR_JSON_FILE}
--extinst-opencl-grammar=${OPENCL_GRAMMAR_JSON_FILE}
>${VIMSYNTAX_FILE}
......@@ -131,12 +131,18 @@ macro(spvtools_extinst_lang_headers NAME GRAMMAR_FILE)
endmacro(spvtools_extinst_lang_headers)
# SPIR-V 1.3 support is in SPIRV-Headers include/spirv/unified1
# Temporarily assume that's the last SPIR-V version in 'unified1'.
# TODO(dneto): Build a single set of tables that embeds versioning
# differences on a per-item basis. That must happen before SPIR-V 1.4, etc.
# https://github.com/KhronosGroup/SPIRV-Tools/issues/1195
spvtools_core_tables("1.0")
spvtools_core_tables("1.1")
spvtools_core_tables("1.2")
spvtools_enum_string_mapping("1.2")
spvtools_opencl_tables("1.2")
spvtools_glsl_tables("1.2")
spvtools_core_tables("unified1")
spvtools_enum_string_mapping("unified1")
spvtools_opencl_tables("unified1")
spvtools_glsl_tables("unified1")
spvtools_vendor_tables("spv-amd-shader-explicit-vertex-parameter")
spvtools_vendor_tables("spv-amd-shader-trinary-minmax")
spvtools_vendor_tables("spv-amd-gcn-shader")
......@@ -144,7 +150,7 @@ spvtools_vendor_tables("spv-amd-shader-ballot")
spvtools_vendor_tables("debuginfo")
spvtools_extinst_lang_headers("DebugInfo" ${DEBUGINFO_GRAMMAR_JSON_FILE})
spvtools_vimsyntax("1.2" "1.0")
spvtools_vimsyntax("unified1" "1.0")
add_custom_target(spirv-tools-vimsyntax DEPENDS ${VIMSYNTAX_FILE})
set_property(TARGET spirv-tools-vimsyntax PROPERTY FOLDER "SPIRV-Tools utilities")
......@@ -334,8 +340,23 @@ target_include_directories(${SPIRV_TOOLS}
set_property(TARGET ${SPIRV_TOOLS} PROPERTY FOLDER "SPIRV-Tools libraries")
spvtools_check_symbol_exports(${SPIRV_TOOLS})
add_library(${SPIRV_TOOLS}-shared SHARED ${SPIRV_SOURCES})
spvtools_default_compile_options(${SPIRV_TOOLS}-shared)
target_include_directories(${SPIRV_TOOLS}-shared
PUBLIC ${spirv-tools_SOURCE_DIR}/include
PRIVATE ${spirv-tools_BINARY_DIR}
PRIVATE ${SPIRV_HEADER_INCLUDE_DIR}
)
set_target_properties(${SPIRV_TOOLS}-shared PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_property(TARGET ${SPIRV_TOOLS}-shared PROPERTY FOLDER "SPIRV-Tools libraries")
spvtools_check_symbol_exports(${SPIRV_TOOLS}-shared)
target_compile_definitions(${SPIRV_TOOLS}-shared
PRIVATE SPIRV_TOOLS_IMPLEMENTATION
PUBLIC SPIRV_TOOLS_SHAREDLIB
)
if(ENABLE_SPIRV_TOOLS_INSTALL)
install(TARGETS ${SPIRV_TOOLS}
install(TARGETS ${SPIRV_TOOLS} ${SPIRV_TOOLS}-shared
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
......
......@@ -25,9 +25,9 @@
#include "assembly_grammar.h"
#include "diagnostic.h"
#include "ext_inst.h"
#include "latest_version_spirv_header.h"
#include "opcode.h"
#include "operand.h"
#include "spirv/1.2/spirv.h"
#include "spirv_constant.h"
#include "spirv_endian.h"
......
......@@ -14,7 +14,9 @@
#include "enum_string_mapping.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <string>
#include <unordered_map>
......
......@@ -17,20 +17,19 @@
#include <string>
#include "spirv/1.1/spirv.h"
#include "extensions.h"
#include "latest_version_spirv_header.h"
namespace libspirv {
// Finds Extension enum corresponding to |str|. Returns false if not found.
bool GetExtensionFromString(const std::string& str, Extension* extension);
bool GetExtensionFromString(const char* str, Extension* extension);
// Returns text string corresponding to |extension|.
std::string ExtensionToString(Extension extension);
const char* ExtensionToString(Extension extension);
// Returns text string corresponding to |capability|.
std::string CapabilityToString(SpvCapability capability);
const char* CapabilityToString(SpvCapability capability);
} // namespace libspirv
......
......@@ -79,6 +79,8 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable,
case SPV_ENV_OPENGL_4_2:
case SPV_ENV_OPENGL_4_3:
case SPV_ENV_OPENGL_4_5:
case SPV_ENV_UNIVERSAL_1_3:
case SPV_ENV_VULKAN_1_1:
*pExtInstTable = &kTable_1_0;
return SPV_SUCCESS;
default:
......
......@@ -110,7 +110,8 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
static spv_result_t GetImportExportPairs(
const MessageConsumer& consumer, const ir::IRContext& linked_context,
const DefUseManager& def_use_manager,
const DecorationManager& decoration_manager, LinkageTable* linkings_to_do);
const DecorationManager& decoration_manager, bool allow_partial_linkage,
LinkageTable* linkings_to_do);
// Checks that for each pair of import and export, the import and export have
// the same type as well as the same decorations.
......@@ -134,7 +135,7 @@ static spv_result_t CheckImportExportCompatibility(
// TODO(pierremoreau): Run a pass for removing dead instructions, for example
// OpName for prototypes of imported funcions.
static spv_result_t RemoveLinkageSpecificInstructions(
const MessageConsumer& consumer, bool create_executable,
const MessageConsumer& consumer, const LinkerOptions& options,
const LinkageTable& linkings_to_do, DecorationManager* decoration_manager,
ir::IRContext* linked_context);
......@@ -222,9 +223,10 @@ spv_result_t Link(const Context& context, const uint32_t* const* binaries,
// Phase 4: Find the import/export pairs
LinkageTable linkings_to_do;
res = GetImportExportPairs(
consumer, linked_context, *linked_context.get_def_use_mgr(),
*linked_context.get_decoration_mgr(), &linkings_to_do);
res = GetImportExportPairs(consumer, linked_context,
*linked_context.get_def_use_mgr(),
*linked_context.get_decoration_mgr(),
options.GetAllowPartialLinkage(), &linkings_to_do);
if (res != SPV_SUCCESS) return res;
// Phase 5: Ensure the import and export have the same types and decorations.
......@@ -246,9 +248,9 @@ spv_result_t Link(const Context& context, const uint32_t* const* binaries,
// Phase 8: Remove linkage specific instructions, such as import/export
// attributes, linkage capability, etc. if applicable
res = RemoveLinkageSpecificInstructions(
consumer, !options.GetCreateLibrary(), linkings_to_do,
linked_context.get_decoration_mgr(), &linked_context);
res = RemoveLinkageSpecificInstructions(consumer, options, linkings_to_do,
linked_context.get_decoration_mgr(),
&linked_context);
if (res != SPV_SUCCESS) return res;
// Phase 9: Compact the IDs used in the module
......@@ -445,6 +447,24 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
linked_module->AddDebug2Inst(
std::unique_ptr<Instruction>(inst.Clone(linked_context)));
for (const auto& module : input_modules)
for (const auto& inst : module->debugs3())
linked_module->AddDebug3Inst(
std::unique_ptr<Instruction>(inst.Clone(linked_context)));
// If the generated module uses SPIR-V 1.1 or higher, add an
// OpModuleProcessed instruction about the linking step.
if (linked_module->version() >= 0x10100) {
const std::string processed_string("Linked by SPIR-V Tools Linker");
const size_t words_nb =
processed_string.size() / 4u + (processed_string.size() % 4u != 0u);
std::vector<uint32_t> processed_words(words_nb, 0u);
std::memcpy(processed_words.data(), processed_string.data(), words_nb * 4u);
linked_module->AddDebug3Inst(std::unique_ptr<Instruction>(
new Instruction(linked_context, SpvOpModuleProcessed, 0u, 0u,
{{SPV_OPERAND_TYPE_LITERAL_STRING, processed_words}})));
}
for (const auto& module : input_modules)
for (const auto& inst : module->annotations())
linked_module->AddAnnotationInst(
......@@ -481,7 +501,8 @@ static spv_result_t MergeModules(const MessageConsumer& consumer,
static spv_result_t GetImportExportPairs(
const MessageConsumer& consumer, const ir::IRContext& linked_context,
const DefUseManager& def_use_manager,
const DecorationManager& decoration_manager, LinkageTable* linkings_to_do) {
const DecorationManager& decoration_manager, bool allow_partial_linkage,
LinkageTable* linkings_to_do) {
spv_position_t position = {};
if (linkings_to_do == nullptr)
......@@ -561,7 +582,7 @@ static spv_result_t GetImportExportPairs(
std::vector<LinkageSymbolInfo> possible_exports;
const auto& exp = exports.find(import.name);
if (exp != exports.end()) possible_exports = exp->second;
if (possible_exports.empty())
if (possible_exports.empty() && !allow_partial_linkage)
return libspirv::DiagnosticStream(position, consumer,
SPV_ERROR_INVALID_BINARY)
<< "Unresolved external reference to \"" << import.name << "\".";
......@@ -571,6 +592,7 @@ static spv_result_t GetImportExportPairs(
<< "Too many external references, " << possible_exports.size()
<< ", were found for \"" << import.name << "\".";
if (!possible_exports.empty())
linkings_to_do->emplace_back(import, possible_exports.front());
}
......@@ -623,7 +645,7 @@ static spv_result_t CheckImportExportCompatibility(
}
static spv_result_t RemoveLinkageSpecificInstructions(
const MessageConsumer& consumer, bool create_executable,
const MessageConsumer& consumer, const LinkerOptions& options,
const LinkageTable& linkings_to_do, DecorationManager* decoration_manager,
ir::IRContext* linked_context) {
spv_position_t position = {};
......@@ -689,21 +711,40 @@ static spv_result_t RemoveLinkageSpecificInstructions(
}
}
// If partial linkage is allowed, we need an efficient way to check whether
// an imported ID had a corresponding export symbol. As uses of the imported
// symbol have already been replaced by the exported symbol, use the exported
// symbol ID.
// TODO(pierremoreau): This will not work if the decoration is applied
// through a group, but the linker does not support that
// either.
std::unordered_set<SpvId> imports;
if (options.GetAllowPartialLinkage()) {
imports.reserve(linkings_to_do.size());
for (const auto& linking_entry : linkings_to_do)
imports.emplace(linking_entry.exported_symbol.id);
}
// Remove import linkage attributes
auto next = linked_context->annotation_begin();
for (auto inst = next; inst != linked_context->annotation_end();
inst = next) {
++next;
// If this is an import annotation:
// * if we do not allow partial linkage, remove all import annotations;
// * otherwise, remove the annotation only if there was a corresponding
// export.
if (inst->opcode() == SpvOpDecorate &&
inst->GetSingleWordOperand(1u) == SpvDecorationLinkageAttributes &&
inst->GetSingleWordOperand(3u) == SpvLinkageTypeImport) {
inst->GetSingleWordOperand(3u) == SpvLinkageTypeImport &&
(!options.GetAllowPartialLinkage() ||
imports.find(inst->GetSingleWordOperand(0u)) != imports.end())) {
linked_context->KillInst(&*inst);
}
}
// Remove export linkage attributes and Linkage capability if making an
// executable
if (create_executable) {
// Remove export linkage attributes if making an executable
if (!options.GetCreateLibrary()) {
next = linked_context->annotation_begin();
for (auto inst = next; inst != linked_context->annotation_end();
inst = next) {
......@@ -714,7 +755,11 @@ static spv_result_t RemoveLinkageSpecificInstructions(
linked_context->KillInst(&*inst);
}
}
}
// Remove Linkage capability if making an executable and partial linkage is
// not allowed
if (!options.GetCreateLibrary() && !options.GetAllowPartialLinkage()) {
for (auto& inst : linked_context->capabilities())
if (inst.GetSingleWordInOperand(0u) == SpvCapabilityLinkage) {
linked_context->KillInst(&inst);
......