Skip to content

Commit

Permalink
Merge pull request #2243 from KhronosGroup/pr-2238
Browse files Browse the repository at this point in the history
Land PR 2238
  • Loading branch information
HansKristian-Work authored Dec 7, 2023
2 parents e6b013a + 833c593 commit 13aab7f
Show file tree
Hide file tree
Showing 24 changed files with 270 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ struct main0_patchOut

struct main0_in
{
uint3 m_86;
ushort2 m_90;
uint3 m_87;
ushort2 m_92;
float4 gl_Position;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct main0_patchOut
struct main0_in
{
float3 in_tc_attr;
ushort2 m_196;
ushort2 m_197;
};

kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], constant uint* spvIndirectParams [[buffer(29)]], device main0_patchOut* spvPatchOut [[buffer(27)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct main0_out
struct main0_in
{
float4 vInputs;
ushort2 m_44;
ushort2 m_45;
};

kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct main0_out
struct main0_in
{
float3 in_tc_attr;
ushort2 m_104;
ushort2 m_105;
};

kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ struct main0_out

struct main0_in
{
uint3 m_82;
ushort2 m_86;
uint3 m_83;
ushort2 m_88;
float4 gl_Position;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct main0_out
struct main0_in
{
float3 in_tc_attr;
ushort2 m_119;
ushort2 m_120;
};

kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
2 changes: 1 addition & 1 deletion reference/opt/shaders-msl/tesc/water_tess.multi-patch.tesc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct main0_patchOut
struct main0_in
{
float3 vPatchPosBase;
ushort2 m_996;
ushort2 m_997;
};

kernel void main0(constant UBO& _41 [[buffer(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]], constant uint* spvIndirectParams [[buffer(29)]], device main0_patchOut* spvPatchOut [[buffer(27)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct main0_out
struct main0_in
{
VertexOutput_1 p;
ushort2 m_173;
ushort2 m_174;
float4 gl_Position;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ struct main0_out

struct main0_in
{
uint3 m_57;
ushort2 m_61;
uint3 m_58;
ushort2 m_63;
spvUnsafeArray<float, 2> gl_ClipDistance;
spvUnsafeArray<float, 1> gl_CullDistance;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ struct main0_patchOut

struct main0_in
{
uint3 m_78;
ushort2 m_82;
uint3 m_79;
ushort2 m_84;
float4 gl_Position;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct main0_patchOut
struct main0_in
{
float3 in_tc_attr;
ushort2 m_179;
ushort2 m_180;
};

kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], constant uint* spvIndirectParams [[buffer(29)]], device main0_patchOut* spvPatchOut [[buffer(27)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct main0_out
struct main0_in
{
float4 vInputs;
ushort2 m_43;
ushort2 m_44;
};

kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
2 changes: 1 addition & 1 deletion reference/shaders-msl/tesc/matrix-output.multi-patch.tesc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct main0_out
struct main0_in
{
float3 in_tc_attr;
ushort2 m_103;
ushort2 m_104;
};

kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
4 changes: 2 additions & 2 deletions reference/shaders-msl/tesc/reload-tess-level.multi-patch.tesc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ struct main0_out

struct main0_in
{
uint3 m_82;
ushort2 m_86;
uint3 m_83;
ushort2 m_88;
float4 gl_Position;
};

Expand Down
2 changes: 1 addition & 1 deletion reference/shaders-msl/tesc/struct-output.multi-patch.tesc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct main0_out
struct main0_in
{
float3 in_tc_attr;
ushort2 m_107;
ushort2 m_108;
};

kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
Expand Down
2 changes: 1 addition & 1 deletion reference/shaders-msl/tesc/water_tess.multi-patch.tesc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct main0_patchOut
struct main0_in
{
float3 vPatchPosBase;
ushort2 m_430;
ushort2 m_431;
};

static inline __attribute__((always_inline))
Expand Down
5 changes: 4 additions & 1 deletion spirv_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ struct SPIRType : IVariant
type = TypeType
};

spv::Op op = spv::Op::OpNop;
explicit SPIRType(spv::Op op_) : op(op_) {}

enum BaseType
{
Unknown,
Expand Down Expand Up @@ -618,7 +621,7 @@ struct SPIRType : IVariant
uint32_t sampled;
spv::ImageFormat format;
spv::AccessQualifier access;
} image;
} image = {};

// Structs can be declared multiple times if they are used as part of interface blocks.
// We want to detect this so that we only emit the struct definition once.
Expand Down
71 changes: 21 additions & 50 deletions spirv_cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,22 @@ bool Compiler::is_matrix(const SPIRType &type) const

bool Compiler::is_array(const SPIRType &type) const
{
return !type.array.empty();
return type.op == OpTypeArray || type.op == OpTypeRuntimeArray;
}

bool Compiler::is_pointer(const SPIRType &type) const
{
return type.op == OpTypePointer && type.basetype != SPIRType::Unknown; // Ignore function pointers.
}

bool Compiler::is_physical_pointer(const SPIRType &type) const
{
return type.op == OpTypePointer && type.storage == StorageClassPhysicalStorageBuffer;
}

bool Compiler::is_runtime_size_array(const SPIRType &type)
{
if (type.array.empty())
return false;
assert(type.array.size() == type.array_size_literal.size());
return type.array_size_literal.back() && type.array.back() == 0;
return type.op == OpTypeRuntimeArray;
}

ShaderResources Compiler::get_shader_resources() const
Expand Down Expand Up @@ -2738,8 +2745,8 @@ void Compiler::CombinedImageSamplerHandler::register_combined_image_sampler(SPIR
auto ptr_type_id = id + 1;
auto combined_id = id + 2;
auto &base = compiler.expression_type(image_id);
auto &type = compiler.set<SPIRType>(type_id);
auto &ptr_type = compiler.set<SPIRType>(ptr_type_id);
auto &type = compiler.set<SPIRType>(type_id, OpTypeSampledImage);
auto &ptr_type = compiler.set<SPIRType>(ptr_type_id, OpTypePointer);

type = base;
type.self = type_id;
Expand Down Expand Up @@ -2998,7 +3005,7 @@ bool Compiler::CombinedImageSamplerHandler::handle(Op opcode, const uint32_t *ar
{
// Have to invent the sampled image type.
sampled_type = compiler.ir.increase_bound_by(1);
auto &type = compiler.set<SPIRType>(sampled_type);
auto &type = compiler.set<SPIRType>(sampled_type, OpTypeSampledImage);
type = compiler.expression_type(args[2]);
type.self = sampled_type;
type.basetype = SPIRType::SampledImage;
Expand All @@ -3017,7 +3024,7 @@ bool Compiler::CombinedImageSamplerHandler::handle(Op opcode, const uint32_t *ar

// Make a new type, pointer to OpTypeSampledImage, so we can make a variable of this type.
// We will probably have this type lying around, but it doesn't hurt to make duplicates for internal purposes.
auto &type = compiler.set<SPIRType>(type_id);
auto &type = compiler.set<SPIRType>(type_id, OpTypePointer);
auto &base = compiler.get<SPIRType>(sampled_type);
type = base;
type.pointer = true;
Expand Down Expand Up @@ -3063,11 +3070,10 @@ VariableID Compiler::build_dummy_sampler_for_combined_images()
auto ptr_type_id = offset + 1;
auto var_id = offset + 2;

SPIRType sampler_type;
auto &sampler = set<SPIRType>(type_id);
auto &sampler = set<SPIRType>(type_id, OpTypeSampler);
sampler.basetype = SPIRType::Sampler;

auto &ptr_sampler = set<SPIRType>(ptr_type_id);
auto &ptr_sampler = set<SPIRType>(ptr_type_id, OpTypePointer);
ptr_sampler = sampler;
ptr_sampler.self = type_id;
ptr_sampler.storage = StorageClassUniformConstant;
Expand Down Expand Up @@ -5497,7 +5503,7 @@ bool Compiler::type_contains_recursion(const SPIRType &type)

bool Compiler::type_is_array_of_pointers(const SPIRType &type) const
{
if (!type_is_top_level_array(type))
if (!is_array(type))
return false;

// BDA types must have parent type hierarchy.
Expand All @@ -5506,45 +5512,10 @@ bool Compiler::type_is_array_of_pointers(const SPIRType &type) const

// Punch through all array layers.
auto *parent = &get<SPIRType>(type.parent_type);
while (type_is_top_level_array(*parent))
while (is_array(*parent))
parent = &get<SPIRType>(parent->parent_type);

return type_is_top_level_pointer(*parent);
}

bool Compiler::type_is_top_level_pointer(const SPIRType &type) const
{
if (!type.pointer)
return false;

// Function pointers, should not be hit by valid SPIR-V.
// Parent type will be SPIRFunction instead.
if (type.basetype == SPIRType::Unknown)
return false;

// Some types are synthesized in-place without complete type hierarchy and might not have parent types,
// but these types are never array-of-pointer or any complicated BDA type, infer reasonable defaults.
if (type.parent_type)
return type.pointer_depth > get<SPIRType>(type.parent_type).pointer_depth;
else
return true;
}

bool Compiler::type_is_top_level_physical_pointer(const SPIRType &type) const
{
return type_is_top_level_pointer(type) && type.storage == StorageClassPhysicalStorageBuffer;
}

bool Compiler::type_is_top_level_array(const SPIRType &type) const
{
if (type.array.empty())
return false;

// If we have pointer and array, we infer pointer-to-array as it's the only meaningful thing outside BDA.
if (type.parent_type)
return type.array.size() > get<SPIRType>(type.parent_type).array.size();
else
return !type.pointer;
return is_pointer(*parent);
}

bool Compiler::flush_phi_required(BlockID from, BlockID to) const
Expand Down
5 changes: 2 additions & 3 deletions spirv_cross.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ class Compiler
bool is_vector(const SPIRType &type) const;
bool is_matrix(const SPIRType &type) const;
bool is_array(const SPIRType &type) const;
bool is_pointer(const SPIRType &type) const;
bool is_physical_pointer(const SPIRType &type) const;
static bool is_runtime_size_array(const SPIRType &type);
uint32_t expression_type_id(uint32_t id) const;
const SPIRType &expression_type(uint32_t id) const;
Expand Down Expand Up @@ -1148,9 +1150,6 @@ class Compiler
bool check_internal_recursion(const SPIRType &type, std::unordered_set<uint32_t> &checked_ids);
bool type_contains_recursion(const SPIRType &type);
bool type_is_array_of_pointers(const SPIRType &type) const;
bool type_is_top_level_physical_pointer(const SPIRType &type) const;
bool type_is_top_level_pointer(const SPIRType &type) const;
bool type_is_top_level_array(const SPIRType &type) const;
bool type_is_block_like(const SPIRType &type) const;
bool type_is_top_level_block(const SPIRType &type) const;
bool type_is_opaque_value(const SPIRType &type) const;
Expand Down
Loading

0 comments on commit 13aab7f

Please sign in to comment.