Coverage Report

Created: 2026-09-28 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/spirv-tools/source/val/validate_primitives.cpp
Line
Count
Source
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 <string>
18
19
#include "source/opcode.h"
20
#include "source/val/instruction.h"
21
#include "source/val/validate.h"
22
#include "source/val/validation_state.h"
23
24
namespace spvtools {
25
namespace val {
26
27
// Validates correctness of primitive instructions.
28
14.3M
spv_result_t PrimitivesPass(ValidationState_t& _, const Instruction* inst) {
29
14.3M
  const spv::Op opcode = inst->opcode();
30
31
14.3M
  switch (opcode) {
32
2.04k
    case spv::Op::OpEmitVertex:
33
2.47k
    case spv::Op::OpEndPrimitive:
34
2.47k
    case spv::Op::OpEmitStreamVertex:
35
2.47k
    case spv::Op::OpEndStreamPrimitive:
36
2.47k
      _.function(inst->function()->id())
37
2.47k
          ->RegisterExecutionModelLimitation(
38
2.47k
              spv::ExecutionModel::Geometry,
39
2.47k
              std::string(spvOpcodeString(opcode)) +
40
2.47k
                  " instructions require Geometry execution model");
41
2.47k
      break;
42
14.3M
    default:
43
14.3M
      break;
44
14.3M
  }
45
46
14.3M
  switch (opcode) {
47
0
    case spv::Op::OpEmitStreamVertex:
48
0
    case spv::Op::OpEndStreamPrimitive: {
49
0
      const uint32_t stream_id = inst->word(1);
50
0
      const uint32_t stream_type = _.GetTypeId(stream_id);
51
0
      if (!_.IsIntScalarType(stream_type)) {
52
0
        return _.diag(SPV_ERROR_INVALID_DATA, inst)
53
0
               << spvOpcodeString(opcode)
54
0
               << ": expected Stream to be int scalar";
55
0
      }
56
57
0
      const spv::Op stream_opcode = _.GetIdOpcode(stream_id);
58
0
      if (!spvOpcodeIsConstant(stream_opcode)) {
59
0
        return _.diag(SPV_ERROR_INVALID_DATA, inst)
60
0
               << spvOpcodeString(opcode)
61
0
               << ": expected Stream to be constant instruction";
62
0
      }
63
0
    }
64
65
14.3M
    default:
66
14.3M
      break;
67
14.3M
  }
68
69
14.3M
  return SPV_SUCCESS;
70
14.3M
}
71
72
}  // namespace val
73
}  // namespace spvtools