Update spirv-tools to v2021.4 (#4862)
This commit is contained in:
+53
-10
@@ -27,6 +27,10 @@ namespace spvtools {
|
||||
namespace val {
|
||||
namespace {
|
||||
|
||||
// Limit the number of checked locations to 4096. Multiplied by 4 to represent
|
||||
// all the components. This limit is set to be well beyond practical use cases.
|
||||
const uint32_t kMaxLocations = 4096 * 4;
|
||||
|
||||
// Returns true if \c inst is an input or output variable.
|
||||
bool is_interface_variable(const Instruction* inst, bool is_spv_1_4) {
|
||||
if (is_spv_1_4) {
|
||||
@@ -195,6 +199,10 @@ uint32_t NumConsumedComponents(ValidationState_t& _, const Instruction* type) {
|
||||
NumConsumedComponents(_, _.FindDef(type->GetOperandAs<uint32_t>(1)));
|
||||
num_components *= type->GetOperandAs<uint32_t>(2);
|
||||
break;
|
||||
case SpvOpTypeArray:
|
||||
// Skip the array.
|
||||
return NumConsumedComponents(_,
|
||||
_.FindDef(type->GetOperandAs<uint32_t>(1)));
|
||||
default:
|
||||
// This is an error that is validated elsewhere.
|
||||
break;
|
||||
@@ -347,6 +355,11 @@ spv_result_t GetLocationsForVariable(
|
||||
uint32_t num_components = NumConsumedComponents(_, sub_type);
|
||||
uint32_t array_location = location + (num_locations * array_idx);
|
||||
uint32_t start = array_location * 4;
|
||||
if (kMaxLocations <= start) {
|
||||
// Too many locations, give up.
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t end = (array_location + num_locations) * 4;
|
||||
if (num_components != 0) {
|
||||
start += component;
|
||||
@@ -416,17 +429,41 @@ spv_result_t GetLocationsForVariable(
|
||||
}
|
||||
|
||||
uint32_t start = location * 4;
|
||||
uint32_t end = (location + num_locations) * 4;
|
||||
if (num_components != 0) {
|
||||
start += component;
|
||||
end = location * 4 + component + num_components;
|
||||
if (kMaxLocations <= start) {
|
||||
// Too many locations, give up.
|
||||
continue;
|
||||
}
|
||||
for (uint32_t l = start; l < end; ++l) {
|
||||
if (!locations->insert(l).second) {
|
||||
return _.diag(SPV_ERROR_INVALID_DATA, entry_point)
|
||||
<< "Entry-point has conflicting " << storage_class
|
||||
<< " location assignment at location " << l / 4
|
||||
<< ", component " << l % 4;
|
||||
|
||||
if (member->opcode() == SpvOpTypeArray && num_components >= 1 &&
|
||||
num_components < 4) {
|
||||
// When an array has an element that takes less than a location in
|
||||
// size, calculate the used locations in a strided manner.
|
||||
for (uint32_t l = location; l < num_locations + location; ++l) {
|
||||
for (uint32_t c = component; c < component + num_components; ++c) {
|
||||
uint32_t check = 4 * l + c;
|
||||
if (!locations->insert(check).second) {
|
||||
return _.diag(SPV_ERROR_INVALID_DATA, entry_point)
|
||||
<< "Entry-point has conflicting " << storage_class
|
||||
<< " location assignment at location " << l
|
||||
<< ", component " << c;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO: There is a hole here is the member is an array of 3- or
|
||||
// 4-element vectors of 64-bit types.
|
||||
uint32_t end = (location + num_locations) * 4;
|
||||
if (num_components != 0) {
|
||||
start += component;
|
||||
end = location * 4 + component + num_components;
|
||||
}
|
||||
for (uint32_t l = start; l < end; ++l) {
|
||||
if (!locations->insert(l).second) {
|
||||
return _.diag(SPV_ERROR_INVALID_DATA, entry_point)
|
||||
<< "Entry-point has conflicting " << storage_class
|
||||
<< " location assignment at location " << l / 4
|
||||
<< ", component " << l % 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -454,6 +491,7 @@ spv_result_t ValidateLocations(ValidationState_t& _,
|
||||
std::unordered_set<uint32_t> input_locations;
|
||||
std::unordered_set<uint32_t> output_locations_index0;
|
||||
std::unordered_set<uint32_t> output_locations_index1;
|
||||
std::unordered_set<uint32_t> seen;
|
||||
for (uint32_t i = 3; i < entry_point->operands().size(); ++i) {
|
||||
auto interface_id = entry_point->GetOperandAs<uint32_t>(i);
|
||||
auto interface_var = _.FindDef(interface_id);
|
||||
@@ -462,6 +500,11 @@ spv_result_t ValidateLocations(ValidationState_t& _,
|
||||
storage_class != SpvStorageClassOutput) {
|
||||
continue;
|
||||
}
|
||||
if (!seen.insert(interface_id).second) {
|
||||
// Pre-1.4 an interface variable could be listed multiple times in an
|
||||
// entry point. Validation for 1.4 or later is done elsewhere.
|
||||
continue;
|
||||
}
|
||||
|
||||
auto locations = (storage_class == SpvStorageClassInput)
|
||||
? &input_locations
|
||||
|
||||
Reference in New Issue
Block a user