2017-11-30 16:29:05 +00:00
|
|
|
// Copyright (c) 2017 Google Inc.
|
2020-10-20 15:55:26 +00:00
|
|
|
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
|
|
|
|
// reserved.
|
2017-11-30 16:29:05 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// Validates correctness of atomic SPIR-V instructions.
|
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/opcode.h"
|
|
|
|
#include "source/spirv_target_env.h"
|
|
|
|
#include "source/util/bitutils.h"
|
|
|
|
#include "source/val/instruction.h"
|
2023-03-28 18:18:19 +00:00
|
|
|
#include "source/val/validate.h"
|
2018-12-06 19:38:15 +00:00
|
|
|
#include "source/val/validate_memory_semantics.h"
|
2018-11-29 19:51:17 +00:00
|
|
|
#include "source/val/validate_scopes.h"
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/val/validation_state.h"
|
2017-11-30 16:29:05 +00:00
|
|
|
|
2019-07-22 12:38:42 +00:00
|
|
|
namespace {
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
bool IsStorageClassAllowedByUniversalRules(spv::StorageClass storage_class) {
|
2019-07-22 12:38:42 +00:00
|
|
|
switch (storage_class) {
|
2022-11-04 21:27:10 +00:00
|
|
|
case spv::StorageClass::Uniform:
|
|
|
|
case spv::StorageClass::StorageBuffer:
|
|
|
|
case spv::StorageClass::Workgroup:
|
|
|
|
case spv::StorageClass::CrossWorkgroup:
|
|
|
|
case spv::StorageClass::Generic:
|
|
|
|
case spv::StorageClass::AtomicCounter:
|
|
|
|
case spv::StorageClass::Image:
|
|
|
|
case spv::StorageClass::Function:
|
|
|
|
case spv::StorageClass::PhysicalStorageBuffer:
|
|
|
|
case spv::StorageClass::TaskPayloadWorkgroupEXT:
|
2019-07-22 12:38:42 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
bool HasReturnType(spv::Op opcode) {
|
2021-03-19 13:23:02 +00:00
|
|
|
switch (opcode) {
|
2022-11-04 21:27:10 +00:00
|
|
|
case spv::Op::OpAtomicStore:
|
|
|
|
case spv::Op::OpAtomicFlagClear:
|
2021-03-19 13:23:02 +00:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
bool HasOnlyFloatReturnType(spv::Op opcode) {
|
2021-03-19 13:23:02 +00:00
|
|
|
switch (opcode) {
|
2022-11-04 21:27:10 +00:00
|
|
|
case spv::Op::OpAtomicFAddEXT:
|
|
|
|
case spv::Op::OpAtomicFMinEXT:
|
|
|
|
case spv::Op::OpAtomicFMaxEXT:
|
2021-03-19 13:23:02 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
bool HasOnlyIntReturnType(spv::Op opcode) {
|
2021-03-19 13:23:02 +00:00
|
|
|
switch (opcode) {
|
2022-11-04 21:27:10 +00:00
|
|
|
case spv::Op::OpAtomicCompareExchange:
|
|
|
|
case spv::Op::OpAtomicCompareExchangeWeak:
|
|
|
|
case spv::Op::OpAtomicIIncrement:
|
|
|
|
case spv::Op::OpAtomicIDecrement:
|
|
|
|
case spv::Op::OpAtomicIAdd:
|
|
|
|
case spv::Op::OpAtomicISub:
|
|
|
|
case spv::Op::OpAtomicSMin:
|
|
|
|
case spv::Op::OpAtomicUMin:
|
|
|
|
case spv::Op::OpAtomicSMax:
|
|
|
|
case spv::Op::OpAtomicUMax:
|
|
|
|
case spv::Op::OpAtomicAnd:
|
|
|
|
case spv::Op::OpAtomicOr:
|
|
|
|
case spv::Op::OpAtomicXor:
|
2021-03-19 13:23:02 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
bool HasIntOrFloatReturnType(spv::Op opcode) {
|
2021-03-19 13:23:02 +00:00
|
|
|
switch (opcode) {
|
2022-11-04 21:27:10 +00:00
|
|
|
case spv::Op::OpAtomicLoad:
|
|
|
|
case spv::Op::OpAtomicExchange:
|
2021-03-19 13:23:02 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
bool HasOnlyBoolReturnType(spv::Op opcode) {
|
2021-03-19 13:23:02 +00:00
|
|
|
switch (opcode) {
|
2022-11-04 21:27:10 +00:00
|
|
|
case spv::Op::OpAtomicFlagTestAndSet:
|
2021-03-19 13:23:02 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-22 12:38:42 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2018-07-10 03:18:44 +00:00
|
|
|
namespace val {
|
2017-11-30 16:29:05 +00:00
|
|
|
|
|
|
|
// Validates correctness of atomic instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t AtomicsPass(ValidationState_t& _, const Instruction* inst) {
|
2022-11-04 21:27:10 +00:00
|
|
|
const spv::Op opcode = inst->opcode();
|
2017-11-30 16:29:05 +00:00
|
|
|
switch (opcode) {
|
2022-11-04 21:27:10 +00:00
|
|
|
case spv::Op::OpAtomicLoad:
|
|
|
|
case spv::Op::OpAtomicStore:
|
|
|
|
case spv::Op::OpAtomicExchange:
|
|
|
|
case spv::Op::OpAtomicFAddEXT:
|
|
|
|
case spv::Op::OpAtomicCompareExchange:
|
|
|
|
case spv::Op::OpAtomicCompareExchangeWeak:
|
|
|
|
case spv::Op::OpAtomicIIncrement:
|
|
|
|
case spv::Op::OpAtomicIDecrement:
|
|
|
|
case spv::Op::OpAtomicIAdd:
|
|
|
|
case spv::Op::OpAtomicISub:
|
|
|
|
case spv::Op::OpAtomicSMin:
|
|
|
|
case spv::Op::OpAtomicUMin:
|
|
|
|
case spv::Op::OpAtomicFMinEXT:
|
|
|
|
case spv::Op::OpAtomicSMax:
|
|
|
|
case spv::Op::OpAtomicUMax:
|
|
|
|
case spv::Op::OpAtomicFMaxEXT:
|
|
|
|
case spv::Op::OpAtomicAnd:
|
|
|
|
case spv::Op::OpAtomicOr:
|
|
|
|
case spv::Op::OpAtomicXor:
|
|
|
|
case spv::Op::OpAtomicFlagTestAndSet:
|
|
|
|
case spv::Op::OpAtomicFlagClear: {
|
2021-03-19 13:23:02 +00:00
|
|
|
const uint32_t result_type = inst->type_id();
|
|
|
|
|
|
|
|
// All current atomics only are scalar result
|
|
|
|
// Validate return type first so can just check if pointer type is same
|
|
|
|
// (if applicable)
|
|
|
|
if (HasReturnType(opcode)) {
|
|
|
|
if (HasOnlyFloatReturnType(opcode) &&
|
|
|
|
!_.IsFloatScalarType(result_type)) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
2021-03-19 13:23:02 +00:00
|
|
|
<< ": expected Result Type to be float scalar type";
|
|
|
|
} else if (HasOnlyIntReturnType(opcode) &&
|
|
|
|
!_.IsIntScalarType(result_type)) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
2021-03-19 13:23:02 +00:00
|
|
|
<< ": expected Result Type to be integer scalar type";
|
|
|
|
} else if (HasIntOrFloatReturnType(opcode) &&
|
|
|
|
!_.IsFloatScalarType(result_type) &&
|
|
|
|
!_.IsIntScalarType(result_type)) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
2021-03-19 13:23:02 +00:00
|
|
|
<< ": expected Result Type to be integer or float scalar type";
|
|
|
|
} else if (HasOnlyBoolReturnType(opcode) &&
|
|
|
|
!_.IsBoolScalarType(result_type)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": expected Result Type to be bool scalar type";
|
2018-03-23 20:15:03 +00:00
|
|
|
}
|
2017-11-30 16:29:05 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 13:23:02 +00:00
|
|
|
uint32_t operand_index = HasReturnType(opcode) ? 2 : 0;
|
2017-11-30 16:29:05 +00:00
|
|
|
const uint32_t pointer_type = _.GetOperandTypeId(inst, operand_index++);
|
|
|
|
uint32_t data_type = 0;
|
2022-11-04 21:27:10 +00:00
|
|
|
spv::StorageClass storage_class;
|
2017-11-30 16:29:05 +00:00
|
|
|
if (!_.GetPointerTypeInfo(pointer_type, &data_type, &storage_class)) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": expected Pointer to be of type OpTypePointer";
|
|
|
|
}
|
|
|
|
|
2021-03-18 14:50:16 +00:00
|
|
|
// Can't use result_type because OpAtomicStore doesn't have a result
|
2022-11-04 21:27:10 +00:00
|
|
|
if (_.IsIntScalarType(data_type) && _.GetBitWidth(data_type) == 64 &&
|
|
|
|
!_.HasCapability(spv::Capability::Int64Atomics)) {
|
2021-03-18 14:50:16 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": 64-bit atomics require the Int64Atomics capability";
|
|
|
|
}
|
|
|
|
|
2019-07-22 12:38:42 +00:00
|
|
|
// Validate storage class against universal rules
|
|
|
|
if (!IsStorageClassAllowedByUniversalRules(storage_class)) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": storage class forbidden by universal validation rules.";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then Shader rules
|
2022-11-04 21:27:10 +00:00
|
|
|
if (_.HasCapability(spv::Capability::Shader)) {
|
2021-03-19 13:23:02 +00:00
|
|
|
// Vulkan environment rule
|
2021-01-14 14:41:18 +00:00
|
|
|
if (spvIsVulkanEnv(_.context()->target_env)) {
|
2022-11-04 21:27:10 +00:00
|
|
|
if ((storage_class != spv::StorageClass::Uniform) &&
|
|
|
|
(storage_class != spv::StorageClass::StorageBuffer) &&
|
|
|
|
(storage_class != spv::StorageClass::Workgroup) &&
|
|
|
|
(storage_class != spv::StorageClass::Image) &&
|
|
|
|
(storage_class != spv::StorageClass::PhysicalStorageBuffer) &&
|
|
|
|
(storage_class != spv::StorageClass::TaskPayloadWorkgroupEXT)) {
|
2021-01-14 14:41:18 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< _.VkErrorID(4686) << spvOpcodeString(opcode)
|
|
|
|
<< ": Vulkan spec only allows storage classes for atomic to "
|
2022-09-02 00:36:15 +00:00
|
|
|
"be: Uniform, Workgroup, Image, StorageBuffer, "
|
|
|
|
"PhysicalStorageBuffer or TaskPayloadWorkgroupEXT.";
|
2021-01-14 14:41:18 +00:00
|
|
|
}
|
2022-11-04 21:27:10 +00:00
|
|
|
} else if (storage_class == spv::StorageClass::Function) {
|
2019-07-22 12:38:42 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": Function storage class forbidden when the Shader "
|
|
|
|
"capability is declared.";
|
|
|
|
}
|
2021-03-19 13:23:02 +00:00
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
if (opcode == spv::Op::OpAtomicFAddEXT) {
|
2021-03-19 13:23:02 +00:00
|
|
|
// result type being float checked already
|
2021-06-24 12:59:43 +00:00
|
|
|
if ((_.GetBitWidth(result_type) == 16) &&
|
2022-11-04 21:27:10 +00:00
|
|
|
(!_.HasCapability(spv::Capability::AtomicFloat16AddEXT))) {
|
2021-06-24 12:59:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": float add atomics require the AtomicFloat32AddEXT "
|
|
|
|
"capability";
|
|
|
|
}
|
2021-03-19 13:23:02 +00:00
|
|
|
if ((_.GetBitWidth(result_type) == 32) &&
|
2022-11-04 21:27:10 +00:00
|
|
|
(!_.HasCapability(spv::Capability::AtomicFloat32AddEXT))) {
|
2021-03-19 13:23:02 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": float add atomics require the AtomicFloat32AddEXT "
|
|
|
|
"capability";
|
|
|
|
}
|
|
|
|
if ((_.GetBitWidth(result_type) == 64) &&
|
2022-11-04 21:27:10 +00:00
|
|
|
(!_.HasCapability(spv::Capability::AtomicFloat64AddEXT))) {
|
2021-03-19 13:23:02 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": float add atomics require the AtomicFloat64AddEXT "
|
|
|
|
"capability";
|
|
|
|
}
|
2022-11-04 21:27:10 +00:00
|
|
|
} else if (opcode == spv::Op::OpAtomicFMinEXT ||
|
|
|
|
opcode == spv::Op::OpAtomicFMaxEXT) {
|
2021-03-24 12:49:21 +00:00
|
|
|
if ((_.GetBitWidth(result_type) == 16) &&
|
2022-11-04 21:27:10 +00:00
|
|
|
(!_.HasCapability(spv::Capability::AtomicFloat16MinMaxEXT))) {
|
2021-03-24 12:49:21 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": float min/max atomics require the "
|
|
|
|
"AtomicFloat16MinMaxEXT capability";
|
|
|
|
}
|
|
|
|
if ((_.GetBitWidth(result_type) == 32) &&
|
2022-11-04 21:27:10 +00:00
|
|
|
(!_.HasCapability(spv::Capability::AtomicFloat32MinMaxEXT))) {
|
2021-03-24 12:49:21 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": float min/max atomics require the "
|
|
|
|
"AtomicFloat32MinMaxEXT capability";
|
|
|
|
}
|
|
|
|
if ((_.GetBitWidth(result_type) == 64) &&
|
2022-11-04 21:27:10 +00:00
|
|
|
(!_.HasCapability(spv::Capability::AtomicFloat64MinMaxEXT))) {
|
2021-03-24 12:49:21 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": float min/max atomics require the "
|
|
|
|
"AtomicFloat64MinMaxEXT capability";
|
|
|
|
}
|
2021-03-19 13:23:02 +00:00
|
|
|
}
|
2019-07-22 12:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// And finally OpenCL environment rules
|
|
|
|
if (spvIsOpenCLEnv(_.context()->target_env)) {
|
2022-11-04 21:27:10 +00:00
|
|
|
if ((storage_class != spv::StorageClass::Function) &&
|
|
|
|
(storage_class != spv::StorageClass::Workgroup) &&
|
|
|
|
(storage_class != spv::StorageClass::CrossWorkgroup) &&
|
|
|
|
(storage_class != spv::StorageClass::Generic)) {
|
2019-07-22 12:38:42 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": storage class must be Function, Workgroup, "
|
|
|
|
"CrossWorkGroup or Generic in the OpenCL environment.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_.context()->target_env == SPV_ENV_OPENCL_1_2) {
|
2022-11-04 21:27:10 +00:00
|
|
|
if (storage_class == spv::StorageClass::Generic) {
|
2018-10-09 15:33:01 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2019-07-22 12:38:42 +00:00
|
|
|
<< "Storage class cannot be Generic in OpenCL 1.2 "
|
|
|
|
"environment";
|
2018-10-09 15:33:01 +00:00
|
|
|
}
|
2019-07-22 12:38:42 +00:00
|
|
|
}
|
2017-11-30 16:29:05 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 13:23:02 +00:00
|
|
|
// If result and pointer type are different, need to do special check here
|
2022-11-04 21:27:10 +00:00
|
|
|
if (opcode == spv::Op::OpAtomicFlagTestAndSet ||
|
|
|
|
opcode == spv::Op::OpAtomicFlagClear) {
|
2017-11-30 16:29:05 +00:00
|
|
|
if (!_.IsIntScalarType(data_type) || _.GetBitWidth(data_type) != 32) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
2021-03-19 13:23:02 +00:00
|
|
|
<< ": expected Pointer to point to a value of 32-bit integer "
|
|
|
|
"type";
|
2017-11-30 16:29:05 +00:00
|
|
|
}
|
2022-11-04 21:27:10 +00:00
|
|
|
} else if (opcode == spv::Op::OpAtomicStore) {
|
2017-11-30 16:29:05 +00:00
|
|
|
if (!_.IsFloatScalarType(data_type) && !_.IsIntScalarType(data_type)) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
2021-03-19 13:23:02 +00:00
|
|
|
<< ": expected Pointer to be a pointer to integer or float "
|
2017-11-30 16:29:05 +00:00
|
|
|
<< "scalar type";
|
|
|
|
}
|
2021-03-19 13:23:02 +00:00
|
|
|
} else if (data_type != result_type) {
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": expected Pointer to point to a value of type Result "
|
|
|
|
"Type";
|
2017-11-30 16:29:05 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
auto memory_scope = inst->GetOperandAs<const uint32_t>(operand_index++);
|
2018-02-06 17:10:11 +00:00
|
|
|
if (auto error = ValidateMemoryScope(_, inst, memory_scope)) {
|
|
|
|
return error;
|
2017-11-30 16:29:05 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 17:35:40 +00:00
|
|
|
const auto equal_semantics_index = operand_index++;
|
2021-03-16 14:53:37 +00:00
|
|
|
if (auto error = ValidateMemorySemantics(_, inst, equal_semantics_index,
|
|
|
|
memory_scope))
|
2018-01-25 18:39:43 +00:00
|
|
|
return error;
|
2017-11-30 16:29:05 +00:00
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
if (opcode == spv::Op::OpAtomicCompareExchange ||
|
|
|
|
opcode == spv::Op::OpAtomicCompareExchangeWeak) {
|
2019-06-17 17:35:40 +00:00
|
|
|
const auto unequal_semantics_index = operand_index++;
|
2021-03-16 14:53:37 +00:00
|
|
|
if (auto error = ValidateMemorySemantics(
|
|
|
|
_, inst, unequal_semantics_index, memory_scope))
|
2018-01-25 18:39:43 +00:00
|
|
|
return error;
|
2019-06-17 17:35:40 +00:00
|
|
|
|
|
|
|
// Volatile bits must match for equal and unequal semantics. Previous
|
|
|
|
// checks guarantee they are 32-bit constants, but we need to recheck
|
|
|
|
// whether they are evaluatable constants.
|
|
|
|
bool is_int32 = false;
|
|
|
|
bool is_equal_const = false;
|
|
|
|
bool is_unequal_const = false;
|
|
|
|
uint32_t equal_value = 0;
|
|
|
|
uint32_t unequal_value = 0;
|
|
|
|
std::tie(is_int32, is_equal_const, equal_value) = _.EvalInt32IfConst(
|
|
|
|
inst->GetOperandAs<uint32_t>(equal_semantics_index));
|
|
|
|
std::tie(is_int32, is_unequal_const, unequal_value) =
|
|
|
|
_.EvalInt32IfConst(
|
|
|
|
inst->GetOperandAs<uint32_t>(unequal_semantics_index));
|
|
|
|
if (is_equal_const && is_unequal_const &&
|
2022-11-04 21:27:10 +00:00
|
|
|
((equal_value & uint32_t(spv::MemorySemanticsMask::Volatile)) ^
|
|
|
|
(unequal_value & uint32_t(spv::MemorySemanticsMask::Volatile)))) {
|
2019-06-17 17:35:40 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_ID, inst)
|
|
|
|
<< "Volatile mask setting must match for Equal and Unequal "
|
|
|
|
"memory semantics";
|
|
|
|
}
|
2017-11-30 16:29:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
if (opcode == spv::Op::OpAtomicStore) {
|
2017-11-30 16:29:05 +00:00
|
|
|
const uint32_t value_type = _.GetOperandTypeId(inst, 3);
|
|
|
|
if (value_type != data_type) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
2018-09-14 18:07:25 +00:00
|
|
|
<< ": expected Value type and the type pointed to by "
|
|
|
|
"Pointer to be the same";
|
2017-11-30 16:29:05 +00:00
|
|
|
}
|
2022-11-04 21:27:10 +00:00
|
|
|
} else if (opcode != spv::Op::OpAtomicLoad &&
|
|
|
|
opcode != spv::Op::OpAtomicIIncrement &&
|
|
|
|
opcode != spv::Op::OpAtomicIDecrement &&
|
|
|
|
opcode != spv::Op::OpAtomicFlagTestAndSet &&
|
|
|
|
opcode != spv::Op::OpAtomicFlagClear) {
|
2017-11-30 16:29:05 +00:00
|
|
|
const uint32_t value_type = _.GetOperandTypeId(inst, operand_index++);
|
|
|
|
if (value_type != result_type) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": expected Value to be of type Result Type";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
if (opcode == spv::Op::OpAtomicCompareExchange ||
|
|
|
|
opcode == spv::Op::OpAtomicCompareExchangeWeak) {
|
2017-11-30 16:29:05 +00:00
|
|
|
const uint32_t comparator_type =
|
|
|
|
_.GetOperandTypeId(inst, operand_index++);
|
|
|
|
if (comparator_type != result_type) {
|
2018-07-31 21:20:43 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-30 16:29:05 +00:00
|
|
|
<< spvOpcodeString(opcode)
|
|
|
|
<< ": expected Comparator to be of type Result Type";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPV_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-07-10 03:18:44 +00:00
|
|
|
} // namespace val
|
2018-07-07 13:38:00 +00:00
|
|
|
} // namespace spvtools
|