2017-09-28 18:53:24 +00:00
|
|
|
// Copyright (c) 2017 Google Inc.
|
|
|
|
//
|
|
|
|
// 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 conversion instructions.
|
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/val/validate.h"
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/diagnostic.h"
|
|
|
|
#include "source/opcode.h"
|
|
|
|
#include "source/val/instruction.h"
|
|
|
|
#include "source/val/validation_state.h"
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2018-07-10 03:18:44 +00:00
|
|
|
namespace val {
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
// Validates correctness of conversion instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t ConversionPass(ValidationState_t& _, const Instruction* inst) {
|
|
|
|
const SpvOp opcode = inst->opcode();
|
|
|
|
const uint32_t result_type = inst->type_id();
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpConvertFToU: {
|
|
|
|
if (!_.IsUnsignedIntScalarType(result_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsUnsignedIntVectorType(result_type) &&
|
|
|
|
!_.IsUnsignedIntCooperativeMatrixType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected unsigned int scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
if (!input_type || (!_.IsFloatScalarType(input_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsFloatVectorType(input_type) &&
|
|
|
|
!_.IsFloatCooperativeMatrixType(input_type)))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be float scalar or vector: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2019-02-25 22:43:11 +00:00
|
|
|
if (_.IsCooperativeMatrixType(result_type) ||
|
|
|
|
_.IsCooperativeMatrixType(input_type)) {
|
|
|
|
spv_result_t ret =
|
|
|
|
_.CooperativeMatrixShapesMatch(inst, result_type, input_type);
|
|
|
|
if (ret != SPV_SUCCESS) return ret;
|
|
|
|
} else {
|
|
|
|
if (_.GetDimension(result_type) != _.GetDimension(input_type))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected input to have the same dimension as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2018-10-19 17:45:26 +00:00
|
|
|
if (!_.features().use_int8_type && (8 == _.GetBitWidth(result_type)))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Invalid cast to 8-bit integer from a floating-point: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpConvertFToS: {
|
2019-02-25 22:43:11 +00:00
|
|
|
if (!_.IsIntScalarType(result_type) && !_.IsIntVectorType(result_type) &&
|
|
|
|
!_.IsIntCooperativeMatrixType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected int scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
if (!input_type || (!_.IsFloatScalarType(input_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsFloatVectorType(input_type) &&
|
|
|
|
!_.IsFloatCooperativeMatrixType(input_type)))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be float scalar or vector: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2019-02-25 22:43:11 +00:00
|
|
|
if (_.IsCooperativeMatrixType(result_type) ||
|
|
|
|
_.IsCooperativeMatrixType(input_type)) {
|
|
|
|
spv_result_t ret =
|
|
|
|
_.CooperativeMatrixShapesMatch(inst, result_type, input_type);
|
|
|
|
if (ret != SPV_SUCCESS) return ret;
|
|
|
|
} else {
|
|
|
|
if (_.GetDimension(result_type) != _.GetDimension(input_type))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected input to have the same dimension as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2018-10-19 17:45:26 +00:00
|
|
|
if (!_.features().use_int8_type && (8 == _.GetBitWidth(result_type)))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Invalid cast to 8-bit integer from a floating-point: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpConvertSToF:
|
|
|
|
case SpvOpConvertUToF: {
|
|
|
|
if (!_.IsFloatScalarType(result_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsFloatVectorType(result_type) &&
|
|
|
|
!_.IsFloatCooperativeMatrixType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
2017-11-08 17:40:02 +00:00
|
|
|
if (!input_type ||
|
2019-02-25 22:43:11 +00:00
|
|
|
(!_.IsIntScalarType(input_type) && !_.IsIntVectorType(input_type) &&
|
|
|
|
!_.IsIntCooperativeMatrixType(input_type)))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be int scalar or vector: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2019-02-25 22:43:11 +00:00
|
|
|
if (_.IsCooperativeMatrixType(result_type) ||
|
|
|
|
_.IsCooperativeMatrixType(input_type)) {
|
|
|
|
spv_result_t ret =
|
|
|
|
_.CooperativeMatrixShapesMatch(inst, result_type, input_type);
|
|
|
|
if (ret != SPV_SUCCESS) return ret;
|
|
|
|
} else {
|
|
|
|
if (_.GetDimension(result_type) != _.GetDimension(input_type))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected input to have the same dimension as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2018-10-19 17:45:26 +00:00
|
|
|
if (!_.features().use_int8_type && (8 == _.GetBitWidth(input_type)))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Invalid cast to floating-point from an 8-bit integer: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpUConvert: {
|
|
|
|
if (!_.IsUnsignedIntScalarType(result_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsUnsignedIntVectorType(result_type) &&
|
|
|
|
!_.IsUnsignedIntCooperativeMatrixType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2018-04-06 13:36:08 +00:00
|
|
|
<< "Expected unsigned int scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
2018-04-06 13:36:08 +00:00
|
|
|
if (!input_type ||
|
2019-02-25 22:43:11 +00:00
|
|
|
(!_.IsIntScalarType(input_type) && !_.IsIntVectorType(input_type) &&
|
|
|
|
!_.IsIntCooperativeMatrixType(input_type)))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2018-04-06 13:36:08 +00:00
|
|
|
<< "Expected input to be int scalar or vector: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2019-02-25 22:43:11 +00:00
|
|
|
if (_.IsCooperativeMatrixType(result_type) ||
|
|
|
|
_.IsCooperativeMatrixType(input_type)) {
|
|
|
|
spv_result_t ret =
|
|
|
|
_.CooperativeMatrixShapesMatch(inst, result_type, input_type);
|
|
|
|
if (ret != SPV_SUCCESS) return ret;
|
|
|
|
} else {
|
|
|
|
if (_.GetDimension(result_type) != _.GetDimension(input_type))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected input to have the same dimension as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (_.GetBitWidth(result_type) == _.GetBitWidth(input_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2018-04-06 13:36:08 +00:00
|
|
|
<< "Expected input to have different bit width from Result "
|
|
|
|
"Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpSConvert: {
|
2019-02-25 22:43:11 +00:00
|
|
|
if (!_.IsIntScalarType(result_type) && !_.IsIntVectorType(result_type) &&
|
|
|
|
!_.IsIntCooperativeMatrixType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected int scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
2017-11-08 17:40:02 +00:00
|
|
|
if (!input_type ||
|
2019-02-25 22:43:11 +00:00
|
|
|
(!_.IsIntScalarType(input_type) && !_.IsIntVectorType(input_type) &&
|
|
|
|
!_.IsIntCooperativeMatrixType(input_type)))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be int scalar or vector: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2019-02-25 22:43:11 +00:00
|
|
|
if (_.IsCooperativeMatrixType(result_type) ||
|
|
|
|
_.IsCooperativeMatrixType(input_type)) {
|
|
|
|
spv_result_t ret =
|
|
|
|
_.CooperativeMatrixShapesMatch(inst, result_type, input_type);
|
|
|
|
if (ret != SPV_SUCCESS) return ret;
|
|
|
|
} else {
|
|
|
|
if (_.GetDimension(result_type) != _.GetDimension(input_type))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected input to have the same dimension as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (_.GetBitWidth(result_type) == _.GetBitWidth(input_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to have different bit width from Result "
|
|
|
|
"Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpFConvert: {
|
|
|
|
if (!_.IsFloatScalarType(result_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsFloatVectorType(result_type) &&
|
|
|
|
!_.IsFloatCooperativeMatrixType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected float scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
if (!input_type || (!_.IsFloatScalarType(input_type) &&
|
2019-02-25 22:43:11 +00:00
|
|
|
!_.IsFloatVectorType(input_type) &&
|
|
|
|
!_.IsFloatCooperativeMatrixType(input_type)))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be float scalar or vector: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2019-02-25 22:43:11 +00:00
|
|
|
if (_.IsCooperativeMatrixType(result_type) ||
|
|
|
|
_.IsCooperativeMatrixType(input_type)) {
|
|
|
|
spv_result_t ret =
|
|
|
|
_.CooperativeMatrixShapesMatch(inst, result_type, input_type);
|
|
|
|
if (ret != SPV_SUCCESS) return ret;
|
|
|
|
} else {
|
|
|
|
if (_.GetDimension(result_type) != _.GetDimension(input_type))
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Expected input to have the same dimension as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (_.GetBitWidth(result_type) == _.GetBitWidth(input_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to have different bit width from Result "
|
|
|
|
"Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpQuantizeToF16: {
|
|
|
|
if ((!_.IsFloatScalarType(result_type) &&
|
2017-11-08 17:40:02 +00:00
|
|
|
!_.IsFloatVectorType(result_type)) ||
|
2017-09-28 18:53:24 +00:00
|
|
|
_.GetBitWidth(result_type) != 32)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected 32-bit float scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
if (input_type != result_type)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input type to be equal to Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpConvertPtrToU: {
|
|
|
|
if (!_.IsUnsignedIntScalarType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected unsigned int scalar type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
if (!_.IsPointerType(input_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be a pointer: " << spvOpcodeString(opcode);
|
2019-01-07 18:19:24 +00:00
|
|
|
|
|
|
|
if (_.addressing_model() == SpvAddressingModelLogical)
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Logical addressing not supported: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
|
|
|
|
if (_.addressing_model() ==
|
|
|
|
SpvAddressingModelPhysicalStorageBuffer64EXT) {
|
|
|
|
uint32_t input_storage_class = 0;
|
|
|
|
uint32_t input_data_type = 0;
|
|
|
|
_.GetPointerTypeInfo(input_type, &input_data_type,
|
|
|
|
&input_storage_class);
|
|
|
|
if (input_storage_class != SpvStorageClassPhysicalStorageBufferEXT)
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Pointer storage class must be PhysicalStorageBufferEXT: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpSatConvertSToU:
|
|
|
|
case SpvOpSatConvertUToS: {
|
|
|
|
if (!_.IsIntScalarType(result_type) && !_.IsIntVectorType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected int scalar or vector type as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
2017-11-08 17:40:02 +00:00
|
|
|
if (!input_type ||
|
|
|
|
(!_.IsIntScalarType(input_type) && !_.IsIntVectorType(input_type)))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected int scalar or vector as input: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (_.GetDimension(result_type) != _.GetDimension(input_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to have the same dimension as Result Type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpConvertUToPtr: {
|
|
|
|
if (!_.IsPointerType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type to be a pointer: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
2018-11-19 20:08:38 +00:00
|
|
|
if (!input_type || !_.IsIntScalarType(input_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected int scalar as input: " << spvOpcodeString(opcode);
|
2019-01-07 18:19:24 +00:00
|
|
|
|
|
|
|
if (_.addressing_model() == SpvAddressingModelLogical)
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Logical addressing not supported: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
|
|
|
|
if (_.addressing_model() ==
|
|
|
|
SpvAddressingModelPhysicalStorageBuffer64EXT) {
|
|
|
|
uint32_t result_storage_class = 0;
|
|
|
|
uint32_t result_data_type = 0;
|
|
|
|
_.GetPointerTypeInfo(result_type, &result_data_type,
|
|
|
|
&result_storage_class);
|
|
|
|
if (result_storage_class != SpvStorageClassPhysicalStorageBufferEXT)
|
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
|
|
|
<< "Pointer storage class must be PhysicalStorageBufferEXT: "
|
|
|
|
<< spvOpcodeString(opcode);
|
|
|
|
}
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpPtrCastToGeneric: {
|
|
|
|
uint32_t result_storage_class = 0;
|
|
|
|
uint32_t result_data_type = 0;
|
|
|
|
if (!_.GetPointerTypeInfo(result_type, &result_data_type,
|
|
|
|
&result_storage_class))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type to be a pointer: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (result_storage_class != SpvStorageClassGeneric)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type to have storage class Generic: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
uint32_t input_storage_class = 0;
|
|
|
|
uint32_t input_data_type = 0;
|
|
|
|
if (!_.GetPointerTypeInfo(input_type, &input_data_type,
|
|
|
|
&input_storage_class))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be a pointer: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (input_storage_class != SpvStorageClassWorkgroup &&
|
|
|
|
input_storage_class != SpvStorageClassCrossWorkgroup &&
|
|
|
|
input_storage_class != SpvStorageClassFunction)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to have storage class Workgroup, "
|
|
|
|
<< "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (result_data_type != input_data_type)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input and Result Type to point to the same type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpGenericCastToPtr: {
|
|
|
|
uint32_t result_storage_class = 0;
|
|
|
|
uint32_t result_data_type = 0;
|
|
|
|
if (!_.GetPointerTypeInfo(result_type, &result_data_type,
|
|
|
|
&result_storage_class))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type to be a pointer: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (result_storage_class != SpvStorageClassWorkgroup &&
|
|
|
|
result_storage_class != SpvStorageClassCrossWorkgroup &&
|
|
|
|
result_storage_class != SpvStorageClassFunction)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type to have storage class Workgroup, "
|
|
|
|
<< "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
uint32_t input_storage_class = 0;
|
|
|
|
uint32_t input_data_type = 0;
|
|
|
|
if (!_.GetPointerTypeInfo(input_type, &input_data_type,
|
|
|
|
&input_storage_class))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be a pointer: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (input_storage_class != SpvStorageClassGeneric)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to have storage class Generic: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (result_data_type != input_data_type)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input and Result Type to point to the same type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpGenericCastToPtrExplicit: {
|
|
|
|
uint32_t result_storage_class = 0;
|
|
|
|
uint32_t result_data_type = 0;
|
|
|
|
if (!_.GetPointerTypeInfo(result_type, &result_data_type,
|
|
|
|
&result_storage_class))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type to be a pointer: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2018-07-10 14:57:52 +00:00
|
|
|
const uint32_t target_storage_class = inst->word(4);
|
2017-09-28 18:53:24 +00:00
|
|
|
if (result_storage_class != target_storage_class)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type to be of target storage class: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
uint32_t input_storage_class = 0;
|
|
|
|
uint32_t input_data_type = 0;
|
|
|
|
if (!_.GetPointerTypeInfo(input_type, &input_data_type,
|
|
|
|
&input_storage_class))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be a pointer: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (input_storage_class != SpvStorageClassGeneric)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to have storage class Generic: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (result_data_type != input_data_type)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input and Result Type to point to the same type: "
|
|
|
|
<< spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (target_storage_class != SpvStorageClassWorkgroup &&
|
|
|
|
target_storage_class != SpvStorageClassCrossWorkgroup &&
|
|
|
|
target_storage_class != SpvStorageClassFunction)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected target storage class to be Workgroup, "
|
|
|
|
<< "CrossWorkgroup or Function: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpBitcast: {
|
|
|
|
const uint32_t input_type = _.GetOperandTypeId(inst, 2);
|
|
|
|
if (!input_type)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to have a type: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
const bool result_is_pointer = _.IsPointerType(result_type);
|
|
|
|
const bool result_is_int_scalar = _.IsIntScalarType(result_type);
|
|
|
|
const bool input_is_pointer = _.IsPointerType(input_type);
|
|
|
|
const bool input_is_int_scalar = _.IsIntScalarType(input_type);
|
|
|
|
|
|
|
|
if (!result_is_pointer && !result_is_int_scalar &&
|
|
|
|
!_.IsIntVectorType(result_type) &&
|
|
|
|
!_.IsFloatScalarType(result_type) &&
|
|
|
|
!_.IsFloatVectorType(result_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected Result Type to be a pointer or int or float vector "
|
|
|
|
<< "or scalar type: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (!input_is_pointer && !input_is_int_scalar &&
|
2017-11-08 17:40:02 +00:00
|
|
|
!_.IsIntVectorType(input_type) && !_.IsFloatScalarType(input_type) &&
|
2017-09-28 18:53:24 +00:00
|
|
|
!_.IsFloatVectorType(input_type))
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be a pointer or int or float vector "
|
|
|
|
<< "or scalar: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (result_is_pointer && !input_is_pointer && !input_is_int_scalar)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to be a pointer or int scalar if Result Type "
|
|
|
|
<< "is pointer: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (input_is_pointer && !result_is_pointer && !result_is_int_scalar)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Pointer can only be converted to another pointer or int "
|
|
|
|
<< "scalar: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
|
|
|
if (!result_is_pointer && !input_is_pointer) {
|
|
|
|
const uint32_t result_size =
|
|
|
|
_.GetBitWidth(result_type) * _.GetDimension(result_type);
|
|
|
|
const uint32_t input_size =
|
|
|
|
_.GetBitWidth(input_type) * _.GetDimension(input_type);
|
|
|
|
if (result_size != input_size)
|
2018-08-01 14:18:06 +00:00
|
|
|
return _.diag(SPV_ERROR_INVALID_DATA, inst)
|
2017-11-08 17:40:02 +00:00
|
|
|
<< "Expected input to have the same total bit width as "
|
|
|
|
<< "Result Type: " << spvOpcodeString(opcode);
|
2017-09-28 18:53:24 +00:00
|
|
|
}
|
|
|
|
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
|