File: mesh_shading.cpp

package info (click to toggle)
vulkan-validationlayers 1.4.341.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,356 kB
  • sloc: cpp: 675,478; python: 12,311; sh: 24; makefile: 24; xml: 14
file content (81 lines) | stat: -rw-r--r-- 4,355 bytes parent folder | download
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
/* Copyright (c) 2025-2026 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 "gpuav/core/gpuav.h"
#include "gpuav/resources/gpuav_state_trackers.h"
#include "gpuav/shaders/gpuav_error_codes.h"
#include "gpuav/shaders/gpuav_error_header.h"

namespace gpuav {

void RegisterMeshShadingValidation(Validator &gpuav, CommandBufferSubState &cb) {
    if (!gpuav.gpuav_settings.shader_instrumentation.mesh_shading) {
        return;
    }

    cb.on_instrumentation_error_logger_register_functions.emplace_back(
        [](Validator &gpuav, CommandBufferSubState &cb, const LastBound &last_bound) {
            CommandBufferSubState::InstrumentationErrorLogger inst_error_logger =
                [](Validator &gpuav, const Location &loc, const uint32_t *error_record, std::string &out_error_msg,
                   std::string &out_vuid_msg) {
                    using namespace glsl;
                    bool error_found = false;
                    if (GetErrorGroup(error_record) != kErrorGroup_InstMeshShading) {
                        return error_found;
                    }
                    error_found = true;

                    std::ostringstream strm;

                    const uint32_t error_sub_code = GetSubError(error_record);
                    switch (error_sub_code) {
                        case kErrorSubCode_MeshShading_SetMeshOutputs: {
                            const uint32_t vertex_count = error_record[kInst_LogError_ParameterOffset_0];
                            const uint32_t primitive_count = error_record[kInst_LogError_ParameterOffset_1];
                            const uint32_t encoded_output = error_record[kInst_LogError_ParameterOffset_2];
                            const uint32_t output_vertices = encoded_output >> kInst_MeshShading_OutputVerticesShift;
                            const uint32_t output_primitive = encoded_output & kInst_MeshShading_OutputPrimitivesMask;

                            // We normally don't do "logic" to determine the VU, but in this case, its valuable to print both value,
                            // so we already have all the information and easier to select the VUID here than via the shader
                            // interface
                            out_vuid_msg = (vertex_count > output_vertices) ? "VUID-RuntimeSpirv-MeshEXT-07332"
                                                                            : "VUID-RuntimeSpirv-MeshEXT-07333";

                            strm << "OpSetMeshOutputsEXT set the Vertex Count to " << vertex_count << " and Primitive Count to "
                                 << primitive_count << ", but they must be less than the OutputVertices (" << output_vertices
                                 << ") and OutputPrimitivesEXT (" << output_primitive << ").";
                            // TODO - Use OpSource to detect this for the user
                            strm << "\n  For GLSL these values are set via \"layout(max_vertices = " << output_vertices
                                 << ") out;\" and "
                                    "\"layout(max_primitives = "
                                 << output_primitive
                                 << ") out;\"\n  For HLSL/Slang these values are set via \"void main(out "
                                    "indices uint3 primitives["
                                 << output_primitive << "], out vertices MeshOutput vertices[" << output_vertices << "])\"";
                        } break;
                        default:
                            error_found = false;
                            break;
                    }
                    out_error_msg += strm.str();
                    return error_found;
                };

            return inst_error_logger;
        });
}

}  // namespace gpuav