diff --git a/src/dxvk/dxvk_shader.h b/src/dxvk/dxvk_shader.h index 63ad4996..45f5617c 100644 --- a/src/dxvk/dxvk_shader.h +++ b/src/dxvk/dxvk_shader.h @@ -5,6 +5,7 @@ #include "dxvk_include.h" #include "./spirv/dxvk_spirv_code_buffer.h" +#include "./spirv/dxvk_spirv_id_counter.h" namespace dxvk { diff --git a/src/dxvk/spirv/dxvk_spirv_code_buffer.cpp b/src/dxvk/spirv/dxvk_spirv_code_buffer.cpp index 11c6e194..b31979ef 100644 --- a/src/dxvk/spirv/dxvk_spirv_code_buffer.cpp +++ b/src/dxvk/spirv/dxvk_spirv_code_buffer.cpp @@ -26,13 +26,15 @@ namespace dxvk { void DxvkSpirvCodeBuffer::append(const DxvkSpirvCodeBuffer& other) { - const size_t size = m_code.size(); - m_code.resize(size + other.m_code.size()); - - uint32_t* dst = this->m_code.data(); - const uint32_t* src = other.m_code.data(); - - std::memcpy(dst + size, src, sizeof(uint32_t) * size); + if (other.size() != 0) { + const size_t size = m_code.size(); + m_code.resize(size + other.m_code.size()); + + uint32_t* dst = this->m_code.data(); + const uint32_t* src = other.m_code.data(); + + std::memcpy(dst + size, src, sizeof(uint32_t) * size); + } } diff --git a/src/dxvk/spirv/dxvk_spirv_id_counter.h b/src/dxvk/spirv/dxvk_spirv_id_counter.h new file mode 100644 index 00000000..bf5eb1e5 --- /dev/null +++ b/src/dxvk/spirv/dxvk_spirv_id_counter.h @@ -0,0 +1,32 @@ +#pragma once + +#include "../dxvk_include.h" + +namespace dxvk { + + /** + * \brief SPIR-V ID counter + * + * Allocates IDs, starting at zero. This is meant + * to be used to allocate unique IDs during code + * generation. + */ + class DxvkSpirvIdCounter { + + public: + + uint32_t nexId() { + return m_id++; + } + + uint32_t numIds() const { + return m_id; + } + + private: + + uint32_t m_id = 0; + + }; + +} \ No newline at end of file