Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaitanyassr patch 1 #2

Open
wants to merge 88 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
521223b
spirv-fuzz: Make functions "livesafe" during donation (#3146)
afd Jan 29, 2020
dd3f8d4
spirv-fuzz: Add outlining test (#3164)
afd Jan 29, 2020
1fc7a9e
spirv-fuzz: Arbitrary variable facts (#3165)
afd Jan 30, 2020
7a2d408
Fix typo in comment. (#3163)
afd Jan 30, 2020
0265a9d
Implement constant folding for many transcendentals (#3166)
zeux Feb 3, 2020
ddcc117
Update CHANGES
s-perron Feb 3, 2020
a9624b4
Handle TimeAMD in AmdExtensionToKhrPass. (#3168)
dnovillo Feb 3, 2020
b7e0998
spirv-fuzz: Disallow copying of null and undefined pointers (#3172)
afd Feb 4, 2020
fdd0c87
Update script that checks copyright years. (#3173)
afd Feb 4, 2020
bb56e89
spirv-fuzz: Fuzzer pass to add composite types (#3171)
afd Feb 4, 2020
76616ba
Update CHANGES
s-perron Feb 4, 2020
8dd1748
Finalize SPIRV-Tools v2020.1
s-perron Feb 4, 2020
da5457f
Start SPIRV-Tools v2020.2
s-perron Feb 4, 2020
a3b5ad9
Fix typos in opt's help. Update environment version. (#3170)
kuhar Feb 4, 2020
9e52bc0
utils/vscode: LSP - Support OpExtInst (#3140)
ben-clayton Feb 4, 2020
1f03ac1
spirv-fuzz: Fuzzer passes to add local and global variables (#3175)
afd Feb 5, 2020
fe10239
spirv-fuzz: Add fuzzer passes to add loads/stores (#3176)
afd Feb 6, 2020
3d4a0dd
spirv-fuzz: Ensure that donated variables are always initialized (#3181)
afd Feb 10, 2020
77fb303
spirv-fuzz: Fuzzer pass to add function calls (#3178)
afd Feb 10, 2020
6c218ec
spirv-fuzz: Fuzzer pass that adds access chains (#3182)
afd Feb 11, 2020
77fefe7
spirvfuzz: Fix type-related bug, change undef to zero, and add assert…
afd Feb 14, 2020
4d912f4
spirv-val: Add support for SPV_AMD_shader_image_load_store_lod (#3186)
samuelig Feb 18, 2020
79f8caf
vscode: Add missing fields to schema.Opcode (#3169)
ben-clayton Feb 18, 2020
03794b8
Fix static libraries linking order (#3189)
danyspin97 Feb 20, 2020
4a80497
Make spvOpcodeString part of the public API (#3174)
s-perron Feb 20, 2020
dea1040
Fix ignored const qualifier warning in static_cast (#3197)
rg3igalia Feb 21, 2020
03c9eff
Brief guide to writing a spirv-fuzz fuzzer pass (#3190)
afd Feb 21, 2020
c316fb1
Add missing dependencies when generating spvtools_core_tables (#3199)
vonture Feb 21, 2020
8910ea5
Fix Wrange-loop-analysis warnings in SPIRV-Tools. (#3201)
nico Feb 23, 2020
fb6e3e4
Combine extinst-name and extinst-output-base into one arg. (#3200)
vonture Feb 25, 2020
70f8881
Add validation rules for OpenCL.DebugInfo.100 extension (#3133)
jaebaek Feb 25, 2020
661e79e
Adding WebGPU specific Workgroup scope rule (#3204)
zoddicus Feb 28, 2020
e1688b6
Avoid use of Python distutils.dir_util (#3203)
dneto0 Feb 28, 2020
a6d3a2d
Refactor FuzzerPass::ApplyTransformation code duplication. (#3206)
andreperezmaselco Mar 4, 2020
044ecc0
spirv-fuzz: Fuzzer pass to add equation instructions (#3202)
afd Mar 4, 2020
66a682b
spirv-fuzz: Add swap commutable operands transformation (#3205)
afd Mar 5, 2020
da4cd21
spirv-fuzz: Use better function name (#3207)
afd Mar 6, 2020
533af49
spirv-fuzz: Add fuzzer pass to permute function parameters (#3212)
Vasniktel Mar 8, 2020
4c02704
spirv-fuzz: Add toggle access chain instruction transformation (#3211)
andreperezmaselco Mar 8, 2020
6594704
spirv-fuzz: Allow OpPhi operand to be replaced with a composite synon…
andreperezmaselco Mar 9, 2020
7c3de21
spirv-fuzz: Remove duplicated functionality (#3220)
Vasniktel Mar 9, 2020
dd3d916
Allow sampledimage types as operand of OpCopyObject (#3222)
jeffbolznv Mar 9, 2020
1af1df3
spirv-fuzz: Fix vector width issue in 'add equation instructions' pas…
afd Mar 12, 2020
6428ad0
spirv-fuzz: Support OpPhi when adding dead break and continue (#3225)
Vasniktel Mar 12, 2020
1fe9bcc
Instrument: Debug Printf support (#3215)
greg-lunarg Mar 12, 2020
7a8f797
Update dependencies (#3228)
Vasniktel Mar 13, 2020
25ede1c
Roll external/spirv-headers/ 30ef660ce..a17e17e36 (1 commit) (#3230)
null77 Mar 16, 2020
5a97e3a
Add support for KHR_ray_{query,tracing} extensions (#3235)
dgkoch Mar 17, 2020
18d3896
Whitelist SPV_EXT_demote_to_helper_invocation for opt passes (#3236)
ehsannas Mar 18, 2020
da52d08
Add RayQueryProvisionalKHR to opt types (#3239)
jiaolu Mar 19, 2020
60104cd
Add opt::Operand::AsCString and AsString (#3240)
dneto0 Mar 19, 2020
7f341ff
Make file formatting comply with POSIX standards (#3242)
aaronfranke Mar 23, 2020
e6f372c
Whitelist SPV_KHR_ray_tracing (#3241)
ehsannas Mar 23, 2020
1c8bda3
Add data structure for DebugScope, DebugDeclare in spirv-opt (#3183)
jaebaek Mar 23, 2020
1346dd5
Disallow phis of images, samplers and sampled images (#3246)
alan-baker Mar 23, 2020
022da4d
Fix identification of Vulkan images and buffers (#3253)
alan-baker Mar 25, 2020
3ef8fe9
Update CHANGES
s-perron Mar 26, 2020
fd8e130
Finalize SPIRV-Tools v2020.2
s-perron Mar 26, 2020
fd773eb
Start SPIRV-Tools v2020.3
s-perron Mar 26, 2020
c37c949
Validate Buffer and BufferBlock apply only to struct types (#3259)
cmarcelo Mar 31, 2020
f20c0d7
Set wrapped kill basic block's parent (#3269)
alan-baker Apr 1, 2020
af01d57
Update dominates to check for null nodes (#3271)
alan-baker Apr 2, 2020
2fdea57
spirv-fuzz: Add validator options (#3254)
afd Apr 2, 2020
8d4261b
spirv-fuzz: Introduce TransformationContext (#3272)
afd Apr 2, 2020
f28cdef
spirv-fuzz: Only replace regular ids with synonyms (#3255)
afd Apr 2, 2020
bfd25ac
spirv-fuzz: Limit adding of new variables to 'basic' types (#3257)
afd Apr 2, 2020
5d491a7
spirv-fuzz: Handle isomorphic types property in composite constructio…
afd Apr 2, 2020
e95fbfb
spirv-fuzz: Transformation to add OpConstantNull (#3273)
afd Apr 2, 2020
4af38c4
spirv-fuzz: Improve support for compute shaders in donation (#3277)
afd Apr 6, 2020
183e324
spirv-fuzz: Handle more general SPIR-V in donation (#3280)
afd Apr 7, 2020
538512e
spirv-fuzz: Improve the handling of equation facts (#3281)
afd Apr 7, 2020
d0490ef
Fix pch macro to ignore clang-cl (#3283)
Malacath-92 Apr 9, 2020
34be233
Handle more cases in dead member elim (#3289)
s-perron Apr 9, 2020
c531099
Update acorn version (#3294)
s-perron Apr 13, 2020
000040e
Preserve debug info in eliminate-dead-functions (#3251)
jaebaek Apr 13, 2020
e70d25f
Struct CFG analysus and single block loop (#3293)
s-perron Apr 13, 2020
ca57515
If SPIRV-Headers is in our tree, include it as subproject (#3299)
dneto0 Apr 14, 2020
4956644
Add tests for recently added command line option (#3297)
s-perron Apr 14, 2020
2a2bdbd
Remove implicit fallthrough (#3298)
alan-baker Apr 14, 2020
7d65bce
Sampled images as read-only storage (#3295)
s-perron Apr 14, 2020
7ce2db1
spirv-fuzz: Fix comment. (#3300)
afd Apr 14, 2020
f82d470
spirv-fuzz: Respect rules for OpSampledImage (#3287)
afd Apr 14, 2020
2f18046
spirv-fuzz: Handle image storage class in donation (#3290)
afd Apr 14, 2020
f460cca
spirv-fuzz: Handle OpRuntimeArray when replacing ids with synonyms (#…
afd Apr 14, 2020
c018fc6
spirv-fuzz: Do not outline regions that produce pointer outputs (#3291)
afd Apr 14, 2020
ed96301
spirv-fuzz: Fix to outliner (#3302)
afd Apr 15, 2020
61b7de3
Remove unreachable code. (#3304)
s-perron Apr 15, 2020
4226b7d
typo fix: in README.md exectuable->executable
Chaitanyassr Apr 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ bazel-testlogs
# C-Lion
/.idea/
/cmake-build-*/

# VSCode
/.vscode/*
4 changes: 2 additions & 2 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/inline_opaque_pass.cpp \
source/opt/inst_bindless_check_pass.cpp \
source/opt/inst_buff_addr_check_pass.cpp \
source/opt/inst_debug_printf_pass.cpp \
source/opt/instruction.cpp \
source/opt/instruction_list.cpp \
source/opt/instrument_pass.cpp \
Expand Down Expand Up @@ -235,9 +236,8 @@ $(1)/$(2).h : \
$(LOCAL_PATH)/utils/generate_language_headers.py \
$(3)
@$(HOST_PYTHON) $(LOCAL_PATH)/utils/generate_language_headers.py \
--extinst-name=$(2) \
--extinst-grammar=$(3) \
--extinst-output-base=$(1)/$(2)
--extinst-output-path=$(1)/$(2).h
@echo "[$(TARGET_ARCH_ABI)] Generate language specific header for $(2): headers <= grammar"
$(foreach F,$(SPVTOOLS_SRC_FILES) $(SPVTOOLS_OPT_SRC_FILES),$(LOCAL_PATH)/$F ) \
: $(1)/$(2).h
Expand Down
14 changes: 8 additions & 6 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ template("spvtools_core_tables") {

sources = [
core_json_file,
debuginfo_insts_file,
cldebuginfo100_insts_file,
]
outputs = [
core_insts_file,
Expand Down Expand Up @@ -184,21 +186,19 @@ template("spvtools_language_header") {
script = "utils/generate_language_headers.py"

name = invoker.name
extinst_output_base = "${target_gen_dir}/${name}"
extinst_output_path = "${target_gen_dir}/${name}.h"

args = [
"--extinst-name",
"${name}",
"--extinst-grammar",
rebase_path(invoker.grammar_file, root_build_dir),
"--extinst-output-base",
rebase_path(extinst_output_base, root_build_dir),
"--extinst-output-path",
rebase_path(extinst_output_path, root_build_dir),
]
inputs = [
invoker.grammar_file,
]
outputs = [
"${extinst_output_base}.h",
"${extinst_output_path}",
]
}
}
Expand Down Expand Up @@ -590,6 +590,8 @@ static_library("spvtools_opt") {
"source/opt/inst_bindless_check_pass.h",
"source/opt/inst_buff_addr_check_pass.cpp",
"source/opt/inst_buff_addr_check_pass.h",
"source/opt/inst_debug_printf_pass.cpp",
"source/opt/inst_debug_printf_pass.h",
"source/opt/instruction.cpp",
"source/opt/instruction.h",
"source/opt/instruction_list.cpp",
Expand Down
56 changes: 54 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,7 +1,59 @@
Revision history for SPIRV-Tools

v2020.1-dev 2019-12-11
- Start v2020.1-dev
v2020.3-dev 2020-03-26
- Start v2020.3-dev

v2020.2 2020-03-26
- General:
- Support extended instructions in the vscode language server
- Make spvOpcodeString part of the public API (#3174)
- Added guide to writing a spirv-fuzz fuzzer pass (#3190)
- Add support for KHR_ray_{query,tracing} extensions (#3235)
- Optimizer
- Debug Printf support (#3215)
- Add data structure for DebugScope, DebugDeclare in spirv-opt (#3183)
- Fix identification of Vulkan images and buffers (#3253)
- Validator
- Add support for SPV_AMD_shader_image_load_store_lod (#3186)
- Add validation rules for OpenCL.DebugInfo.100 extension (#3133)
- Adding WebGPU specific Workgroup scope rule (#3204)
- Disallow phis of images, samplers and sampled images (#3246)
- Reduce
- Fuzz
- Fuzzer passes to add local and global variables (#3175)
- Add fuzzer passes to add loads/stores (#3176)
- Fuzzer pass to add function calls (#3178)
- Fuzzer pass that adds access chains (#3182)
- Fuzzer pass to add equation instructions (#3202)
- Add swap commutable operands transformation (#3205)
- Add fuzzer pass to permute function parameters (#3212)
- Allow OpPhi operand to be replaced with a composite synonym (#3221)
- Linker

v2020.1 2020-02-03
- General:
- Add support for SPV_KHR_non_semantic_info (#3110)
- Support OpenCL.DebugInfo.100 extended instruction set (#3080)
- Added support for Vulkan 1.2
- Add API function to better handle getting the necessary environment (#3142)
- Clarify mapping of target env to SPIR-V version (#3150)
- Implement constant folding for many transcendentals (#3166)
- Optimizer
- Change default version for CreatInstBindlessCheckPass to 2 (#3096, #3119)
- Better handling of OpLine on merge blocks (#3130)
- Use dummy switch instead of dummy loop in MergeReturn pass. (#3151)
- Handle TimeAMD in AmdExtensionToKhrPass. (#3168)
- Validator
- Fix structured exit validation (#3141)
- Reduce
- Fuzz
- Fuzzer pass to merge blocks (#3097)
- Transformation to add a new function to a module (#3114)
- Add fuzzer pass to perform module donation (#3117)
- Fuzzer passes to create and branch to new dead blocks (#3135)
- Fuzzer pass to add composite types (#3171)
- Linker:
- Remove names and decorations of imported symbols (#3081)

v2019.5 2019-12-11
- General:
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ endif()

# Precompiled header macro. Parameters are source file list and filename for pch cpp file.
macro(spvtools_pch SRCS PCHPREFIX)
if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio")
if(MSVC AND CMAKE_GENERATOR MATCHES "^Visual Studio" AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(PCH_NAME "$(IntDir)\\${PCHPREFIX}.pch")
# make source files use/depend on PCH_NAME
set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS "/Yu${PCHPREFIX}.h /FI${PCHPREFIX}.h /Fp${PCH_NAME} /Zm300" OBJECT_DEPENDS "${PCH_NAME}")
Expand Down Expand Up @@ -300,7 +300,7 @@ if (NOT "${SPIRV_SKIP_TESTS}")
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

set(SPIRV_LIBRARIES "-lSPIRV-Tools -lSPIRV-Tools-link -lSPIRV-Tools-opt")
set(SPIRV_LIBRARIES "-lSPIRV-Tools-opt -lSPIRV-Tools -lSPIRV-Tools-link")
set(SPIRV_SHARED_LIBRARIES "-lSPIRV-Tools-shared")

# Build pkg-config file
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ vars = {
'effcee_revision': 'cd25ec17e9382f99a895b9ef53ff3c277464d07d',
'googletest_revision': 'f2fb48c3b3d79a75a88a99fba6576b25d42ec528',
're2_revision': '5bd613749fd530b576b890283bfb6bc6ea6246cb',
'spirv_headers_revision': 'dc77030acc9c6fe7ca21fff54c5a9d7b532d7da6',
'spirv_headers_revision': 'f8bf11a0253a32375c32cad92c841237b96696c0',
}

deps = {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ assembly and binary files with suffix `.spvasm` and `.spv`, respectively.

The assembler reads the assembly language text, and emits the binary form.

The standalone assembler is the exectuable called `spirv-as`, and is located in
The standalone assembler is the executable called `spirv-as`, and is located in
`<spirv-build-dir>/tools/spirv-as`. The functionality of the assembler is implemented
by the `spvTextToBinary` library function.

Expand Down
8 changes: 4 additions & 4 deletions build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,16 @@ def generate_vendor_tables(extension, operand_kind_prefix = ""):
def generate_extinst_lang_headers(name, grammar = None):
if not grammar:
fail("Must specify grammar", "grammar")
fmtargs = [name]
outs = [name + ".h"]
fmtargs = outs
native.genrule(
name = "gen_extinst_lang_headers_" + name,
srcs = [grammar],
outs = [name + ".h"],
outs = outs,
cmd = (
"$(location :generate_language_headers) " +
"--extinst-name={0} " +
"--extinst-grammar=$< " +
"--extinst-output-base=$(@D)/{0}"
"--extinst-output-path=$(location {0})"
).format(*fmtargs),
tools = [":generate_language_headers"],
visibility = ["//visibility:private"],
Expand Down
83 changes: 83 additions & 0 deletions docs/spirv-fuzz.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Guide to writing a spirv-fuzz fuzzer pass

Writing a spirv-fuzz fuzzer pass usually requires two main contributions:

- A *transformation*, capturing a small semantics-preserving change that can be made to a SPIR-V module. This requires adding a protobuf message representing the transformation, and a corresponding class that implements the `Transformation` interface.
- A new *fuzzer pass* class, implementing the `FuzzerPass` interface, that knows how to walk a SPIR-V module and apply the new transformation in a randomized fashion.

In some cases, more than one kind of transformation is required for a single fuzzer pass, and in some cases the transformations that a new fuzzer pass requires have already been introduced by existing passes. But the most common case is to introduce a transformation and fuzzer pass together.

As an example, let's consider the `TransformationSetSelectionControl` transformation. In SPIR-V, an `OpSelectionMerge` instruction (which intuitively indicates the start of an `if` or `switch` statement in a function) has a *selection control* mask, that can be one of `None`, `Flatten` or `DontFlatten`. The details of these do not matter much for this little tutorial, but in brief, this parameter provides a hint to the shader compiler as to whether it would be profitable to attempt to flatten a piece of conditional code so that all of its statements are executed in a predicated fashion.

As the selection control mask is just a hint, changing the value of this mask should have no semantic impact on the module. The `TransformationSelectionControl` transformation specifies a new value for a given selection control mask.

## Adding a new protobuf message

Take a look at the `Transformation` message in `spvtoolsfuzz.proto`. This has a `oneof` field that can be any one of the different spirv-fuzz transformations. Observe that one of the options is `TransformationSetSelectionControl`. When adding a transformation you first need to add an option for your transformation to the end of the `oneof` declaration.

Now look at the `TransformationSetSelectionControl` message. If adding your own transformation you need to add a new message for your transformation, and it should be placed alphabetically with respect to other transformations.

The fields of `TransformationSetSelectionControl` provide just enough information to (a) determine whether a given example of this transformation is actually applicable, and (b) apply the transformation in the case that it is applicable. The details of the transformation message will vary a lot between transformations. In this case, the message has a `block_id` field, specifying a block that must end with `OpSelectionMerge`, and a `selection_control` field, which is the new value for the selection control mask of the `OpSelectionMerge` instruction.

## Adding a new transformation class

If your transformation is called `TransformationSomeThing`, you need to add `transformation_some_thing.h` and `transformation_some_thing.cpp` to `source/fuzz` and the corresponding `CMakeLists.txt` file. So for `TransformationSetSelectionControl` we have `transformation_selection_control.h` and `transformation_selection_control.cpp`, and we will use this as an example to illustrate the expected contents of these files.

The header file contains the specification of a class, `TransformationSetSelectionControl`, that implements the `Transformation` interface (from `transformation.h`).

A transformation class should always have a single field, which should be the associated protobuf message; in our case:

```
private:
protobufs::TransformationSetSelectionControl message_;
```

and two public constructors, one that takes a protobuf message; in our case:

```
explicit TransformationSetSelectionControl(
const protobufs::TransformationSetSelectionControl& message);
```

and one that takes a parameter for each protobuf message field; in our case:

```
TransformationSetSelectionControl(uint32_t block_id);
```

The first constructor allows an instance of the class to be created from a corresponding protobuf message. The second should provide the ingredients necessary to populate a protobuf message.

The class should also override the `IsApplicable`, `Apply` and `ToMessage` methods from `Transformation`.

See `transformation_set_selection_control.h` for an example.

The `IsApplicable` method should have a comment in the header file describing the conditions for applicability in simple terms. These conditions should be implemented in the body of this method in the `.cpp` file.

In the case of `TransformationSetSelectionControl`, `IsApplicable` involves checking that `block_id` is indeed the id of a block that has an `OpSelectoinMerge` instruction, and that `selection_control` is a valid selection mask.

The `Apply` method should have a comment in the header file summarising the result of applying the transformation. It should be implemented in the `.cpp` file, and you should assume that `IsApplicable` holds whenever `Apply` is invoked.

## Writing tests for the transformation class

Whenever you add a transformation class, `TransformationSomeThing`, you should add an associated test file, `transformation_some_thing_test.cpp`, under `test/fuzz`, adding it to the associated `CMakeLists.txt` file.

For example `test/fuzz/transformation_set_selection_control_test.cpp` contains tests for `TransformationSetSelectionControl`. Your tests should aim to cover one example from each scenario where the transformation is inapplicable, and check that it is indeed deemed inapplicable, and then check that the transformation does the right thing when applied in a few different ways.

For example, the tests for `TransformationSetSelectionControl` check that a transformation of this kind is inapplicable if the `block_id` field of the transformation is not a block, or does not end in `OpSelectionMerge`, or if the `selection_control` mask has an illegal value. It also checks that applying a sequence of valid transformations to a SPIR-V shader leads to a shader with appropriately modified selection controls.

## Adding a new fuzzer pass class

A *fuzzer pass* traverses a SPIR-V module looking for places to apply a certain kind of transformation, and randomly decides at which of these points to actually apply the transformation. It might be necessary to apply other transformations in order to apply a given transformation (for example, if a transformation requires a certain type to be present in the module, said type can be added if not already present via another transformation).

A fuzzer pass implements the `FuzzerPass` interface, and overrides its `Apply` method. If your fuzzer pass is named `FuzzerPassSomeThing` then it should be represented by `fuzzer_pass_some_thing.h` and `fuzzer_pass_some_thing.cpp`, under `source/fuzz`; these should be added to the associated `CMakeLists.txt` file.

Have a look at the source filed for `FuzzerPassAdjustSelectionControls`. This pass considers every block that ends with `OpSelectionMerge`. It decides randomly whether to adjust the selection control of this merge instruction via:

```
if (!GetFuzzerContext()->ChoosePercentage(
GetFuzzerContext()->GetChanceOfAdjustingSelectionControl())) {
continue;
}
```

The `GetChanceOfAddingSelectionControl()` method has been added to `FuzzerContext` specifically to support this pass, and returns a percentage between 0 and 100. It returns the `chance_of_adjusting_selection_control_` of `FuzzerContext`, which is randomly initialized to lie with the interval defined by `kChanceOfAdjustingSelectionControl` in `fuzzer_context.cpp`. For any pass you write, you will need to add an analogous `GetChanceOf...` method to `FuzzerContext`, backed by an appropriate field, and you will need to decide on lower and upper bounds for this field and specify these via a `kChanceOf...` constant.
2 changes: 1 addition & 1 deletion examples/cpp-interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ add_spvtools_example(
TARGET spirv-tools-cpp-example
SRCS main.cpp
LIBS SPIRV-Tools-opt
)
)
10 changes: 10 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ else()
endif()

if (IS_DIRECTORY ${SPIRV_HEADER_DIR})
# TODO(dneto): We should not be modifying the parent scope.
set(SPIRV_HEADER_INCLUDE_DIR ${SPIRV_HEADER_DIR}/include PARENT_SCOPE)

# Add SPIRV-Headers as a sub-project if it isn't already defined.
# Do this so enclosing projects can use SPIRV-Headers_SOURCE_DIR to find
# headers to include.
if (NOT DEFINED SPIRV-Headers_SOURCE_DIR)
set(SPIRV_HEADERS_SKIP_INSTALL ON)
set(SPIRV_HEADERS_SKIP_EXAMPLES ON)
add_subdirectory(${SPIRV_HEADER_DIR})
endif()
else()
message(FATAL_ERROR
"SPIRV-Headers was not found - please checkout a copy under external/.")
Expand Down
3 changes: 3 additions & 0 deletions include/spirv-tools/instrument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ static const int kDebugInputBindingBindless = 1;
// The binding for the input buffer read by InstBuffAddrCheckPass.
static const int kDebugInputBindingBuffAddr = 2;

// This is the output buffer written by InstDebugPrintfPass.
static const int kDebugOutputPrintfStream = 3;

// Bindless Validation Input Buffer Format
//
// An input buffer for bindless validation consists of a single array of
Expand Down
13 changes: 12 additions & 1 deletion include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2015-2016 The Khronos Group Inc.
// Copyright (c) 2015-2020 The Khronos Group Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
// reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -165,6 +167,12 @@ typedef enum spv_operand_type_t {
SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS, // SPIR-V Sec 3.29
SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO, // SPIR-V Sec 3.30
SPV_OPERAND_TYPE_CAPABILITY, // SPIR-V Sec 3.31
SPV_OPERAND_TYPE_RAY_FLAGS, // SPIR-V Sec 3.RF
SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION, // SPIR-V Sec 3.RQIntersection
SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE, // SPIR-V Sec
// 3.RQCommitted
SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE, // SPIR-V Sec
// 3.RQCandidate

// Set 5: Operands that are a single word bitmask.
// Sometimes a set bit indicates the instruction requires still more operands.
Expand Down Expand Up @@ -766,6 +774,9 @@ SPIRV_TOOLS_EXPORT void spvDiagnosticDestroy(spv_diagnostic diagnostic);
SPIRV_TOOLS_EXPORT spv_result_t
spvDiagnosticPrint(const spv_diagnostic diagnostic);

// Gets the name of an instruction, without the "Op" prefix.
SPIRV_TOOLS_EXPORT const char* spvOpcodeString(const uint32_t opcode);

// The binary parser interface.

// A pointer to a function that accepts a parsed SPIR-V header.
Expand Down
12 changes: 12 additions & 0 deletions include/spirv-tools/optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,18 @@ Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t desc_set,
uint32_t shader_id,
uint32_t version = 2);

// Create a pass to instrument OpDebugPrintf instructions.
// This pass replaces all OpDebugPrintf instructions with instructions to write
// a record containing the string id and the all specified values into a special
// printf output buffer (if space allows). This pass is designed to support
// the printf validation in the Vulkan validation layers.
//
// The instrumentation will write buffers in debug descriptor set |desc_set|.
// It will write |shader_id| in each output record to identify the shader
// module which generated the record.
Optimizer::PassToken CreateInstDebugPrintfPass(uint32_t desc_set,
uint32_t shader_id);

// Create a pass to upgrade to the VulkanKHR memory model.
// This pass upgrades the Logical GLSL450 memory model to Logical VulkanKHR.
// Additionally, it modifies memory, image, atomic and barrier operations to
Expand Down
6 changes: 2 additions & 4 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ macro(spvtools_vendor_tables VENDOR_TABLE SHORT_NAME OPERAND_KIND_PREFIX)
endmacro(spvtools_vendor_tables)

macro(spvtools_extinst_lang_headers NAME GRAMMAR_FILE)
set(OUTBASE ${spirv-tools_BINARY_DIR}/${NAME})
set(OUT_H ${OUTBASE}.h)
set(OUT_H ${spirv-tools_BINARY_DIR}/${NAME}.h)
add_custom_command(OUTPUT ${OUT_H}
COMMAND ${PYTHON_EXECUTABLE} ${LANG_HEADER_PROCESSING_SCRIPT}
--extinst-name=${NAME}
--extinst-grammar=${GRAMMAR_FILE}
--extinst-output-base=${OUTBASE}
--extinst-output-path=${OUT_H}
DEPENDS ${LANG_HEADER_PROCESSING_SCRIPT} ${GRAMMAR_FILE}
COMMENT "Generate language specific header for ${NAME}.")
add_custom_target(spirv-tools-header-${NAME} DEPENDS ${OUT_H})
Expand Down
Loading