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 //   CreateInstBuffAddrCheckPass
27 //   CreateInstDebugPrintfPass
28 //
29 // More detailed documentation of these routines can be found in optimizer.hpp
30 
31 namespace spvtools {
32 
33 // Stream Output Buffer Offsets
34 //
35 // The following values provide offsets into the output buffer struct
36 // generated by InstrumentPass::GenDebugStreamWrite. This method is utilized
37 // by InstBindlessCheckPass, InstBuffAddrCheckPass, and InstDebugPrintfPass.
38 //
39 // The 1st member of the debug output buffer contains a set of flags
40 // controlling the behavior of instrumentation code.
41 static const int kDebugOutputFlagsOffset = 0;
42 
43 // Values stored at kDebugOutputFlagsOffset
44 enum kInstFlags : unsigned int {
45   kInstBufferOOBEnable = 0x1,
46 };
47 
48 // The 2nd member of the debug output buffer contains the next available word
49 // in the data stream to be written. Shaders will atomically read and update
50 // this value so as not to overwrite each others records. This value must be
51 // initialized to zero
52 static const int kDebugOutputSizeOffset = 1;
53 
54 // The 3rd member of the output buffer is the start of the stream of records
55 // written by the instrumented shaders. Each record represents a validation
56 // error. The format of the records is documented below.
57 static const int kDebugOutputDataOffset = 2;
58 
59 // Common Stream Record Offsets
60 //
61 // The following are offsets to fields which are common to all records written
62 // to the output stream.
63 //
64 // Each record first contains the size of the record in 32-bit words, including
65 // the size word.
66 static const int kInstCommonOutSize = 0;
67 
68 // This is the shader id passed by the layer when the instrumentation pass is
69 // created.
70 static const int kInstCommonOutShaderId = 1;
71 
72 // This is the ordinal position of the instruction within the SPIR-V shader
73 // which generated the validation error.
74 static const int kInstCommonOutInstructionIdx = 2;
75 
76 // Debug Buffer Bindings
77 //
78 // These are the bindings for the different buffers which are
79 // read or written by the instrumentation passes.
80 //
81 // This is the output buffer written by InstDebugPrintfPass.
82 static const int kDebugOutputPrintfStream = 3;
83 
84 }  // namespace spvtools
85 
86 #endif  // INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_
87