1 // Copyright (c) 2018 The Khronos Group Inc. 2 // Copyright (c) 2018 Valve Corporation 3 // Copyright (c) 2018 LunarG Inc. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #ifndef INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_ 18 #define INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_ 19 20 // Shader Instrumentation Interface 21 // 22 // This file provides an external interface for applications that wish to 23 // communicate with shaders instrumented by passes created by: 24 // 25 // CreateInstBindlessCheckPass 26 // 27 // More detailed documentation of this routine can be found in optimizer.hpp 28 29 namespace spvtools { 30 31 // Stream Output Buffer Offsets 32 // 33 // The following values provide 32-bit word offsets into the output buffer 34 // generated by InstrumentPass::GenDebugStreamWrite. This method is utilized 35 // by InstBindlessCheckPass. 36 // 37 // The first word of the debug output buffer contains the next available word 38 // in the data stream to be written. Shaders will atomically read and update 39 // this value so as not to overwrite each others records. This value must be 40 // initialized to zero 41 static const int kDebugOutputSizeOffset = 0; 42 43 // The second word of the output buffer is the start of the stream of records 44 // written by the instrumented shaders. Each record represents a validation 45 // error. The format of the records is documented below. 46 static const int kDebugOutputDataOffset = 1; 47 48 // Common Stream Record Offsets 49 // 50 // The following are offsets to fields which are common to all records written 51 // to the output stream. 52 // 53 // Each record first contains the size of the record in 32-bit words, including 54 // the size word. 55 static const int kInstCommonOutSize = 0; 56 57 // This is the shader id passed by the layer when the instrumentation pass is 58 // created. 59 static const int kInstCommonOutShaderId = 1; 60 61 // This is the ordinal position of the instruction within the SPIR-V shader 62 // which generated the validation error. 63 static const int kInstCommonOutInstructionIdx = 2; 64 65 // This is the stage which generated the validation error. This word is used 66 // to determine the contents of the next two words in the record. 67 // 0:Vert, 1:TessCtrl, 2:TessEval, 3:Geom, 4:Frag, 5:Compute 68 static const int kInstCommonOutStageIdx = 3; 69 static const int kInstCommonOutCnt = 4; 70 71 // Stage-specific Stream Record Offsets 72 // 73 // Each stage will contain different values in the next two words of the record 74 // used to identify which instantiation of the shader generated the validation 75 // error. 76 // 77 // Vertex Shader Output Record Offsets 78 static const int kInstVertOutVertexIndex = kInstCommonOutCnt; 79 static const int kInstVertOutInstanceIndex = kInstCommonOutCnt + 1; 80 81 // Frag Shader Output Record Offsets 82 static const int kInstFragOutFragCoordX = kInstCommonOutCnt; 83 static const int kInstFragOutFragCoordY = kInstCommonOutCnt + 1; 84 85 // Compute Shader Output Record Offsets 86 static const int kInstCompOutGlobalInvocationId = kInstCommonOutCnt; 87 static const int kInstCompOutUnused = kInstCommonOutCnt + 1; 88 89 // Tessellation Shader Output Record Offsets 90 static const int kInstTessOutInvocationId = kInstCommonOutCnt; 91 static const int kInstTessOutUnused = kInstCommonOutCnt + 1; 92 93 // Geometry Shader Output Record Offsets 94 static const int kInstGeomOutPrimitiveId = kInstCommonOutCnt; 95 static const int kInstGeomOutInvocationId = kInstCommonOutCnt + 1; 96 97 // Size of Common and Stage-specific Members 98 static const int kInstStageOutCnt = kInstCommonOutCnt + 2; 99 100 // Validation Error Code 101 // 102 // This identifies the validation error. It also helps to identify 103 // how many words follow in the record and their meaning. 104 static const int kInstValidationOutError = kInstStageOutCnt; 105 106 // Validation-specific Output Record Offsets 107 // 108 // Each different validation will generate a potentially different 109 // number of words at the end of the record giving more specifics 110 // about the validation error. 111 // 112 // A bindless bounds error will output the index and the bound. 113 static const int kInstBindlessOutDescIndex = kInstStageOutCnt + 1; 114 static const int kInstBindlessOutDescBound = kInstStageOutCnt + 2; 115 static const int kInstBindlessOutCnt = kInstStageOutCnt + 3; 116 117 // Maximum Output Record Member Count 118 static const int kInstMaxOutCnt = kInstStageOutCnt + 3; 119 120 // Validation Error Codes 121 // 122 // These are the possible validation error codes. 123 static const int kInstErrorBindlessBounds = 0; 124 125 // Debug Buffer Bindings 126 // 127 // These are the bindings for the different buffers which are 128 // read or written by the instrumentation passes. 129 // 130 // This is the output buffer written by InstBindlessCheckPass. 131 static const int kDebugOutputBindingStream = 0; 132 133 } // namespace spvtools 134 135 #endif // INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_ 136