mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 05:38:31 +09:00
[Fix] (Diligent/PSO): Try to bind input layout locations for GLSL.
This commit is contained in:
@@ -87,6 +87,50 @@ namespace MG_Diligent {
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t PipelineStateManager::CalculateStateHash(
|
||||
CommonState &commonState,
|
||||
VertexArrayState &vaState,
|
||||
GLFramebufferInfo& fbInfo) {
|
||||
uint64_t hash = 0;
|
||||
|
||||
MG_Global::unordered_map<GLenum, bool> capabilities = commonState.capabilities;
|
||||
|
||||
hash ^= std::hash<int>()(commonState.blendSrcRGB);
|
||||
hash ^= std::hash<int>()(commonState.blendDstRGB);
|
||||
hash ^= std::hash<int>()(commonState.blendSrcAlpha);
|
||||
hash ^= std::hash<int>()(commonState.blendDstAlpha);
|
||||
hash ^= std::hash<bool>()(capabilities[GL_BLEND]);
|
||||
|
||||
hash ^= std::hash<int>()(commonState.depthFunc);
|
||||
hash ^= std::hash<bool>()(commonState.depthMask);
|
||||
hash ^= std::hash<bool>()(capabilities[GL_DEPTH_TEST]);
|
||||
|
||||
hash ^= std::hash<int>()(0); // TODO: Cull Face Mode
|
||||
hash ^= std::hash<bool>()(capabilities[GL_CULL_FACE]);
|
||||
|
||||
hash ^= std::hash<bool>()(capabilities[GL_STENCIL_TEST]);
|
||||
|
||||
auto *pVAO = vaState.GetCurrentVAO();
|
||||
for (const auto &[index, attrib]: pVAO->attribs) {
|
||||
if (attrib.enabled) {
|
||||
hash ^= std::hash<int>()(index);
|
||||
hash ^= std::hash<int>()(attrib.size);
|
||||
hash ^= std::hash<int>()(attrib.type);
|
||||
hash ^= std::hash<bool>()(attrib.normalized);
|
||||
}
|
||||
}
|
||||
|
||||
hash ^= std::hash<size_t>()(fbInfo.ColorRTVs.size());
|
||||
for (const auto& rtv : fbInfo.ColorRTVs) {
|
||||
if (rtv) {
|
||||
hash ^= std::hash<uint32_t>()(rtv->GetDesc().Format);
|
||||
}
|
||||
}
|
||||
|
||||
hash ^= std::hash<uint32_t>()(fbInfo.DepthStencilFormat);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
void PipelineStateManager::ConfigurePSO(
|
||||
Diligent::GraphicsPipelineStateCreateInfo &PSOCreateInfo,
|
||||
@@ -311,9 +355,26 @@ namespace MG_Diligent {
|
||||
|
||||
for (GLuint shaderId : programObj.attachedShaders) {
|
||||
auto it = MG_State_T::programState->shaders_.find(shaderId);
|
||||
if (it != MG_State_T::programState->shaders_.end() &&
|
||||
!it->second.markedForDeletion) {
|
||||
shaderSourcesMap[it->first] = it->second.source;
|
||||
if (it != MG_State_T::programState->shaders_.end() && !it->second.markedForDeletion) {
|
||||
std::string shaderSource;
|
||||
if (it->second.type == GL_VERTEX_SHADER) {
|
||||
std::string infoLog;
|
||||
auto spirv =
|
||||
MG_Util::Program::CompileGLSLToSPIRV(it->second.type,
|
||||
it->second.source,
|
||||
infoLog);
|
||||
if (spirv.empty()) {
|
||||
MG_Util::Debug::LogE("Failed to compile shader %u: %s", shaderId,
|
||||
infoLog.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
shaderSource = MG_Util::Program::BindInputLayoutLocationsForGLSL(spirv,
|
||||
programObj.attribLocations);
|
||||
} else {
|
||||
shaderSource = it->second.source;
|
||||
}
|
||||
shaderSourcesMap[it->first] = shaderSource;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,47 +192,7 @@ namespace MG_Diligent {
|
||||
uint64_t CalculateStateHash(
|
||||
CommonState &commonState,
|
||||
VertexArrayState &vaState,
|
||||
GLFramebufferInfo& fbInfo) {
|
||||
uint64_t hash = 0;
|
||||
|
||||
MG_Global::unordered_map<GLenum, bool> capabilities = commonState.capabilities;
|
||||
|
||||
hash ^= std::hash<int>()(commonState.blendSrcRGB);
|
||||
hash ^= std::hash<int>()(commonState.blendDstRGB);
|
||||
hash ^= std::hash<int>()(commonState.blendSrcAlpha);
|
||||
hash ^= std::hash<int>()(commonState.blendDstAlpha);
|
||||
hash ^= std::hash<bool>()(capabilities[GL_BLEND]);
|
||||
|
||||
hash ^= std::hash<int>()(commonState.depthFunc);
|
||||
hash ^= std::hash<bool>()(commonState.depthMask);
|
||||
hash ^= std::hash<bool>()(capabilities[GL_DEPTH_TEST]);
|
||||
|
||||
hash ^= std::hash<int>()(0); // TODO: Cull Face Mode
|
||||
hash ^= std::hash<bool>()(capabilities[GL_CULL_FACE]);
|
||||
|
||||
hash ^= std::hash<bool>()(capabilities[GL_STENCIL_TEST]);
|
||||
|
||||
auto *pVAO = vaState.GetCurrentVAO();
|
||||
for (const auto &[index, attrib]: pVAO->attribs) {
|
||||
if (attrib.enabled) {
|
||||
hash ^= std::hash<int>()(index);
|
||||
hash ^= std::hash<int>()(attrib.size);
|
||||
hash ^= std::hash<int>()(attrib.type);
|
||||
hash ^= std::hash<bool>()(attrib.normalized);
|
||||
}
|
||||
}
|
||||
|
||||
hash ^= std::hash<size_t>()(fbInfo.ColorRTVs.size());
|
||||
for (const auto& rtv : fbInfo.ColorRTVs) {
|
||||
if (rtv) {
|
||||
hash ^= std::hash<uint32_t>()(rtv->GetDesc().Format);
|
||||
}
|
||||
}
|
||||
|
||||
hash ^= std::hash<uint32_t>()(fbInfo.DepthStencilFormat);
|
||||
|
||||
return hash;
|
||||
}
|
||||
GLFramebufferInfo& fbInfo);
|
||||
|
||||
void ConfigurePSO(
|
||||
Diligent::GraphicsPipelineStateCreateInfo &PSOCreateInfo,
|
||||
|
||||
@@ -224,6 +224,11 @@ namespace MG_GL::GL {
|
||||
|
||||
void ShaderSource(GLuint shader, GLsizei count, const GLchar *const*string, const GLint* length) {
|
||||
MG_Util::Debug::LogD("glShaderSource, shader: %u, count: %d", shader, count);
|
||||
if (count > 0 && string != nullptr && string[0] != nullptr) {
|
||||
MG_Util::Debug::LogD("Shader source for shader %u:\n%s", shader, string[0]);
|
||||
} else {
|
||||
MG_Util::Debug::LogD("Shader source for shader %u is empty or null.", shader);
|
||||
}
|
||||
GLenum result = MG_State::UploadShaderSource(shader, count, (const GLchar **)string, length);
|
||||
if (result == GL_NO_ERROR) return;
|
||||
MG_State::SetError(result);
|
||||
@@ -251,13 +256,36 @@ namespace MG_GL::GL {
|
||||
}
|
||||
|
||||
MG_Global::unordered_map<GLuint, std::string> shaderSources;
|
||||
for (GLuint shaderId : programInfo.AttachedShadersID) {
|
||||
auto& shaderObj = MG_State_T::programState->shaders_[shaderId];
|
||||
shaderSources[shaderId] = shaderObj.source;
|
||||
for (GLuint shaderId : programObj.attachedShaders) {
|
||||
auto it = MG_State_T::programState->shaders_.find(shaderId);
|
||||
if (it != MG_State_T::programState->shaders_.end() && !it->second.markedForDeletion) {
|
||||
std::string shaderSource;
|
||||
if (it->second.type == GL_VERTEX_SHADER) {
|
||||
std::string infoLog;
|
||||
auto spirv =
|
||||
MG_Util::Program::CompileGLSLToSPIRV(it->second.type,
|
||||
it->second.source,
|
||||
infoLog);
|
||||
if (spirv.empty()) {
|
||||
MG_Util::Debug::LogE("Failed to compile shader %u: %s", shaderId,
|
||||
infoLog.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
shaderSource = MG_Util::Program::BindInputLayoutLocationsForGLSL(spirv,
|
||||
programObj.attribLocations);
|
||||
} else {
|
||||
shaderSource = it->second.source;
|
||||
}
|
||||
shaderSources[it->first] = shaderSource;
|
||||
}
|
||||
}
|
||||
|
||||
MG_Util::Program::GenerateDefaultUBOForGLSL_Multi(shaderSources, programInfo.uniformBufferNames);
|
||||
|
||||
MG_Util::Debug::LogD("Shader sources after UBO generation for program %u:", program);
|
||||
for (const auto& [shaderId, source] : shaderSources) {
|
||||
MG_Util::Debug::LogD(" Program %u Shader %u:\n%s", program, shaderId, source.c_str());
|
||||
}
|
||||
// Compile attached shaders
|
||||
for (GLuint shaderId : programInfo.AttachedShadersID) {
|
||||
auto& shaderObj = MG_State_T::programState->shaders_[shaderId];
|
||||
|
||||
Reference in New Issue
Block a user