From 6944f6f7281dfa04c500e517e1660c7abd265d01 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 9 Feb 2018 12:17:40 +0000 Subject: [PATCH] Don't allow direct == or != on SPIRVIterator, use < * The reason is if comparing directly against the end of a section, we could skip over it if the section ends in a nop and the next section starts in a nop. Instead < will always work as expected. --- renderdoc/driver/shaders/spirv/spirv_editor.cpp | 2 +- renderdoc/driver/shaders/spirv/spirv_editor.h | 8 +++----- renderdoc/driver/vulkan/vk_postvs.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/renderdoc/driver/shaders/spirv/spirv_editor.cpp b/renderdoc/driver/shaders/spirv/spirv_editor.cpp index 610289b45..3ec465721 100644 --- a/renderdoc/driver/shaders/spirv/spirv_editor.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_editor.cpp @@ -325,7 +325,7 @@ SPIRVIterator SPIRVEditor::GetEntry(SPIRVId id) SPIRVIterator it(spirv, entryPointSection.startOffset); SPIRVIterator end(spirv, entryPointSection.endOffset); - while(it && it != end) + while(it && it < end) { if(it.word(2) == id) return it; diff --git a/renderdoc/driver/shaders/spirv/spirv_editor.h b/renderdoc/driver/shaders/spirv/spirv_editor.h index beebec7c9..2d2471468 100644 --- a/renderdoc/driver/shaders/spirv/spirv_editor.h +++ b/renderdoc/driver/shaders/spirv/spirv_editor.h @@ -77,11 +77,9 @@ public: return *this; } - bool operator==(const SPIRVIterator &it) const - { - return words == it.words && offset == it.offset; - } - bool operator!=(const SPIRVIterator &it) const { return !(*this == it); } + bool operator==(const SPIRVIterator &it) const = delete; + bool operator!=(const SPIRVIterator &it) const = delete; + bool operator<(const SPIRVIterator &it) const { return words == it.words && offset < it.offset; } // utility functions explicit operator bool() const { return words != NULL && offset < words->size(); } uint32_t &operator*() { return cur(); } diff --git a/renderdoc/driver/vulkan/vk_postvs.cpp b/renderdoc/driver/vulkan/vk_postvs.cpp index 49e24d91e..b57390488 100644 --- a/renderdoc/driver/vulkan/vk_postvs.cpp +++ b/renderdoc/driver/vulkan/vk_postvs.cpp @@ -49,7 +49,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV descSet = 0; - for(SPIRVIterator it = editor.BeginDecorations(), end = editor.EndDecorations(); it != end; ++it) + for(SPIRVIterator it = editor.BeginDecorations(), end = editor.EndDecorations(); it < end; ++it) { // we will use the descriptor set immediately after the last set statically used by the shader. // This means we don't have to worry about if the descriptor set layout declares more sets which @@ -103,7 +103,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV std::map typeReplacements; // rewrite any inputs and outputs to be private storage class - for(SPIRVIterator it = editor.BeginTypes(), end = editor.EndTypes(); it != end; ++it) + for(SPIRVIterator it = editor.BeginTypes(), end = editor.EndTypes(); it < end; ++it) { // rewrite any input/output variables to private, and build up inputs/outputs list if(it.opcode() == spv::OpTypePointer) @@ -246,7 +246,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV } // detect builtin inputs or outputs, and remove builtin decorations - for(SPIRVIterator it = editor.BeginDecorations(), end = editor.EndDecorations(); it != end; ++it) + for(SPIRVIterator it = editor.BeginDecorations(), end = editor.EndDecorations(); it < end; ++it) { // remove any builtin decorations if(it.opcode() == spv::OpDecorate && it.word(2) == spv::DecorationBuiltIn) @@ -335,7 +335,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV RDCASSERT(entryID); - for(SPIRVIterator it = editor.BeginDebug(), end2 = editor.EndDebug(); it != end2; ++it) + for(SPIRVIterator it = editor.BeginDebug(), end2 = editor.EndDebug(); it < end2; ++it) { if(it.opcode() == spv::OpName && (inputs.find(it.word(1)) != inputs.end() || outputs.find(it.word(1)) != outputs.end())) @@ -659,7 +659,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV ++it; } - for(SPIRVIterator end = editor.EndEntries(); it != end; ++it) + for(SPIRVIterator end = editor.EndEntries(); it < end; ++it) editor.Remove(it); editor.AddOperation(