Shader: Add SpirvDecoder

This commit is contained in:
Jérôme Leclercq
2021-04-04 20:29:23 +02:00
parent 5a63eb4d97
commit 09df5f389e
6 changed files with 194 additions and 90 deletions

View File

@@ -0,0 +1,59 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Shader generator"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SPIRVDECODER_HPP
#define NAZARA_SPIRVDECODER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Shader/Config.hpp>
#include <Nazara/Shader/SpirvData.hpp>
#include <functional>
#include <string>
#include <vector>
namespace Nz
{
class NAZARA_SHADER_API SpirvDecoder
{
public:
SpirvDecoder() = default;
SpirvDecoder(const SpirvDecoder&) = default;
SpirvDecoder(SpirvDecoder&&) = default;
~SpirvDecoder() = default;
void Decode(const UInt32* codepoints, std::size_t count);
SpirvDecoder& operator=(const SpirvDecoder&) = default;
SpirvDecoder& operator=(SpirvDecoder&&) = default;
protected:
struct SpirvHeader;
inline const UInt32* GetCurrentPtr() const;
virtual bool HandleHeader(const SpirvHeader& header);
virtual bool HandleOpcode(const SpirvInstruction& instruction, UInt32 wordCount) = 0;
std::string ReadString();
UInt32 ReadWord();
struct SpirvHeader
{
UInt32 generatorId;
UInt32 bound;
UInt32 schema;
UInt32 versionNumber;
};
private:
const UInt32* m_currentCodepoint;
const UInt32* m_codepointEnd;
};
}
#include <Nazara/Shader/SpirvDecoder.inl>
#endif

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Shader generator"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/SpirvDecoder.hpp>
#include <Nazara/Shader/Debug.hpp>
namespace Nz
{
inline const UInt32* SpirvDecoder::GetCurrentPtr() const
{
return m_currentCodepoint;
}
}
#include <Nazara/Shader/DebugOff.hpp>

View File

@@ -9,12 +9,13 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Shader/Config.hpp>
#include <Nazara/Shader/SpirvDecoder.hpp>
#include <string>
#include <vector>
namespace Nz
{
class NAZARA_SHADER_API SpirvPrinter
class NAZARA_SHADER_API SpirvPrinter : SpirvDecoder
{
public:
struct Settings;
@@ -39,9 +40,8 @@ namespace Nz
};
private:
void AppendInstruction();
std::string ReadString();
UInt32 ReadWord();
bool HandleHeader(const SpirvHeader& header) override;
bool HandleOpcode(const SpirvInstruction& instruction, UInt32 wordCount) override;
struct State;

View File

@@ -9,8 +9,8 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Shader/Config.hpp>
#include <Nazara/Shader/ShaderAstCache.hpp>
#include <Nazara/Shader/ShaderConstantValue.hpp>
#include <Nazara/Shader/ShaderNodes.hpp>
#include <Nazara/Shader/ShaderWriter.hpp>
#include <Nazara/Shader/SpirvConstantCache.hpp>
#include <string>
@@ -90,9 +90,7 @@ namespace Nz
struct Context
{
ShaderAst::AstCache cache;
const States* states = nullptr;
std::vector<SpirvBlock> functionBlocks;
};
struct ExtVar