mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-07 19:58:32 +09:00
Revert "[Chore] (MG_Util/Program): use SPIRV-Cross C++ API instead of C ones"
This reverts commit 8e0284faec.
This commit is contained in:
@@ -48,8 +48,6 @@
|
||||
#include <glslang/Public/ShaderLang.h>
|
||||
#include <glslang/Include/Types.h>
|
||||
#include <glslang/Public/ShaderLang.h>
|
||||
#include <spirv_cross/spirv_cross.hpp>
|
||||
#include <spirv_cross/spirv_glsl.hpp>
|
||||
#include <spirv_cross/spirv_cross_c.h>
|
||||
#include <glslang/SPIRV/GlslangToSpv.h>
|
||||
#include <glslang/Include/intermediate.h>
|
||||
|
||||
@@ -7,6 +7,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
|
||||
set(LINK_LIBRARIES
|
||||
${VULKAN_LIB_DIR}/libglslang.a
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-c-shared.dylib
|
||||
${VULKAN_LIB_DIR}/libGenericCodeGen.a
|
||||
${VULKAN_LIB_DIR}/libglslang-default-resource-limits.a
|
||||
${VULKAN_LIB_DIR}/libMachineIndependent.a
|
||||
@@ -18,18 +19,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
${VULKAN_LIB_DIR}/libSPIRV-Tools-reduce.a
|
||||
${VULKAN_LIB_DIR}/libSPIRV-Tools.a
|
||||
${VULKAN_LIB_DIR}/libSPIRV.a
|
||||
${VULKAN_LIB_DIR}/libSPVRemapper.a
|
||||
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-c-shared.dylib
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-core.a
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-cpp.a
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-glsl.a
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-hlsl.a
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-msl.a
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-reflect.a
|
||||
${VULKAN_LIB_DIR}/libspirv-cross-util.a
|
||||
|
||||
)
|
||||
${VULKAN_LIB_DIR}/libSPVRemapper.a)
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
find_package(Vulkan REQUIRED)
|
||||
get_filename_component(VULKAN_LIB_DIR ${Vulkan_LIBRARY} PATH)
|
||||
|
||||
@@ -148,7 +148,7 @@ TEST_F(ProgramTest, DecompProgram) {
|
||||
ShaderAttrib fs_attrib {
|
||||
.shaderType = GL_FRAGMENT_SHADER,
|
||||
.sourceStr = fs
|
||||
};
|
||||
};
|
||||
auto fs_res = ShaderCompiler::CompileShader(fs_attrib);
|
||||
if (!fs_res) {
|
||||
ASSERT_NE(fs_res.error().errc, 0);
|
||||
@@ -168,10 +168,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;
|
||||
spirv_cross::CompilerGLSL compiler(spirvs[i]);
|
||||
auto src = ShaderCompiler::DecompileShader(compiler);
|
||||
auto src = ShaderCompiler::DecompileShader(sessions[i]);
|
||||
if (!src) {
|
||||
ASSERT_NE(src.error().errc, 0);
|
||||
FAIL() << "errc: " << src.error().errc << "\nlog: " << src.error().log;
|
||||
@@ -181,42 +185,42 @@ TEST_F(ProgramTest, DecompProgram) {
|
||||
}
|
||||
|
||||
// spirv link check
|
||||
// auto vs_outputs = sessions[0].GetShaderInterface(SPVC_RESOURCE_TYPE_STAGE_OUTPUT);
|
||||
// auto fs_inputs = sessions[1].GetShaderInterface(SPVC_RESOURCE_TYPE_STAGE_INPUT);
|
||||
//
|
||||
// ASSERT_EQ(vs_outputs.size(), fs_inputs.size());
|
||||
//
|
||||
// for (size_t i = 0; i < vs_outputs.size(); ++i) {
|
||||
// EXPECT_EQ(vs_outputs[i].location, fs_inputs[i].location);
|
||||
// }
|
||||
//
|
||||
// auto vs_uniforms = sessions[0].GetShaderInterface(SPVC_RESOURCE_TYPE_GL_PLAIN_UNIFORM);
|
||||
// auto fs_uniforms = sessions[1].GetShaderInterface(SPVC_RESOURCE_TYPE_GL_PLAIN_UNIFORM);
|
||||
//
|
||||
// std::unordered_map<std::string, uint32_t> uniform_locations;
|
||||
// for (const auto& uniform : vs_uniforms) {
|
||||
// uniform_locations[uniform.name] = uniform.location;
|
||||
// }
|
||||
//
|
||||
// for (const auto& uniform : fs_uniforms) {
|
||||
// auto it = uniform_locations.find(uniform.name);
|
||||
// if (it != uniform_locations.end()) {
|
||||
// EXPECT_EQ(it->second, uniform.location);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// auto vs_samplers = sessions[0].GetShaderInterface(SPVC_RESOURCE_TYPE_SAMPLED_IMAGE);
|
||||
// auto fs_samplers = sessions[1].GetShaderInterface(SPVC_RESOURCE_TYPE_SAMPLED_IMAGE);
|
||||
//
|
||||
// std::unordered_map<std::string, uint32_t> sampler_locations;
|
||||
// for (const auto& uniform : vs_uniforms) {
|
||||
// sampler_locations[uniform.name] = uniform.location;
|
||||
// }
|
||||
//
|
||||
// for (const auto& uniform : fs_uniforms) {
|
||||
// auto it = sampler_locations.find(uniform.name);
|
||||
// if (it != sampler_locations.end()) {
|
||||
// EXPECT_EQ(it->second, uniform.location);
|
||||
// }
|
||||
// }
|
||||
auto vs_outputs = sessions[0].GetShaderInterface(SPVC_RESOURCE_TYPE_STAGE_OUTPUT);
|
||||
auto fs_inputs = sessions[1].GetShaderInterface(SPVC_RESOURCE_TYPE_STAGE_INPUT);
|
||||
|
||||
ASSERT_EQ(vs_outputs.size(), fs_inputs.size());
|
||||
|
||||
for (size_t i = 0; i < vs_outputs.size(); ++i) {
|
||||
EXPECT_EQ(vs_outputs[i].location, fs_inputs[i].location);
|
||||
}
|
||||
|
||||
auto vs_uniforms = sessions[0].GetShaderInterface(SPVC_RESOURCE_TYPE_GL_PLAIN_UNIFORM);
|
||||
auto fs_uniforms = sessions[1].GetShaderInterface(SPVC_RESOURCE_TYPE_GL_PLAIN_UNIFORM);
|
||||
|
||||
std::unordered_map<std::string, uint32_t> uniform_locations;
|
||||
for (const auto& uniform : vs_uniforms) {
|
||||
uniform_locations[uniform.name] = uniform.location;
|
||||
}
|
||||
|
||||
for (const auto& uniform : fs_uniforms) {
|
||||
auto it = uniform_locations.find(uniform.name);
|
||||
if (it != uniform_locations.end()) {
|
||||
EXPECT_EQ(it->second, uniform.location);
|
||||
}
|
||||
}
|
||||
|
||||
auto vs_samplers = sessions[0].GetShaderInterface(SPVC_RESOURCE_TYPE_SAMPLED_IMAGE);
|
||||
auto fs_samplers = sessions[1].GetShaderInterface(SPVC_RESOURCE_TYPE_SAMPLED_IMAGE);
|
||||
|
||||
std::unordered_map<std::string, uint32_t> sampler_locations;
|
||||
for (const auto& uniform : vs_uniforms) {
|
||||
sampler_locations[uniform.name] = uniform.location;
|
||||
}
|
||||
|
||||
for (const auto& uniform : fs_uniforms) {
|
||||
auto it = sampler_locations.find(uniform.name);
|
||||
if (it != sampler_locations.end()) {
|
||||
EXPECT_EQ(it->second, uniform.location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,10 @@ namespace MobileGL {
|
||||
WideCharToMultiByte(CP_UTF8, 0, desc, -1, buffer, sizeof(buffer), nullptr, nullptr);
|
||||
LocalFree(desc);
|
||||
}
|
||||
#elif defined(__ANDROID__) || defined(__linux__) || defined(__APPLE__)
|
||||
#elif defined(__ANDROID__) || defined(__linux__)
|
||||
pthread_getname_np(pthread_self(), buffer, sizeof(buffer));
|
||||
#elif defined(__APPLE__)
|
||||
pthread_getname_np(buffer, sizeof(buffer));
|
||||
#endif
|
||||
return buffer[0] ? buffer : "UnknownThread";
|
||||
}
|
||||
|
||||
@@ -207,37 +207,18 @@ namespace MobileGL {
|
||||
const char *result = nullptr;
|
||||
session.Compile(&result);
|
||||
|
||||
// if (!result) {
|
||||
// ResultInfo r;
|
||||
// r.log += "Failed to compile the shader to GLSL: \n";
|
||||
// r.log += session.GetLastErrorString();
|
||||
// r.errc = -5;
|
||||
// return std::unexpected(r);
|
||||
// }
|
||||
if (!result) {
|
||||
ResultInfo r;
|
||||
r.log += "Failed to compile the shader to GLSL: \n";
|
||||
r.log += session.GetLastErrorString();
|
||||
r.errc = -5;
|
||||
return std::unexpected(r);
|
||||
}
|
||||
|
||||
std::string glsl = result;
|
||||
|
||||
return glsl;
|
||||
}
|
||||
|
||||
Result<String> ShaderCompiler::DecompileShader(spirv_cross::CompilerGLSL& compiler) {
|
||||
try {
|
||||
spirv_cross::CompilerGLSL::Options options;
|
||||
options.version = 450;
|
||||
options.es = false;
|
||||
options.vulkan_semantics = true;
|
||||
compiler.set_common_options(options);
|
||||
|
||||
auto result = compiler.compile();
|
||||
return result;
|
||||
} catch (const spirv_cross::CompilerError& e) {
|
||||
ResultInfo r;
|
||||
r.log += "Failed to compile the shader to GLSL: \n";
|
||||
r.log += e.what();
|
||||
r.errc = -5;
|
||||
return std::unexpected(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ namespace ShaderTranspiler {
|
||||
static Result<SharedPtr<glslang::TShader>> CompileShader(const ShaderAttrib& attrib);
|
||||
static Result<Vector<Vector<unsigned>>> LinkProgram(const ProgramAttrib& attrib);
|
||||
static Result<String> DecompileShader(SpvcSession& session);
|
||||
static Result<String> DecompileShader(spirv_cross::CompilerGLSL& compiler);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user