mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-10-09 13:51:31 +00:00
Move SPIR-V utility/parsing/editing code into rdcspv namespace
* Everything except the reflection code which will be replaced
This commit is contained in:
19 files changed
+636
-638
No files matched your search
@@ -69,11 +69,11 @@ GLuint GLReplay::CreateSPIRVShader(GLenum shaderType, const std::string &src)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPIRVCompilationSettings settings(SPIRVSourceLanguage::OpenGLGLSL,
|
||||
SPIRVShaderStage(ShaderIdx(shaderType)));
|
||||
rdcspv::CompilationSettings settings(rdcspv::InputLanguage::OpenGLGLSL,
|
||||
rdcspv::ShaderStage(ShaderIdx(shaderType)));
|
||||
|
||||
std::vector<uint32_t> spirv;
|
||||
std::string s = CompileSPIRV(settings, {src}, spirv);
|
||||
std::string s = rdcspv::Compile(settings, {src}, spirv);
|
||||
|
||||
if(spirv.empty())
|
||||
{
|
||||
|
||||
@@ -699,8 +699,8 @@ WrappedOpenGL::WrappedOpenGL(GLPlatform &platform)
|
||||
ResourceIDGen::SetReplayResourceIDs();
|
||||
}
|
||||
|
||||
InitSPIRVCompiler();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&ShutdownSPIRVCompiler);
|
||||
rdcspv::Init();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&rdcspv::Shutdown);
|
||||
|
||||
m_CurrentDefaultFBO = 0;
|
||||
|
||||
|
||||
@@ -3434,8 +3434,8 @@ void MakeOfflineShaderReflection(ShaderStage stage, const std::string &source,
|
||||
const std::string &entryPoint, ShaderReflection &refl,
|
||||
ShaderBindpointMapping &mapping)
|
||||
{
|
||||
InitSPIRVCompiler();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&ShutdownSPIRVCompiler);
|
||||
rdcspv::Init();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&rdcspv::Shutdown);
|
||||
|
||||
RDCASSERT(entryPoint == "main");
|
||||
|
||||
@@ -3451,7 +3451,7 @@ void MakeOfflineShaderReflection(ShaderStage stage, const std::string &source,
|
||||
GL = GLDispatchTable();
|
||||
GL.EmulateRequiredExtensions();
|
||||
|
||||
glslang::TShader *sh = CompileShaderForReflection(SPIRVShaderStage(stage), {source});
|
||||
glslang::TShader *sh = CompileShaderForReflection(rdcspv::ShaderStage(stage), {source});
|
||||
|
||||
REQUIRE(sh);
|
||||
|
||||
@@ -3575,8 +3575,8 @@ void main() {
|
||||
|
||||
)";
|
||||
|
||||
InitSPIRVCompiler();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&ShutdownSPIRVCompiler);
|
||||
rdcspv::Init();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&rdcspv::Shutdown);
|
||||
|
||||
// as a hack, create a local 'driver' and just populate m_Programs with what we want.
|
||||
GLDummyPlatform dummy;
|
||||
@@ -3589,8 +3589,8 @@ void main() {
|
||||
GL.EmulateRequiredExtensions();
|
||||
|
||||
glslang::TProgram *prog = LinkProgramForReflection(
|
||||
{CompileShaderForReflection(SPIRVShaderStage::Vertex, {vssource}),
|
||||
CompileShaderForReflection(SPIRVShaderStage::Fragment, {fssource})});
|
||||
{CompileShaderForReflection(rdcspv::ShaderStage::Vertex, {vssource}),
|
||||
CompileShaderForReflection(rdcspv::ShaderStage::Fragment, {fssource})});
|
||||
|
||||
REQUIRE(prog);
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ void WrappedOpenGL::ShaderData::ProcessCompilation(WrappedOpenGL &drv, ResourceI
|
||||
// if we don't have program_interface_query, need to compile the shader with glslang to be able
|
||||
// to reflect with. This is needed on capture or replay
|
||||
if(!HasExt[ARB_program_interface_query] && status == 1)
|
||||
glslangShader = CompileShaderForReflection(SPIRVShaderStage(ShaderIdx(type)), sources);
|
||||
glslangShader = CompileShaderForReflection(rdcspv::ShaderStage(ShaderIdx(type)), sources);
|
||||
|
||||
if(IsReplayMode(drv.GetState()) && !drv.IsInternalShader())
|
||||
{
|
||||
@@ -262,10 +262,10 @@ void WrappedOpenGL::ShaderData::ProcessCompilation(WrappedOpenGL &drv, ResourceI
|
||||
{
|
||||
std::vector<uint32_t> spirvwords;
|
||||
|
||||
SPIRVCompilationSettings settings(SPIRVSourceLanguage::OpenGLGLSL,
|
||||
SPIRVShaderStage(ShaderIdx(type)));
|
||||
rdcspv::CompilationSettings settings(rdcspv::InputLanguage::OpenGLGLSL,
|
||||
rdcspv::ShaderStage(ShaderIdx(type)));
|
||||
|
||||
std::string s = CompileSPIRV(settings, sources, spirvwords);
|
||||
std::string s = rdcspv::Compile(settings, sources, spirvwords);
|
||||
if(!spirvwords.empty())
|
||||
ParseSPIRV(&spirvwords.front(), spirvwords.size(), spirv);
|
||||
else
|
||||
|
||||
@@ -148,7 +148,7 @@ TBuiltInResource *GetDefaultResources()
|
||||
return &DefaultResources;
|
||||
}
|
||||
|
||||
void InitSPIRVCompiler()
|
||||
void rdcspv::Init()
|
||||
{
|
||||
if(!glslang_inited)
|
||||
{
|
||||
@@ -160,7 +160,7 @@ void InitSPIRVCompiler()
|
||||
}
|
||||
}
|
||||
|
||||
void ShutdownSPIRVCompiler()
|
||||
void rdcspv::Shutdown()
|
||||
{
|
||||
if(glslang_inited)
|
||||
{
|
||||
@@ -181,7 +181,7 @@ void ShutdownSPIRVCompiler()
|
||||
}
|
||||
}
|
||||
|
||||
glslang::TShader *CompileShaderForReflection(SPIRVShaderStage stage,
|
||||
glslang::TShader *CompileShaderForReflection(rdcspv::ShaderStage stage,
|
||||
const std::vector<std::string> &sources)
|
||||
{
|
||||
EShLanguage lang = EShLanguage(stage);
|
||||
|
||||
@@ -34,7 +34,7 @@ class TShader;
|
||||
class TProgram;
|
||||
};
|
||||
|
||||
glslang::TShader *CompileShaderForReflection(SPIRVShaderStage stage,
|
||||
glslang::TShader *CompileShaderForReflection(rdcspv::ShaderStage stage,
|
||||
const std::vector<std::string> &sources);
|
||||
glslang::TProgram *LinkProgramForReflection(const std::vector<glslang::TShader *> &shaders);
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
#include "3rdparty/glslang/SPIRV/GlslangToSpv.h"
|
||||
#include "3rdparty/glslang/glslang/Public/ShaderLang.h"
|
||||
|
||||
std::string CompileSPIRV(const SPIRVCompilationSettings &settings,
|
||||
const std::vector<std::string> &sources, std::vector<uint32_t> &spirv)
|
||||
std::string rdcspv::Compile(const rdcspv::CompilationSettings &settings,
|
||||
const std::vector<std::string> &sources, std::vector<uint32_t> &spirv)
|
||||
{
|
||||
if(settings.stage == SPIRVShaderStage::Invalid)
|
||||
if(settings.stage == rdcspv::ShaderStage::Invalid)
|
||||
return "Invalid shader stage specified";
|
||||
|
||||
std::string errors = "";
|
||||
@@ -45,11 +45,11 @@ std::string CompileSPIRV(const SPIRVCompilationSettings &settings,
|
||||
for(size_t i = 0; i < sources.size(); i++)
|
||||
strs[i] = sources[i].c_str();
|
||||
|
||||
RDCCOMPILE_ASSERT((int)EShLangVertex == (int)SPIRVShaderStage::Vertex &&
|
||||
(int)EShLangTessControl == (int)SPIRVShaderStage::TessControl &&
|
||||
(int)EShLangTessEvaluation == (int)SPIRVShaderStage::TessEvaluation &&
|
||||
(int)EShLangGeometry == (int)SPIRVShaderStage::Geometry &&
|
||||
(int)EShLangCompute == (int)SPIRVShaderStage::Compute,
|
||||
RDCCOMPILE_ASSERT((int)EShLangVertex == (int)rdcspv::ShaderStage::Vertex &&
|
||||
(int)EShLangTessControl == (int)rdcspv::ShaderStage::TessControl &&
|
||||
(int)EShLangTessEvaluation == (int)rdcspv::ShaderStage::TessEvaluation &&
|
||||
(int)EShLangGeometry == (int)rdcspv::ShaderStage::Geometry &&
|
||||
(int)EShLangCompute == (int)rdcspv::ShaderStage::Compute,
|
||||
"Shader language enums don't match");
|
||||
|
||||
{
|
||||
@@ -65,9 +65,9 @@ std::string CompileSPIRV(const SPIRVCompilationSettings &settings,
|
||||
|
||||
EShMessages flags = EShMsgSpvRules;
|
||||
|
||||
if(settings.lang == SPIRVSourceLanguage::VulkanGLSL)
|
||||
if(settings.lang == rdcspv::InputLanguage::VulkanGLSL)
|
||||
flags = EShMessages(flags | EShMsgVulkanRules);
|
||||
if(settings.lang == SPIRVSourceLanguage::VulkanHLSL)
|
||||
if(settings.lang == rdcspv::InputLanguage::VulkanHLSL)
|
||||
flags = EShMessages(flags | EShMsgVulkanRules | EShMsgReadHlsl);
|
||||
|
||||
bool success = shader->parse(GetDefaultResources(), 110, false, flags);
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum class SPIRVShaderStage
|
||||
namespace rdcspv
|
||||
{
|
||||
enum class ShaderStage
|
||||
{
|
||||
Vertex,
|
||||
TessControl,
|
||||
@@ -38,7 +40,7 @@ enum class SPIRVShaderStage
|
||||
Invalid,
|
||||
};
|
||||
|
||||
enum class SPIRVSourceLanguage
|
||||
enum class InputLanguage
|
||||
{
|
||||
Unknown,
|
||||
OpenGLGLSL,
|
||||
@@ -46,18 +48,20 @@ enum class SPIRVSourceLanguage
|
||||
VulkanHLSL,
|
||||
};
|
||||
|
||||
struct SPIRVCompilationSettings
|
||||
struct CompilationSettings
|
||||
{
|
||||
SPIRVCompilationSettings(SPIRVSourceLanguage l, SPIRVShaderStage s) : stage(s), lang(l) {}
|
||||
SPIRVCompilationSettings() = default;
|
||||
CompilationSettings(InputLanguage l, ShaderStage s) : stage(s), lang(l) {}
|
||||
CompilationSettings() = default;
|
||||
|
||||
SPIRVShaderStage stage = SPIRVShaderStage::Invalid;
|
||||
SPIRVSourceLanguage lang = SPIRVSourceLanguage::Unknown;
|
||||
ShaderStage stage = ShaderStage::Invalid;
|
||||
InputLanguage lang = InputLanguage::Unknown;
|
||||
std::string entryPoint;
|
||||
};
|
||||
|
||||
void InitSPIRVCompiler();
|
||||
void ShutdownSPIRVCompiler();
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
std::string CompileSPIRV(const SPIRVCompilationSettings &settings,
|
||||
const std::vector<std::string> &sources, std::vector<uint32_t> &spirv);
|
||||
std::string Compile(const CompilationSettings &settings, const std::vector<std::string> &sources,
|
||||
std::vector<uint32_t> &spirv);
|
||||
|
||||
}; // namespace rdcspv
|
||||
File diff suppressed because it is too large.
Load diff
@@ -34,37 +34,39 @@
|
||||
#include "spirv_common.h"
|
||||
#include "spirv_op_helpers.h"
|
||||
|
||||
class SPIRVEditor;
|
||||
|
||||
struct SPIRVBinding
|
||||
namespace rdcspv
|
||||
{
|
||||
SPIRVBinding() = default;
|
||||
SPIRVBinding(uint32_t s, uint32_t b) : set(s), binding(b) {}
|
||||
class Editor;
|
||||
|
||||
struct Binding
|
||||
{
|
||||
Binding() = default;
|
||||
Binding(uint32_t s, uint32_t b) : set(s), binding(b) {}
|
||||
uint32_t set = 0;
|
||||
uint32_t binding = ~0U;
|
||||
|
||||
bool operator<(const SPIRVBinding &o) const
|
||||
bool operator<(const Binding &o) const
|
||||
{
|
||||
if(set != o.set)
|
||||
return set < o.set;
|
||||
return binding < o.binding;
|
||||
}
|
||||
|
||||
bool operator!=(const SPIRVBinding &o) const { return !operator==(o); }
|
||||
bool operator==(const SPIRVBinding &o) const { return set == o.set && binding == o.binding; }
|
||||
bool operator!=(const Binding &o) const { return !operator==(o); }
|
||||
bool operator==(const Binding &o) const { return set == o.set && binding == o.binding; }
|
||||
};
|
||||
|
||||
struct SPIRVScalar
|
||||
struct Scalar
|
||||
{
|
||||
SPIRVScalar() : type(rdcspv::Op::Max), width(0), signedness(false) {}
|
||||
constexpr SPIRVScalar(rdcspv::Op t, uint32_t w, bool s) : type(t), width(w), signedness(s) {}
|
||||
SPIRVScalar(rdcspv::Iter op);
|
||||
Scalar() : type(Op::Max), width(0), signedness(false) {}
|
||||
constexpr Scalar(Op t, uint32_t w, bool s) : type(t), width(w), signedness(s) {}
|
||||
Scalar(Iter op);
|
||||
|
||||
rdcspv::Op type;
|
||||
Op type;
|
||||
uint32_t width;
|
||||
bool signedness;
|
||||
|
||||
bool operator<(const SPIRVScalar &o) const
|
||||
bool operator<(const Scalar &o) const
|
||||
{
|
||||
if(type != o.type)
|
||||
return type < o.type;
|
||||
@@ -73,125 +75,121 @@ struct SPIRVScalar
|
||||
return width < o.width;
|
||||
}
|
||||
|
||||
bool operator!=(const SPIRVScalar &o) const { return !operator==(o); }
|
||||
bool operator==(const SPIRVScalar &o) const
|
||||
bool operator!=(const Scalar &o) const { return !operator==(o); }
|
||||
bool operator==(const Scalar &o) const
|
||||
{
|
||||
return type == o.type && width == o.width && signedness == o.signedness;
|
||||
}
|
||||
|
||||
rdcspv::Operation decl(SPIRVEditor &editor) const
|
||||
Operation decl(Editor &editor) const
|
||||
{
|
||||
if(type == rdcspv::Op::TypeVoid)
|
||||
return rdcspv::OpTypeVoid(rdcspv::Id());
|
||||
else if(type == rdcspv::Op::TypeBool)
|
||||
return rdcspv::OpTypeBool(rdcspv::Id());
|
||||
else if(type == rdcspv::Op::TypeFloat)
|
||||
return rdcspv::OpTypeFloat(rdcspv::Id(), width);
|
||||
else if(type == rdcspv::Op::TypeInt)
|
||||
return rdcspv::OpTypeInt(rdcspv::Id(), width, signedness ? 1U : 0U);
|
||||
if(type == Op::TypeVoid)
|
||||
return OpTypeVoid(Id());
|
||||
else if(type == Op::TypeBool)
|
||||
return OpTypeBool(Id());
|
||||
else if(type == Op::TypeFloat)
|
||||
return OpTypeFloat(Id(), width);
|
||||
else if(type == Op::TypeInt)
|
||||
return OpTypeInt(Id(), width, signedness ? 1U : 0U);
|
||||
else
|
||||
return rdcspv::OpNop();
|
||||
return OpNop();
|
||||
}
|
||||
};
|
||||
|
||||
// helper to create SPIRVScalar objects for known types
|
||||
// helper to create Scalar objects for known types
|
||||
template <typename T>
|
||||
inline constexpr SPIRVScalar scalar();
|
||||
inline constexpr Scalar scalar();
|
||||
|
||||
#define SCALAR_TYPE(ctype, op, width, sign) \
|
||||
template <> \
|
||||
inline constexpr SPIRVScalar scalar<ctype>() \
|
||||
{ \
|
||||
return SPIRVScalar(op, width, sign); \
|
||||
#define SCALAR_TYPE(ctype, op, width, sign) \
|
||||
template <> \
|
||||
inline constexpr Scalar scalar<ctype>() \
|
||||
{ \
|
||||
return Scalar(op, width, sign); \
|
||||
}
|
||||
|
||||
SCALAR_TYPE(void, rdcspv::Op::TypeVoid, 0, false);
|
||||
SCALAR_TYPE(bool, rdcspv::Op::TypeBool, 0, false);
|
||||
SCALAR_TYPE(uint8_t, rdcspv::Op::TypeInt, 8, false);
|
||||
SCALAR_TYPE(uint16_t, rdcspv::Op::TypeInt, 16, false);
|
||||
SCALAR_TYPE(uint32_t, rdcspv::Op::TypeInt, 32, false);
|
||||
SCALAR_TYPE(uint64_t, rdcspv::Op::TypeInt, 64, false);
|
||||
SCALAR_TYPE(int8_t, rdcspv::Op::TypeInt, 8, true);
|
||||
SCALAR_TYPE(int16_t, rdcspv::Op::TypeInt, 16, true);
|
||||
SCALAR_TYPE(int32_t, rdcspv::Op::TypeInt, 32, true);
|
||||
SCALAR_TYPE(int64_t, rdcspv::Op::TypeInt, 64, true);
|
||||
SCALAR_TYPE(float, rdcspv::Op::TypeFloat, 32, false);
|
||||
SCALAR_TYPE(double, rdcspv::Op::TypeFloat, 64, false);
|
||||
SCALAR_TYPE(void, Op::TypeVoid, 0, false);
|
||||
SCALAR_TYPE(bool, Op::TypeBool, 0, false);
|
||||
SCALAR_TYPE(uint8_t, Op::TypeInt, 8, false);
|
||||
SCALAR_TYPE(uint16_t, Op::TypeInt, 16, false);
|
||||
SCALAR_TYPE(uint32_t, Op::TypeInt, 32, false);
|
||||
SCALAR_TYPE(uint64_t, Op::TypeInt, 64, false);
|
||||
SCALAR_TYPE(int8_t, Op::TypeInt, 8, true);
|
||||
SCALAR_TYPE(int16_t, Op::TypeInt, 16, true);
|
||||
SCALAR_TYPE(int32_t, Op::TypeInt, 32, true);
|
||||
SCALAR_TYPE(int64_t, Op::TypeInt, 64, true);
|
||||
SCALAR_TYPE(float, Op::TypeFloat, 32, false);
|
||||
SCALAR_TYPE(double, Op::TypeFloat, 64, false);
|
||||
|
||||
struct SPIRVVector
|
||||
struct Vector
|
||||
{
|
||||
SPIRVVector(const SPIRVScalar &s, uint32_t c) : scalar(s), count(c) {}
|
||||
SPIRVScalar scalar;
|
||||
Vector(const Scalar &s, uint32_t c) : scalar(s), count(c) {}
|
||||
Scalar scalar;
|
||||
uint32_t count;
|
||||
|
||||
bool operator<(const SPIRVVector &o) const
|
||||
bool operator<(const Vector &o) const
|
||||
{
|
||||
if(scalar != o.scalar)
|
||||
return scalar < o.scalar;
|
||||
return count < o.count;
|
||||
}
|
||||
|
||||
bool operator!=(const SPIRVVector &o) const { return !operator==(o); }
|
||||
bool operator==(const SPIRVVector &o) const { return scalar == o.scalar && count == o.count; }
|
||||
rdcspv::Operation decl(SPIRVEditor &editor) const;
|
||||
bool operator!=(const Vector &o) const { return !operator==(o); }
|
||||
bool operator==(const Vector &o) const { return scalar == o.scalar && count == o.count; }
|
||||
Operation decl(Editor &editor) const;
|
||||
};
|
||||
|
||||
struct SPIRVMatrix
|
||||
struct Matrix
|
||||
{
|
||||
SPIRVMatrix(const SPIRVVector &v, uint32_t c) : vector(v), count(c) {}
|
||||
SPIRVVector vector;
|
||||
Matrix(const Vector &v, uint32_t c) : vector(v), count(c) {}
|
||||
Vector vector;
|
||||
uint32_t count;
|
||||
|
||||
bool operator<(const SPIRVMatrix &o) const
|
||||
bool operator<(const Matrix &o) const
|
||||
{
|
||||
if(vector != o.vector)
|
||||
return vector < o.vector;
|
||||
return count < o.count;
|
||||
}
|
||||
|
||||
bool operator!=(const SPIRVMatrix &o) const { return !operator==(o); }
|
||||
bool operator==(const SPIRVMatrix &o) const { return vector == o.vector && count == o.count; }
|
||||
rdcspv::Operation decl(SPIRVEditor &editor) const;
|
||||
bool operator!=(const Matrix &o) const { return !operator==(o); }
|
||||
bool operator==(const Matrix &o) const { return vector == o.vector && count == o.count; }
|
||||
Operation decl(Editor &editor) const;
|
||||
};
|
||||
|
||||
struct SPIRVPointer
|
||||
struct Pointer
|
||||
{
|
||||
SPIRVPointer(rdcspv::Id b, rdcspv::StorageClass s) : baseId(b), storage(s) {}
|
||||
rdcspv::Id baseId;
|
||||
rdcspv::StorageClass storage;
|
||||
Pointer(Id b, StorageClass s) : baseId(b), storage(s) {}
|
||||
Id baseId;
|
||||
StorageClass storage;
|
||||
|
||||
bool operator<(const SPIRVPointer &o) const
|
||||
bool operator<(const Pointer &o) const
|
||||
{
|
||||
if(baseId != o.baseId)
|
||||
return baseId < o.baseId;
|
||||
return storage < o.storage;
|
||||
}
|
||||
|
||||
bool operator!=(const SPIRVPointer &o) const { return !operator==(o); }
|
||||
bool operator==(const SPIRVPointer &o) const
|
||||
{
|
||||
return baseId == o.baseId && storage == o.storage;
|
||||
}
|
||||
rdcspv::Operation decl(SPIRVEditor &editor) const;
|
||||
bool operator!=(const Pointer &o) const { return !operator==(o); }
|
||||
bool operator==(const Pointer &o) const { return baseId == o.baseId && storage == o.storage; }
|
||||
Operation decl(Editor &editor) const;
|
||||
};
|
||||
|
||||
struct SPIRVImage
|
||||
struct Image
|
||||
{
|
||||
SPIRVImage(SPIRVScalar ret, rdcspv::Dim d, uint32_t dp, uint32_t ar, uint32_t m, uint32_t samp,
|
||||
rdcspv::ImageFormat f)
|
||||
Image(Scalar ret, Dim d, uint32_t dp, uint32_t ar, uint32_t m, uint32_t samp, ImageFormat f)
|
||||
: retType(ret), dim(d), depth(dp), arrayed(ar), ms(m), sampled(samp), format(f)
|
||||
{
|
||||
}
|
||||
|
||||
SPIRVScalar retType;
|
||||
rdcspv::Dim dim;
|
||||
Scalar retType;
|
||||
Dim dim;
|
||||
uint32_t depth;
|
||||
uint32_t arrayed;
|
||||
uint32_t ms;
|
||||
uint32_t sampled;
|
||||
rdcspv::ImageFormat format;
|
||||
ImageFormat format;
|
||||
|
||||
bool operator<(const SPIRVImage &o) const
|
||||
bool operator<(const Image &o) const
|
||||
{
|
||||
if(retType != o.retType)
|
||||
return retType < o.retType;
|
||||
@@ -207,66 +205,64 @@ struct SPIRVImage
|
||||
return sampled < o.sampled;
|
||||
return format < o.format;
|
||||
}
|
||||
bool operator!=(const SPIRVImage &o) const { return !operator==(o); }
|
||||
bool operator==(const SPIRVImage &o) const
|
||||
bool operator!=(const Image &o) const { return !operator==(o); }
|
||||
bool operator==(const Image &o) const
|
||||
{
|
||||
return retType == o.retType && dim == o.dim && depth == o.depth && arrayed == o.arrayed &&
|
||||
ms == o.ms && sampled == o.sampled && format == o.format;
|
||||
}
|
||||
rdcspv::Operation decl(SPIRVEditor &editor) const;
|
||||
Operation decl(Editor &editor) const;
|
||||
};
|
||||
|
||||
struct SPIRVSampler
|
||||
struct Sampler
|
||||
{
|
||||
// no properties, all sampler types are equal
|
||||
bool operator<(const SPIRVSampler &o) const { return false; }
|
||||
bool operator!=(const SPIRVSampler &o) const { return false; }
|
||||
bool operator==(const SPIRVSampler &o) const { return true; }
|
||||
rdcspv::Operation decl(SPIRVEditor &editor) const;
|
||||
bool operator<(const Sampler &o) const { return false; }
|
||||
bool operator!=(const Sampler &o) const { return false; }
|
||||
bool operator==(const Sampler &o) const { return true; }
|
||||
Operation decl(Editor &editor) const;
|
||||
};
|
||||
|
||||
struct SPIRVSampledImage
|
||||
struct SampledImage
|
||||
{
|
||||
SPIRVSampledImage(rdcspv::Id b) : baseId(b) {}
|
||||
rdcspv::Id baseId;
|
||||
SampledImage(Id b) : baseId(b) {}
|
||||
Id baseId;
|
||||
|
||||
bool operator<(const SPIRVSampledImage &o) const { return baseId < o.baseId; }
|
||||
bool operator!=(const SPIRVSampledImage &o) const { return !operator==(o); }
|
||||
bool operator==(const SPIRVSampledImage &o) const { return baseId == o.baseId; }
|
||||
rdcspv::Operation decl(SPIRVEditor &editor) const;
|
||||
bool operator<(const SampledImage &o) const { return baseId < o.baseId; }
|
||||
bool operator!=(const SampledImage &o) const { return !operator==(o); }
|
||||
bool operator==(const SampledImage &o) const { return baseId == o.baseId; }
|
||||
Operation decl(Editor &editor) const;
|
||||
};
|
||||
|
||||
struct SPIRVFunction
|
||||
struct Function
|
||||
{
|
||||
SPIRVFunction(rdcspv::Id ret, const rdcarray<rdcspv::Id> &args) : returnId(ret), argumentIds(args)
|
||||
{
|
||||
}
|
||||
rdcspv::Id returnId;
|
||||
rdcarray<rdcspv::Id> argumentIds;
|
||||
Function(Id ret, const rdcarray<Id> &args) : returnId(ret), argumentIds(args) {}
|
||||
Id returnId;
|
||||
rdcarray<Id> argumentIds;
|
||||
|
||||
bool operator<(const SPIRVFunction &o) const
|
||||
bool operator<(const Function &o) const
|
||||
{
|
||||
if(returnId != o.returnId)
|
||||
return returnId < o.returnId;
|
||||
return argumentIds < o.argumentIds;
|
||||
}
|
||||
|
||||
bool operator!=(const SPIRVFunction &o) const { return !operator==(o); }
|
||||
bool operator==(const SPIRVFunction &o) const
|
||||
bool operator!=(const Function &o) const { return !operator==(o); }
|
||||
bool operator==(const Function &o) const
|
||||
{
|
||||
return returnId == o.returnId && argumentIds == o.argumentIds;
|
||||
}
|
||||
rdcspv::Operation decl(SPIRVEditor &editor) const;
|
||||
Operation decl(Editor &editor) const;
|
||||
};
|
||||
|
||||
template <typename SPIRVType>
|
||||
using SPIRVTypeId = std::pair<SPIRVType, rdcspv::Id>;
|
||||
template <typename Type>
|
||||
using TypeId = std::pair<Type, Id>;
|
||||
|
||||
template <typename SPIRVType>
|
||||
using SPIRVTypeIds = std::vector<SPIRVTypeId<SPIRVType>>;
|
||||
template <typename Type>
|
||||
using TypeIds = std::vector<TypeId<Type>>;
|
||||
|
||||
// hack around enum class being useless for array indices :(
|
||||
struct SPIRVSection
|
||||
struct Section
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
@@ -289,94 +285,87 @@ struct SPIRVSection
|
||||
};
|
||||
};
|
||||
|
||||
class SPIRVEditor
|
||||
class Editor
|
||||
{
|
||||
public:
|
||||
SPIRVEditor(std::vector<uint32_t> &spirvWords);
|
||||
~SPIRVEditor() { StripNops(); }
|
||||
Editor(std::vector<uint32_t> &spirvWords);
|
||||
~Editor() { StripNops(); }
|
||||
void StripNops();
|
||||
|
||||
rdcspv::Id MakeId();
|
||||
Id MakeId();
|
||||
|
||||
void AddOperation(rdcspv::Iter iter, const rdcspv::Operation &op);
|
||||
void AddOperation(Iter iter, const Operation &op);
|
||||
|
||||
// callbacks to allow us to update our internal structures over changes
|
||||
|
||||
// called before any modifications are made. Removes the operation from internal structures.
|
||||
void PreModify(rdcspv::Iter iter) { UnregisterOp(iter); }
|
||||
void PreModify(Iter iter) { UnregisterOp(iter); }
|
||||
// called after any modifications, re-adds the operation to internal structures with its new
|
||||
// properties
|
||||
void PostModify(rdcspv::Iter iter) { RegisterOp(iter); }
|
||||
void PostModify(Iter iter) { RegisterOp(iter); }
|
||||
// removed an operation and replaces it with nops
|
||||
void Remove(rdcspv::Iter iter)
|
||||
void Remove(Iter iter)
|
||||
{
|
||||
UnregisterOp(iter);
|
||||
iter.nopRemove();
|
||||
}
|
||||
|
||||
void SetName(rdcspv::Id id, const char *name);
|
||||
void AddDecoration(const rdcspv::Operation &op);
|
||||
void AddCapability(rdcspv::Capability cap);
|
||||
void SetName(Id id, const char *name);
|
||||
void AddDecoration(const Operation &op);
|
||||
void AddCapability(Capability cap);
|
||||
void AddExtension(const rdcstr &extension);
|
||||
void AddExecutionMode(const rdcspv::Operation &mode);
|
||||
rdcspv::Id ImportExtInst(const char *setname);
|
||||
rdcspv::Id AddType(const rdcspv::Operation &op);
|
||||
rdcspv::Id AddVariable(const rdcspv::Operation &op);
|
||||
rdcspv::Id AddConstant(const rdcspv::Operation &op);
|
||||
void AddFunction(const rdcspv::Operation *ops, size_t count);
|
||||
void AddExecutionMode(const Operation &mode);
|
||||
Id ImportExtInst(const char *setname);
|
||||
Id AddType(const Operation &op);
|
||||
Id AddVariable(const Operation &op);
|
||||
Id AddConstant(const Operation &op);
|
||||
void AddFunction(const Operation *ops, size_t count);
|
||||
|
||||
rdcspv::Iter GetID(rdcspv::Id id);
|
||||
Iter GetID(Id id);
|
||||
// the entry point has 'two' opcodes, the entrypoint declaration and the function.
|
||||
// This returns the first, GetID returns the second.
|
||||
rdcspv::Iter GetEntry(rdcspv::Id id);
|
||||
rdcspv::Iter Begin(SPIRVSection::Type section)
|
||||
{
|
||||
return rdcspv::Iter(spirv, sections[section].startOffset);
|
||||
}
|
||||
rdcspv::Iter End(SPIRVSection::Type section)
|
||||
{
|
||||
return rdcspv::Iter(spirv, sections[section].endOffset);
|
||||
}
|
||||
|
||||
Iter GetEntry(Id id);
|
||||
Iter Begin(Section::Type section) { return Iter(spirv, sections[section].startOffset); }
|
||||
Iter End(Section::Type section) { return Iter(spirv, sections[section].endOffset); }
|
||||
// fetches the id of this type. If it exists already the old ID will be returned, otherwise it
|
||||
// will be declared and the new ID returned
|
||||
template <typename SPIRVType>
|
||||
rdcspv::Id DeclareType(const SPIRVType &t)
|
||||
template <typename Type>
|
||||
Id DeclareType(const Type &t)
|
||||
{
|
||||
std::map<SPIRVType, rdcspv::Id> &table = GetTable<SPIRVType>();
|
||||
std::map<Type, Id> &table = GetTable<Type>();
|
||||
|
||||
auto it = table.lower_bound(t);
|
||||
if(it != table.end() && it->first == t)
|
||||
return it->second;
|
||||
|
||||
rdcspv::Operation decl = t.decl(*this);
|
||||
rdcspv::Id id = MakeId();
|
||||
Operation decl = t.decl(*this);
|
||||
Id id = MakeId();
|
||||
decl[1] = id.value();
|
||||
AddType(decl);
|
||||
|
||||
table.insert(it, std::pair<SPIRVType, rdcspv::Id>(t, id));
|
||||
table.insert(it, std::pair<Type, Id>(t, id));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
template <typename SPIRVType>
|
||||
rdcspv::Id GetType(const SPIRVType &t)
|
||||
template <typename Type>
|
||||
Id GetType(const Type &t)
|
||||
{
|
||||
std::map<SPIRVType, rdcspv::Id> &table = GetTable<SPIRVType>();
|
||||
std::map<Type, Id> &table = GetTable<Type>();
|
||||
|
||||
auto it = table.find(t);
|
||||
if(it != table.end())
|
||||
return it->second;
|
||||
|
||||
return rdcspv::Id();
|
||||
return Id();
|
||||
}
|
||||
|
||||
template <typename SPIRVType>
|
||||
SPIRVTypeIds<SPIRVType> GetTypes()
|
||||
template <typename Type>
|
||||
TypeIds<Type> GetTypes()
|
||||
{
|
||||
std::map<SPIRVType, rdcspv::Id> &table = GetTable<SPIRVType>();
|
||||
std::map<Type, Id> &table = GetTable<Type>();
|
||||
|
||||
SPIRVTypeIds<SPIRVType> ret;
|
||||
TypeIds<Type> ret;
|
||||
|
||||
for(auto it = table.begin(); it != table.end(); ++it)
|
||||
ret.push_back(*it);
|
||||
@@ -384,47 +373,47 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename SPIRVType>
|
||||
const std::map<SPIRVType, rdcspv::Id> &GetTypeInfo() const
|
||||
template <typename Type>
|
||||
const std::map<Type, Id> &GetTypeInfo() const
|
||||
{
|
||||
return GetTable<SPIRVType>();
|
||||
return GetTable<Type>();
|
||||
}
|
||||
|
||||
SPIRVBinding GetBinding(rdcspv::Id id) const
|
||||
Binding GetBinding(Id id) const
|
||||
{
|
||||
auto it = bindings.find(id);
|
||||
if(it == bindings.end())
|
||||
return SPIRVBinding();
|
||||
return Binding();
|
||||
return it->second;
|
||||
}
|
||||
const std::set<rdcspv::Id> &GetStructTypes() const { return structTypes; }
|
||||
rdcspv::Id DeclareStructType(const std::vector<rdcspv::Id> &members);
|
||||
const std::set<Id> &GetStructTypes() const { return structTypes; }
|
||||
Id DeclareStructType(const std::vector<Id> &members);
|
||||
|
||||
// helper for AddConstant
|
||||
template <typename T>
|
||||
rdcspv::Id AddConstantImmediate(T t)
|
||||
Id AddConstantImmediate(T t)
|
||||
{
|
||||
rdcspv::Id typeId = DeclareType(scalar<T>());
|
||||
Id typeId = DeclareType(scalar<T>());
|
||||
std::vector<uint32_t> words = {typeId.value(), MakeId().value()};
|
||||
|
||||
words.insert(words.end(), sizeof(T) / 4, 0U);
|
||||
|
||||
memcpy(&words[2], &t, sizeof(T));
|
||||
|
||||
return AddConstant(rdcspv::Operation(rdcspv::Op::Constant, words));
|
||||
return AddConstant(Operation(Op::Constant, words));
|
||||
}
|
||||
|
||||
// accessors to structs/vectors of data
|
||||
const std::vector<rdcspv::OpEntryPoint> &GetEntries() { return entries; }
|
||||
const std::vector<rdcspv::OpVariable> &GetVariables() { return variables; }
|
||||
const std::vector<rdcspv::Id> &GetFunctions() { return functions; }
|
||||
rdcspv::Id GetIDType(rdcspv::Id id) { return idTypes[id.value()]; }
|
||||
const std::vector<OpEntryPoint> &GetEntries() { return entries; }
|
||||
const std::vector<OpVariable> &GetVariables() { return variables; }
|
||||
const std::vector<Id> &GetFunctions() { return functions; }
|
||||
Id GetIDType(Id id) { return idTypes[id.value()]; }
|
||||
private:
|
||||
inline void addWords(size_t offs, size_t num) { addWords(offs, (int32_t)num); }
|
||||
void addWords(size_t offs, int32_t num);
|
||||
|
||||
void RegisterOp(rdcspv::Iter iter);
|
||||
void UnregisterOp(rdcspv::Iter iter);
|
||||
void RegisterOp(Iter iter);
|
||||
void UnregisterOp(Iter iter);
|
||||
|
||||
struct LogicalSection
|
||||
{
|
||||
@@ -432,47 +421,47 @@ private:
|
||||
size_t endOffset = 0;
|
||||
};
|
||||
|
||||
LogicalSection sections[SPIRVSection::Count];
|
||||
LogicalSection sections[Section::Count];
|
||||
|
||||
rdcspv::AddressingModel addressmodel;
|
||||
rdcspv::MemoryModel memorymodel;
|
||||
AddressingModel addressmodel;
|
||||
MemoryModel memorymodel;
|
||||
|
||||
std::vector<rdcspv::OpDecorate> decorations;
|
||||
std::vector<OpDecorate> decorations;
|
||||
|
||||
std::map<rdcspv::Id, SPIRVBinding> bindings;
|
||||
std::map<Id, Binding> bindings;
|
||||
|
||||
std::vector<size_t> idOffsets;
|
||||
std::vector<rdcspv::Id> idTypes;
|
||||
std::vector<Id> idTypes;
|
||||
|
||||
std::vector<rdcspv::OpEntryPoint> entries;
|
||||
std::vector<rdcspv::OpVariable> variables;
|
||||
std::vector<rdcspv::Id> functions;
|
||||
std::vector<OpEntryPoint> entries;
|
||||
std::vector<OpVariable> variables;
|
||||
std::vector<Id> functions;
|
||||
std::set<rdcstr> extensions;
|
||||
std::set<rdcspv::Capability> capabilities;
|
||||
std::set<Capability> capabilities;
|
||||
|
||||
std::map<rdcstr, rdcspv::Id> extSets;
|
||||
std::map<rdcstr, Id> extSets;
|
||||
|
||||
std::map<SPIRVScalar, rdcspv::Id> scalarTypes;
|
||||
std::map<SPIRVVector, rdcspv::Id> vectorTypes;
|
||||
std::map<SPIRVMatrix, rdcspv::Id> matrixTypes;
|
||||
std::map<SPIRVPointer, rdcspv::Id> pointerTypes;
|
||||
std::map<SPIRVImage, rdcspv::Id> imageTypes;
|
||||
std::map<SPIRVSampler, rdcspv::Id> samplerTypes;
|
||||
std::map<SPIRVSampledImage, rdcspv::Id> sampledImageTypes;
|
||||
std::map<SPIRVFunction, rdcspv::Id> functionTypes;
|
||||
std::map<Scalar, Id> scalarTypes;
|
||||
std::map<Vector, Id> vectorTypes;
|
||||
std::map<Matrix, Id> matrixTypes;
|
||||
std::map<Pointer, Id> pointerTypes;
|
||||
std::map<Image, Id> imageTypes;
|
||||
std::map<Sampler, Id> samplerTypes;
|
||||
std::map<SampledImage, Id> sampledImageTypes;
|
||||
std::map<Function, Id> functionTypes;
|
||||
|
||||
std::set<rdcspv::Id> structTypes;
|
||||
std::set<Id> structTypes;
|
||||
|
||||
template <typename SPIRVType>
|
||||
std::map<SPIRVType, rdcspv::Id> &GetTable();
|
||||
template <typename Type>
|
||||
std::map<Type, Id> &GetTable();
|
||||
|
||||
template <typename SPIRVType>
|
||||
const std::map<SPIRVType, rdcspv::Id> &GetTable() const;
|
||||
template <typename Type>
|
||||
const std::map<Type, Id> &GetTable() const;
|
||||
|
||||
std::vector<uint32_t> &spirv;
|
||||
};
|
||||
|
||||
inline bool operator<(const rdcspv::OpDecorate &a, const rdcspv::OpDecorate &b)
|
||||
inline bool operator<(const OpDecorate &a, const OpDecorate &b)
|
||||
{
|
||||
if(a.target != b.target)
|
||||
return a.target < b.target;
|
||||
@@ -482,7 +471,9 @@ inline bool operator<(const rdcspv::OpDecorate &a, const rdcspv::OpDecorate &b)
|
||||
return memcmp(&a.decoration, &b.decoration, sizeof(a.decoration)) < 0;
|
||||
}
|
||||
|
||||
inline bool operator==(const rdcspv::OpDecorate &a, const rdcspv::OpDecorate &b)
|
||||
inline bool operator==(const OpDecorate &a, const OpDecorate &b)
|
||||
{
|
||||
return a.target == b.target && !memcmp(&a.decoration, &b.decoration, sizeof(a.decoration));
|
||||
}
|
||||
}
|
||||
|
||||
}; // namespace rdcspv
|
||||
@@ -57,7 +57,7 @@ void FillSpecConstantVariables(const rdcarray<ShaderConstant> &invars,
|
||||
void AddXFBAnnotations(const ShaderReflection &refl, const SPIRVPatchData &patchData,
|
||||
const char *entryName, std::vector<uint32_t> &modSpirv, uint32_t &xfbStride)
|
||||
{
|
||||
SPIRVEditor editor(modSpirv);
|
||||
rdcspv::Editor editor(modSpirv);
|
||||
|
||||
rdcarray<SigParameter> outsig = refl.outputSignature;
|
||||
std::vector<SPIRVPatchData::InterfaceAccess> outpatch = patchData.outputs;
|
||||
@@ -74,8 +74,8 @@ void AddXFBAnnotations(const ShaderReflection &refl, const SPIRVPatchData &patch
|
||||
|
||||
bool hasXFB = false;
|
||||
|
||||
for(rdcspv::Iter it = editor.Begin(SPIRVSection::ExecutionMode);
|
||||
it < editor.End(SPIRVSection::ExecutionMode); ++it)
|
||||
for(rdcspv::Iter it = editor.Begin(rdcspv::Section::ExecutionMode);
|
||||
it < editor.End(rdcspv::Section::ExecutionMode); ++it)
|
||||
{
|
||||
rdcspv::OpExecutionMode execMode(it);
|
||||
|
||||
@@ -88,8 +88,8 @@ void AddXFBAnnotations(const ShaderReflection &refl, const SPIRVPatchData &patch
|
||||
|
||||
if(hasXFB)
|
||||
{
|
||||
for(rdcspv::Iter it = editor.Begin(SPIRVSection::Annotations);
|
||||
it < editor.End(SPIRVSection::Annotations); ++it)
|
||||
for(rdcspv::Iter it = editor.Begin(rdcspv::Section::Annotations);
|
||||
it < editor.End(rdcspv::Section::Annotations); ++it)
|
||||
{
|
||||
// remove any existing xfb decorations
|
||||
if(it.opcode() == rdcspv::Op::Decorate)
|
||||
@@ -208,15 +208,15 @@ TEST_CASE("Validate SPIR-V reflection", "[spirv][reflection]")
|
||||
auto compiler = [&type](ShaderStage stage, const std::string &source, const std::string &entryPoint,
|
||||
ShaderReflection &refl, ShaderBindpointMapping &mapping) {
|
||||
|
||||
InitSPIRVCompiler();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&ShutdownSPIRVCompiler);
|
||||
rdcspv::Init();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&rdcspv::Shutdown);
|
||||
|
||||
std::vector<uint32_t> spirv;
|
||||
SPIRVCompilationSettings settings(type == ShaderType::eShaderVulkan
|
||||
? SPIRVSourceLanguage::VulkanGLSL
|
||||
: SPIRVSourceLanguage::OpenGLGLSL,
|
||||
SPIRVShaderStage(stage));
|
||||
std::string errors = CompileSPIRV(settings, {source}, spirv);
|
||||
rdcspv::CompilationSettings settings(type == ShaderType::eShaderVulkan
|
||||
? rdcspv::InputLanguage::VulkanGLSL
|
||||
: rdcspv::InputLanguage::OpenGLGLSL,
|
||||
rdcspv::ShaderStage(stage));
|
||||
std::string errors = rdcspv::Compile(settings, {source}, spirv);
|
||||
|
||||
INFO("SPIR-V compile output: " << errors);
|
||||
|
||||
|
||||
@@ -36,15 +36,15 @@ struct feedbackData
|
||||
};
|
||||
|
||||
void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
const std::map<SPIRVBinding, feedbackData> &offsetMap, VkDeviceAddress addr,
|
||||
const std::map<rdcspv::Binding, feedbackData> &offsetMap, VkDeviceAddress addr,
|
||||
std::vector<uint32_t> &modSpirv)
|
||||
{
|
||||
SPIRVEditor editor(modSpirv);
|
||||
rdcspv::Editor editor(modSpirv);
|
||||
|
||||
const bool useBufferAddress = (addr != 0);
|
||||
|
||||
rdcspv::Id uint32ID = editor.DeclareType(scalar<uint32_t>());
|
||||
rdcspv::Id int32ID = editor.DeclareType(scalar<int32_t>());
|
||||
rdcspv::Id uint32ID = editor.DeclareType(rdcspv::scalar<uint32_t>());
|
||||
rdcspv::Id int32ID = editor.DeclareType(rdcspv::scalar<int32_t>());
|
||||
rdcspv::Id uint64ID, int64ID;
|
||||
rdcspv::Id uint32StructID;
|
||||
rdcspv::Id funcParamType;
|
||||
@@ -52,8 +52,8 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
if(useBufferAddress)
|
||||
{
|
||||
// declare the int64 types we'll need
|
||||
uint64ID = editor.DeclareType(scalar<uint64_t>());
|
||||
int64ID = editor.DeclareType(scalar<int64_t>());
|
||||
uint64ID = editor.DeclareType(rdcspv::scalar<uint64_t>());
|
||||
int64ID = editor.DeclareType(rdcspv::scalar<int64_t>());
|
||||
|
||||
uint32StructID = editor.AddType(rdcspv::OpTypeStruct(editor.MakeId(), {uint32ID}));
|
||||
|
||||
@@ -93,7 +93,7 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
continue;
|
||||
|
||||
// get this variable's binding info
|
||||
SPIRVBinding bind = editor.GetBinding(var.result);
|
||||
rdcspv::Binding bind = editor.GetBinding(var.result);
|
||||
|
||||
// if this is one of the bindings we care about
|
||||
auto it = offsetMap.find(bind);
|
||||
@@ -132,7 +132,7 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
editor.AddExtension("SPV_EXT_physical_storage_buffer");
|
||||
|
||||
// change the memory model to physical storage buffer 64
|
||||
rdcspv::Iter it = editor.Begin(SPIRVSection::MemoryModel);
|
||||
rdcspv::Iter it = editor.Begin(rdcspv::Section::MemoryModel);
|
||||
rdcspv::OpMemoryModel model(it);
|
||||
model.addressingModel = rdcspv::AddressingModel::PhysicalStorageBuffer64EXT;
|
||||
it = model;
|
||||
@@ -144,7 +144,7 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
// declare the address constants and make our pointers physical storage buffer pointers
|
||||
bufferAddressConst = editor.AddConstantImmediate<uint64_t>(addr);
|
||||
uint32ptrtype =
|
||||
editor.DeclareType(SPIRVPointer(uint32ID, rdcspv::StorageClass::PhysicalStorageBufferEXT));
|
||||
editor.DeclareType(rdcspv::Pointer(uint32ID, rdcspv::StorageClass::PhysicalStorageBufferEXT));
|
||||
|
||||
editor.SetName(bufferAddressConst, "__rd_feedbackAddress");
|
||||
|
||||
@@ -155,12 +155,12 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
{
|
||||
// the pointers are uniform pointers
|
||||
rdcspv::Id bufptrtype =
|
||||
editor.DeclareType(SPIRVPointer(uint32StructID, rdcspv::StorageClass::Uniform));
|
||||
uint32ptrtype = editor.DeclareType(SPIRVPointer(uint32ID, rdcspv::StorageClass::Uniform));
|
||||
editor.DeclareType(rdcspv::Pointer(uint32StructID, rdcspv::StorageClass::Uniform));
|
||||
uint32ptrtype = editor.DeclareType(rdcspv::Pointer(uint32ID, rdcspv::StorageClass::Uniform));
|
||||
|
||||
// patch all bindings up by 1
|
||||
for(rdcspv::Iter it = editor.Begin(SPIRVSection::Annotations),
|
||||
end = editor.End(SPIRVSection::Annotations);
|
||||
for(rdcspv::Iter it = editor.Begin(rdcspv::Section::Annotations),
|
||||
end = editor.End(rdcspv::Section::Annotations);
|
||||
it < end; ++it)
|
||||
{
|
||||
// we will use descriptor set 0 for our own purposes if we don't have a buffer address.
|
||||
@@ -202,9 +202,9 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
rdcspv::Id semantics = editor.AddConstantImmediate<uint32_t>(0U);
|
||||
rdcspv::Id uint32shift = editor.AddConstantImmediate<uint32_t>(2U);
|
||||
|
||||
std::map<rdcspv::Id, SPIRVScalar> intTypeLookup;
|
||||
std::map<rdcspv::Id, rdcspv::Scalar> intTypeLookup;
|
||||
|
||||
for(auto scalarType : editor.GetTypeInfo<SPIRVScalar>())
|
||||
for(auto scalarType : editor.GetTypeInfo<rdcspv::Scalar>())
|
||||
if(scalarType.first.type == rdcspv::Op::TypeInt)
|
||||
intTypeLookup[scalarType.second] = scalarType.first;
|
||||
|
||||
@@ -218,7 +218,7 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
}
|
||||
}
|
||||
|
||||
SPIRVTypeIds<SPIRVFunction> funcTypes = editor.GetTypes<SPIRVFunction>();
|
||||
rdcspv::TypeIds<rdcspv::Function> funcTypes = editor.GetTypes<rdcspv::Function>();
|
||||
|
||||
// functions that have been patched with annotation & extra function parameters if needed
|
||||
std::set<rdcspv::Id> patchedFunctions;
|
||||
@@ -254,11 +254,11 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
rdcspv::OpFunction func(it);
|
||||
|
||||
// find the function's type declaration, add the necessary arguments, redeclare and patch it
|
||||
for(const SPIRVTypeId<SPIRVFunction> &funcType : funcTypes)
|
||||
for(const rdcspv::TypeId<rdcspv::Function> &funcType : funcTypes)
|
||||
{
|
||||
if(funcType.second == func.functionType)
|
||||
{
|
||||
SPIRVFunction patchedFuncType = funcType.first;
|
||||
rdcspv::Function patchedFuncType = funcType.first;
|
||||
for(size_t i = 0; i < patchArgIndices.size(); i++)
|
||||
patchedFuncType.argumentIds.push_back(funcParamType);
|
||||
|
||||
@@ -412,7 +412,7 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
indexType = uint32ID;
|
||||
}
|
||||
|
||||
SPIRVScalar indexTypeData = scalar<uint32_t>();
|
||||
rdcspv::Scalar indexTypeData = rdcspv::scalar<uint32_t>();
|
||||
auto indexTypeIt = intTypeLookup.find(indexType);
|
||||
|
||||
if(indexTypeIt != intTypeLookup.end())
|
||||
@@ -441,7 +441,7 @@ void AnnotateShader(const SPIRVPatchData &patchData, const char *entryName,
|
||||
if(indexTypeData.width != targetIndexWidth)
|
||||
{
|
||||
rdcspv::Id extendedtype =
|
||||
editor.DeclareType(SPIRVScalar(rdcspv::Op::TypeInt, targetIndexWidth, false));
|
||||
editor.DeclareType(rdcspv::Scalar(rdcspv::Op::TypeInt, targetIndexWidth, false));
|
||||
rdcspv::Id extendedindex = editor.MakeId();
|
||||
editor.AddOperation(it, rdcspv::OpUConvert(extendedtype, extendedindex, index));
|
||||
it++;
|
||||
@@ -548,13 +548,13 @@ void VulkanReplay::FetchShaderFeedback(uint32_t eventId)
|
||||
|
||||
VkDeviceSize feedbackStorageSize = 0;
|
||||
|
||||
std::map<SPIRVBinding, feedbackData> offsetMap;
|
||||
std::map<rdcspv::Binding, feedbackData> offsetMap;
|
||||
|
||||
{
|
||||
const std::vector<ResourceId> &descSetLayoutIds =
|
||||
creationInfo.m_PipelineLayout[pipeInfo.layout].descSetLayouts;
|
||||
|
||||
SPIRVBinding key;
|
||||
rdcspv::Binding key;
|
||||
|
||||
for(size_t set = 0; set < descSetLayoutIds.size(); set++)
|
||||
{
|
||||
|
||||
@@ -111,8 +111,8 @@ WrappedVulkan::WrappedVulkan() : m_RenderState(this, &m_CreationInfo)
|
||||
|
||||
m_SectionVersion = VkInitParams::CurrentVersion;
|
||||
|
||||
InitSPIRVCompiler();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&ShutdownSPIRVCompiler);
|
||||
rdcspv::Init();
|
||||
RenderDoc::Inst().RegisterShutdownFunction(&rdcspv::Shutdown);
|
||||
|
||||
m_Replay.SetDriver(this);
|
||||
|
||||
|
||||
@@ -2475,9 +2475,9 @@ void VulkanReplay::HistogramMinMax::Init(WrappedVulkan *driver, VkDescriptorPool
|
||||
for(size_t i = 0; i < ARRAY_COUNT(m_HistogramDescSet); i++)
|
||||
CREATE_OBJECT(m_HistogramDescSet[i], descriptorPool, m_HistogramDescSetLayout);
|
||||
|
||||
SPIRVCompilationSettings compileSettings;
|
||||
compileSettings.lang = SPIRVSourceLanguage::VulkanGLSL;
|
||||
compileSettings.stage = SPIRVShaderStage::Compute;
|
||||
rdcspv::CompilationSettings compileSettings;
|
||||
compileSettings.lang = rdcspv::InputLanguage::VulkanGLSL;
|
||||
compileSettings.stage = rdcspv::ShaderStage::Compute;
|
||||
|
||||
// type max is one higher than the last RESTYPE, and RESTYPES are 1-indexed
|
||||
RDCCOMPILE_ASSERT(RESTYPE_TEXTYPEMAX == ARRAY_COUNT(m_MinMaxTilePipe),
|
||||
|
||||
@@ -46,8 +46,6 @@ struct MeshDisplayPipelines
|
||||
VkPipeline pipes[ePipe_Count] = {};
|
||||
};
|
||||
|
||||
struct SPIRVCompilationSettings;
|
||||
|
||||
struct CopyPixelParams;
|
||||
|
||||
struct PixelHistoryResources;
|
||||
|
||||
@@ -54,15 +54,15 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
uint32_t numViews, std::vector<uint32_t> &modSpirv,
|
||||
uint32_t &bufStride)
|
||||
{
|
||||
SPIRVEditor editor(modSpirv);
|
||||
rdcspv::Editor editor(modSpirv);
|
||||
|
||||
uint32_t numInputs = (uint32_t)refl.inputSignature.size();
|
||||
|
||||
uint32_t numOutputs = (uint32_t)refl.outputSignature.size();
|
||||
RDCASSERT(numOutputs > 0);
|
||||
|
||||
for(rdcspv::Iter it = editor.Begin(SPIRVSection::Annotations),
|
||||
end = editor.End(SPIRVSection::Annotations);
|
||||
for(rdcspv::Iter it = editor.Begin(rdcspv::Section::Annotations),
|
||||
end = editor.End(rdcspv::Section::Annotations);
|
||||
it < end; ++it)
|
||||
{
|
||||
// we will use descriptor set 0 bindings 0..N for our own purposes.
|
||||
@@ -125,8 +125,8 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
std::map<rdcspv::Id, rdcspv::Id> typeReplacements;
|
||||
|
||||
// rewrite any inputs and outputs to be private storage class
|
||||
for(rdcspv::Iter it = editor.Begin(SPIRVSection::TypesVariablesConstants),
|
||||
end = editor.End(SPIRVSection::TypesVariablesConstants);
|
||||
for(rdcspv::Iter it = editor.Begin(rdcspv::Section::TypesVariablesConstants),
|
||||
end = editor.End(rdcspv::Section::TypesVariablesConstants);
|
||||
it < end; ++it)
|
||||
{
|
||||
// rewrite any input/output variables to private, and build up inputs/outputs list
|
||||
@@ -153,7 +153,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
if(id)
|
||||
{
|
||||
SPIRVPointer privPtr(ptr.type, rdcspv::StorageClass::Private);
|
||||
rdcspv::Pointer privPtr(ptr.type, rdcspv::StorageClass::Private);
|
||||
|
||||
rdcspv::Id origId = editor.GetType(privPtr);
|
||||
|
||||
@@ -279,7 +279,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
}
|
||||
}
|
||||
|
||||
for(rdcspv::Iter it = editor.Begin(SPIRVSection::Functions); it; ++it)
|
||||
for(rdcspv::Iter it = editor.Begin(rdcspv::Section::Functions); it; ++it)
|
||||
{
|
||||
// identify functions with result types we might want to replace
|
||||
if(it.opcode() == rdcspv::Op::Function || it.opcode() == rdcspv::Op::FunctionParameter ||
|
||||
@@ -301,8 +301,8 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
}
|
||||
|
||||
// detect builtin inputs or outputs, and remove builtin decorations
|
||||
for(rdcspv::Iter it = editor.Begin(SPIRVSection::Annotations),
|
||||
end = editor.End(SPIRVSection::Annotations);
|
||||
for(rdcspv::Iter it = editor.Begin(rdcspv::Section::Annotations),
|
||||
end = editor.End(rdcspv::Section::Annotations);
|
||||
it < end; ++it)
|
||||
{
|
||||
if(it.opcode() == rdcspv::Op::Decorate)
|
||||
@@ -311,7 +311,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
// remove any builtin decorations
|
||||
if(decorate.decoration == rdcspv::Decoration::BuiltIn)
|
||||
{
|
||||
// we don't have to do anything, the ID mapping is in the SPIRVPatchData, so just discard
|
||||
// we don't have to do anything, the ID mapping is in the rdcspv::PatchData, so just discard
|
||||
// the
|
||||
// location information
|
||||
editor.Remove(it);
|
||||
@@ -323,7 +323,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
}
|
||||
else if(decorate.decoration == rdcspv::Decoration::Location)
|
||||
{
|
||||
// we don't have to do anything, the ID mapping is in the SPIRVPatchData, so just discard
|
||||
// we don't have to do anything, the ID mapping is in the rdcspv::PatchData, so just discard
|
||||
// the location information
|
||||
editor.Remove(it);
|
||||
}
|
||||
@@ -358,7 +358,8 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
RDCASSERT(entryID);
|
||||
|
||||
for(rdcspv::Iter it = editor.Begin(SPIRVSection::Debug), end2 = editor.End(SPIRVSection::Debug);
|
||||
for(rdcspv::Iter it = editor.Begin(rdcspv::Section::Debug),
|
||||
end2 = editor.End(rdcspv::Section::Debug);
|
||||
it < end2; ++it)
|
||||
{
|
||||
if(it.opcode() == rdcspv::Op::Name)
|
||||
@@ -394,28 +395,30 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
// base type - either a scalar or a vector, since matrix outputs are decayed to vectors
|
||||
{
|
||||
SPIRVScalar scalarType = scalar<uint32_t>();
|
||||
rdcspv::Scalar scalarType = rdcspv::scalar<uint32_t>();
|
||||
|
||||
if(refl.outputSignature[i].compType == CompType::UInt)
|
||||
scalarType = scalar<uint32_t>();
|
||||
scalarType = rdcspv::scalar<uint32_t>();
|
||||
else if(refl.outputSignature[i].compType == CompType::SInt)
|
||||
scalarType = scalar<int32_t>();
|
||||
scalarType = rdcspv::scalar<int32_t>();
|
||||
else if(refl.outputSignature[i].compType == CompType::Float)
|
||||
scalarType = scalar<float>();
|
||||
scalarType = rdcspv::scalar<float>();
|
||||
else if(refl.outputSignature[i].compType == CompType::Double)
|
||||
scalarType = scalar<double>();
|
||||
scalarType = rdcspv::scalar<double>();
|
||||
|
||||
io.vec4ID = editor.DeclareType(SPIRVVector(scalarType, 4));
|
||||
io.vec4ID = editor.DeclareType(rdcspv::Vector(scalarType, 4));
|
||||
|
||||
if(refl.outputSignature[i].compCount > 1)
|
||||
io.basetypeID =
|
||||
editor.DeclareType(SPIRVVector(scalarType, refl.outputSignature[i].compCount));
|
||||
editor.DeclareType(rdcspv::Vector(scalarType, refl.outputSignature[i].compCount));
|
||||
else
|
||||
io.basetypeID = editor.DeclareType(scalarType);
|
||||
}
|
||||
|
||||
io.uniformPtrID = editor.DeclareType(SPIRVPointer(io.basetypeID, rdcspv::StorageClass::Uniform));
|
||||
io.privatePtrID = editor.DeclareType(SPIRVPointer(io.basetypeID, rdcspv::StorageClass::Private));
|
||||
io.uniformPtrID =
|
||||
editor.DeclareType(rdcspv::Pointer(io.basetypeID, rdcspv::StorageClass::Uniform));
|
||||
io.privatePtrID =
|
||||
editor.DeclareType(rdcspv::Pointer(io.basetypeID, rdcspv::StorageClass::Private));
|
||||
|
||||
RDCASSERT(io.basetypeID && io.vec4ID && io.constID && io.privatePtrID && io.uniformPtrID,
|
||||
io.basetypeID, io.vec4ID, io.constID, io.privatePtrID, io.uniformPtrID);
|
||||
@@ -433,43 +436,45 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
io.variableID = rdcspv::Id::fromWord(patchData.inputs[i].ID);
|
||||
|
||||
SPIRVScalar scalarType = scalar<uint32_t>();
|
||||
rdcspv::Scalar scalarType = rdcspv::scalar<uint32_t>();
|
||||
|
||||
// base type - either a scalar or a vector, since matrix outputs are decayed to vectors
|
||||
if(refl.inputSignature[i].compType == CompType::UInt)
|
||||
{
|
||||
scalarType = scalar<uint32_t>();
|
||||
scalarType = rdcspv::scalar<uint32_t>();
|
||||
io.tbuffer = tbuffer_uint;
|
||||
}
|
||||
else if(refl.inputSignature[i].compType == CompType::SInt)
|
||||
{
|
||||
scalarType = scalar<int32_t>();
|
||||
scalarType = rdcspv::scalar<int32_t>();
|
||||
io.tbuffer = tbuffer_sint;
|
||||
}
|
||||
else if(refl.inputSignature[i].compType == CompType::Float)
|
||||
{
|
||||
scalarType = scalar<float>();
|
||||
scalarType = rdcspv::scalar<float>();
|
||||
io.tbuffer = tbuffer_float;
|
||||
}
|
||||
else if(refl.inputSignature[i].compType == CompType::Double)
|
||||
{
|
||||
scalarType = scalar<double>();
|
||||
scalarType = rdcspv::scalar<double>();
|
||||
// doubles are loaded packed from a uint tbuffer
|
||||
io.tbuffer = tbuffer_uint;
|
||||
}
|
||||
|
||||
// doubles are loaded as uvec4 and then packed in pairs, so we need to declare vec4ID as uvec4
|
||||
if(refl.inputSignature[i].compType == CompType::Double)
|
||||
io.vec4ID = editor.DeclareType(SPIRVVector(scalar<uint32_t>(), 4));
|
||||
io.vec4ID = editor.DeclareType(rdcspv::Vector(rdcspv::scalar<uint32_t>(), 4));
|
||||
else
|
||||
io.vec4ID = editor.DeclareType(SPIRVVector(scalarType, 4));
|
||||
io.vec4ID = editor.DeclareType(rdcspv::Vector(scalarType, 4));
|
||||
|
||||
if(refl.inputSignature[i].compCount > 1)
|
||||
io.basetypeID = editor.DeclareType(SPIRVVector(scalarType, refl.inputSignature[i].compCount));
|
||||
io.basetypeID =
|
||||
editor.DeclareType(rdcspv::Vector(scalarType, refl.inputSignature[i].compCount));
|
||||
else
|
||||
io.basetypeID = editor.DeclareType(scalarType);
|
||||
|
||||
io.privatePtrID = editor.DeclareType(SPIRVPointer(io.basetypeID, rdcspv::StorageClass::Private));
|
||||
io.privatePtrID =
|
||||
editor.DeclareType(rdcspv::Pointer(io.basetypeID, rdcspv::StorageClass::Private));
|
||||
|
||||
RDCASSERT(io.basetypeID && io.vec4ID && io.constID && io.privatePtrID, io.basetypeID, io.vec4ID,
|
||||
io.constID, io.privatePtrID);
|
||||
@@ -487,32 +492,33 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
for(tbufferType tb : {tbuffer_float, tbuffer_sint, tbuffer_uint})
|
||||
{
|
||||
SPIRVScalar scalarType = scalar<float>();
|
||||
rdcspv::Scalar scalarType = rdcspv::scalar<float>();
|
||||
const char *name = "float_vbuffers";
|
||||
|
||||
if(tb == tbuffer_sint)
|
||||
{
|
||||
scalarType = scalar<int32_t>();
|
||||
scalarType = rdcspv::scalar<int32_t>();
|
||||
name = "int_vbuffers";
|
||||
}
|
||||
else if(tb == tbuffer_uint)
|
||||
{
|
||||
scalarType = scalar<uint32_t>();
|
||||
scalarType = rdcspv::scalar<uint32_t>();
|
||||
name = "uint_vbuffers";
|
||||
}
|
||||
|
||||
tbuffers[tb].imageTypeID = editor.DeclareType(
|
||||
SPIRVImage(scalarType, rdcspv::Dim::Buffer, 0, 0, 0, 1, rdcspv::ImageFormat::Unknown));
|
||||
tbuffers[tb].imageSampledTypeID = editor.DeclareType(SPIRVSampledImage(tbuffers[tb].imageTypeID));
|
||||
rdcspv::Image(scalarType, rdcspv::Dim::Buffer, 0, 0, 0, 1, rdcspv::ImageFormat::Unknown));
|
||||
tbuffers[tb].imageSampledTypeID =
|
||||
editor.DeclareType(rdcspv::SampledImage(tbuffers[tb].imageTypeID));
|
||||
|
||||
rdcspv::Id arrayType = editor.MakeId();
|
||||
editor.AddType(rdcspv::OpTypeArray(arrayType, tbuffers[tb].imageSampledTypeID, arraySize));
|
||||
|
||||
rdcspv::Id arrayPtrType =
|
||||
editor.DeclareType(SPIRVPointer(arrayType, rdcspv::StorageClass::UniformConstant));
|
||||
editor.DeclareType(rdcspv::Pointer(arrayType, rdcspv::StorageClass::UniformConstant));
|
||||
|
||||
tbuffers[tb].pointerTypeID = editor.DeclareType(
|
||||
SPIRVPointer(tbuffers[tb].imageSampledTypeID, rdcspv::StorageClass::UniformConstant));
|
||||
rdcspv::Pointer(tbuffers[tb].imageSampledTypeID, rdcspv::StorageClass::UniformConstant));
|
||||
|
||||
tbuffers[tb].variableID = editor.MakeId();
|
||||
editor.AddVariable(rdcspv::OpVariable(arrayPtrType, tbuffers[tb].variableID,
|
||||
@@ -533,14 +539,14 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
if(draw->flags & DrawFlags::Indexed)
|
||||
{
|
||||
uint32Vec4ID = editor.DeclareType(SPIRVVector(scalar<uint32_t>(), 4));
|
||||
uint32Vec4ID = editor.DeclareType(rdcspv::Vector(rdcspv::scalar<uint32_t>(), 4));
|
||||
|
||||
idxImageTypeID = editor.DeclareType(SPIRVImage(scalar<uint32_t>(), rdcspv::Dim::Buffer, 0, 0, 0,
|
||||
1, rdcspv::ImageFormat::Unknown));
|
||||
idxSampledTypeID = editor.DeclareType(SPIRVSampledImage(idxImageTypeID));
|
||||
idxImageTypeID = editor.DeclareType(rdcspv::Image(
|
||||
rdcspv::scalar<uint32_t>(), rdcspv::Dim::Buffer, 0, 0, 0, 1, rdcspv::ImageFormat::Unknown));
|
||||
idxSampledTypeID = editor.DeclareType(rdcspv::SampledImage(idxImageTypeID));
|
||||
|
||||
rdcspv::Id idxImagePtrType =
|
||||
editor.DeclareType(SPIRVPointer(idxSampledTypeID, rdcspv::StorageClass::UniformConstant));
|
||||
editor.DeclareType(rdcspv::Pointer(idxSampledTypeID, rdcspv::StorageClass::UniformConstant));
|
||||
|
||||
idxImagePtr = editor.MakeId();
|
||||
editor.AddVariable(
|
||||
@@ -589,7 +595,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
// meshOutput *
|
||||
rdcspv::Id outputStructPtrID =
|
||||
editor.DeclareType(SPIRVPointer(outputStructID, rdcspv::StorageClass::Uniform));
|
||||
editor.DeclareType(rdcspv::Pointer(outputStructID, rdcspv::StorageClass::Uniform));
|
||||
editor.SetName(outputStructPtrID, "meshOutput_ptr");
|
||||
|
||||
// meshOutput *outputData;
|
||||
@@ -650,9 +656,9 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
outBufferVarID, rdcspv::DecorationParam<rdcspv::Decoration::Binding>(0)));
|
||||
}
|
||||
|
||||
rdcspv::Id uint32Vec3ID = editor.DeclareType(SPIRVVector(scalar<uint32_t>(), 3));
|
||||
rdcspv::Id uint32Vec3ID = editor.DeclareType(rdcspv::Vector(rdcspv::scalar<uint32_t>(), 3));
|
||||
rdcspv::Id invocationPtr =
|
||||
editor.DeclareType(SPIRVPointer(uint32Vec3ID, rdcspv::StorageClass::Input));
|
||||
editor.DeclareType(rdcspv::Pointer(uint32Vec3ID, rdcspv::StorageClass::Input));
|
||||
rdcspv::Id invocationId = editor.AddVariable(
|
||||
rdcspv::OpVariable(invocationPtr, editor.MakeId(), rdcspv::StorageClass::Input));
|
||||
editor.AddDecoration(rdcspv::OpDecorate(
|
||||
@@ -669,7 +675,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
// editor.SetName(wrapperEntry, "RenderDoc_MeshFetch_Wrapper_Entrypoint");
|
||||
|
||||
// we remove all entry points and just create one of our own.
|
||||
rdcspv::Iter it = editor.Begin(SPIRVSection::EntryPoints);
|
||||
rdcspv::Iter it = editor.Begin(rdcspv::Section::EntryPoints);
|
||||
|
||||
{
|
||||
// there should already have been at least one entry point
|
||||
@@ -694,12 +700,12 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
++it;
|
||||
}
|
||||
|
||||
for(rdcspv::Iter end = editor.End(SPIRVSection::EntryPoints); it < end; ++it)
|
||||
for(rdcspv::Iter end = editor.End(rdcspv::Section::EntryPoints); it < end; ++it)
|
||||
editor.Remove(it);
|
||||
|
||||
// Strip away any execution modes from the original shaders
|
||||
for(it = editor.Begin(SPIRVSection::ExecutionMode); it < editor.End(SPIRVSection::ExecutionMode);
|
||||
++it)
|
||||
for(it = editor.Begin(rdcspv::Section::ExecutionMode);
|
||||
it < editor.End(rdcspv::Section::ExecutionMode); ++it)
|
||||
{
|
||||
if(it.opcode() == rdcspv::Op::ExecutionMode)
|
||||
{
|
||||
@@ -727,14 +733,14 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
wrapperEntry,
|
||||
rdcspv::ExecutionModeParam<rdcspv::ExecutionMode::LocalSize>(MeshOutputDispatchWidth, 1, 1)));
|
||||
|
||||
rdcspv::Id uint32ID = editor.DeclareType(scalar<uint32_t>());
|
||||
rdcspv::Id uint32ID = editor.DeclareType(rdcspv::scalar<uint32_t>());
|
||||
|
||||
// add the wrapper function
|
||||
{
|
||||
std::vector<rdcspv::Operation> ops;
|
||||
|
||||
rdcspv::Id voidType = editor.DeclareType(scalar<void>());
|
||||
rdcspv::Id funcType = editor.DeclareType(SPIRVFunction(voidType, {}));
|
||||
rdcspv::Id voidType = editor.DeclareType(rdcspv::scalar<void>());
|
||||
rdcspv::Id funcType = editor.DeclareType(rdcspv::Function(voidType, {}));
|
||||
|
||||
ops.push_back(rdcspv::OpFunction(voidType, wrapperEntry, rdcspv::FunctionControl::None, funcType));
|
||||
|
||||
@@ -771,8 +777,8 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
// bool inBounds = viewID < numViews;
|
||||
rdcspv::Id inBounds = editor.MakeId();
|
||||
ops.push_back(rdcspv::OpULessThan(editor.DeclareType(scalar<bool>()), inBounds, viewID,
|
||||
numViewsConstID));
|
||||
ops.push_back(rdcspv::OpULessThan(editor.DeclareType(rdcspv::scalar<bool>()), inBounds,
|
||||
viewID, numViewsConstID));
|
||||
|
||||
// if(inBounds) goto continueLabel; else goto killLabel;
|
||||
rdcspv::Id killLabel = editor.MakeId();
|
||||
@@ -981,7 +987,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
|
||||
rdcspv::Id glsl450 = editor.ImportExtInst("GLSL.std.450");
|
||||
|
||||
rdcspv::Id uvec2Type = editor.DeclareType(SPIRVVector(scalar<uint32_t>(), 2));
|
||||
rdcspv::Id uvec2Type = editor.DeclareType(rdcspv::Vector(rdcspv::scalar<uint32_t>(), 2));
|
||||
rdcspv::Id comps[4] = {};
|
||||
|
||||
for(uint32_t c = 0; c < refl.inputSignature[i].compCount; c++)
|
||||
@@ -1002,7 +1008,7 @@ static void ConvertToMeshOutputCompute(const ShaderReflection &refl, const SPIRV
|
||||
ops.push_back(rdcspv::Operation(
|
||||
rdcspv::Op::ExtInst,
|
||||
{
|
||||
editor.DeclareType(scalar<double>()).value(), comps[c].value(),
|
||||
editor.DeclareType(rdcspv::scalar<double>()).value(), comps[c].value(),
|
||||
glsl450.value(), (uint32_t)rdcspv::GLSLstd450::PackDouble2x32, packed.value(),
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -3760,16 +3760,16 @@ void VulkanReplay::BuildTargetShader(ShaderEncoding sourceEncoding, bytebuf sour
|
||||
|
||||
if(sourceEncoding == ShaderEncoding::GLSL)
|
||||
{
|
||||
SPIRVShaderStage stage = SPIRVShaderStage::Invalid;
|
||||
rdcspv::ShaderStage stage = rdcspv::ShaderStage::Invalid;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case ShaderStage::Vertex: stage = SPIRVShaderStage::Vertex; break;
|
||||
case ShaderStage::Hull: stage = SPIRVShaderStage::TessControl; break;
|
||||
case ShaderStage::Domain: stage = SPIRVShaderStage::TessEvaluation; break;
|
||||
case ShaderStage::Geometry: stage = SPIRVShaderStage::Geometry; break;
|
||||
case ShaderStage::Pixel: stage = SPIRVShaderStage::Fragment; break;
|
||||
case ShaderStage::Compute: stage = SPIRVShaderStage::Compute; break;
|
||||
case ShaderStage::Vertex: stage = rdcspv::ShaderStage::Vertex; break;
|
||||
case ShaderStage::Hull: stage = rdcspv::ShaderStage::TessControl; break;
|
||||
case ShaderStage::Domain: stage = rdcspv::ShaderStage::TessEvaluation; break;
|
||||
case ShaderStage::Geometry: stage = rdcspv::ShaderStage::Geometry; break;
|
||||
case ShaderStage::Pixel: stage = rdcspv::ShaderStage::Fragment; break;
|
||||
case ShaderStage::Compute: stage = rdcspv::ShaderStage::Compute; break;
|
||||
default:
|
||||
RDCERR("Unexpected type in BuildShader!");
|
||||
*id = ResourceId();
|
||||
@@ -3779,9 +3779,9 @@ void VulkanReplay::BuildTargetShader(ShaderEncoding sourceEncoding, bytebuf sour
|
||||
std::vector<std::string> sources;
|
||||
sources.push_back(std::string((char *)source.begin(), (char *)source.end()));
|
||||
|
||||
SPIRVCompilationSettings settings(SPIRVSourceLanguage::VulkanGLSL, stage);
|
||||
rdcspv::CompilationSettings settings(rdcspv::InputLanguage::VulkanGLSL, stage);
|
||||
|
||||
std::string output = CompileSPIRV(settings, sources, spirv);
|
||||
std::string output = rdcspv::Compile(settings, sources, spirv);
|
||||
|
||||
if(spirv.empty())
|
||||
{
|
||||
|
||||
@@ -41,48 +41,48 @@ struct BuiltinShaderConfig
|
||||
{
|
||||
BuiltinShader builtin;
|
||||
EmbeddedResourceType resource;
|
||||
SPIRVShaderStage stage;
|
||||
rdcspv::ShaderStage stage;
|
||||
FeatureCheck checks;
|
||||
bool uniforms;
|
||||
};
|
||||
|
||||
static const BuiltinShaderConfig builtinShaders[] = {
|
||||
{BuiltinShader::BlitVS, EmbeddedResource(glsl_blit_vert), SPIRVShaderStage::Vertex,
|
||||
{BuiltinShader::BlitVS, EmbeddedResource(glsl_blit_vert), rdcspv::ShaderStage::Vertex,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::CheckerboardFS, EmbeddedResource(glsl_checkerboard_frag),
|
||||
SPIRVShaderStage::Fragment, FeatureCheck::NoCheck, true},
|
||||
rdcspv::ShaderStage::Fragment, FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::TexDisplayFS, EmbeddedResource(glsl_texdisplay_frag),
|
||||
SPIRVShaderStage::Fragment, FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::FixedColFS, EmbeddedResource(glsl_fixedcol_frag), SPIRVShaderStage::Fragment,
|
||||
rdcspv::ShaderStage::Fragment, FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::FixedColFS, EmbeddedResource(glsl_fixedcol_frag), rdcspv::ShaderStage::Fragment,
|
||||
FeatureCheck::NoCheck, false},
|
||||
{BuiltinShader::TextVS, EmbeddedResource(glsl_vktext_vert), SPIRVShaderStage::Vertex,
|
||||
{BuiltinShader::TextVS, EmbeddedResource(glsl_vktext_vert), rdcspv::ShaderStage::Vertex,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::TextFS, EmbeddedResource(glsl_vktext_frag), SPIRVShaderStage::Fragment,
|
||||
{BuiltinShader::TextFS, EmbeddedResource(glsl_vktext_frag), rdcspv::ShaderStage::Fragment,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::MeshVS, EmbeddedResource(glsl_mesh_vert), SPIRVShaderStage::Vertex,
|
||||
{BuiltinShader::MeshVS, EmbeddedResource(glsl_mesh_vert), rdcspv::ShaderStage::Vertex,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::MeshGS, EmbeddedResource(glsl_mesh_geom), SPIRVShaderStage::Geometry,
|
||||
{BuiltinShader::MeshGS, EmbeddedResource(glsl_mesh_geom), rdcspv::ShaderStage::Geometry,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::MeshFS, EmbeddedResource(glsl_mesh_frag), SPIRVShaderStage::Fragment,
|
||||
{BuiltinShader::MeshFS, EmbeddedResource(glsl_mesh_frag), rdcspv::ShaderStage::Fragment,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::MeshCS, EmbeddedResource(glsl_mesh_comp), SPIRVShaderStage::Compute,
|
||||
{BuiltinShader::MeshCS, EmbeddedResource(glsl_mesh_comp), rdcspv::ShaderStage::Compute,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::QuadResolveFS, EmbeddedResource(glsl_quadresolve_frag),
|
||||
SPIRVShaderStage::Fragment, FeatureCheck::FragmentStores, true},
|
||||
{BuiltinShader::QuadWriteFS, EmbeddedResource(glsl_quadwrite_frag), SPIRVShaderStage::Fragment,
|
||||
rdcspv::ShaderStage::Fragment, FeatureCheck::FragmentStores, true},
|
||||
{BuiltinShader::QuadWriteFS, EmbeddedResource(glsl_quadwrite_frag), rdcspv::ShaderStage::Fragment,
|
||||
FeatureCheck::FragmentStores | FeatureCheck::NonMetalBackend, false},
|
||||
{BuiltinShader::TrisizeGS, EmbeddedResource(glsl_trisize_geom), SPIRVShaderStage::Geometry,
|
||||
{BuiltinShader::TrisizeGS, EmbeddedResource(glsl_trisize_geom), rdcspv::ShaderStage::Geometry,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::TrisizeFS, EmbeddedResource(glsl_trisize_frag), SPIRVShaderStage::Fragment,
|
||||
{BuiltinShader::TrisizeFS, EmbeddedResource(glsl_trisize_frag), rdcspv::ShaderStage::Fragment,
|
||||
FeatureCheck::NoCheck, true},
|
||||
{BuiltinShader::MS2ArrayCS, EmbeddedResource(glsl_ms2array_comp), SPIRVShaderStage::Compute,
|
||||
{BuiltinShader::MS2ArrayCS, EmbeddedResource(glsl_ms2array_comp), rdcspv::ShaderStage::Compute,
|
||||
FeatureCheck::ShaderMSAAStorage | FeatureCheck::NonMetalBackend, true},
|
||||
{BuiltinShader::Array2MSCS, EmbeddedResource(glsl_array2ms_comp), SPIRVShaderStage::Compute,
|
||||
{BuiltinShader::Array2MSCS, EmbeddedResource(glsl_array2ms_comp), rdcspv::ShaderStage::Compute,
|
||||
FeatureCheck::ShaderMSAAStorage | FeatureCheck::NonMetalBackend, true},
|
||||
{BuiltinShader::DepthMS2ArrayFS, EmbeddedResource(glsl_depthms2arr_frag),
|
||||
SPIRVShaderStage::Fragment, FeatureCheck::NonMetalBackend, true},
|
||||
rdcspv::ShaderStage::Fragment, FeatureCheck::NonMetalBackend, true},
|
||||
{BuiltinShader::DepthArray2MSFS, EmbeddedResource(glsl_deptharr2ms_frag),
|
||||
SPIRVShaderStage::Fragment, FeatureCheck::NonMetalBackend, true},
|
||||
rdcspv::ShaderStage::Fragment, FeatureCheck::NonMetalBackend, true},
|
||||
};
|
||||
|
||||
RDCCOMPILE_ASSERT(ARRAY_COUNT(builtinShaders) == arraydim<BuiltinShader>(),
|
||||
@@ -134,8 +134,8 @@ VulkanShaderCache::VulkanShaderCache(WrappedVulkan *driver)
|
||||
m_GlobalDefines += "#define METAL_BACKEND\n";
|
||||
|
||||
std::string src;
|
||||
SPIRVCompilationSettings compileSettings;
|
||||
compileSettings.lang = SPIRVSourceLanguage::VulkanGLSL;
|
||||
rdcspv::CompilationSettings compileSettings;
|
||||
compileSettings.lang = rdcspv::InputLanguage::VulkanGLSL;
|
||||
|
||||
for(auto i : indices<BuiltinShader>())
|
||||
{
|
||||
@@ -166,7 +166,7 @@ VulkanShaderCache::VulkanShaderCache(WrappedVulkan *driver)
|
||||
continue;
|
||||
}
|
||||
|
||||
if(config.stage == SPIRVShaderStage::Geometry && !features.geometryShader)
|
||||
if(config.stage == rdcspv::ShaderStage::Geometry && !features.geometryShader)
|
||||
continue;
|
||||
|
||||
src = GenerateGLSLShader(GetDynamicEmbeddedResource(config.resource), eShaderVulkan, 430,
|
||||
@@ -217,7 +217,7 @@ VulkanShaderCache::~VulkanShaderCache()
|
||||
m_pDriver->vkDestroyShaderModule(m_Device, m_BuiltinShaderModules[i], NULL);
|
||||
}
|
||||
|
||||
std::string VulkanShaderCache::GetSPIRVBlob(const SPIRVCompilationSettings &settings,
|
||||
std::string VulkanShaderCache::GetSPIRVBlob(const rdcspv::CompilationSettings &settings,
|
||||
const std::string &src, SPIRVBlob &outBlob)
|
||||
{
|
||||
RDCASSERT(!src.empty());
|
||||
@@ -236,7 +236,7 @@ std::string VulkanShaderCache::GetSPIRVBlob(const SPIRVCompilationSettings &sett
|
||||
}
|
||||
|
||||
SPIRVBlob spirv = new std::vector<uint32_t>();
|
||||
std::string errors = CompileSPIRV(settings, {src}, *spirv);
|
||||
std::string errors = rdcspv::Compile(settings, {src}, *spirv);
|
||||
|
||||
if(!errors.empty())
|
||||
{
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
VulkanShaderCache(WrappedVulkan *driver);
|
||||
~VulkanShaderCache();
|
||||
|
||||
std::string GetSPIRVBlob(const SPIRVCompilationSettings &settings, const std::string &src,
|
||||
std::string GetSPIRVBlob(const rdcspv::CompilationSettings &settings, const std::string &src,
|
||||
SPIRVBlob &outBlob);
|
||||
|
||||
SPIRVBlob GetBuiltinBlob(BuiltinShader builtin) { return m_BuiltinShaderBlobs[(size_t)builtin]; }
|
||||
|
||||
Reference in new issue
Block a user