2018-11-08 18:54:54 +00:00
|
|
|
// Copyright (c) 2018 The Khronos Group Inc.
|
|
|
|
// Copyright (c) 2018 Valve Corporation
|
|
|
|
// Copyright (c) 2018 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.
|
|
|
|
|
|
|
|
#ifndef INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_
|
|
|
|
#define INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_
|
|
|
|
|
|
|
|
// Shader Instrumentation Interface
|
|
|
|
//
|
|
|
|
// This file provides an external interface for applications that wish to
|
|
|
|
// communicate with shaders instrumented by passes created by:
|
|
|
|
//
|
|
|
|
// CreateInstBindlessCheckPass
|
2019-08-16 13:18:34 +00:00
|
|
|
// CreateInstBuffAddrCheckPass
|
2020-09-16 13:23:46 +00:00
|
|
|
// CreateInstDebugPrintfPass
|
2018-11-08 18:54:54 +00:00
|
|
|
//
|
2019-08-16 13:18:34 +00:00
|
|
|
// More detailed documentation of these routines can be found in optimizer.hpp
|
2018-11-08 18:54:54 +00:00
|
|
|
|
|
|
|
namespace spvtools {
|
|
|
|
|
|
|
|
// Stream Output Buffer Offsets
|
|
|
|
//
|
2019-02-07 19:00:36 +00:00
|
|
|
// The following values provide offsets into the output buffer struct
|
2018-11-08 18:54:54 +00:00
|
|
|
// generated by InstrumentPass::GenDebugStreamWrite. This method is utilized
|
2020-09-16 13:23:46 +00:00
|
|
|
// by InstBindlessCheckPass, InstBuffAddrCheckPass, and InstDebugPrintfPass.
|
2018-11-08 18:54:54 +00:00
|
|
|
//
|
2022-11-10 17:35:18 +00:00
|
|
|
// The 1st member of the debug output buffer contains a set of flags
|
|
|
|
// controlling the behavior of instrumentation code.
|
|
|
|
static const int kDebugOutputFlagsOffset = 0;
|
|
|
|
|
|
|
|
// Values stored at kDebugOutputFlagsOffset
|
|
|
|
enum kInstFlags : unsigned int {
|
|
|
|
kInstBufferOOBEnable = 0x1,
|
|
|
|
};
|
|
|
|
|
|
|
|
// The 2nd member of the debug output buffer contains the next available word
|
2018-11-08 18:54:54 +00:00
|
|
|
// in the data stream to be written. Shaders will atomically read and update
|
|
|
|
// this value so as not to overwrite each others records. This value must be
|
|
|
|
// initialized to zero
|
2022-11-10 17:35:18 +00:00
|
|
|
static const int kDebugOutputSizeOffset = 1;
|
2018-11-08 18:54:54 +00:00
|
|
|
|
2022-11-10 17:35:18 +00:00
|
|
|
// The 3rd member of the output buffer is the start of the stream of records
|
2018-11-08 18:54:54 +00:00
|
|
|
// written by the instrumented shaders. Each record represents a validation
|
|
|
|
// error. The format of the records is documented below.
|
2022-11-10 17:35:18 +00:00
|
|
|
static const int kDebugOutputDataOffset = 2;
|
2018-11-08 18:54:54 +00:00
|
|
|
|
|
|
|
// Common Stream Record Offsets
|
|
|
|
//
|
|
|
|
// The following are offsets to fields which are common to all records written
|
|
|
|
// to the output stream.
|
|
|
|
//
|
|
|
|
// Each record first contains the size of the record in 32-bit words, including
|
|
|
|
// the size word.
|
|
|
|
static const int kInstCommonOutSize = 0;
|
|
|
|
|
|
|
|
// This is the shader id passed by the layer when the instrumentation pass is
|
|
|
|
// created.
|
|
|
|
static const int kInstCommonOutShaderId = 1;
|
|
|
|
|
|
|
|
// This is the ordinal position of the instruction within the SPIR-V shader
|
|
|
|
// which generated the validation error.
|
|
|
|
static const int kInstCommonOutInstructionIdx = 2;
|
|
|
|
|
|
|
|
// This is the stage which generated the validation error. This word is used
|
|
|
|
// to determine the contents of the next two words in the record.
|
|
|
|
// 0:Vert, 1:TessCtrl, 2:TessEval, 3:Geom, 4:Frag, 5:Compute
|
|
|
|
static const int kInstCommonOutStageIdx = 3;
|
|
|
|
static const int kInstCommonOutCnt = 4;
|
|
|
|
|
|
|
|
// Stage-specific Stream Record Offsets
|
|
|
|
//
|
2019-05-29 19:08:21 +00:00
|
|
|
// Each stage will contain different values in the next set of words of the
|
|
|
|
// record used to identify which instantiation of the shader generated the
|
|
|
|
// validation error.
|
2018-11-08 18:54:54 +00:00
|
|
|
//
|
|
|
|
// Vertex Shader Output Record Offsets
|
2019-01-16 23:02:07 +00:00
|
|
|
static const int kInstVertOutVertexIndex = kInstCommonOutCnt;
|
|
|
|
static const int kInstVertOutInstanceIndex = kInstCommonOutCnt + 1;
|
2019-05-29 19:08:21 +00:00
|
|
|
static const int kInstVertOutUnused = kInstCommonOutCnt + 2;
|
2018-11-08 18:54:54 +00:00
|
|
|
|
|
|
|
// Frag Shader Output Record Offsets
|
|
|
|
static const int kInstFragOutFragCoordX = kInstCommonOutCnt;
|
|
|
|
static const int kInstFragOutFragCoordY = kInstCommonOutCnt + 1;
|
2019-05-29 19:08:21 +00:00
|
|
|
static const int kInstFragOutUnused = kInstCommonOutCnt + 2;
|
2018-11-08 18:54:54 +00:00
|
|
|
|
|
|
|
// Compute Shader Output Record Offsets
|
2019-05-29 19:08:21 +00:00
|
|
|
static const int kInstCompOutGlobalInvocationIdX = kInstCommonOutCnt;
|
|
|
|
static const int kInstCompOutGlobalInvocationIdY = kInstCommonOutCnt + 1;
|
|
|
|
static const int kInstCompOutGlobalInvocationIdZ = kInstCommonOutCnt + 2;
|
|
|
|
|
|
|
|
// Tessellation Control Shader Output Record Offsets
|
|
|
|
static const int kInstTessCtlOutInvocationId = kInstCommonOutCnt;
|
|
|
|
static const int kInstTessCtlOutPrimitiveId = kInstCommonOutCnt + 1;
|
|
|
|
static const int kInstTessCtlOutUnused = kInstCommonOutCnt + 2;
|
|
|
|
|
|
|
|
// Tessellation Eval Shader Output Record Offsets
|
|
|
|
static const int kInstTessEvalOutPrimitiveId = kInstCommonOutCnt;
|
|
|
|
static const int kInstTessEvalOutTessCoordU = kInstCommonOutCnt + 1;
|
|
|
|
static const int kInstTessEvalOutTessCoordV = kInstCommonOutCnt + 2;
|
|
|
|
|
2018-11-08 18:54:54 +00:00
|
|
|
// Geometry Shader Output Record Offsets
|
|
|
|
static const int kInstGeomOutPrimitiveId = kInstCommonOutCnt;
|
|
|
|
static const int kInstGeomOutInvocationId = kInstCommonOutCnt + 1;
|
2019-05-29 19:08:21 +00:00
|
|
|
static const int kInstGeomOutUnused = kInstCommonOutCnt + 2;
|
2018-11-08 18:54:54 +00:00
|
|
|
|
2019-07-15 20:24:42 +00:00
|
|
|
// Ray Tracing Shader Output Record Offsets
|
|
|
|
static const int kInstRayTracingOutLaunchIdX = kInstCommonOutCnt;
|
|
|
|
static const int kInstRayTracingOutLaunchIdY = kInstCommonOutCnt + 1;
|
|
|
|
static const int kInstRayTracingOutLaunchIdZ = kInstCommonOutCnt + 2;
|
|
|
|
|
2020-07-14 15:55:24 +00:00
|
|
|
// Mesh Shader Output Record Offsets
|
|
|
|
static const int kInstMeshOutGlobalInvocationIdX = kInstCommonOutCnt;
|
|
|
|
static const int kInstMeshOutGlobalInvocationIdY = kInstCommonOutCnt + 1;
|
|
|
|
static const int kInstMeshOutGlobalInvocationIdZ = kInstCommonOutCnt + 2;
|
|
|
|
|
|
|
|
// Task Shader Output Record Offsets
|
|
|
|
static const int kInstTaskOutGlobalInvocationIdX = kInstCommonOutCnt;
|
|
|
|
static const int kInstTaskOutGlobalInvocationIdY = kInstCommonOutCnt + 1;
|
|
|
|
static const int kInstTaskOutGlobalInvocationIdZ = kInstCommonOutCnt + 2;
|
|
|
|
|
2018-11-08 18:54:54 +00:00
|
|
|
// Size of Common and Stage-specific Members
|
2019-12-16 19:18:47 +00:00
|
|
|
static const int kInstStageOutCnt = kInstCommonOutCnt + 3;
|
2018-11-08 18:54:54 +00:00
|
|
|
|
2019-05-29 19:08:21 +00:00
|
|
|
// Validation Error Code Offset
|
2018-11-08 18:54:54 +00:00
|
|
|
//
|
|
|
|
// This identifies the validation error. It also helps to identify
|
|
|
|
// how many words follow in the record and their meaning.
|
|
|
|
static const int kInstValidationOutError = kInstStageOutCnt;
|
|
|
|
|
|
|
|
// Validation-specific Output Record Offsets
|
|
|
|
//
|
|
|
|
// Each different validation will generate a potentially different
|
|
|
|
// number of words at the end of the record giving more specifics
|
|
|
|
// about the validation error.
|
|
|
|
//
|
|
|
|
// A bindless bounds error will output the index and the bound.
|
2023-05-01 18:23:30 +00:00
|
|
|
static const int kInstBindlessBoundsOutDescSet = kInstStageOutCnt + 1;
|
|
|
|
static const int kInstBindlessBoundsOutDescBinding = kInstStageOutCnt + 2;
|
|
|
|
static const int kInstBindlessBoundsOutDescIndex = kInstStageOutCnt + 3;
|
|
|
|
static const int kInstBindlessBoundsOutDescBound = kInstStageOutCnt + 4;
|
|
|
|
static const int kInstBindlessBoundsOutUnused = kInstStageOutCnt + 5;
|
|
|
|
static const int kInstBindlessBoundsOutCnt = kInstStageOutCnt + 6;
|
2019-03-19 13:53:43 +00:00
|
|
|
|
2020-09-16 13:23:46 +00:00
|
|
|
// A descriptor uninitialized error will output the index.
|
2023-05-01 18:23:30 +00:00
|
|
|
static const int kInstBindlessUninitOutDescSet = kInstStageOutCnt + 1;
|
|
|
|
static const int kInstBindlessUninitOutBinding = kInstStageOutCnt + 2;
|
|
|
|
static const int kInstBindlessUninitOutDescIndex = kInstStageOutCnt + 3;
|
|
|
|
static const int kInstBindlessUninitOutUnused = kInstStageOutCnt + 4;
|
|
|
|
static const int kInstBindlessUninitOutUnused2 = kInstStageOutCnt + 5;
|
|
|
|
static const int kInstBindlessUninitOutCnt = kInstStageOutCnt + 6;
|
2020-09-16 13:23:46 +00:00
|
|
|
|
|
|
|
// A buffer out-of-bounds error will output the descriptor
|
|
|
|
// index, the buffer offset and the buffer size
|
2023-05-01 18:23:30 +00:00
|
|
|
static const int kInstBindlessBuffOOBOutDescSet = kInstStageOutCnt + 1;
|
|
|
|
static const int kInstBindlessBuffOOBOutDescBinding = kInstStageOutCnt + 2;
|
|
|
|
static const int kInstBindlessBuffOOBOutDescIndex = kInstStageOutCnt + 3;
|
|
|
|
static const int kInstBindlessBuffOOBOutBuffOff = kInstStageOutCnt + 4;
|
|
|
|
static const int kInstBindlessBuffOOBOutBuffSize = kInstStageOutCnt + 5;
|
|
|
|
static const int kInstBindlessBuffOOBOutCnt = kInstStageOutCnt + 6;
|
2019-03-19 13:53:43 +00:00
|
|
|
|
2019-08-16 13:18:34 +00:00
|
|
|
// A buffer address unalloc error will output the 64-bit pointer in
|
|
|
|
// two 32-bit pieces, lower bits first.
|
2019-12-16 19:18:47 +00:00
|
|
|
static const int kInstBuffAddrUnallocOutDescPtrLo = kInstStageOutCnt + 1;
|
|
|
|
static const int kInstBuffAddrUnallocOutDescPtrHi = kInstStageOutCnt + 2;
|
|
|
|
static const int kInstBuffAddrUnallocOutCnt = kInstStageOutCnt + 3;
|
|
|
|
|
2018-11-08 18:54:54 +00:00
|
|
|
// Maximum Output Record Member Count
|
2023-05-01 18:23:30 +00:00
|
|
|
static const int kInstMaxOutCnt = kInstStageOutCnt + 6;
|
2018-11-08 18:54:54 +00:00
|
|
|
|
|
|
|
// Validation Error Codes
|
|
|
|
//
|
|
|
|
// These are the possible validation error codes.
|
2023-06-22 15:39:49 +00:00
|
|
|
static const int kInstErrorBindlessBounds = 1;
|
|
|
|
static const int kInstErrorBindlessUninit = 2;
|
|
|
|
static const int kInstErrorBuffAddrUnallocRef = 3;
|
|
|
|
static const int kInstErrorOOB = 4;
|
|
|
|
static const int kInstErrorMax = kInstErrorOOB;
|
2018-11-08 18:54:54 +00:00
|
|
|
|
2019-02-07 19:00:36 +00:00
|
|
|
// Direct Input Buffer Offsets
|
|
|
|
//
|
|
|
|
// The following values provide member offsets into the input buffers
|
|
|
|
// consumed by InstrumentPass::GenDebugDirectRead(). This method is utilized
|
|
|
|
// by InstBindlessCheckPass.
|
|
|
|
//
|
|
|
|
// The only object in an input buffer is a runtime array of unsigned
|
|
|
|
// integers. Each validation will have its own formatting of this array.
|
|
|
|
static const int kDebugInputDataOffset = 0;
|
|
|
|
|
2018-11-08 18:54:54 +00:00
|
|
|
// Debug Buffer Bindings
|
|
|
|
//
|
|
|
|
// These are the bindings for the different buffers which are
|
|
|
|
// read or written by the instrumentation passes.
|
|
|
|
//
|
2019-08-16 13:18:34 +00:00
|
|
|
// This is the output buffer written by InstBindlessCheckPass,
|
|
|
|
// InstBuffAddrCheckPass, and possibly other future validations.
|
2018-11-08 18:54:54 +00:00
|
|
|
static const int kDebugOutputBindingStream = 0;
|
|
|
|
|
2019-08-16 13:18:34 +00:00
|
|
|
// The binding for the input buffer read by InstBindlessCheckPass.
|
2019-02-07 19:00:36 +00:00
|
|
|
static const int kDebugInputBindingBindless = 1;
|
|
|
|
|
2019-08-16 13:18:34 +00:00
|
|
|
// The binding for the input buffer read by InstBuffAddrCheckPass.
|
|
|
|
static const int kDebugInputBindingBuffAddr = 2;
|
|
|
|
|
2020-03-12 13:19:52 +00:00
|
|
|
// This is the output buffer written by InstDebugPrintfPass.
|
|
|
|
static const int kDebugOutputPrintfStream = 3;
|
|
|
|
|
2023-04-26 20:28:01 +00:00
|
|
|
// clang-format off
|
2019-02-07 19:00:36 +00:00
|
|
|
// Bindless Validation Input Buffer Format
|
|
|
|
//
|
2023-04-26 20:28:01 +00:00
|
|
|
// An input buffer for bindless validation has this structure:
|
|
|
|
// GLSL:
|
|
|
|
// layout(buffer_reference, std430, buffer_reference_align = 8) buffer DescriptorSetData {
|
|
|
|
// uint num_bindings;
|
|
|
|
// uint data[];
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// layout(set = 7, binding = 1, std430) buffer inst_bindless_InputBuffer
|
|
|
|
// {
|
|
|
|
// DescriptorSetData desc_sets[32];
|
|
|
|
// } inst_bindless_input_buffer;
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// To look up the length of a binding:
|
|
|
|
// uint length = inst_bindless_input_buffer[set].data[binding];
|
|
|
|
// Scalar bindings have a length of 1.
|
|
|
|
//
|
|
|
|
// To look up the initialization state of a descriptor in a binding:
|
|
|
|
// uint num_bindings = inst_bindless_input_buffer[set].num_bindings;
|
|
|
|
// uint binding_state_start = inst_bindless_input_buffer[set].data[num_bindings + binding];
|
|
|
|
// uint init_state = inst_bindless_input_buffer[set].data[binding_state_start + index];
|
|
|
|
//
|
|
|
|
// For scalar bindings, use 0 for the index.
|
|
|
|
// clang-format on
|
|
|
|
//
|
|
|
|
// The size of the inst_bindless_input_buffer array, regardless of how many
|
|
|
|
// descriptor sets the device supports.
|
|
|
|
static const int kDebugInputBindlessMaxDescSets = 32;
|
2019-02-07 19:00:36 +00:00
|
|
|
|
2019-08-16 13:18:34 +00:00
|
|
|
// Buffer Device Address Input Buffer Format
|
|
|
|
//
|
|
|
|
// An input buffer for buffer device address validation consists of a single
|
|
|
|
// array of unsigned 64-bit integers we will call Data[]. This array is
|
|
|
|
// formatted as follows:
|
|
|
|
//
|
|
|
|
// At offset kDebugInputBuffAddrPtrOffset is a list of sorted valid buffer
|
|
|
|
// addresses. The list is terminated with the address 0xffffffffffffffff.
|
|
|
|
// If 0x0 is not a valid buffer address, this address is inserted at the
|
|
|
|
// start of the list.
|
|
|
|
//
|
|
|
|
static const int kDebugInputBuffAddrPtrOffset = 1;
|
|
|
|
//
|
|
|
|
// At offset kDebugInputBuffAddrLengthOffset in Data[] is a single uint64 which
|
|
|
|
// gives an offset to the start of the buffer length data. More
|
|
|
|
// specifically, for a buffer whose pointer is located at input buffer offset
|
|
|
|
// i, the length is located at:
|
|
|
|
//
|
|
|
|
// Data[ i - kDebugInputBuffAddrPtrOffset
|
|
|
|
// + Data[ kDebugInputBuffAddrLengthOffset ] ]
|
|
|
|
//
|
|
|
|
// The length associated with the 0xffffffffffffffff address is zero. If
|
|
|
|
// not a valid buffer, the length associated with the 0x0 address is zero.
|
|
|
|
static const int kDebugInputBuffAddrLengthOffset = 0;
|
|
|
|
|
2018-11-08 18:54:54 +00:00
|
|
|
} // namespace spvtools
|
|
|
|
|
|
|
|
#endif // INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_
|