Coverage Report

Created: 2023-03-01 07:33

/src/spirv-tools/source/val/validate_primitives.cpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2017 LunarG Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// Validates correctness of primitive SPIR-V instructions.
16
17
#include "source/val/validate.h"
18
19
#include <string>
20
21
#include "source/diagnostic.h"
22
#include "source/opcode.h"
23
#include "source/val/instruction.h"
24
#include "source/val/validation_state.h"
25
26
namespace spvtools {
27
namespace val {
28
29
// Validates correctness of primitive instructions.
30
2.69M
spv_result_t PrimitivesPass(ValidationState_t& _, const Instruction* inst) {
31
2.69M
  const spv::Op opcode = inst->opcode();
32
33
2.69M
  switch (opcode) {
34
0
    case spv::Op::OpEmitVertex:
35
0
    case spv::Op::OpEndPrimitive:
36
0
    case spv::Op::OpEmitStreamVertex:
37
0
    case spv::Op::OpEndStreamPrimitive:
38
0
      _.function(inst->function()->id())
39
0
          ->RegisterExecutionModelLimitation(
40
0
              spv::ExecutionModel::Geometry,
41
0
              std::string(spvOpcodeString(opcode)) +
42
0
                  " instructions require Geometry execution model");
43
0
      break;
44
2.69M
    default:
45
2.69M
      break;
46
2.69M
  }
47
48
2.69M
  switch (opcode) {
49
0
    case spv::Op::OpEmitStreamVertex:
50
0
    case spv::Op::OpEndStreamPrimitive: {
51
0
      const uint32_t stream_id = inst->word(1);
52
0
      const uint32_t stream_type = _.GetTypeId(stream_id);
53
0
      if (!_.IsIntScalarType(stream_type)) {
54
0
        return _.diag(SPV_ERROR_INVALID_DATA, inst)
55
0
               << spvOpcodeString(opcode)
56
0
               << ": expected Stream to be int scalar";
57
0
      }
58
59
0
      const spv::Op stream_opcode = _.GetIdOpcode(stream_id);
60
0
      if (!spvOpcodeIsConstant(stream_opcode)) {
61
0
        return _.diag(SPV_ERROR_INVALID_DATA, inst)
62
0
               << spvOpcodeString(opcode)
63
0
               << ": expected Stream to be constant instruction";
64
0
      }
65
0
    }
66
67
2.69M
    default:
68
2.69M
      break;
69
2.69M
  }
70
71
2.69M
  return SPV_SUCCESS;
72
2.69M
}
73
74
}  // namespace val
75
}  // namespace spvtools