mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
[Chore] (MG_Util/Program): SpvcSession rule-of-three?
This commit is contained in:
@@ -218,9 +218,14 @@ TEST_F(ProgramTest, DecompProgram) {
|
||||
|
||||
auto spirvs = program_res.value();
|
||||
|
||||
Vector<SpvcSession> sessions(spirvs.size());
|
||||
for (SizeT i = 0; i < spirvs.size(); ++i) {
|
||||
sessions[i] = SpvcSession(spirvs[i]);
|
||||
}
|
||||
|
||||
for (SizeT i = 0; i < spirvs.size(); ++i) {
|
||||
std::cout << "Decompiling " << MG_Util::ConvertGLEnumToString(programAttrib.shaderTypes[i]) << std::endl;
|
||||
auto src = ShaderCompiler::DecompileShader(spirvs[i]);
|
||||
auto src = ShaderCompiler::DecompileShader(sessions[i]);
|
||||
if (!src) {
|
||||
ASSERT_NE(src.error().errc, 0);
|
||||
FAIL() << "errc: " << src.error().errc << "\nlog: " << src.error().log;
|
||||
|
||||
@@ -197,8 +197,7 @@ namespace MobileGL {
|
||||
return allSpirv;
|
||||
}
|
||||
|
||||
Result<String> ShaderCompiler::DecompileShader(Vector<unsigned int> spirv) {
|
||||
SpvcSession session(spirv);
|
||||
Result<String> ShaderCompiler::DecompileShader(SpvcSession& session) {
|
||||
spvc_compiler_options options;
|
||||
session.CreateOptions(&options);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace ShaderTranspiler {
|
||||
public:
|
||||
static Result<SharedPtr<glslang::TShader>> CompileShader(const ShaderAttrib& attrib);
|
||||
static Result<Vector<Vector<unsigned>>> LinkProgram(const ProgramAttrib& attrib);
|
||||
static Result<String> DecompileShader(Vector<unsigned int> spirv);
|
||||
static Result<String> DecompileShader(SpvcSession& session);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,11 @@ namespace MobileGL {
|
||||
template <typename T>
|
||||
using Result = std::expected<T, ResultInfo>;
|
||||
|
||||
struct SpvcSession {
|
||||
SpvcSession(Vector<unsigned int> spirv) {
|
||||
class SpvcSession {
|
||||
public:
|
||||
SpvcSession() {}
|
||||
|
||||
explicit SpvcSession(Vector<unsigned int> spirv) {
|
||||
const SpvId *p_spirv = spirv.data();
|
||||
size_t word_count = spirv.size();
|
||||
|
||||
@@ -38,6 +41,25 @@ namespace MobileGL {
|
||||
spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler);
|
||||
}
|
||||
|
||||
SpvcSession(SpvcSession&) = delete;
|
||||
|
||||
SpvcSession(SpvcSession&& that) {
|
||||
std::swap(this->context, that.context);
|
||||
std::swap(this->compiler, that.compiler);
|
||||
std::swap(this->ir, that.ir);
|
||||
std::swap(this->compiler_options, that.compiler_options);
|
||||
}
|
||||
|
||||
SpvcSession& operator=(SpvcSession& session) = delete;
|
||||
|
||||
SpvcSession& operator=(SpvcSession&& that) {
|
||||
std::swap(this->context, that.context);
|
||||
std::swap(this->compiler, that.compiler);
|
||||
std::swap(this->ir, that.ir);
|
||||
std::swap(this->compiler_options, that.compiler_options);
|
||||
return *this;
|
||||
}
|
||||
|
||||
spvc_result CreateOptions(spvc_compiler_options *options) {
|
||||
return spvc_compiler_create_compiler_options(compiler, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user