#pragma once #include #include #include "dxbc_tag.h" namespace dxvk { /** * \brief DXBC bytecode reader * * Holds references to the shader byte code and * provides methods to read */ class DxbcReader { public: DxbcReader(const char* data, size_t size) : DxbcReader(data, size, 0) { } auto readu8 () { return this->readNum (); } auto readu16() { return this->readNum(); } auto readu32() { return this->readNum(); } auto readu64() { return this->readNum(); } auto readi8 () { return this->readNum (); } auto readi16() { return this->readNum (); } auto readi32() { return this->readNum (); } auto readi64() { return this->readNum (); } auto readf32() { return this->readNum (); } auto readf64() { return this->readNum (); } template auto readEnum() { using Tx = std::underlying_type_t; return static_cast(this->readNum()); } DxbcTag readTag(); std::string readString(); void read(void* dst, size_t n); void skip(size_t n); DxbcReader clone(size_t pos) const; DxbcReader resize(size_t size) const; bool eof() const { return m_pos >= m_size; } private: DxbcReader(const char* data, size_t size, size_t pos) : m_data(data), m_size(size), m_pos(pos) { } const char* m_data = nullptr; size_t m_size = 0; size_t m_pos = 0; template T readNum() { T result; this->read(&result, sizeof(result)); return result; } }; }