[Improvement] (...): Optimize code.

This commit is contained in:
BZLZHH
2025-10-31 13:29:48 +08:00
parent 2652a12fdc
commit d982928a23
39 changed files with 284 additions and 775 deletions
+3 -1
View File
@@ -38,18 +38,20 @@ set(SOURCE_FILES
MobileGL/MG_Util/Converters/MGToStr/BufferEnumConverter.cpp
MobileGL/MG_Util/Converters/MGToStr/FramebufferEnumConverter.cpp
MobileGL/MG_Util/Converters/MGToStr/TextureEnumConverter.cpp
MobileGL/MG_Util/Converters/GLToGlslang/GLShaderLangConverter.cpp
MobileGL/MG_Util/Converters/GLToGlslang/ProgramEnumConverter.cpp
MobileGL/MG_Util/Converters/MGToGL/ErrorCodeConverter.cpp
MobileGL/MG_Util/Converters/MGToGL/BufferEnumConverter.cpp
MobileGL/MG_Util/Converters/MGToGL/FramebufferEnumConverter.cpp
MobileGL/MG_Util/Converters/MGToGL/TextureEnumConverter.cpp
MobileGL/MG_Util/Converters/MGToGL/DataTypeConverter.cpp
MobileGL/MG_Util/Converters/MGToGL/RenderStateEnumConverter.cpp
MobileGL/MG_Util/Converters/MGToGL/ProgramEnumConverter.cpp
MobileGL/MG_Util/Converters/GLToMG/BufferEnumConverter.cpp
MobileGL/MG_Util/Converters/GLToMG/FramebufferEnumConverter.cpp
MobileGL/MG_Util/Converters/GLToMG/TextureEnumConverter.cpp
MobileGL/MG_Util/Converters/GLToMG/DataTypeConverter.cpp
MobileGL/MG_Util/Converters/GLToMG/RenderStateEnumConverter.cpp
MobileGL/MG_Util/Converters/GLToMG/ProgramEnumConverter.cpp
MobileGL/MG_Util/Converters/MGToMG/TextureEnumConverter.cpp
MobileGL/MG_Util/ShaderTranspiler/ShaderCompiler.cpp
+15 -15
View File
@@ -245,8 +245,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
} // namespace PrgramImpl
void BindCurrentFBO(FramebufferTarget target) {
const auto& currentFBO =
MG_State::pGLContext->GetFramebufferBindingSlot(target).GetBoundObject();
const auto& currentFBO = MG_State::pGLContext->GetFramebufferBindingSlot(target).GetBoundObject();
if (currentFBO && currentFBO != MG_Impl::GLImpl::FramebufferImpl::pDefaultFramebufferInfo->defaultFBO) {
const auto& backendFBOIt = FramebufferImpl::g_backendFramebufferObjects.find(currentFBO);
if (backendFBOIt != FramebufferImpl::g_backendFramebufferObjects.end()) {
@@ -300,9 +299,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
const auto& samplerObj = textureObject->GetSamplerObject();
const auto minfilter = samplerObj->GetMinFilter();
MG_External::GLES::glTexParameteri(target, GL_TEXTURE_MIN_FILTER, MG_Util::ConvertSamplerFilterModeToGLEnum(minfilter));
MG_External::GLES::glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
MG_Util::ConvertSamplerFilterModeToGLEnum(minfilter));
const auto magfilter = samplerObj->GetMagFilter();
MG_External::GLES::glTexParameteri(target, GL_TEXTURE_MAG_FILTER, MG_Util::ConvertSamplerFilterModeToGLEnum(magfilter));
MG_External::GLES::glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
MG_Util::ConvertSamplerFilterModeToGLEnum(magfilter));
MG_External::GLES::glTexParameterf(target, GL_TEXTURE_MIN_LOD, samplerObj->GetMinLod());
MG_External::GLES::glTexParameterf(target, GL_TEXTURE_MAX_LOD, samplerObj->GetMaxLod());
}
@@ -322,11 +323,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
currentProgram->MapUBO());
MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER, 0);
Uint blockIndex = MG_External::GLES::glGetUniformBlockIndex(backendProgramIt->second->GetBackendProgramId(),
MG_Util::ShaderTranspiler::GLOBAL_UBO_NAME);
Uint blockIndex = MG_External::GLES::glGetUniformBlockIndex(
backendProgramIt->second->GetBackendProgramId(), MG_Util::ShaderTranspiler::GLOBAL_UBO_NAME);
MG_External::GLES::glUniformBlockBinding(
backendProgramIt->second->GetBackendProgramId(), blockIndex, 0);
MG_External::GLES::glUniformBlockBinding(backendProgramIt->second->GetBackendProgramId(), blockIndex,
0);
MG_External::GLES::glBindBufferBase(GL_UNIFORM_BUFFER, 0,
backendProgramIt->second->GetBackendGlobalUBOId());
@@ -335,10 +336,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
auto maxUniformLoc = currentProgram->GetMaxUniformLocation();
for (int loc = 0; loc < maxUniformLoc; ++loc) {
auto unit = currentProgram->GetUniformSamplerOrImageUnitIndex(loc);
if (unit == -1)
continue;
if (unit == -1) continue;
auto& name = currentProgram->GetUniformName(loc);
auto locAtBackend = MG_External::GLES::glGetUniformLocation(backendProgramIt->second->GetBackendProgramId(), name.c_str());
auto locAtBackend = MG_External::GLES::glGetUniformLocation(
backendProgramIt->second->GetBackendProgramId(), name.c_str());
MG_External::GLES::glUniform1i(locAtBackend, unit);
}
} else {
@@ -383,8 +384,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
}
}
void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0,
GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) {
void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1,
GLint dstY1, GLbitfield mask, GLenum filter) {
TextureImpl::SyncNeccessaryTextures();
FramebufferImpl::SyncCurrentFBO();
RenderStateImpl::SyncRenderState();
@@ -392,8 +393,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
BindCurrentFBO(FramebufferTarget::Draw);
BindCurrentFBO(FramebufferTarget::Read);
MG_External::GLES::glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
dstX1, dstY1, mask, filter);
MG_External::GLES::glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
}
const GLubyte* GetString(GLenum name) {
+2 -2
View File
@@ -14,7 +14,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
GLsizei drawcount);
void MultiDrawElementsBaseVertex(GLenum mode, const GLsizei* count, GLenum type, const GLvoid* const* indices,
GLsizei drawcount, const GLint* basevertex);
void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0,
GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1,
GLint dstY1, GLbitfield mask, GLenum filter);
const GLubyte* GetString(GLenum name);
} // namespace MobileGL::MG_Backend::DirectGLES
+13 -14
View File
@@ -9,6 +9,7 @@
#include <MG_Util/Converters/MGToGL/DataTypeConverter.h>
#include <MG_Util/Converters/MGToGL/BufferEnumConverter.h>
#include <MG_Util/Converters/MGToGL/TextureEnumConverter.h>
#include <MG_Util/Converters/MGToGL/ProgramEnumConverter.h>
#include <MG_Util/Converters/MGToGL/FramebufferEnumConverter.h>
#include <MG_State/GLState/FramebufferState/FramebufferObject.h>
@@ -111,8 +112,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
(invalidate ? GL_MAP_INVALIDATE_BUFFER_BIT : 0) | GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
const void* data = stateBufferObject->GetDataReadOnly()->data();
if (mappedData) {
Memcpy(mappedData, ((const char*)(data) + range.start),
range.end - range.start);
Memcpy(mappedData, ((const char*)(data) + range.start), range.end - range.start);
MGLOG_D("Mapped buffer data successfully for object with ID: %u", m_backendBufferId);
MG_External::GLES::glUnmapBuffer(TempBufferTarget);
} else {
@@ -152,7 +152,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
return;
}
MGLOG_D("Syncing VAO object with ID: %u to backend for state: 0x%p", m_backendVAOId, stateVAOObject.get());
MGLOG_D("Syncing VAO object with ID: %u to backend for state: %p", m_backendVAOId, stateVAOObject.get());
BufferImpl::BackendBufferBindingProtector backendBufferBindingProtector(BufferImpl::TempBufferTarget);
BackendVertexArrayBindingProtector backendVAOBindingProtector;
@@ -179,13 +179,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
MG_External::GLES::glEnableVertexAttribArray(attribIndex);
if (!attrib.IsInteger) {
MG_External::GLES::glVertexAttribPointer(
attribIndex, attrib.Size, MG_Util::ConvertDataTypeToGLEnum(attrib.Type),
attrib.Normalized ? GL_TRUE : GL_FALSE,
attrib.Stride, (const void *)attrib.Offset);
attribIndex, attrib.Size, MG_Util::ConvertDataTypeToGLEnum(attrib.Type),
attrib.Normalized ? GL_TRUE : GL_FALSE, attrib.Stride, (const void*)attrib.Offset);
} else {
MG_External::GLES::glVertexAttribIPointer(
attribIndex, attrib.Size, MG_Util::ConvertDataTypeToGLEnum(attrib.Type),
attrib.Stride, (const void *)attrib.Offset);
MG_External::GLES::glVertexAttribIPointer(attribIndex, attrib.Size,
MG_Util::ConvertDataTypeToGLEnum(attrib.Type),
attrib.Stride, (const void*)attrib.Offset);
}
// TODO: divisor
@@ -234,7 +233,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
return;
}
MGLOG_D("Syncing texture object with ID: %u to backend for state: 0x%p", m_backendTextureId,
MGLOG_D("Syncing texture object with ID: %u to backend for state: %p", m_backendTextureId,
stateTextureObject.get());
GLenum target = MG_Util::ConvertTextureTargetToGLEnum(stateTextureObject->GetTarget());
@@ -356,7 +355,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
return;
}
MGLOG_D("Syncing FBO object with ID: %u to backend for state: 0x%p", m_backendFBOId, stateFBOObject.get());
MGLOG_D("Syncing FBO object with ID: %u to backend for state: %p", m_backendFBOId, stateFBOObject.get());
BackendFramebufferBindingProtector backendFBOBindingProtector(GL_FRAMEBUFFER);
// TODO: do i really need to bind here?
@@ -425,11 +424,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
}
if (!stateProgramObject->GetLinkStatus()) {
MGLOG_E("Program object is not linked, skipping backend sync. Program: 0x%p", stateProgramObject.get());
MGLOG_E("Program object is not linked, skipping backend sync. Program: %p", stateProgramObject.get());
return;
}
MGLOG_D("Syncing program to backend. State program: 0x%p, Backend ID: 0x%p", stateProgramObject.get(),
MGLOG_D("Syncing program to backend. State program: %p, Backend ID: %p", stateProgramObject.get(),
m_backendProgramId);
// Detach all existing shaders
@@ -457,7 +456,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
for (int index = 0; index < attachedShaders.size(); ++index) {
auto& shader = attachedShaders[index];
GLenum glShaderType = MG_State::GLState::ConvertGLShaderTypeByMGLShaderStage(shader->GetShaderStage());
GLenum glShaderType = MG_Util::ConvertShaderStageToGLEnum(shader->GetShaderStage());
GLuint backendShaderId = MG_External::GLES::glCreateShader(glShaderType);
if (backendShaderId == 0) {
+13 -13
View File
@@ -8,22 +8,22 @@ namespace MobileGL {
// TODO: tidy this mess up
RendererInfo* RendererInfoPtr =
#if MOBILEGL_BACKEND == MOBILEGL_BACKEND_DILIGENT
switch (MG_Config::Backend::Diligent::SpecificBackend) {
case MG_Backend::Diligent::SpecificBackendType::Vulkan:
MG_Config::RendererInfoPtr = &MG_Backend::Diligent::RendererInfoVulkan;
break;
case MG_Backend::Diligent::SpecificBackendType::Metal:
MG_Config::RendererInfoPtr = &MG_Backend::Diligent::RendererInfoMetal;
break;
default:
throw RuntimeError("Unsupported renderer type");
}
switch (MG_Config::Backend::Diligent::SpecificBackend) {
case MG_Backend::Diligent::SpecificBackendType::Vulkan:
MG_Config::RendererInfoPtr = &MG_Backend::Diligent::RendererInfoVulkan;
break;
case MG_Backend::Diligent::SpecificBackendType::Metal:
MG_Config::RendererInfoPtr = &MG_Backend::Diligent::RendererInfoMetal;
break;
default:
throw RuntimeError("Unsupported renderer type");
}
#elif MOBILEGL_BACKEND == MOBILEGL_BACKEND_TYPE_DIRECT_GLES
&MG_Backend::DirectGLES::RendererInfo;
&MG_Backend::DirectGLES::RendererInfo;
#else
MG_Config::RendererInfoPtr = &RendererInfoUnknown;
MG_Config::RendererInfoPtr = &RendererInfoUnknown;
#endif
}
} // namespace MG_Config
namespace MG_Backend {
static RendererInfo RendererInfo;
@@ -1,71 +1,8 @@
cmake_minimum_required(VERSION 3.24)
# # Add the directory containing our custom Find modules
# list(APPEND CMAKE_MODULE_PATH "${MGL_ROOT}/buildsystem/cmake")
# # Find the required libraries using our custom Find modules
# find_package(glslang REQUIRED)
# find_package(SPIRVCross REQUIRED)
# find_package(SPIRVTools)
# message(STATUS "glslang_LIBRARIES: ${glslang_LIBRARIES}")
# message(STATUS "SPIRVTools_LIBRARIES: ${SPIRVTools_LIBRARIES}")
# message(STATUS "SPIRVCross_LIBRARIES: ${SPIRVCross_LIBRARIES}")
# # Set the libraries to link against
# set(LINK_LIBRARIES
# ${glslang_LIBRARIES}
# ${SPIRVCross_LIBRARIES}
# )
# if (SPIRVTools_FOUND)
# list(APPEND LINK_LIBRARIES ${SPIRVTools_LIBRARIES})
# endif()
add_executable(
ProgramBench
ProgramBench.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ShaderObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ProgramState.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToStr/GLEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToGlslang/GLShaderLangConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/ShaderCompiler.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/glslang/UniformTraverser.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/SPIRVCrossToGL/SpvcTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/Core.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureUnit.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ErrorState/Error.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Buffer/Validators.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/VertexArray/Validators.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/VertexArray/GL_VertexArray.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToStr/GLEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/GLExtensionConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToGlslang/GLShaderLangConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/ErrorCodeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToMG/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToMG/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Metrics/BufferMetrics.cpp
# ${MGL_ROOT}/MobileGL/MG_Backend/Init.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Debug/Log.cpp
)
target_include_directories(ProgramBench PRIVATE
@@ -13,8 +13,8 @@ namespace MobileGL {
void BlitFramebuffer_Backend(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0,
GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) {
#if MOBILEGL_BACKEND == MOBILEGL_BACKEND_TYPE_DIRECT_GLES
MG_Backend::DirectGLES::BlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0,
dstX1, dstY1, mask, filter);
MG_Backend::DirectGLES::BlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask,
filter);
#endif
}
+3 -2
View File
@@ -49,8 +49,9 @@ namespace MobileGL {
case GL_RENDERER: {
if (rendererString.empty()) {
const char* backendStr = (const char*)GetString_Backend(GL_RENDER);
rendererString = std::format("{} ({}) ({})", MG_Config::RendererInfoPtr->RendererName.c_str(),
MG_Config::CoreName.c_str(), backendStr ? backendStr : "<unknown GPU>");
rendererString =
std::format("{} ({}) ({})", MG_Config::RendererInfoPtr->RendererName.c_str(),
MG_Config::CoreName.c_str(), backendStr ? backendStr : "<unknown GPU>");
}
return (const GLubyte*)rendererString.c_str();
}
@@ -1,7 +1,8 @@
#include "GL_Program.h"
#include "MG_State/GLState/Core.h"
#include "MG_Util/Converters/SPIRVCrossToGL/SpvcTypeConverter.h"
#include <MG_State/GLState/Core.h>
#include <MG_Util/Converters/GLToMG/ProgramEnumConverter.h>
#include <MG_Util/Converters/MGToGL/ProgramEnumConverter.h>
#include <MG_Util/Converters/SPIRVCrossToGL/SpvcTypeConverter.h>
namespace MobileGL {
namespace MG_Impl::GLImpl {
@@ -111,8 +112,7 @@ namespace MobileGL {
}
GLuint CreateShader_State(GLenum type) {
auto shaderId =
MG_State::pGLContext->CreateShader(MG_State::GLState::ConvertMGLShaderStageByGLShaderType(type));
auto shaderId = MG_State::pGLContext->CreateShader(MG_Util::ConvertGLEnumToShaderStage(type));
if (shaderId == 0) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidValue,
@@ -300,7 +300,7 @@ namespace MobileGL {
switch (pname) {
case GL_SHADER_TYPE:
*params = ConvertGLShaderTypeByMGLShaderStage(shaderObject->GetShaderStage());
*params = MG_Util::ConvertShaderStageToGLEnum(shaderObject->GetShaderStage());
break;
case GL_DELETE_STATUS:
*params = shaderObject->GetDeleteStatus();
+9 -33
View File
@@ -4,46 +4,22 @@
namespace MobileGL {
namespace MG_Impl::GLImpl {
GLsync FenceSync_Backend(GLenum condition, GLbitfield flags) {
GLsync FenceSync_Backend(GLenum condition, GLbitfield flags) {}
}
GLenum ClientWaitSync_Backend(GLsync sync, GLbitfield flags, GLuint64 timeout) {}
GLenum ClientWaitSync_Backend(GLsync sync,
GLbitfield flags,
GLuint64 timeout) {
void DeleteSync_Backend(GLsync sync) {}
}
GLsync FenceSync_State(GLenum condition, GLbitfield flags) {}
void DeleteSync_Backend(GLsync sync) {
GLenum ClientWaitSync_State(GLsync sync, GLbitfield flags, GLuint64 timeout) {}
}
void DeleteSync_State(GLsync sync) {}
GLsync FenceSync_State(GLenum condition, GLbitfield flags) {
GLsync FenceSync(GLenum condition, GLbitfield flags) {}
}
GLenum ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) {}
GLenum ClientWaitSync_State(GLsync sync,
GLbitfield flags,
GLuint64 timeout) {
}
void DeleteSync_State(GLsync sync) {
}
GLsync FenceSync(GLenum condition, GLbitfield flags) {
}
GLenum ClientWaitSync(GLsync sync,
GLbitfield flags,
GLuint64 timeout) {
}
void DeleteSync(GLsync sync) {
}
void DeleteSync(GLsync sync) {}
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
+1 -3
View File
@@ -4,9 +4,7 @@
namespace MobileGL {
namespace MG_Impl::GLImpl {
GLsync FenceSync(GLenum condition, GLbitfield flags);
GLenum ClientWaitSync(GLsync sync,
GLbitfield flags,
GLuint64 timeout);
GLenum ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout);
void DeleteSync(GLsync sync);
} // namespace MG_Impl::GLImpl
} // namespace MobileGL
+15 -16
View File
@@ -58,16 +58,15 @@ namespace MobileGL {
if (!TextureImpl::ValidateTextureSubImageOffsets(textureObject, xoffset, width, yoffset, height)) return;
// ======================= Processing ================================
// SizeT imageSize =
// MG_Util::CalculateInputTextureImageSize(textureInternalFormat,
// texturePixelDataType,
// {width, height, 1});
// SizeT imageSize =
// MG_Util::CalculateInputTextureImageSize(textureInternalFormat,
// texturePixelDataType,
// {width, height, 1});
auto& mipmap = textureObject->GetMipmap(level);
Vector<Uint8>& data = mipmap.data;
SizeT bytesPerPixel =
MG_Util::GetInputBytesPerPixel(textureInternalFormat, texturePixelDataType);
// SizeT rowStride = mipmap.size.x() * bytesPerPixel;
SizeT bytesPerPixel = MG_Util::GetInputBytesPerPixel(textureInternalFormat, texturePixelDataType);
// SizeT rowStride = mipmap.size.x() * bytesPerPixel;
const Uint8* srcData = reinterpret_cast<const Uint8*>(pixels);
if (!srcData) {
@@ -90,9 +89,9 @@ namespace MobileGL {
Memcpy(data.data() + dstOffset, srcData + srcOffset, width * bytesPerPixel);
} else {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"Copy failed. Dest image does not have sufficient space."));
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
"Copy failed. Dest image does not have sufficient space."));
break;
}
}
@@ -308,12 +307,11 @@ namespace MobileGL {
if (!TextureImpl::ValidateTextureObject(textureObject)) return;
// ======================= Processing ================================
SizeT imageSize = isProxy ? 0 :
MG_Util::CalculateInputTextureImageSize(textureInternalFormat,
texturePixelDataType,
{width, height, 1});
SizeT imageSize = isProxy ? 0
: MG_Util::CalculateInputTextureImageSize(
textureInternalFormat, texturePixelDataType, {width, height, 1});
Uint8* skippedPixels = (Uint8 *) pixels;
Uint8* skippedPixels = (Uint8*)pixels;
if (pixels != nullptr) {
auto rowsToSkip = MG_State::pGLContext->GetPixelStoreParam(PixelStoreParam::UnpackSkipRows);
auto pixelsToSkip = MG_State::pGLContext->GetPixelStoreParam(PixelStoreParam::UnpackSkipPixels);
@@ -323,7 +321,8 @@ namespace MobileGL {
textureObject->SetInternalFormat(textureInternalFormat);
MG_State::GLState::MipmapLevelInput mipmap = MG_State::GLState::MipmapLevelInput(
{width, height, 1}, level, false, 0, {const_cast<void*>(isProxy ? (void*)skippedPixels : nullptr), imageSize});
{width, height, 1}, level, false, 0,
{const_cast<void*>(isProxy ? (void*)skippedPixels : nullptr), imageSize});
textureObject->SetMipmapLevel(mipmap);
}
@@ -210,7 +210,7 @@ namespace MobileGL::MG_Impl::GLImpl {
internalFormat != TextureInternalFormat::DepthComponent24 &&
internalFormat != TextureInternalFormat::DepthComponent32F &&
internalFormat != TextureInternalFormat::DepthComponent32 // workaround for Minecraft 1.21.5+
)) {
)) {
MG_State::pGLContext->RecordError(
ErrorCode::InvalidOperation,
MakeShared<GenericErrorInfo>("MG_Impl/GLImpl", "ValidateTextureFormatWithType",
@@ -1,5 +1,6 @@
#include "ProgramObject.h"
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
#include <MG_Util/Converters/MGToGL/ProgramEnumConverter.h>
#include <MG_Util/Converters/SPIRVCrossToGL/SpvcTypeConverter.h>
namespace MobileGL {
@@ -25,17 +26,14 @@ namespace MobileGL {
}
void ProgramObject::Link() {
// PreLink();
Vector<GLenum> shaderTypes(m_shaders.size());
Vector<SharedPtr<glslang::TShader>> shaders(m_shaders.size());
for (SizeT i = 0; i < m_shaders.size(); i++) {
shaderTypes[i] = ConvertGLShaderTypeByMGLShaderStage(m_shaders[i]->GetShaderStage());
shaderTypes[i] = MG_Util::ConvertShaderStageToGLEnum(m_shaders[i]->GetShaderStage());
shaders[i] = m_shaders[i]->GetCompiledShader();
}
MG_Util::ShaderTranspiler::ProgramAttrib attrib{
// .shaderTypes = Move(shaderTypes),
.shaders = Move(shaders),
};
@@ -48,8 +46,6 @@ namespace MobileGL {
m_infoLog = result.error().log;
}
// PostLink();
DoReflection();
GenerateBinary();
}
@@ -108,11 +104,10 @@ namespace MobileGL {
}
SizeT locNeedle = 0;
for (auto index: unallocatedUniformIndex) {
for (auto index : unallocatedUniformIndex) {
auto& uniform = m_program->getUniform(index);
for (; locNeedle <= m_maxUniformLocation; locNeedle++) {
if (m_uniformIndexInTProgram[locNeedle] != 4095)
continue;
if (m_uniformIndexInTProgram[locNeedle] != 4095) continue;
// Found a vacant location at locNeedle
m_uniformIndexInTProgram[locNeedle] = index;
m_uniformLocations[uniform.name] = locNeedle;
@@ -220,7 +215,7 @@ namespace MobileGL {
Vector<SharedPtr<glslang::TShader>> shaders(m_shaders.size());
Vector<GLenum> shaderTypes(m_shaders.size());
for (SizeT i = 0; i < m_shaders.size(); i++) {
auto shaderType = ConvertGLShaderTypeByMGLShaderStage(m_shaders[i]->GetShaderStage());
auto shaderType = MG_Util::ConvertShaderStageToGLEnum(m_shaders[i]->GetShaderStage());
shaderTypes[i] = shaderType;
ShaderAttrib attrib{
.shaderType = shaderType, .sourceStr = m_shaders[i]->GetShaderSource(), .flags = 0};
@@ -244,7 +239,7 @@ namespace MobileGL {
assert(binaryResult);
m_generatedSpirv = Move(binaryResult.value());
for (auto spv: m_generatedSpirv) {
for (auto spv : m_generatedSpirv) {
SpvcSession session(spv);
auto result = session.ParseMetaData();
if (result < 0) {
@@ -255,7 +250,6 @@ namespace MobileGL {
// auto src = srcResult.value();
// printf("decompiled src: \n%s\n", src.c_str());
auto& meta = session.GetMetadata();
auto size = meta.uboSize;
m_uboScratch.resize(size);
@@ -280,100 +274,6 @@ namespace MobileGL {
void ProgramObject::SetExplicitAttribLocation(Uint index, const char* name) {
m_explicitAttribLocations[name] = index;
}
// void ProgramObject::PreLink() {
// m_uniforms.clear();
// m_uniformOffsets.clear();
//
// for (const auto& shader : m_shaders) {
// for (const auto& [name, loc] : shader->GetUniformLocations()) {
// // collect all the names to map
// if (loc != 4095 || m_uniforms.find(name) == m_uniforms.end()) {
// m_uniforms[name] = loc;
// }
//
// // set a flag for those who have an explicit location
// if (loc != 4095) {
// if (loc >= m_uniformOffsets.size()) {
// m_uniformOffsets.reserve(std::bit_ceil(loc + 1));
// m_uniformOffsets.resize(loc + 1, 0);
// }
// assert(m_uniformOffsets[loc] == 0);
// m_uniformOffsets[loc] = 1;
// }
// }
// }
//
// // Let's find a location for those who doesn't have one yet
// Uint nextLocation = 0;
//
// // Find first empty location
// for (SizeT i = 0; i < m_uniformOffsets.size(); i++) {
// if (m_uniformOffsets[i] == 0) {
// nextLocation = i;
// break;
// }
// }
//
// for (auto& [name, loc] : m_uniforms) {
// if (loc == 4095) {
// // check if we drained all the holes already
// if (nextLocation >= m_uniformOffsets.size()) {
// loc = nextLocation;
// m_uniformOffsets.push_back(1);
// nextLocation++;
// continue;
// }
//
// // assign an empty location
// loc = nextLocation;
// m_uniformOffsets[loc] = 1;
//
// // Find next empty location
// for (nextLocation++; nextLocation < m_uniformOffsets.size(); nextLocation++) {
// if (m_uniformOffsets[nextLocation] == 0) break;
// }
// }
// }
//
// m_uniformNames.resize(m_uniformOffsets.size());
// for (auto& [name, loc] : m_uniforms) {
// m_uniformNames[loc] = name;
// m_uniformNameMaxLength = std::max(m_uniformNameMaxLength, (Int)name.length());
// }
// }
//
// void ProgramObject::PostLink() {
// if (m_programBinary.empty()) {
// assert(false);
// return;
// }
// MG_Util::ShaderTranspiler::SpvcSession session(m_programBinary[0]);
// const char* src = nullptr; // we don't care the source atm
// auto result = session.Compile(&src);
// if (result != SPVC_SUCCESS) {
// assert(false);
// return;
// }
// m_metadata = session.GetMetadata();
// auto& uniformOffsets = m_metadata.plainUniformOffsetsInUBO;
// for (const auto& [name, offset] : uniformOffsets) {
// assert(m_uniforms.find(name) != m_uniforms.end());
// assert(m_uniforms[name] < m_uniformOffsets.size());
// m_uniformOffsets[m_uniforms[name]] = offset;
// }
// m_uboScratch.resize(m_metadata.uboSize, 0);
//
// auto& types = m_metadata.plainUniformMemberTypes;
//
// assert(types.size() == m_uniformOffsets.size());
// m_uniformTypes.resize(m_uniformOffsets.size());
// for (const auto& [name, type] : types) {
// auto gltype = MG_Util::ConvertSpvcTypeToGLEnum(type);
// auto location = m_uniforms[name];
// m_uniformTypes[location] = gltype;
// }
// }
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
@@ -25,8 +25,7 @@ namespace MobileGL {
Uint GetMaxUniformLocation() const { return m_maxUniformLocation; }
Int GetUniformLocation(const String& name) {
const auto it = m_uniformLocations.find(name);
if (it == m_uniformLocations.end())
return -1;
if (it == m_uniformLocations.end()) return -1;
return (Int)it->second;
}
@@ -40,9 +39,7 @@ namespace MobileGL {
return uniform.getType();
}
Bool IsUniformOpaqueAtLocation(Uint location) const {
return GetUniformTType(location)->isOpaque();
}
Bool IsUniformOpaqueAtLocation(Uint location) const { return GetUniformTType(location)->isOpaque(); }
const String& GetUniformName(Uint location) const {
auto& uniform = m_program->getUniform(m_uniformIndexInTProgram[location]);
@@ -85,9 +82,6 @@ namespace MobileGL {
void DoReflection();
void GenerateBinary();
void WaitUntilGenerationCompleted();
// void PreLink();
// void PostLink();
const Uint m_id = 0;
Vector<SharedPtr<ShaderObject>> m_shaders;
@@ -101,8 +95,6 @@ namespace MobileGL {
Vector<GLenum> m_attribTypes;
// Uniforms
// MG_Util::ShaderTranspiler::SpvcMetadata m_metadata;
UnorderedMap<String, Uint> m_uniformLocations;
// Ordered by location,
// aka. m_uniformIndexInTProgram[loc] == "uniform index of TProgram at location `loc`"
@@ -1,5 +1,6 @@
#include "ShaderObject.h"
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
#include <MG_Util/Converters/MGToGL/ProgramEnumConverter.h>
#include <MG_Util/ShaderTranspiler/glslang/UniformTraverser.h>
namespace MobileGL {
@@ -14,16 +15,12 @@ namespace MobileGL {
}
void ShaderObject::Compile() {
// if (!DoReflection()) {
// return;
// }
using namespace MG_Util::ShaderTranspiler;
// Compile for OpenGL here, so that we can do validation and link
// like a real OpenGL driver at linking stage
// Will compile for other backends later.
ShaderAttrib attrib{.shaderType = ConvertGLShaderTypeByMGLShaderStage(m_stage),
ShaderAttrib attrib{.shaderType = MG_Util::ConvertShaderStageToGLEnum(m_stage),
.sourceStr = m_source,
.flags = ShaderCompileBits::CompileForOpenGL};
@@ -40,37 +37,6 @@ namespace MobileGL {
void ShaderObject::MarkAsDeleted() {
m_deleteStatus = true;
}
// bool ShaderObject::DoReflection() {
// using namespace MG_Util::ShaderTranspiler;
// ShaderAttrib attrib{
// .shaderType = GetGLShaderTypeByMGLShaderStage(m_stage),
// .sourceStr = m_source,
// .flags = ShaderCompileBits::CompileForOpenGL
// };
//
// auto result = ShaderCompiler::CompileShader(attrib);
// if (!result) {
// m_compileStatus = false;
// m_infoLog = result.error().log;
//
// const std::string e = std::format("Shader compilation failed: \nerrc: {}\nmsg: {}\n",
// result.error().errc, result.error().log);
// return false;
// }
//
// auto pShader = result.value();
// auto root = pShader->getIntermediate()->getTreeRoot();
// UniformTraverser traverser;
// root->traverse(&traverser);
// auto& symbols = traverser.GetCollectedSymbols();
// for (const auto& symbol : symbols) {
// m_uniforms[symbol->getName().c_str()] = symbol->getQualifier().layoutLocation;
// }
//
// return true;
// }
} // namespace GLState
} // namespace MG_State
} // namespace MobileGL
@@ -2,58 +2,18 @@
#include <Includes.h>
namespace MobileGL {
enum class ShaderStage {
Vertex,
TessControl,
TessEval,
Geometry,
Fragment,
Compute,
Unknown = -1
};
namespace MG_State {
namespace GLState {
enum class ShaderStage {
Vertex,
TessControl,
TessEval,
Geometry,
Fragment,
Compute,
Unknown = -1
};
inline static GLenum ConvertGLShaderTypeByMGLShaderStage(ShaderStage stage) {
switch (stage) {
case ShaderStage::Vertex:
return GL_VERTEX_SHADER;
case ShaderStage::TessControl:
return GL_TESS_CONTROL_SHADER;
case ShaderStage::TessEval:
return GL_TESS_EVALUATION_SHADER;
case ShaderStage::Geometry:
return GL_GEOMETRY_SHADER;
case ShaderStage::Fragment:
return GL_FRAGMENT_SHADER;
case ShaderStage::Compute:
return GL_COMPUTE_SHADER;
default:
assert(false);
return GL_FALSE;
}
}
inline static ShaderStage ConvertMGLShaderStageByGLShaderType(GLenum type) {
switch (type) {
case GL_VERTEX_SHADER:
return ShaderStage::Vertex;
case GL_TESS_CONTROL_SHADER:
return ShaderStage::TessControl;
case GL_TESS_EVALUATION_SHADER:
return ShaderStage::TessEval;
case GL_GEOMETRY_SHADER:
return ShaderStage::Geometry;
case GL_FRAGMENT_SHADER:
return ShaderStage::Fragment;
case GL_COMPUTE_SHADER:
return ShaderStage::Compute;
default:
assert(false);
return ShaderStage::Unknown;
}
}
class ShaderObject {
public:
ShaderObject(const ShaderStage stage, const Uint id) : m_stage(stage), m_id(id) {}
@@ -72,7 +32,6 @@ namespace MobileGL {
Bool GetDeleteStatus() const { return m_deleteStatus; }
private:
// bool DoReflection();
const Uint m_id = 0;
const ShaderStage m_stage;
String m_source;
-3
View File
@@ -1,6 +1,3 @@
//
// Created by Swung 0x48 on 2025/7/17.
//
#include <gtest/gtest.h>
#include "Includes.h"
-36
View File
@@ -3,42 +3,6 @@ cmake_minimum_required(VERSION 3.14)
add_executable(
BufferTest
BufferTest.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/Core.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureUnit.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ErrorState/Error.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ShaderObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ProgramState.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Buffer/Validators.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/VertexArray/Validators.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/VertexArray/GL_VertexArray.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToStr/GLEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/GLExtensionConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToGlslang/GLShaderLangConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/ErrorCodeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToMG/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToMG/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Metrics/BufferMetrics.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/ShaderCompiler.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp
# ${MGL_ROOT}/MobileGL/MG_Backend/Init.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Debug/Log.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/glslang/UniformTraverser.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/SPIRVCrossToGL/SpvcTypeConverter.cpp
)
target_include_directories(BufferTest PRIVATE
+1 -42
View File
@@ -5,7 +5,7 @@ add_executable(
ProgramUtilTest.cpp
${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToStr/GLEnumConverter.cpp
${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToGlslang/GLShaderLangConverter.cpp
${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToGlslang/ProgramEnumConverter.cpp
${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/ShaderCompiler.cpp
${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp
${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/glslang/UniformTraverser.cpp
@@ -25,47 +25,6 @@ target_link_libraries(
add_executable(
ProgramTest
ProgramTest.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ShaderObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ProgramState.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToStr/GLEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToGlslang/GLShaderLangConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/ShaderCompiler.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/glslang/UniformTraverser.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/SPIRVCrossToGL/SpvcTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/Core.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureUnit.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ErrorState/Error.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Buffer/Validators.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/VertexArray/Validators.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/VertexArray/GL_VertexArray.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToStr/GLEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/GLExtensionConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToGlslang/GLShaderLangConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/ErrorCodeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToMG/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToMG/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Metrics/BufferMetrics.cpp
# ${MGL_ROOT}/MobileGL/MG_Backend/Init.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Debug/Log.cpp
)
target_include_directories(ProgramTest PRIVATE
-1
View File
@@ -688,4 +688,3 @@ TEST_F(ProgramTest, MinecraftBlitScreenLightmap) {
auto programObject = MG_State::pGLContext->GetCurrentProgram();
ASSERT_GT(programObject->GetUBOSize(), 0);
}
+1 -4
View File
@@ -1,14 +1,11 @@
//
// Created by Swung 0x48 on 2025/7/17.
//
#include <gtest/gtest.h>
#include "Includes.h"
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
#include <MG_Util/ShaderTranspiler/Types.h>
#include <MG_Util/ShaderTranspiler/glslang/UniformTraverser.h>
#include "MG_Util/ShaderTranspiler/glslang/UniformTraverser.h"
using namespace MobileGL;
class ProgramUtilTest : public ::testing::Test {
@@ -3,42 +3,6 @@ cmake_minimum_required(VERSION 3.14)
add_executable(
VertexArrayTest
VertexArrayTest.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/Core.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/BufferState/BufferObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/VertexArrayState/VertexArrayState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureUnit.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/TextureState/TextureState.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ErrorState/Error.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ShaderObject.cpp
# ${MGL_ROOT}/MobileGL/MG_State/GLState/ProgramState/ProgramState.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Buffer/GL_Buffer.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/Buffer/Validators.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/VertexArray/Validators.cpp
# ${MGL_ROOT}/MobileGL/MG_Impl/GLImpl/VertexArray/GL_VertexArray.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToStr/GLEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/GLExtensionConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToStr/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToGlslang/GLShaderLangConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/ErrorCodeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/MGToGL/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToMG/BufferEnumConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/GLToMG/DataTypeConverter.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Metrics/BufferMetrics.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/ShaderCompiler.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp
# ${MGL_ROOT}/MobileGL/MG_Backend/Init.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Debug/Log.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/ShaderTranspiler/glslang/UniformTraverser.cpp
# ${MGL_ROOT}/MobileGL/MG_Util/Converters/SPIRVCrossToGL/SpvcTypeConverter.cpp
)
target_include_directories(VertexArrayTest PRIVATE
@@ -1,4 +1,4 @@
#include "GLShaderLangConverter.h"
#include "ProgramEnumConverter.h"
namespace MobileGL {
namespace MG_Util {
@@ -0,0 +1,24 @@
#include "ProgramEnumConverter.h"
namespace MobileGL {
namespace MG_Util {
ShaderStage ConvertGLEnumToShaderStage(GLenum type) {
switch (type) {
case GL_VERTEX_SHADER:
return ShaderStage::Vertex;
case GL_TESS_CONTROL_SHADER:
return ShaderStage::TessControl;
case GL_TESS_EVALUATION_SHADER:
return ShaderStage::TessEval;
case GL_GEOMETRY_SHADER:
return ShaderStage::Geometry;
case GL_FRAGMENT_SHADER:
return ShaderStage::Fragment;
case GL_COMPUTE_SHADER:
return ShaderStage::Compute;
default:
return ShaderStage::Unknown;
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -0,0 +1,9 @@
#pragma once
#include <Includes.h>
#include <MG_State/GLState/ProgramState/ShaderObject.h>
namespace MobileGL {
namespace MG_Util {
ShaderStage ConvertGLEnumToShaderStage(GLenum type);
}
} // namespace MobileGL
@@ -0,0 +1,24 @@
#include "ProgramEnumConverter.h"
namespace MobileGL {
namespace MG_Util {
GLenum ConvertShaderStageToGLEnum(ShaderStage stage) {
switch (stage) {
case ShaderStage::Vertex:
return GL_VERTEX_SHADER;
case ShaderStage::TessControl:
return GL_TESS_CONTROL_SHADER;
case ShaderStage::TessEval:
return GL_TESS_EVALUATION_SHADER;
case ShaderStage::Geometry:
return GL_GEOMETRY_SHADER;
case ShaderStage::Fragment:
return GL_FRAGMENT_SHADER;
case ShaderStage::Compute:
return GL_COMPUTE_SHADER;
default:
return GL_UNKNOWN_MGL;
}
}
} // namespace MG_Util
} // namespace MobileGL
@@ -0,0 +1,9 @@
#pragma once
#include <Includes.h>
#include <MG_State/GLState/ProgramState/ShaderObject.h>
namespace MobileGL {
namespace MG_Util {
GLenum ConvertShaderStageToGLEnum(ShaderStage stage);
}
} // namespace MobileGL
@@ -1,10 +1,5 @@
//
// Created by Swung0x48 on 2025/8/14.
//
#include "SpvcTypeConverter.h"
#include "MG_Util/ShaderTranspiler/SpvcSession.h"
#include <MG_Util/ShaderTranspiler/SpvcSession.h>
namespace MobileGL {
namespace MG_Util {
@@ -1,7 +1,6 @@
#pragma once
#include <Includes.h>
#include "MG_Util/ShaderTranspiler/SpvcSession.h"
#include <MG_Util/ShaderTranspiler/SpvcSession.h>
namespace MobileGL {
namespace MG_Util {
@@ -1,7 +1,3 @@
//
// Created by Swung0x48 on 2025/8/22.
//
#include "BufferMetrics.h"
namespace MobileGL {
+1 -9
View File
@@ -1,10 +1,4 @@
//
// Created by Swung0x48 on 2025/8/22.
//
#ifndef BUFFERMETRICS_H
#define BUFFERMETRICS_H
#pragma once
#include <Includes.h>
namespace MobileGL {
@@ -12,5 +6,3 @@ namespace MobileGL {
SizeT GetGLTypeSize(GLenum type);
}
} // namespace MobileGL
#endif // BUFFERMETRICS_H
+102 -105
View File
@@ -10,7 +10,7 @@ namespace MobileGL {
case TextureInternalFormat::R8I:
case TextureInternalFormat::R8UI:
case TextureInternalFormat::R3G3B2:
return 1;
return 1;
case TextureInternalFormat::R16:
case TextureInternalFormat::R16Snorm:
@@ -85,124 +85,122 @@ namespace MobileGL {
SizeT GetBaseInternalFormatComponentCount(TextureInternalFormat format) {
switch (format) {
case TextureInternalFormat::DepthComponent:
case TextureInternalFormat::DepthStencil:
// Depth stencil is actually 2 components
// tho real formats always gives byte size in whole
// so we count this as one here
case TextureInternalFormat::Red:
case TextureInternalFormat::R8:
case TextureInternalFormat::R8Snorm:
case TextureInternalFormat::R8I:
case TextureInternalFormat::R8UI:
case TextureInternalFormat::R16:
case TextureInternalFormat::R16Snorm:
case TextureInternalFormat::R16I:
case TextureInternalFormat::R16UI:
case TextureInternalFormat::R16F:
return 1;
case TextureInternalFormat::RG:
case TextureInternalFormat::RG8:
case TextureInternalFormat::RG8Snorm:
case TextureInternalFormat::RG8I:
case TextureInternalFormat::RG8UI:
case TextureInternalFormat::RG16:
case TextureInternalFormat::RG16Snorm:
case TextureInternalFormat::RG16I:
case TextureInternalFormat::RG16UI:
case TextureInternalFormat::RG16F:
case TextureInternalFormat::RG32F:
case TextureInternalFormat::RG32I:
case TextureInternalFormat::RG32UI:
return 2;
case TextureInternalFormat::RGB:
case TextureInternalFormat::RGB4:
case TextureInternalFormat::RGB5:
case TextureInternalFormat::RGB8:
case TextureInternalFormat::RGB8Snorm:
case TextureInternalFormat::SRGB8:
case TextureInternalFormat::RGB8I:
case TextureInternalFormat::RGB8UI:
case TextureInternalFormat::RGB16F:
case TextureInternalFormat::RGB32F:
case TextureInternalFormat::RGB16I:
case TextureInternalFormat::RGB16UI:
case TextureInternalFormat::RGB32I:
case TextureInternalFormat::RGB32UI:
case TextureInternalFormat::R11FG11FB10F:
case TextureInternalFormat::RGB9E5:
return 3;
case TextureInternalFormat::RGBA:
case TextureInternalFormat::RGBA2:
case TextureInternalFormat::RGBA4:
case TextureInternalFormat::RGBA8:
case TextureInternalFormat::RGBA8Snorm:
case TextureInternalFormat::RGBA8I:
case TextureInternalFormat::RGBA8UI:
case TextureInternalFormat::RGBA12:
case TextureInternalFormat::RGBA16:
case TextureInternalFormat::RGBA16I:
case TextureInternalFormat::RGBA16UI:
case TextureInternalFormat::RGBA16F:
case TextureInternalFormat::RGBA32F:
case TextureInternalFormat::RGBA32I:
case TextureInternalFormat::RGBA32UI:
case TextureInternalFormat::RGB10A2:
case TextureInternalFormat::RGB10A2UI:
return 4;
default:
return 0;
case TextureInternalFormat::DepthComponent:
case TextureInternalFormat::DepthStencil:
// Depth stencil is actually 2 components
// tho real formats always gives byte size in whole
// so we count this as one here
case TextureInternalFormat::Red:
case TextureInternalFormat::R8:
case TextureInternalFormat::R8Snorm:
case TextureInternalFormat::R8I:
case TextureInternalFormat::R8UI:
case TextureInternalFormat::R16:
case TextureInternalFormat::R16Snorm:
case TextureInternalFormat::R16I:
case TextureInternalFormat::R16UI:
case TextureInternalFormat::R16F:
return 1;
case TextureInternalFormat::RG:
case TextureInternalFormat::RG8:
case TextureInternalFormat::RG8Snorm:
case TextureInternalFormat::RG8I:
case TextureInternalFormat::RG8UI:
case TextureInternalFormat::RG16:
case TextureInternalFormat::RG16Snorm:
case TextureInternalFormat::RG16I:
case TextureInternalFormat::RG16UI:
case TextureInternalFormat::RG16F:
case TextureInternalFormat::RG32F:
case TextureInternalFormat::RG32I:
case TextureInternalFormat::RG32UI:
return 2;
case TextureInternalFormat::RGB:
case TextureInternalFormat::RGB4:
case TextureInternalFormat::RGB5:
case TextureInternalFormat::RGB8:
case TextureInternalFormat::RGB8Snorm:
case TextureInternalFormat::SRGB8:
case TextureInternalFormat::RGB8I:
case TextureInternalFormat::RGB8UI:
case TextureInternalFormat::RGB16F:
case TextureInternalFormat::RGB32F:
case TextureInternalFormat::RGB16I:
case TextureInternalFormat::RGB16UI:
case TextureInternalFormat::RGB32I:
case TextureInternalFormat::RGB32UI:
case TextureInternalFormat::R11FG11FB10F:
case TextureInternalFormat::RGB9E5:
return 3;
case TextureInternalFormat::RGBA:
case TextureInternalFormat::RGBA2:
case TextureInternalFormat::RGBA4:
case TextureInternalFormat::RGBA8:
case TextureInternalFormat::RGBA8Snorm:
case TextureInternalFormat::RGBA8I:
case TextureInternalFormat::RGBA8UI:
case TextureInternalFormat::RGBA12:
case TextureInternalFormat::RGBA16:
case TextureInternalFormat::RGBA16I:
case TextureInternalFormat::RGBA16UI:
case TextureInternalFormat::RGBA16F:
case TextureInternalFormat::RGBA32F:
case TextureInternalFormat::RGBA32I:
case TextureInternalFormat::RGBA32UI:
case TextureInternalFormat::RGB10A2:
case TextureInternalFormat::RGB10A2UI:
return 4;
default:
return 0;
}
}
SizeT GetSizedTexturePixelDataTypeSize(TexturePixelDataType type) {
switch (type) {
case TexturePixelDataType::UnsignedByte332:
case TexturePixelDataType::UnsignedByte233Rev:
return 1;
case TexturePixelDataType::UnsignedShort565:
case TexturePixelDataType::UnsignedShort565Rev:
case TexturePixelDataType::UnsignedShort4444:
case TexturePixelDataType::UnsignedShort4444Rev:
case TexturePixelDataType::UnsignedShort5551:
case TexturePixelDataType::UnsignedShort1555Rev:
return 2;
case TexturePixelDataType::UnsignedInt8888:
case TexturePixelDataType::UnsignedInt8888Rev:
case TexturePixelDataType::UnsignedInt1010102:
case TexturePixelDataType::UnsignedInt2101010Rev:
case TexturePixelDataType::UnsignedInt101111Rev:
case TexturePixelDataType::UnsignedInt5999Rev:
return 4;
default:
return 0;
case TexturePixelDataType::UnsignedByte332:
case TexturePixelDataType::UnsignedByte233Rev:
return 1;
case TexturePixelDataType::UnsignedShort565:
case TexturePixelDataType::UnsignedShort565Rev:
case TexturePixelDataType::UnsignedShort4444:
case TexturePixelDataType::UnsignedShort4444Rev:
case TexturePixelDataType::UnsignedShort5551:
case TexturePixelDataType::UnsignedShort1555Rev:
return 2;
case TexturePixelDataType::UnsignedInt8888:
case TexturePixelDataType::UnsignedInt8888Rev:
case TexturePixelDataType::UnsignedInt1010102:
case TexturePixelDataType::UnsignedInt2101010Rev:
case TexturePixelDataType::UnsignedInt101111Rev:
case TexturePixelDataType::UnsignedInt5999Rev:
return 4;
default:
return 0;
}
}
SizeT GetBaseTexturePixelDataTypeSize(TexturePixelDataType type) {
switch (type) {
case TexturePixelDataType::UnsignedByte:
case TexturePixelDataType::Byte:
return 1;
case TexturePixelDataType::UnsignedShort:
case TexturePixelDataType::Short:
return 2;
case TexturePixelDataType::UnsignedInt:
case TexturePixelDataType::Int:
case TexturePixelDataType::Float:
return 4;
default:
return 0;
case TexturePixelDataType::UnsignedByte:
case TexturePixelDataType::Byte:
return 1;
case TexturePixelDataType::UnsignedShort:
case TexturePixelDataType::Short:
return 2;
case TexturePixelDataType::UnsignedInt:
case TexturePixelDataType::Int:
case TexturePixelDataType::Float:
return 4;
default:
return 0;
}
}
SizeT GetInternalBytesPerPixel(TextureInternalFormat internalformat, TexturePixelDataType type) {
SizeT sizedTextureFormatSize = GetSizedInternalFormatSizeInBytes(internalformat);
if (sizedTextureFormatSize > 0)
return sizedTextureFormatSize;
if (sizedTextureFormatSize > 0) return sizedTextureFormatSize;
SizeT sizedPixelFormatSize = GetSizedTexturePixelDataTypeSize(type);
if (sizedPixelFormatSize > 0)
return sizedPixelFormatSize;
if (sizedPixelFormatSize > 0) return sizedPixelFormatSize;
SizeT chCount = GetBaseInternalFormatComponentCount(internalformat);
SizeT bytesPerChannel = GetBaseTexturePixelDataTypeSize(type);
return chCount * bytesPerChannel;
@@ -210,8 +208,7 @@ namespace MobileGL {
SizeT GetInputBytesPerPixel(TextureInternalFormat internalformat, TexturePixelDataType type) {
SizeT sizedPixelFormatSize = GetSizedTexturePixelDataTypeSize(type);
if (sizedPixelFormatSize > 0)
return sizedPixelFormatSize;
if (sizedPixelFormatSize > 0) return sizedPixelFormatSize;
SizeT bytesPerChannel = GetBaseTexturePixelDataTypeSize(type);
SizeT chCount = GetBaseInternalFormatComponentCount(internalformat);
return chCount * bytesPerChannel;
@@ -1,6 +1,6 @@
#include "ShaderCompiler.h"
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
#include <MG_Util/Converters/GLToGlslang/GLShaderLangConverter.h>
#include <MG_Util/Converters/GLToGlslang/ProgramEnumConverter.h>
namespace MobileGL {
namespace MG_Util {
@@ -117,7 +117,7 @@ namespace MobileGL {
auto shaderType = attrib.shaderType;
auto& sourceStr = attrib.sourceStr;
auto lang = GetEShLanguageByShaderType(shaderType);
auto lang = MG_Util::ConvertGLEnumToEShLanguage(shaderType);
if (lang == EShLanguage::EShLangCount) {
ResultInfo r;
r.log += "Error: [Preprocess] Unsupported shader type: " + ConvertGLEnumToString(shaderType);
@@ -79,8 +79,8 @@ namespace MobileGL {
// Should be called once, and only once, for every SPIR-V binary
spvc_result ParseMetaData();
private:
private:
spvc_context context = nullptr;
spvc_parsed_ir ir = nullptr;
spvc_compiler compiler = nullptr;
+2 -120
View File
@@ -20,7 +20,6 @@ namespace MobileGL {
};
struct ProgramAttrib {
// Vector<GLenum> shaderTypes;
Vector<SharedPtr<glslang::TShader>> shaders;
};
@@ -38,8 +37,8 @@ namespace MobileGL {
using Result = std::expected<T, ResultInfo>;
struct InterfaceVariable {
std::string name;
uint32_t location;
String name;
Uint32 location;
Bool operator<(const InterfaceVariable& other) const { return location < other.location; }
@@ -47,123 +46,6 @@ namespace MobileGL {
return location == other.location && name == other.name;
}
};
// class SpvcSession {
// public:
// SpvcSession() {}
//
// explicit SpvcSession(const Vector<unsigned int>& spirv) {
// const SpvId *p_spirv = spirv.data();
// size_t word_count = spirv.size();
//
// spvc_context_create(&context);
// spvc_context_parse_spirv(context, p_spirv, word_count, &ir);
// spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP,
// &compiler); spvc_compiler_create_shader_resources(compiler, &resources);
// }
//
// 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);
// std::swap(this->resources, that.resources);
// }
//
// 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);
// std::swap(this->resources, that.resources);
// return *this;
// }
//
// spvc_result CreateOptions(spvc_compiler_options *options) {
// return spvc_compiler_create_compiler_options(compiler, options);
// }
//
// spvc_result SetOptions(spvc_compiler_options options) {
// compiler_options = options;
// return spvc_compiler_install_compiler_options(compiler, options);
// }
//
// Vector<InterfaceVariable> GetShaderInterface(spvc_resource_type resource_type) const {
// const spvc_reflected_resource *list = nullptr;
// size_t count = 0;
// spvc_resources_get_resource_list_for_type(resources, resource_type, &list, &count);
//
// Vector<InterfaceVariable> variables;
// for (size_t i = 0; i < count; ++i) {
// if (spvc_compiler_has_decoration(compiler, list[i].id, SpvDecorationBuiltIn)) {
// continue;
// }
//
// InterfaceVariable var;
// var.name = list[i].name;
// var.location = spvc_compiler_get_decoration(compiler, list[i].id, SpvDecorationLocation);
// variables.push_back(var);
//
// if (resource_type == SPVC_RESOURCE_TYPE_UNIFORM_BUFFER) {
// spvc_type type = spvc_compiler_get_type_handle(compiler, list[i].base_type_id);
// size_t num_members = spvc_type_get_num_member_types(type);
// printf("uniform %s {\n", var.name.c_str());
// for (size_t j = 0; j < num_members; ++j) {
// const char *memberName = spvc_compiler_get_member_name(compiler,
// list[i].base_type_id, j);
// // auto memberTypeId = spvc_type_get_member_type(type, j);
// // auto memberType = spvc_compiler_get_type_handle(compiler, memberTypeId);
//
// unsigned memberOffset = 0;
// spvc_compiler_type_struct_member_offset(compiler, type, j, &memberOffset);
// printf("\b%s; // %u\n", memberName, memberOffset);
// }
// printf("}\n");
// }
// }
// std::sort(variables.begin(), variables.end());
// return variables;
// }
//
// spvc_result Compile(const char** result) const {
// return spvc_compiler_compile(compiler, result);
// }
//
// const char* GetLastErrorString() const {
// return spvc_context_get_last_error_string(context);
// }
//
// ~SpvcSession() { spvc_context_destroy(context); }
// private:
// spvc_context context = nullptr;
// spvc_parsed_ir ir = nullptr;
// spvc_compiler compiler = nullptr;
// spvc_compiler_options compiler_options = nullptr;
// spvc_resources resources = nullptr;
// };
inline static EShLanguage GetEShLanguageByShaderType(GLenum shaderType) {
switch (shaderType) {
case GL_VERTEX_SHADER:
return EShLanguage::EShLangVertex;
case GL_FRAGMENT_SHADER:
return EShLanguage::EShLangFragment;
case GL_COMPUTE_SHADER:
return EShLanguage::EShLangCompute;
case GL_TESS_CONTROL_SHADER:
return EShLanguage::EShLangTessControl;
case GL_TESS_EVALUATION_SHADER:
return EShLanguage::EShLangTessEvaluation;
case GL_GEOMETRY_SHADER:
return EShLanguage::EShLangGeometry;
default:
return EShLanguage::EShLangCount;
}
}
} // namespace ShaderTranspiler
} // namespace MG_Util
} // namespace MobileGL
@@ -1,7 +1,3 @@
//
// Created by Swung 0x48 on 2025/7/20.
//
#include "UniformTraverser.h"
namespace MobileGL {
@@ -16,22 +12,7 @@ namespace MobileGL {
const auto& type = symbol->getType();
if (symbol->getQualifier().isUniform() && type.getBasicType() != glslang::EbtSampler) {
m_collectedSymbols.emplace_back(symbol);
// auto& name = symbol->getName();
// auto qualifier = symbol->getQualifier();
//
// printf("layout(location = %d) uniform %s\n", qualifier.layoutLocation, name.c_str());
// auto &uniform = uniforms.emplace_back();
// uniform.name = name;
// uniform.storageQualifier = qualifier.storage;
// uniform.layoutLocation = qualifier.layoutLocation;
// uniform.layoutBinding = qualifier.layoutBinding;
// uniform.layoutPacking = qualifier.layoutPacking;
}
// else if (type.getBasicType() == glslang::EbtSampler) {
// auto &uniform = samplers.emplace_back();
// uniform.name = symbol->getName();
// uniform.sampler = type.getSampler();
// }
}
} // namespace ShaderTranspiler
} // namespace MG_Util
@@ -1,10 +1,4 @@
//
// Created by Swung 0x48 on 2025/7/20.
//
#ifndef MOBILEGL_UNIFORMTRAVERSER_H
#define MOBILEGL_UNIFORMTRAVERSER_H
#pragma once
#include "Includes.h"
namespace MobileGL {
@@ -20,6 +14,4 @@ namespace MobileGL {
};
} // namespace ShaderTranspiler
} // namespace MG_Util
} // namespace MobileGL
#endif // MOBILEGL_UNIFORMTRAVERSER_H
} // namespace MobileGL