mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Updated spirv-tools.
This commit is contained in:
77
3rdparty/spirv-tools/source/val/validate.cpp
vendored
77
3rdparty/spirv-tools/source/val/validate.cpp
vendored
@@ -111,57 +111,6 @@ spv_result_t ValidateForwardDecls(ValidationState_t& _) {
|
||||
<< id_str.substr(0, id_str.size() - 1);
|
||||
}
|
||||
|
||||
std::vector<std::string> CalculateNamesForEntryPoint(ValidationState_t& _,
|
||||
const uint32_t id) {
|
||||
auto id_descriptions = _.entry_point_descriptions(id);
|
||||
auto id_names = std::vector<std::string>();
|
||||
id_names.reserve((id_descriptions.size()));
|
||||
|
||||
for (auto description : id_descriptions) id_names.push_back(description.name);
|
||||
|
||||
return id_names;
|
||||
}
|
||||
|
||||
spv_result_t ValidateEntryPointNameUnique(ValidationState_t& _,
|
||||
const uint32_t id) {
|
||||
auto id_names = CalculateNamesForEntryPoint(_, id);
|
||||
const auto names =
|
||||
std::unordered_set<std::string>(id_names.begin(), id_names.end());
|
||||
|
||||
if (id_names.size() != names.size()) {
|
||||
std::sort(id_names.begin(), id_names.end());
|
||||
for (size_t i = 0; i < id_names.size() - 1; i++) {
|
||||
if (id_names[i] == id_names[i + 1]) {
|
||||
return _.diag(SPV_ERROR_INVALID_BINARY, _.FindDef(id))
|
||||
<< "Entry point name \"" << id_names[i]
|
||||
<< "\" is not unique, which is not allow in WebGPU env.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto other_id : _.entry_points()) {
|
||||
if (other_id == id) continue;
|
||||
const auto other_id_names = CalculateNamesForEntryPoint(_, other_id);
|
||||
for (const auto& other_id_name : other_id_names) {
|
||||
if (names.find(other_id_name) != names.end()) {
|
||||
return _.diag(SPV_ERROR_INVALID_BINARY, _.FindDef(id))
|
||||
<< "Entry point name \"" << other_id_name
|
||||
<< "\" is not unique, which is not allow in WebGPU env.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SPV_SUCCESS;
|
||||
}
|
||||
|
||||
spv_result_t ValidateEntryPointNamesUnique(ValidationState_t& _) {
|
||||
for (const auto id : _.entry_points()) {
|
||||
auto result = ValidateEntryPointNameUnique(_, id);
|
||||
if (result != SPV_SUCCESS) return result;
|
||||
}
|
||||
return SPV_SUCCESS;
|
||||
}
|
||||
|
||||
// Entry point validation. Based on 2.16.1 (Universal Validation Rules) of the
|
||||
// SPIRV spec:
|
||||
// * There is at least one OpEntryPoint instruction, unless the Linkage
|
||||
@@ -169,8 +118,7 @@ spv_result_t ValidateEntryPointNamesUnique(ValidationState_t& _) {
|
||||
// * No function can be targeted by both an OpEntryPoint instruction and an
|
||||
// OpFunctionCall instruction.
|
||||
//
|
||||
// Additionally enforces that entry points for Vulkan and WebGPU should not have
|
||||
// recursion. And that entry names should be unique for WebGPU.
|
||||
// Additionally enforces that entry points for Vulkan should not have recursion.
|
||||
spv_result_t ValidateEntryPoints(ValidationState_t& _) {
|
||||
_.ComputeFunctionToEntryPointMapping();
|
||||
_.ComputeRecursiveEntryPoints();
|
||||
@@ -189,21 +137,15 @@ spv_result_t ValidateEntryPoints(ValidationState_t& _) {
|
||||
"an OpFunctionCall instruction.";
|
||||
}
|
||||
|
||||
// For Vulkan and WebGPU, the static function-call graph for an entry point
|
||||
// For Vulkan, the static function-call graph for an entry point
|
||||
// must not contain cycles.
|
||||
if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
|
||||
if (spvIsVulkanEnv(_.context()->target_env)) {
|
||||
if (_.recursive_entry_points().find(entry_point) !=
|
||||
_.recursive_entry_points().end()) {
|
||||
return _.diag(SPV_ERROR_INVALID_BINARY, _.FindDef(entry_point))
|
||||
<< "Entry points may not have a call graph with cycles.";
|
||||
}
|
||||
}
|
||||
|
||||
// For WebGPU all entry point names must be unique.
|
||||
if (spvIsWebGPUEnv(_.context()->target_env)) {
|
||||
const auto result = ValidateEntryPointNamesUnique(_);
|
||||
if (result != SPV_SUCCESS) return result;
|
||||
}
|
||||
}
|
||||
|
||||
return SPV_SUCCESS;
|
||||
@@ -223,12 +165,6 @@ spv_result_t ValidateBinaryUsingContextAndValidationState(
|
||||
<< "Invalid SPIR-V magic number.";
|
||||
}
|
||||
|
||||
if (spvIsWebGPUEnv(context.target_env) && endian != SPV_ENDIANNESS_LITTLE) {
|
||||
return DiagnosticStream(position, context.consumer, "",
|
||||
SPV_ERROR_INVALID_BINARY)
|
||||
<< "WebGPU requires SPIR-V to be little endian.";
|
||||
}
|
||||
|
||||
spv_header_t header;
|
||||
if (spvBinaryHeaderGet(binary.get(), endian, &header)) {
|
||||
return DiagnosticStream(position, context.consumer, "",
|
||||
@@ -321,13 +257,6 @@ spv_result_t ValidateBinaryUsingContextAndValidationState(
|
||||
}
|
||||
|
||||
const auto called_id = inst->GetOperandAs<uint32_t>(2);
|
||||
if (spvIsWebGPUEnv(context.target_env) &&
|
||||
!vstate->IsFunctionCallDefined(called_id)) {
|
||||
return vstate->diag(SPV_ERROR_INVALID_LAYOUT, &instruction)
|
||||
<< "For WebGPU, functions need to be defined before being "
|
||||
"called.";
|
||||
}
|
||||
|
||||
vstate->AddFunctionCallTarget(called_id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user