Skip to content

Commit

Permalink
Squashed 'deps/SPIRV-Cross/' changes from 9c57364f18..8aa6731925
Browse files Browse the repository at this point in the history
8aa6731925 Merge pull request libretro#1065 from KhronosGroup/msvc-2013-workaround
909040e2eb MSVC 2013: Work around another compiler bug with array init.
53ab2144b9 Merge pull request libretro#1064 from KhronosGroup/fix-1062
e0cd8595a4 Merge pull request libretro#1063 from KhronosGroup/fix-1061
50342966c0 Fall back to complex loop if non-trivial continue block is found.
fa9af7223a Add test shaders for NonUniformEXT propagation.
d12b54bbb4 Propagate NonUniformEXT to dependent expressions.
13378ad1ac Add simple test for extended debug operations.
6d9c502a3a Merge branch 'master' of git://github.com/lifpan/SPIRV-Cross
5ca8779044 Parse SPIR-V debug information extended instructions, as well as OpNoLine.
c5904dd245 Merge pull request libretro#1059 from KhronosGroup/fix-1056
4056d0b74e Don't use scalar dot().
041f103d44 MSL/HLSL: Support scalar reflect and refract.
9a6e2534e9 Merge pull request libretro#1058 from KhronosGroup/fix-1054
fc9fe4e480 Fix variable scope when an if or else block dominates a variable.
3af18e741f Merge pull request libretro#1055 from cdavis5e/msl21-frag-subgroup-builtins
31b6c93516 MSL: Support SubgroupLocalInvocationId and SubgroupSize in all stages.
41399fc899 Merge pull request libretro#1051 from KhronosGroup/fix-1049
f8b084de61 MSL/HLSL: Support OpOuterProduct.
04e29895a3 Merge pull request libretro#1001 from cdavis5e/msl-multiview
7eecf5a46b MSL: Support SPV_KHR_multiview.
8ee8e60f70 Merge pull request libretro#1048 from KhronosGroup/fix-1047
ff87419607 Deal with scalar input values for distance/length/normalize.
d1bdb6d491 Merge pull request libretro#1046 from KhronosGroup/texture-fp16-coord
964ec44822 Merge pull request libretro#1045 from KhronosGroup/c-api-get-declared-struct-member-size
1543bdaf7b Run format_all.sh.
581ed0fd59 HLSL: Does not support case-fallthrough.
c76b99b711 Handle more cases with FP16 and texture sampling.
656d129c00 Add C API for get_declared_struct_member_size.
45805857e5 MSL: De-virtualize get_declared_struct_member_size.
02b2a1015d MSL: Fix minor XCode /analyze warning.
8f6939cb0d Merge pull request libretro#1041 from KhronosGroup/fix-1011
4bbf343a7f Merge pull request libretro#1043 from KhronosGroup/fix-1042
bcef66fbf3 Fix declaration of loop variables with a Phi helper copy.
845628cd4e Merge pull request libretro#1040 from KhronosGroup/fix-1037
ab3798fd91 MSL: Add support for SubgroupSize / SubgroupInvocationID in fragment.
048f2380f3 MSL: Support custom bindings for argument buffer itself.

git-subtree-dir: deps/SPIRV-Cross
git-subtree-split: 8aa67319253b55f874d1fc7eb85d201299a8f488
  • Loading branch information
inactive123 committed Jul 9, 2019
1 parent 7016d8b commit 695837e
Show file tree
Hide file tree
Showing 97 changed files with 3,466 additions and 60 deletions.
8 changes: 7 additions & 1 deletion deps/SPIRV-Cross/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ if (SPIRV_CROSS_STATIC)
endif()

set(spirv-cross-abi-major 0)
set(spirv-cross-abi-minor 14)
set(spirv-cross-abi-minor 16)
set(spirv-cross-abi-patch 0)

if (SPIRV_CROSS_SHARED)
Expand Down Expand Up @@ -457,6 +457,10 @@ if (SPIRV_CROSS_CLI)
target_link_libraries(spirv-cross-msl-constexpr-test spirv-cross-c)
set_target_properties(spirv-cross-msl-constexpr-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")

add_executable(spirv-cross-msl-resource-binding-test tests-other/msl_resource_bindings.cpp)
target_link_libraries(spirv-cross-msl-resource-binding-test spirv-cross-c)
set_target_properties(spirv-cross-msl-resource-binding-test PROPERTIES LINK_FLAGS "${spirv-cross-link-flags}")

if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
target_compile_options(spirv-cross-c-api-test PRIVATE -std=c89 -Wall -Wextra)
endif()
Expand All @@ -469,6 +473,8 @@ if (SPIRV_CROSS_CLI)
COMMAND $<TARGET_FILE:spirv-cross-small-vector-test>)
add_test(NAME spirv-cross-msl-constexpr-test
COMMAND $<TARGET_FILE:spirv-cross-msl-constexpr-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_constexpr_test.spv)
add_test(NAME spirv-cross-msl-resource-binding-test
COMMAND $<TARGET_FILE:spirv-cross-msl-resource-binding-test> ${CMAKE_CURRENT_SOURCE_DIR}/tests-other/msl_resource_binding.spv)
add_test(NAME spirv-cross-test
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shaders.py --parallel
${spirv-cross-externals}
Expand Down
4 changes: 4 additions & 0 deletions deps/SPIRV-Cross/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ struct CLIArguments
bool msl_domain_lower_left = false;
bool msl_argument_buffers = false;
bool msl_texture_buffer_native = false;
bool msl_multiview = false;
bool glsl_emit_push_constant_as_ubo = false;
bool glsl_emit_ubo_as_plain_uniforms = false;
bool emit_line_directives = false;
Expand Down Expand Up @@ -592,6 +593,7 @@ static void print_help()
"\t[--msl-argument-buffers]\n"
"\t[--msl-texture-buffer-native]\n"
"\t[--msl-discrete-descriptor-set <index>]\n"
"\t[--msl-multiview]\n"
"\t[--hlsl]\n"
"\t[--reflect]\n"
"\t[--shader-model]\n"
Expand Down Expand Up @@ -750,6 +752,7 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
msl_opts.tess_domain_origin_lower_left = args.msl_domain_lower_left;
msl_opts.argument_buffers = args.msl_argument_buffers;
msl_opts.texture_buffer_native = args.msl_texture_buffer_native;
msl_opts.multiview = args.msl_multiview;
msl_comp->set_msl_options(msl_opts);
for (auto &v : args.msl_discrete_descriptor_sets)
msl_comp->add_discrete_descriptor_set(v);
Expand Down Expand Up @@ -1069,6 +1072,7 @@ static int main_inner(int argc, char *argv[])
cbs.add("--msl-discrete-descriptor-set",
[&args](CLIParser &parser) { args.msl_discrete_descriptor_sets.push_back(parser.next_uint()); });
cbs.add("--msl-texture-buffer-native", [&args](CLIParser &) { args.msl_texture_buffer_native = true; });
cbs.add("--msl-multiview", [&args](CLIParser &) { args.msl_multiview = true; });
cbs.add("--extension", [&args](CLIParser &parser) { args.extensions.push_back(parser.next_string()); });
cbs.add("--rename-entry-point", [&args](CLIParser &parser) {
auto old_name = parser.next_string();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ inline bool spvSubgroupAllEqual(bool value)

kernel void main0(device SSBO& _9 [[buffer(0)]], uint gl_NumSubgroups [[simdgroups_per_threadgroup]], uint gl_SubgroupID [[simdgroup_index_in_threadgroup]], uint gl_SubgroupSize [[thread_execution_width]], uint gl_SubgroupInvocationID [[thread_index_in_simdgroup]])
{
uint4 gl_SubgroupEqMask = 27 > 32 ? uint4(0, (1 << (gl_SubgroupInvocationID - 32)), uint2(0)) : uint4(1 << gl_SubgroupInvocationID, uint3(0));
uint4 gl_SubgroupEqMask = gl_SubgroupInvocationID > 32 ? uint4(0, (1 << (gl_SubgroupInvocationID - 32)), uint2(0)) : uint4(1 << gl_SubgroupInvocationID, uint3(0));
uint4 gl_SubgroupGeMask = uint4(extract_bits(0xFFFFFFFF, min(gl_SubgroupInvocationID, 32u), (uint)max(min((int)gl_SubgroupSize, 32) - (int)gl_SubgroupInvocationID, 0)), extract_bits(0xFFFFFFFF, (uint)max((int)gl_SubgroupInvocationID - 32, 0), (uint)max((int)gl_SubgroupSize - (int)max(gl_SubgroupInvocationID, 32u), 0)), uint2(0));
uint4 gl_SubgroupGtMask = uint4(extract_bits(0xFFFFFFFF, min(gl_SubgroupInvocationID + 1, 32u), (uint)max(min((int)gl_SubgroupSize, 32) - (int)gl_SubgroupInvocationID - 1, 0)), extract_bits(0xFFFFFFFF, (uint)max((int)gl_SubgroupInvocationID + 1 - 32, 0), (uint)max((int)gl_SubgroupSize - (int)max(gl_SubgroupInvocationID + 1, 32u), 0)), uint2(0));
uint4 gl_SubgroupLeMask = uint4(extract_bits(0xFFFFFFFF, 0, min(gl_SubgroupInvocationID + 1, 32u)), extract_bits(0xFFFFFFFF, 0, (uint)max((int)gl_SubgroupInvocationID + 1 - 32, 0)), uint2(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ void frag_main()
case 0:
{
_30 = 3;
j = _30;
_31 = 0;
j = _31;
break;
}
default:
{
j = _30;
_31 = 0;
j = _31;
break;
}
case 1:
case 11:
{
j = _31;
break;
}
case 2:
{
Expand All @@ -59,6 +66,8 @@ void frag_main()
}
case 4:
{
i = 0;
break;
}
case 5:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ inline bool spvSubgroupAllEqual(bool value)

kernel void main0(device SSBO& _9 [[buffer(0)]], uint gl_NumSubgroups [[simdgroups_per_threadgroup]], uint gl_SubgroupID [[simdgroup_index_in_threadgroup]], uint gl_SubgroupSize [[thread_execution_width]], uint gl_SubgroupInvocationID [[thread_index_in_simdgroup]])
{
uint4 gl_SubgroupEqMask = 27 > 32 ? uint4(0, (1 << (gl_SubgroupInvocationID - 32)), uint2(0)) : uint4(1 << gl_SubgroupInvocationID, uint3(0));
uint4 gl_SubgroupEqMask = gl_SubgroupInvocationID > 32 ? uint4(0, (1 << (gl_SubgroupInvocationID - 32)), uint2(0)) : uint4(1 << gl_SubgroupInvocationID, uint3(0));
uint4 gl_SubgroupGeMask = uint4(extract_bits(0xFFFFFFFF, min(gl_SubgroupInvocationID, 32u), (uint)max(min((int)gl_SubgroupSize, 32) - (int)gl_SubgroupInvocationID, 0)), extract_bits(0xFFFFFFFF, (uint)max((int)gl_SubgroupInvocationID - 32, 0), (uint)max((int)gl_SubgroupSize - (int)max(gl_SubgroupInvocationID, 32u), 0)), uint2(0));
uint4 gl_SubgroupGtMask = uint4(extract_bits(0xFFFFFFFF, min(gl_SubgroupInvocationID + 1, 32u), (uint)max(min((int)gl_SubgroupSize, 32) - (int)gl_SubgroupInvocationID - 1, 0)), extract_bits(0xFFFFFFFF, (uint)max((int)gl_SubgroupInvocationID + 1 - 32, 0), (uint)max((int)gl_SubgroupSize - (int)max(gl_SubgroupInvocationID + 1, 32u), 0)), uint2(0));
uint4 gl_SubgroupLeMask = uint4(extract_bits(0xFFFFFFFF, 0, min(gl_SubgroupInvocationID + 1, 32u)), extract_bits(0xFFFFFFFF, 0, (uint)max((int)gl_SubgroupInvocationID + 1 - 32, 0)), uint2(0));
Expand Down
52 changes: 45 additions & 7 deletions deps/SPIRV-Cross/spirv_cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,25 @@ bool CFG::is_back_edge(uint32_t to) const
// We have a back edge if the visit order is set with the temporary magic value 0.
// Crossing edges will have already been recorded with a visit order.
auto itr = visit_order.find(to);
assert(itr != end(visit_order));
return itr->second.get() == 0;
return itr != end(visit_order) && itr->second.get() == 0;
}

bool CFG::has_visited_forward_edge(uint32_t to) const
{
// If > 0, we have visited the edge already, and this is not a back edge branch.
auto itr = visit_order.find(to);
return itr != end(visit_order) && itr->second.get() > 0;
}

bool CFG::post_order_visit(uint32_t block_id)
{
// If we have already branched to this block (back edge), stop recursion.
// If our branches are back-edges, we do not record them.
// We have to record crossing edges however.
if (visit_order[block_id].get() >= 0)
return !is_back_edge(block_id);
if (has_visited_forward_edge(block_id))
return true;
else if (is_back_edge(block_id))
return false;

// Block back-edges from recursively revisiting ourselves.
visit_order[block_id].get() = 0;
Expand Down Expand Up @@ -123,9 +131,39 @@ bool CFG::post_order_visit(uint32_t block_id)
// This is needed to avoid annoying cases with do { ... } while(false) loops often generated by inliners.
// To the CFG, this is linear control flow, but we risk picking the do/while scope as our dominating block.
// This makes sure that if we are accessing a variable outside the do/while, we choose the loop header as dominator.
if (block.merge == SPIRBlock::MergeLoop)
if (post_order_visit(block.merge_block))
add_branch(block_id, block.merge_block);
// We could use has_visited_forward_edge, but this break code-gen where the merge block is unreachable in the CFG.
if (block.merge == SPIRBlock::MergeLoop && post_order_visit(block.merge_block))
add_branch(block_id, block.merge_block);

// If this is a selection merge, add an implied branch to the merge target.
// This is needed to avoid cases where an inner branch dominates the outer branch.
// This can happen if one of the branches exit early, e.g.:
// if (cond) { ...; break; } else { var = 100 } use_var(var);
// We can use the variable without a Phi since there is only one possible parent here.
// However, in this case, we need to hoist out the inner variable to outside the branch.
// Use same strategy as loops.
if (block.merge == SPIRBlock::MergeSelection && post_order_visit(block.next_block))
{
// If there is only one preceding edge to the merge block and it's not ourselves, we need a fixup.
// Add a fake branch so any dominator in either the if (), or else () block, or a lone case statement
// will be hoisted out to outside the selection merge.
// If size > 1, the variable will be automatically hoisted, so we should not mess with it.
// Adding fake branches unconditionally breaks parameter preservation analysis,
// which looks at how variables are accessed through the CFG.
auto pred_itr = preceding_edges.find(block.next_block);
if (pred_itr != end(preceding_edges))
{
auto &pred = pred_itr->second;
if (pred.size() == 1 && *pred.begin() != block_id)
add_branch(block_id, block.next_block);
}
else
{
// If the merge block does not have any preceding edges, i.e. unreachable, hallucinate it.
// We're going to do code-gen for it, and domination analysis requires that we have at least one preceding edge.
add_branch(block_id, block.next_block);
}
}

// Then visit ourselves. Start counting at one, to let 0 be a magic value for testing back vs. crossing edges.
visit_order[block_id].get() = ++visit_count;
Expand Down
1 change: 1 addition & 0 deletions deps/SPIRV-Cross/spirv_cfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class CFG
uint32_t visit_count = 0;

bool is_back_edge(uint32_t to) const;
bool has_visited_forward_edge(uint32_t to) const;
};

class DominatorBuilder
Expand Down
1 change: 1 addition & 0 deletions deps/SPIRV-Cross/spirv_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ struct SPIRExtension : IVariant
{
Unsupported,
GLSL,
SPV_debug_info,
SPV_AMD_shader_ballot,
SPV_AMD_shader_explicit_vertex_parameter,
SPV_AMD_shader_trinary_minmax,
Expand Down
2 changes: 2 additions & 0 deletions deps/SPIRV-Cross/spirv_cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,7 @@ bool Compiler::AnalyzeVariableScopeAccessHandler::handle(spv::Op op, const uint3

case OpArrayLength:
case OpLine:
case OpNoLine:
// Uses literals, but cannot be a phi variable or temporary, so ignore.
break;

Expand Down Expand Up @@ -4266,6 +4267,7 @@ bool Compiler::instruction_to_result_type(uint32_t &result_type, uint32_t &resul
case OpGroupCommitReadPipe:
case OpGroupCommitWritePipe:
case OpLine:
case OpNoLine:
return false;

default:
Expand Down
2 changes: 1 addition & 1 deletion deps/SPIRV-Cross/spirv_cross.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class Compiler
size_t get_declared_struct_size_runtime_array(const SPIRType &struct_type, size_t array_size) const;

// Returns the effective size of a buffer block struct member.
virtual size_t get_declared_struct_member_size(const SPIRType &struct_type, uint32_t index) const;
size_t get_declared_struct_member_size(const SPIRType &struct_type, uint32_t index) const;

// Returns a set of all global variables which are statically accessed
// by the control flow graph from the current entry point.
Expand Down
10 changes: 10 additions & 0 deletions deps/SPIRV-Cross/spirv_cross_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,16 @@ spvc_result spvc_compiler_get_declared_struct_size_runtime_array(spvc_compiler c
return SPVC_SUCCESS;
}

spvc_result spvc_compiler_get_declared_struct_member_size(spvc_compiler compiler, spvc_type struct_type, unsigned index, size_t *size)
{
SPVC_BEGIN_SAFE_SCOPE
{
*size = compiler->compiler->get_declared_struct_member_size(*static_cast<const SPIRType *>(struct_type), index);
}
SPVC_END_SAFE_SCOPE(compiler->context, SPVC_ERROR_INVALID_ARGUMENT)
return SPVC_SUCCESS;
}

spvc_result spvc_compiler_type_struct_member_offset(spvc_compiler compiler, spvc_type type, unsigned index, unsigned *offset)
{
SPVC_BEGIN_SAFE_SCOPE
Expand Down
4 changes: 3 additions & 1 deletion deps/SPIRV-Cross/spirv_cross_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
/* Bumped if ABI or API breaks backwards compatibility. */
#define SPVC_C_API_VERSION_MAJOR 0
/* Bumped if APIs or enumerations are added in a backwards compatible way. */
#define SPVC_C_API_VERSION_MINOR 14
#define SPVC_C_API_VERSION_MINOR 16
/* Bumped if internal implementation details change. */
#define SPVC_C_API_VERSION_PATCH 0

Expand Down Expand Up @@ -303,6 +303,7 @@ SPVC_PUBLIC_API void spvc_msl_resource_binding_init(spvc_msl_resource_binding *b
#define SPVC_MSL_PUSH_CONSTANT_BINDING (0)
#define SPVC_MSL_SWIZZLE_BUFFER_BINDING (~(1u))
#define SPVC_MSL_BUFFER_SIZE_BUFFER_BINDING (~(2u))
#define SPVC_MSL_ARGUMENT_BUFFER_BINDING (~(3u))

/* Obsolete. Sticks around for backwards compatibility. */
#define SPVC_MSL_AUX_BUFFER_STRUCT_VERSION 1
Expand Down Expand Up @@ -659,6 +660,7 @@ SPVC_PUBLIC_API SpvAccessQualifier spvc_type_get_image_access_qualifier(spvc_typ
SPVC_PUBLIC_API spvc_result spvc_compiler_get_declared_struct_size(spvc_compiler compiler, spvc_type struct_type, size_t *size);
SPVC_PUBLIC_API spvc_result spvc_compiler_get_declared_struct_size_runtime_array(spvc_compiler compiler,
spvc_type struct_type, size_t array_size, size_t *size);
SPVC_PUBLIC_API spvc_result spvc_compiler_get_declared_struct_member_size(spvc_compiler compiler, spvc_type type, unsigned index, size_t *size);

SPVC_PUBLIC_API spvc_result spvc_compiler_type_struct_member_offset(spvc_compiler compiler,
spvc_type type, unsigned index, unsigned *offset);
Expand Down
Loading

0 comments on commit 695837e

Please sign in to comment.