-
Notifications
You must be signed in to change notification settings - Fork 474
gpuav: Bounds checking for shared/private/function arrays #11872
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
Open
jeffbolznv
wants to merge
10
commits into
KhronosGroup:main
Choose a base branch
from
jeffbolznv:shared_memory_oob
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2966cef
gpuav: Bounds checking for shared memory accesses
jeffbolznv 4d1d425
gpuav: Safe mode
jeffbolznv 3cde4f5
gpuav: Better error messages
jeffbolznv 9ca855f
gpuav: Test changes
jeffbolznv fb11604
gpuav: Test fixes, don't disable datarace
jeffbolznv 4bceb25
gpuav: Regenerate
jeffbolznv fd1996d
gpuav: Handle Private/Function storage
jeffbolznv 333210b
gpuav: Rename to ArrayOob
jeffbolznv 6ada90b
gpuav: Fix pass order
jeffbolznv 2759d86
gpuav: Coerce OOB indices to 0
jeffbolznv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* Copyright (c) 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 "generated/spirv_grammar_helper.h" | ||
| #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" | ||
| #include "error_message/spirv_logging.h" | ||
|
|
||
| namespace gpuav { | ||
|
|
||
| void RegisterArrayOobValidation(Validator& gpuav, CommandBufferSubState& cb) { | ||
| if (!gpuav.gpuav_settings.shader_instrumentation.array_oob) { | ||
| 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, const InstrumentedShader* instrumented_shader, | ||
| std::string& out_error_msg, std::string& out_vuid_msg) { | ||
| using namespace glsl; | ||
| bool error_found = false; | ||
| if (GetErrorGroup(error_record) != kErrorGroup_ArrayOob) { | ||
| return error_found; | ||
| } | ||
| error_found = true; | ||
|
|
||
| const uint32_t index = error_record[kInst_LogError_ParameterOffset_0]; | ||
| const uint32_t encoded_bound = error_record[kInst_LogError_ParameterOffset_1]; | ||
| const uint32_t variable_id = error_record[kInst_LogError_ParameterOffset_2]; | ||
|
|
||
| const uint32_t bound = encoded_bound & 0x00FFFFFFu; | ||
| const uint32_t access_type = (encoded_bound >> 24) & 0x3u; | ||
| const uint32_t dim_index = (encoded_bound >> 26) & 0x1Fu; | ||
|
|
||
| const uint32_t instruction_position_offset = error_record[kHeader_StageInstructionIdOffset] & kInstructionId_Mask; | ||
|
|
||
| std::ostringstream strm; | ||
| strm << "Variable \""; | ||
| if (instrumented_shader) { | ||
| ::spirv::FindGlobalName(strm, instrumented_shader->original_spirv, (uint32_t)spv::OpVariable, variable_id); | ||
| } else { | ||
| strm << "[error, original SPIR-V not found]"; | ||
| } | ||
| strm << "\" "; | ||
| if (access_type == 1) { | ||
| strm << "vector component"; | ||
| } else { | ||
| strm << "array index"; | ||
| if (dim_index > 0) { | ||
| strm << " (dimension " << dim_index << ")"; | ||
| } | ||
| } | ||
| strm << " " << index << " is >= " << ((access_type == 1) ? "vector size " : "array size ") << bound << "."; | ||
|
|
||
| uint32_t opcode = (uint32_t)spv::OpMax; | ||
| if (instrumented_shader) { | ||
| opcode = ::spirv::GetOpcodeAtOffset(instrumented_shader->original_spirv, instruction_position_offset); | ||
| } | ||
| strm << GetSpirvSpecLink(opcode); | ||
|
|
||
| out_vuid_msg = std::string("SPIRV-ArrayOob-") + string_SpvOpcode(opcode); | ||
|
|
||
| out_error_msg += strm.str(); | ||
| return error_found; | ||
| }; | ||
|
|
||
| return inst_error_logger; | ||
| }); | ||
| } | ||
|
|
||
| } // namespace gpuav | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) 2026 The Khronos Group Inc. | ||
| // Copyright (c) 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. | ||
|
|
||
| // NOTE: This file doesn't contain any entrypoints and should be compiled with the --no-link option for glslang | ||
|
|
||
| #version 450 | ||
| #extension GL_GOOGLE_include_directive : enable | ||
| #include "common_descriptor_sets.h" | ||
| #include "error_payload.h" | ||
|
|
||
| bool inst_array_oob(const uint index, const uint encoded_bound, const uint inst_offset, const uint variable_id) { | ||
| const uint bound = encoded_bound & 0x00FFFFFFu; | ||
| if (index >= bound) { | ||
| error_payload = ErrorPayload( | ||
| inst_offset, | ||
| SpecConstantLinkShaderId | (kErrorGroup_ArrayOob << kErrorGroup_Shift), | ||
| index, | ||
| encoded_bound, | ||
| variable_id); | ||
| return false; | ||
| } | ||
| return true; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.