From 9f88249b91ce15bcfa73c74f33f0b030fcd1a86e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 19 Nov 2019 12:12:05 +0100 Subject: [PATCH] [spirv] Add method to allocate new ID from code buffer. --- src/spirv/spirv_code_buffer.cpp | 10 ++++++++++ src/spirv/spirv_code_buffer.h | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/spirv/spirv_code_buffer.cpp b/src/spirv/spirv_code_buffer.cpp index 327f359d..5a936ba8 100644 --- a/src/spirv/spirv_code_buffer.cpp +++ b/src/spirv/spirv_code_buffer.cpp @@ -40,6 +40,16 @@ namespace dxvk { } + uint32_t SpirvCodeBuffer::allocId() { + constexpr size_t BoundIdsOffset = 3; + + if (m_code.size() <= BoundIdsOffset) + return 0; + + return m_code[BoundIdsOffset]++; + } + + void SpirvCodeBuffer::append(const SpirvCodeBuffer& other) { if (other.size() != 0) { const size_t size = m_code.size(); diff --git a/src/spirv/spirv_code_buffer.h b/src/spirv/spirv_code_buffer.h index 81ba24da..ab080ceb 100644 --- a/src/spirv/spirv_code_buffer.h +++ b/src/spirv/spirv_code_buffer.h @@ -76,6 +76,15 @@ namespace dxvk { return SpirvInstructionIterator(nullptr, 0, 0); } + /** + * \brief Allocates a new ID + * + * Returns a new valid ID and increments the + * maximum ID count stored in the header. + * \returns The new SPIR-V ID + */ + uint32_t allocId(); + /** * \brief Merges two code buffers * @@ -101,7 +110,7 @@ namespace dxvk { * \param [in] wordCount Number of words */ void putIns(spv::Op opCode, uint16_t wordCount); - + /** * \brief Appends a 32-bit integer to the buffer * \param [in] value The number to add