File: vertex_attribute_fetch_oob.vert

package info (click to toggle)
vulkan-validationlayers 1.4.328.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 49,412 kB
  • sloc: cpp: 615,223; python: 12,115; sh: 24; makefile: 20; xml: 14
file content (71 lines) | stat: -rw-r--r-- 3,693 bytes parent folder | download | duplicates (5)
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
// Copyright (c) 2024-2025 The Khronos Group Inc.
// Copyright (c) 2024-2025 Valve Corporation
// Copyright (c) 2024-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.

// NOTE: This file doesn't contain any entrypoints and should be compiled with the --no-link option for glslang

#version 450
#extension GL_GOOGLE_include_directive : enable
#include "common_descriptor_sets.h"

layout(set = kInstDefaultDescriptorSet, binding = kBindingInstVertexAttributeFetchLimits, scalar)
readonly buffer VertexAttributeFetchLimits {
    uint has_max_vbb_vertex_input_rate;
    uint vertex_attribute_fetch_limit_vertex_input_rate;

    uint has_max_vbb_instance_input_rate;
    uint vertex_attribute_fetch_limit_instance_input_rate;
};

void inst_vertex_attribute_fetch_oob(const uvec4 stage_info)
{
    const uint vertex_index = stage_info[1];
    const uint instance_index = stage_info[2];

    bool valid_vertex_attribute_fetch_vertex_input_rate = true;
    bool valid_vertex_attribute_fetch_instance_input_rate = true;

    if (has_max_vbb_vertex_input_rate == 1u) {
        valid_vertex_attribute_fetch_vertex_input_rate = vertex_index < vertex_attribute_fetch_limit_vertex_input_rate;
    }
    if (has_max_vbb_instance_input_rate == 1u) {
        valid_vertex_attribute_fetch_instance_input_rate = instance_index < vertex_attribute_fetch_limit_instance_input_rate;
    }

    if (!valid_vertex_attribute_fetch_vertex_input_rate || !valid_vertex_attribute_fetch_instance_input_rate) {
        const uint cmd_id = inst_error_logger_index_buffer.index[0];
        const uint cmd_errors_count = atomicAdd(inst_cmd_errors_count_buffer.errors_count[cmd_id], 1);
        const bool max_cmd_errors_count_reached = cmd_errors_count >= kMaxErrorsPerCmd;

        if (max_cmd_errors_count_reached) return;

        uint write_pos = atomicAdd(inst_errors_buffer.written_count, kErrorRecordSize);
        const bool errors_buffer_not_filled = (write_pos + kErrorRecordSize) <= uint(inst_errors_buffer.data.length());

        if (errors_buffer_not_filled) {
            const uint error = valid_vertex_attribute_fetch_vertex_input_rate ? kErrorSubCode_IndexedDraw_OOBInstanceIndex : kErrorSubCode_IndexedDraw_OOBVertexIndex;

            inst_errors_buffer.data[write_pos + kHeaderErrorRecordSizeOffset] = kErrorRecordSize;
            inst_errors_buffer.data[write_pos + kHeaderShaderIdErrorOffset] = SpecConstantLinkShaderId | (kErrorGroupInstIndexedDraw << kErrorGroupShift) | (error << kErrorSubCodeShift);
            // The shader stage is irrelevant because we know it is a vertex shader
            inst_errors_buffer.data[write_pos + kHeaderStageInstructionIdOffset] = stage_info[0] << kStageIdShift;
            inst_errors_buffer.data[write_pos + kHeaderStageInfoOffset_0] = stage_info[1];
            inst_errors_buffer.data[write_pos + kHeaderStageInfoOffset_1] = stage_info[2];
            inst_errors_buffer.data[write_pos + kHeaderStageInfoOffset_2] = stage_info[3];

            inst_errors_buffer.data[write_pos + kHeaderActionIdErrorLoggerIdOffset] = (inst_action_index_buffer.index[0] << kActionIdShift) | inst_error_logger_index_buffer.index[0];
        }
    }
}