Merge branch 'vulkan2' of https://github.com/coelckers/gzdoom into vulkan2

This commit is contained in:
Rachael Alexanderson 2019-04-08 08:40:47 -04:00
commit 1e3425910c
2 changed files with 13 additions and 6 deletions

View file

@ -858,7 +858,7 @@ PPCustomShaderInstance::PPCustomShaderInstance(PostProcessShader *desc) : Desc(d
case PostProcessUniformType::Float: AddUniformField(offset, name, UniformType::Float, sizeof(float)); break;
case PostProcessUniformType::Int: AddUniformField(offset, name, UniformType::Int, sizeof(int)); break;
case PostProcessUniformType::Vec2: AddUniformField(offset, name, UniformType::Vec2, sizeof(float) * 2); break;
case PostProcessUniformType::Vec3: AddUniformField(offset, name, UniformType::Vec3, sizeof(float) * 3); break;
case PostProcessUniformType::Vec3: AddUniformField(offset, name, UniformType::Vec3, sizeof(float) * 3, sizeof(float) * 4); break;
default: break;
}
}
@ -993,9 +993,9 @@ void PPCustomShaderInstance::SetUniforms(PPRenderState *renderstate)
renderstate->Uniforms.Data = uniforms;
}
void PPCustomShaderInstance::AddUniformField(size_t &offset, const FString &name, UniformType type, size_t fieldsize)
void PPCustomShaderInstance::AddUniformField(size_t &offset, const FString &name, UniformType type, size_t fieldsize, size_t alignment)
{
size_t alignment = fieldsize;
if (alignment == 0) alignment = fieldsize;
offset = (offset + alignment - 1) / alignment * alignment;
FieldOffset[name] = offset;
@ -1004,6 +1004,14 @@ void PPCustomShaderInstance::AddUniformField(size_t &offset, const FString &name
auto chars = name2->GetChars();
FieldNames.push_back(std::move(name2));
Fields.push_back({ chars, type, offset });
offset += fieldsize;
if (fieldsize != alignment) // Workaround for buggy OpenGL drivers that does not do std140 layout correctly for vec3
{
name2 = std::make_unique<FString>(name + "__padding");
chars = name2->GetChars();
FieldNames.push_back(std::move(name2));
Fields.push_back({ chars, UniformType::Float, offset });
offset += alignment - fieldsize;
}
}

View file

@ -790,8 +790,7 @@ public:
PostProcessShader *Desc = nullptr;
private:
void CreateShaders();
void AddUniformField(size_t &offset, const FString &name, UniformType type, size_t fieldsize);
void AddUniformField(size_t &offset, const FString &name, UniformType type, size_t fieldsize, size_t alignment = 0);
void SetTextures(PPRenderState *renderstate);
void SetUniforms(PPRenderState *renderstate);