Skip to content

Commit

Permalink
[update #3] dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tiawl committed Apr 23, 2024
2 parents 927d040 + fed2510 commit 8918dee
Show file tree
Hide file tree
Showing 28 changed files with 397 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .versions/spirv-tools
Original file line number Diff line number Diff line change
@@ -1 +1 @@
vulkan-sdk-1.3.280.0
v2024.2.rc1
10 changes: 9 additions & 1 deletion spirv-tools/source/ext_inst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "glsl.std.450.insts.inc"
#include "nonsemantic.clspvreflection.insts.inc"
#include "nonsemantic.shader.debuginfo.100.insts.inc"
#include "nonsemantic.vkspreflection.insts.inc"
#include "opencl.debuginfo.100.insts.inc"
#include "opencl.std.insts.inc"

Expand Down Expand Up @@ -62,6 +63,9 @@ static const spv_ext_inst_group_t kGroups_1_0[] = {
{SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION,
ARRAY_SIZE(nonsemantic_clspvreflection_entries),
nonsemantic_clspvreflection_entries},
{SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION,
ARRAY_SIZE(nonsemantic_vkspreflection_entries),
nonsemantic_vkspreflection_entries},
};

static const spv_ext_inst_table_t kTable_1_0 = {ARRAY_SIZE(kGroups_1_0),
Expand Down Expand Up @@ -138,6 +142,9 @@ spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) {
if (!strncmp("NonSemantic.ClspvReflection.", name, 28)) {
return SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION;
}
if (!strncmp("NonSemantic.VkspReflection.", name, 27)) {
return SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION;
}
// ensure to add any known non-semantic extended instruction sets
// above this point, and update spvExtInstIsNonSemantic()
if (!strncmp("NonSemantic.", name, 12)) {
Expand All @@ -149,7 +156,8 @@ spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) {
bool spvExtInstIsNonSemantic(const spv_ext_inst_type_t type) {
if (type == SPV_EXT_INST_TYPE_NONSEMANTIC_UNKNOWN ||
type == SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100 ||
type == SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION) {
type == SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION ||
type == SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION) {
return true;
}
return false;
Expand Down
3 changes: 3 additions & 0 deletions spirv-tools/source/opcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ bool spvOpcodeReturnsLogicalVariablePointer(const spv::Op opcode) {
case spv::Op::OpPtrAccessChain:
case spv::Op::OpLoad:
case spv::Op::OpConstantNull:
case spv::Op::OpRawAccessChainNV:
return true;
default:
return false;
Expand All @@ -309,6 +310,7 @@ int32_t spvOpcodeReturnsLogicalPointer(const spv::Op opcode) {
case spv::Op::OpFunctionParameter:
case spv::Op::OpImageTexelPointer:
case spv::Op::OpCopyObject:
case spv::Op::OpRawAccessChainNV:
return true;
default:
return false;
Expand Down Expand Up @@ -754,6 +756,7 @@ bool spvOpcodeIsAccessChain(spv::Op opcode) {
case spv::Op::OpInBoundsAccessChain:
case spv::Op::OpPtrAccessChain:
case spv::Op::OpInBoundsPtrAccessChain:
case spv::Op::OpRawAccessChainNV:
return true;
default:
return false;
Expand Down
4 changes: 2 additions & 2 deletions spirv-tools/source/opt/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ const Constant* ConstantManager::GetIntConst(uint64_t val, int32_t bitWidth,
int32_t num_of_bit_to_ignore = 64 - bitWidth;
val = static_cast<int64_t>(val << num_of_bit_to_ignore) >>
num_of_bit_to_ignore;
} else {
} else if (bitWidth < 64) {
// Clear the upper bit that are not used.
uint64_t mask = ((1ull << bitWidth) - 1);
val &= mask;
Expand All @@ -511,7 +511,7 @@ const Constant* ConstantManager::GetIntConst(uint64_t val, int32_t bitWidth,
// If the value is more than 32-bit, we need to split the operands into two
// 32-bit integers.
return GetConstant(
int_type, {static_cast<uint32_t>(val >> 32), static_cast<uint32_t>(val)});
int_type, {static_cast<uint32_t>(val), static_cast<uint32_t>(val >> 32)});
}

uint32_t ConstantManager::GetUIntConstId(uint32_t val) {
Expand Down
13 changes: 13 additions & 0 deletions spirv-tools/source/opt/inline_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ uint32_t InlinePass::CreateReturnVar(
{(uint32_t)spv::StorageClass::Function}}}));
new_vars->push_back(std::move(var_inst));
get_decoration_mgr()->CloneDecorations(calleeFn->result_id(), returnVarId);

// Decorate the return var with AliasedPointer if the storage class of the
// pointee type is PhysicalStorageBuffer.
auto const pointee_type =
type_mgr->GetType(returnVarTypeId)->AsPointer()->pointee_type();
if (pointee_type->AsPointer() != nullptr) {
if (pointee_type->AsPointer()->storage_class() ==
spv::StorageClass::PhysicalStorageBuffer) {
get_decoration_mgr()->AddDecoration(
returnVarId, uint32_t(spv::Decoration::AliasedPointer));
}
}

return returnVarId;
}

Expand Down
3 changes: 3 additions & 0 deletions spirv-tools/source/opt/ir_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ void IRContext::BuildInvalidAnalyses(IRContext::Analysis set) {
if (set & kAnalysisDebugInfo) {
BuildDebugInfoManager();
}
if (set & kAnalysisLiveness) {
BuildLivenessManager();
}
}

void IRContext::InvalidateAnalysesExceptFor(
Expand Down
2 changes: 1 addition & 1 deletion spirv-tools/source/opt/ir_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class IRContext {
kAnalysisTypes = 1 << 15,
kAnalysisDebugInfo = 1 << 16,
kAnalysisLiveness = 1 << 17,
kAnalysisEnd = 1 << 17
kAnalysisEnd = 1 << 18
};

using ProcessFunction = std::function<bool(Function*)>;
Expand Down
3 changes: 2 additions & 1 deletion spirv-tools/source/opt/trim_capabilities_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class TrimCapabilitiesPass : public Pass {
spv::Capability::StoragePushConstant16,
spv::Capability::StorageUniform16,
spv::Capability::StorageUniformBufferBlock16,
spv::Capability::VulkanMemoryModelDeviceScope
spv::Capability::VulkanMemoryModelDeviceScope,
spv::Capability::GroupNonUniformPartitionedNV
// clang-format on
};

Expand Down
64 changes: 40 additions & 24 deletions spirv-tools/source/opt/type_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,24 @@ void TypeManager::CreateDecoration(uint32_t target,
context()->get_def_use_mgr()->AnalyzeInstUse(inst);
}

Type* TypeManager::RebuildType(const Type& type) {
Type* TypeManager::RebuildType(uint32_t type_id, const Type& type) {
assert(type_id != 0);

// The comparison and hash on the type pool will avoid inserting the rebuilt
// type if an equivalent type already exists. The rebuilt type will be deleted
// when it goes out of scope at the end of the function in that case. Repeated
// insertions of the same Type will, at most, keep one corresponding object in
// the type pool.
std::unique_ptr<Type> rebuilt_ty;

// If |type_id| is already present in the type pool, return the existing type.
// This saves extra work in the type builder and prevents running into
// circular issues (https://github.com/KhronosGroup/SPIRV-Tools/issues/5623).
Type* pool_ty = GetType(type_id);
if (pool_ty != nullptr) {
return pool_ty;
}

switch (type.kind()) {
#define DefineNoSubtypeCase(kind) \
case Type::k##kind: \
Expand All @@ -550,51 +561,54 @@ Type* TypeManager::RebuildType(const Type& type) {
case Type::kVector: {
const Vector* vec_ty = type.AsVector();
const Type* ele_ty = vec_ty->element_type();
rebuilt_ty =
MakeUnique<Vector>(RebuildType(*ele_ty), vec_ty->element_count());
rebuilt_ty = MakeUnique<Vector>(RebuildType(GetId(ele_ty), *ele_ty),
vec_ty->element_count());
break;
}
case Type::kMatrix: {
const Matrix* mat_ty = type.AsMatrix();
const Type* ele_ty = mat_ty->element_type();
rebuilt_ty =
MakeUnique<Matrix>(RebuildType(*ele_ty), mat_ty->element_count());
rebuilt_ty = MakeUnique<Matrix>(RebuildType(GetId(ele_ty), *ele_ty),
mat_ty->element_count());
break;
}
case Type::kImage: {
const Image* image_ty = type.AsImage();
const Type* ele_ty = image_ty->sampled_type();
rebuilt_ty =
MakeUnique<Image>(RebuildType(*ele_ty), image_ty->dim(),
image_ty->depth(), image_ty->is_arrayed(),
image_ty->is_multisampled(), image_ty->sampled(),
image_ty->format(), image_ty->access_qualifier());
rebuilt_ty = MakeUnique<Image>(
RebuildType(GetId(ele_ty), *ele_ty), image_ty->dim(),
image_ty->depth(), image_ty->is_arrayed(),
image_ty->is_multisampled(), image_ty->sampled(), image_ty->format(),
image_ty->access_qualifier());
break;
}
case Type::kSampledImage: {
const SampledImage* image_ty = type.AsSampledImage();
const Type* ele_ty = image_ty->image_type();
rebuilt_ty = MakeUnique<SampledImage>(RebuildType(*ele_ty));
rebuilt_ty =
MakeUnique<SampledImage>(RebuildType(GetId(ele_ty), *ele_ty));
break;
}
case Type::kArray: {
const Array* array_ty = type.AsArray();
rebuilt_ty =
MakeUnique<Array>(array_ty->element_type(), array_ty->length_info());
const Type* ele_ty = array_ty->element_type();
rebuilt_ty = MakeUnique<Array>(RebuildType(GetId(ele_ty), *ele_ty),
array_ty->length_info());
break;
}
case Type::kRuntimeArray: {
const RuntimeArray* array_ty = type.AsRuntimeArray();
const Type* ele_ty = array_ty->element_type();
rebuilt_ty = MakeUnique<RuntimeArray>(RebuildType(*ele_ty));
rebuilt_ty =
MakeUnique<RuntimeArray>(RebuildType(GetId(ele_ty), *ele_ty));
break;
}
case Type::kStruct: {
const Struct* struct_ty = type.AsStruct();
std::vector<const Type*> subtypes;
subtypes.reserve(struct_ty->element_types().size());
for (const auto* ele_ty : struct_ty->element_types()) {
subtypes.push_back(RebuildType(*ele_ty));
subtypes.push_back(RebuildType(GetId(ele_ty), *ele_ty));
}
rebuilt_ty = MakeUnique<Struct>(subtypes);
Struct* rebuilt_struct = rebuilt_ty->AsStruct();
Expand All @@ -611,7 +625,7 @@ Type* TypeManager::RebuildType(const Type& type) {
case Type::kPointer: {
const Pointer* pointer_ty = type.AsPointer();
const Type* ele_ty = pointer_ty->pointee_type();
rebuilt_ty = MakeUnique<Pointer>(RebuildType(*ele_ty),
rebuilt_ty = MakeUnique<Pointer>(RebuildType(GetId(ele_ty), *ele_ty),
pointer_ty->storage_class());
break;
}
Expand All @@ -621,9 +635,10 @@ Type* TypeManager::RebuildType(const Type& type) {
std::vector<const Type*> param_types;
param_types.reserve(function_ty->param_types().size());
for (const auto* param_ty : function_ty->param_types()) {
param_types.push_back(RebuildType(*param_ty));
param_types.push_back(RebuildType(GetId(param_ty), *param_ty));
}
rebuilt_ty = MakeUnique<Function>(RebuildType(*ret_ty), param_types);
rebuilt_ty = MakeUnique<Function>(RebuildType(GetId(ret_ty), *ret_ty),
param_types);
break;
}
case Type::kForwardPointer: {
Expand All @@ -633,24 +648,25 @@ Type* TypeManager::RebuildType(const Type& type) {
const Pointer* target_ptr = forward_ptr_ty->target_pointer();
if (target_ptr) {
rebuilt_ty->AsForwardPointer()->SetTargetPointer(
RebuildType(*target_ptr)->AsPointer());
RebuildType(GetId(target_ptr), *target_ptr)->AsPointer());
}
break;
}
case Type::kCooperativeMatrixNV: {
const CooperativeMatrixNV* cm_type = type.AsCooperativeMatrixNV();
const Type* component_type = cm_type->component_type();
rebuilt_ty = MakeUnique<CooperativeMatrixNV>(
RebuildType(*component_type), cm_type->scope_id(), cm_type->rows_id(),
cm_type->columns_id());
RebuildType(GetId(component_type), *component_type),
cm_type->scope_id(), cm_type->rows_id(), cm_type->columns_id());
break;
}
case Type::kCooperativeMatrixKHR: {
const CooperativeMatrixKHR* cm_type = type.AsCooperativeMatrixKHR();
const Type* component_type = cm_type->component_type();
rebuilt_ty = MakeUnique<CooperativeMatrixKHR>(
RebuildType(*component_type), cm_type->scope_id(), cm_type->rows_id(),
cm_type->columns_id(), cm_type->use_id());
RebuildType(GetId(component_type), *component_type),
cm_type->scope_id(), cm_type->rows_id(), cm_type->columns_id(),
cm_type->use_id());
break;
}
default:
Expand All @@ -669,7 +685,7 @@ Type* TypeManager::RebuildType(const Type& type) {
void TypeManager::RegisterType(uint32_t id, const Type& type) {
// Rebuild |type| so it and all its constituent types are owned by the type
// pool.
Type* rebuilt = RebuildType(type);
Type* rebuilt = RebuildType(id, type);
assert(rebuilt->IsSame(&type));
id_to_type_[id] = rebuilt;
if (GetId(rebuilt) == 0) {
Expand Down
4 changes: 3 additions & 1 deletion spirv-tools/source/opt/type_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ class TypeManager {
// Returns an equivalent pointer to |type| built in terms of pointers owned by
// |type_pool_|. For example, if |type| is a vec3 of bool, it will be rebuilt
// replacing the bool subtype with one owned by |type_pool_|.
Type* RebuildType(const Type& type);
//
// The re-built type will have ID |type_id|.
Type* RebuildType(uint32_t type_id, const Type& type);

// Completes the incomplete type |type|, by replaces all references to
// ForwardPointer by the defining Pointer.
Expand Down
2 changes: 1 addition & 1 deletion spirv-tools/source/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ typedef struct spv_ext_inst_desc_t {
const uint32_t ext_inst;
const uint32_t numCapabilities;
const spv::Capability* capabilities;
const spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger?
const spv_operand_type_t operandTypes[40]; // vksp needs at least 40
} spv_ext_inst_desc_t;

typedef struct spv_ext_inst_group_t {
Expand Down
3 changes: 3 additions & 0 deletions spirv-tools/source/val/validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ spv_result_t ValidateEntryPoints(ValidationState_t& _) {
if (auto error = ValidateFloatControls2(_)) {
return error;
}
if (auto error = ValidateDuplicateExecutionModes(_)) {
return error;
}

return SPV_SUCCESS;
}
Expand Down
7 changes: 7 additions & 0 deletions spirv-tools/source/val/validate.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ spv_result_t ValidateInterfaces(ValidationState_t& _);
/// @return SPV_SUCCESS if no errors are found.
spv_result_t ValidateFloatControls2(ValidationState_t& _);

/// @brief Validates duplicated execution modes for each entry point.
///
/// @param[in] _ the validation state of the module
///
/// @return SPV_SUCCESS if no errors are found.
spv_result_t ValidateDuplicateExecutionModes(ValidationState_t& _);

/// @brief Validates memory instructions
///
/// @param[in] _ the validation state of the module
Expand Down
3 changes: 2 additions & 1 deletion spirv-tools/source/val/validate_annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ spv_result_t ValidateDecorationTarget(ValidationState_t& _, spv::Decoration dec,
case spv::Decoration::RestrictPointer:
case spv::Decoration::AliasedPointer:
if (target->opcode() != spv::Op::OpVariable &&
target->opcode() != spv::Op::OpFunctionParameter) {
target->opcode() != spv::Op::OpFunctionParameter &&
target->opcode() != spv::Op::OpRawAccessChainNV) {
return fail(0) << "must be a memory object declaration";
}
if (_.GetIdOpcode(target->type_id()) != spv::Op::OpTypePointer) {
Expand Down
21 changes: 8 additions & 13 deletions spirv-tools/source/val/validate_decorations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,21 +1325,14 @@ spv_result_t CheckDecorationsOfBuffers(ValidationState_t& vstate) {

// Returns true if |decoration| cannot be applied to the same id more than once.
bool AtMostOncePerId(spv::Decoration decoration) {
return decoration == spv::Decoration::ArrayStride;
return decoration != spv::Decoration::UserSemantic &&
decoration != spv::Decoration::FuncParamAttr;
}

// Returns true if |decoration| cannot be applied to the same member more than
// once.
bool AtMostOncePerMember(spv::Decoration decoration) {
switch (decoration) {
case spv::Decoration::Offset:
case spv::Decoration::MatrixStride:
case spv::Decoration::RowMajor:
case spv::Decoration::ColMajor:
return true;
default:
return false;
}
return decoration != spv::Decoration::UserSemantic;
}

spv_result_t CheckDecorationsCompatibility(ValidationState_t& vstate) {
Expand Down Expand Up @@ -1556,7 +1549,8 @@ spv_result_t CheckNonWritableDecoration(ValidationState_t& vstate,
const auto opcode = inst.opcode();
const auto type_id = inst.type_id();
if (opcode != spv::Op::OpVariable &&
opcode != spv::Op::OpFunctionParameter) {
opcode != spv::Op::OpFunctionParameter &&
opcode != spv::Op::OpRawAccessChainNV) {
return vstate.diag(SPV_ERROR_INVALID_ID, &inst)
<< "Target of NonWritable decoration must be a memory object "
"declaration (a variable or a function parameter)";
Expand All @@ -1569,10 +1563,11 @@ spv_result_t CheckNonWritableDecoration(ValidationState_t& vstate,
vstate.features().nonwritable_var_in_function_or_private) {
// New permitted feature in SPIR-V 1.4.
} else if (
// It may point to a UBO, SSBO, or storage image.
// It may point to a UBO, SSBO, storage image, or raw access chain.
vstate.IsPointerToUniformBlock(type_id) ||
vstate.IsPointerToStorageBuffer(type_id) ||
vstate.IsPointerToStorageImage(type_id)) {
vstate.IsPointerToStorageImage(type_id) ||
opcode == spv::Op::OpRawAccessChainNV) {
} else {
return vstate.diag(SPV_ERROR_INVALID_ID, &inst)
<< "Target of NonWritable decoration is invalid: must point to a "
Expand Down
Loading

0 comments on commit 8918dee

Please sign in to comment.