mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 13:48:30 +09:00
[Chore] (MG_Util/Program): SpvcSession rule-of-three?
This commit is contained in:
@@ -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