File: vertex_attribute_fetch_oob.cpp

package info (click to toggle)
vulkan-validationlayers 1.4.321.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,412 kB
  • sloc: cpp: 594,175; python: 11,321; sh: 24; makefile: 20; xml: 14
file content (86 lines) | stat: -rw-r--r-- 3,611 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright (c) 2025 The Khronos Group Inc.
 * Copyright (c) 2025 Valve Corporation
 * Copyright (c) 2025 LunarG, 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.
 */

#include "vertex_attribute_fetch_oob.h"
#include "module.h"
#include "generated/gpuav_offline_spirv.h"

#include <iostream>

#include "profiling/profiling.h"

namespace gpuav {
namespace spirv {

const static OfflineModule kOfflineModule = {instrumentation_vertex_attribute_fetch_oob_vert,
                                             instrumentation_vertex_attribute_fetch_oob_vert_size};

const static OfflineFunction kOfflineFunction = {"inst_vertex_attribute_fetch_oob",
                                                 instrumentation_vertex_attribute_fetch_oob_vert_function_0_offset};

VertexAttributeFetchOob::VertexAttributeFetchOob(Module& module) : Pass(module, kOfflineModule) {}

uint32_t VertexAttributeFetchOob::GetLinkFunctionId() { return GetLinkFunction(link_function_id_, kOfflineFunction); }

bool VertexAttributeFetchOob::Instrument() {
    for (const auto& entry_point_inst : module_.entry_points_) {
        const uint32_t execution_model = entry_point_inst->Word(1);
        if (execution_model != spv::ExecutionModelVertex) continue;

        const uint32_t vertex_shader_entry_point_id = entry_point_inst->Word(2);
        for (const auto& function : module_.functions_) {
            if (function->instrumentation_added_) continue;
            const uint32_t function_id = function->GetDef().ResultId();
            if (vertex_shader_entry_point_id != function_id) continue;

            BasicBlock& first_block = function->GetFirstBlock();
            InstructionIt first_injectable_instruction = first_block.GetFirstInjectableInstrution();

            const uint32_t stage_info_id = GetStageInfo(*function, first_block, first_injectable_instruction);

            InstructionIt stage_info_inst_it;
            for (auto inst_it = first_block.instructions_.begin(); inst_it != first_block.instructions_.end(); ++inst_it) {
                if ((*inst_it)->ResultId() == stage_info_id) {
                    stage_info_inst_it = inst_it;
                    break;
                }
            }
            ++stage_info_inst_it;

            std::vector<uint32_t> index_validation_inst_words;
            const uint32_t void_type = module_.type_manager_.GetTypeVoid().Id();
            const uint32_t function_result = module_.TakeNextId();
            const uint32_t function_def = GetLinkFunctionId();

            first_block.CreateInstruction(spv::OpFunctionCall, {void_type, function_result, function_def, stage_info_id},
                                          &stage_info_inst_it);

            instrumentation_performed = true;
            return true;
        }
    }
    return false;
}

void VertexAttributeFetchOob::PrintDebugInfo() const {
    std::cout << "VertexAttributeFetchOob instrumentation performed: " << std::boolalpha << instrumentation_performed << '\n';
    VVL_TracyPlot(__FUNCTION__, int64_t(instrumentation_performed));
}

}  // namespace spirv

}  // namespace gpuav