Skip to content

Commit

Permalink
Fix some ES2 issues
Browse files Browse the repository at this point in the history
Fix specification of mipmaps when generating textures.

Fix oversight where emulated UBOs would not replace uniforms when swapped out
for another.
  • Loading branch information
elizagamedev committed Nov 14, 2023
1 parent b0a584c commit 766e4f2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions NEW_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).

- engine: Support up to 4 side-by-side stereoscopic eyes, configurable at Engine creation time. See
`Engine::Config::stereoscopicEyeCount`. [⚠️ **Recompile Materials**]
- engine: Fix critical GLES 2.0 bugs
18 changes: 12 additions & 6 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ OpenGLDriver::OpenGLDriver(OpenGLPlatform* platform, const Platform::DriverConfi
mShaderCompilerService(*this),
mHandleAllocator("Handles", driverConfig.handleArenaSize),
mSamplerMap(32) {

std::fill(mSamplerBindings.begin(), mSamplerBindings.end(), nullptr);

// set a reasonable default value for our stream array
Expand Down Expand Up @@ -268,9 +268,9 @@ void OpenGLDriver::useProgram(OpenGLProgram* p) noexcept {

if (UTILS_UNLIKELY(mContext.isES2())) {
for (uint32_t i = 0; i < Program::UNIFORM_BINDING_COUNT; i++) {
auto [buffer, age] = mUniformBindings[i];
auto [id, buffer, age] = mUniformBindings[i];
if (buffer) {
p->updateUniforms(i, buffer, age);
p->updateUniforms(i, id, buffer, age);
}
}
// Set the output colorspace for this program (linear or rec709). This in only relevant
Expand Down Expand Up @@ -479,6 +479,7 @@ void OpenGLDriver::createBufferObjectR(Handle<HwBufferObject> boh,

GLBufferObject* bo = construct<GLBufferObject>(boh, byteCount, bindingType, usage);
if (UTILS_UNLIKELY(bindingType == BufferObjectBinding::UNIFORM && gl.isES2())) {
bo->gl.id = ++mLastAssignedEmulatedUboId;
bo->gl.buffer = malloc(byteCount);
memset(bo->gl.buffer, 0, byteCount);
} else {
Expand Down Expand Up @@ -595,8 +596,9 @@ void OpenGLDriver::textureStorage(OpenGLDriver::GLTexture* t,
}
} else {
glTexImage2D(t->gl.target, level, GLint(t->gl.internalFormat),
GLsizei(width), GLsizei(height), 0,
format, type, nullptr);
std::max(GLsizei(1), GLsizei(width >> level)),
std::max(GLsizei(1), GLsizei(height >> level)),
0, format, type, nullptr);
}
}
}
Expand Down Expand Up @@ -2901,7 +2903,11 @@ void OpenGLDriver::bindBufferRange(BufferObjectBinding bindingType, uint32_t ind
assert_invariant(offset + size <= ub->byteCount);

if (UTILS_UNLIKELY(ub->bindingType == BufferObjectBinding::UNIFORM && gl.isES2())) {
mUniformBindings[index] = { static_cast<uint8_t const*>(ub->gl.buffer) + offset, ub->age };
mUniformBindings[index] = {
ub->gl.id,
static_cast<uint8_t const*>(ub->gl.buffer) + offset,
ub->age,
};
} else {
GLenum const target = GLUtils::getBufferBindingType(bindingType);

Expand Down
9 changes: 4 additions & 5 deletions filament/backend/src/opengl/OpenGLDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ class OpenGLDriver final : public DriverBase {
}

struct {
GLuint id;
union {
struct {
GLuint id;
GLenum binding;
};
GLenum binding;
void* buffer;
};
} gl;
Expand Down Expand Up @@ -363,7 +361,8 @@ class OpenGLDriver final : public DriverBase {
void setScissor(Viewport const& scissor) noexcept;

// ES2 only. Uniform buffer emulation binding points
std::array<std::pair<void const*, uint16_t>, Program::UNIFORM_BINDING_COUNT> mUniformBindings = {};
GLuint mLastAssignedEmulatedUboId = 0;
std::array<std::tuple<GLuint, void const*, uint16_t>, Program::UNIFORM_BINDING_COUNT> mUniformBindings = {};

// sampler buffer binding points (nullptr if not used)
std::array<GLSamplerGroup*, Program::SAMPLER_BINDING_COUNT> mSamplerBindings = {}; // 4 pointers
Expand Down
5 changes: 3 additions & 2 deletions filament/backend/src/opengl/OpenGLProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,16 @@ void OpenGLProgram::updateSamplers(OpenGLDriver* const gld) const noexcept {
CHECK_GL_ERROR(utils::slog.e)
}

void OpenGLProgram::updateUniforms(uint32_t index, void const* buffer, uint16_t age) noexcept {
void OpenGLProgram::updateUniforms(uint32_t index, GLuint id, void const* buffer, uint16_t age) noexcept {
assert_invariant(mUniformsRecords);
assert_invariant(buffer);

// only update the uniforms if the UBO has changed since last time we updated
UniformsRecord const& records = mUniformsRecords[index];
if (records.age == age) {
if (records.id == id && records.age == age) {
return;
}
records.id = id;
records.age = age;

assert_invariant(records.uniforms.size() == records.locations.size());
Expand Down
3 changes: 2 additions & 1 deletion filament/backend/src/opengl/OpenGLProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class OpenGLProgram : public HwProgram {
} gl; // 12 bytes

// For ES2 only
void updateUniforms(uint32_t index, void const* buffer, uint16_t age) noexcept;
void updateUniforms(uint32_t index, GLuint id, void const* buffer, uint16_t age) noexcept;
void setRec709ColorSpace(bool rec709) const noexcept;

private:
Expand All @@ -98,6 +98,7 @@ class OpenGLProgram : public HwProgram {
struct UniformsRecord {
Program::UniformInfo uniforms;
LocationInfo locations;
mutable GLuint id = 0;
mutable uint16_t age = std::numeric_limits<uint16_t>::max();
};
UniformsRecord const* mUniformsRecords = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion filament/src/PostProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,8 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::upscale(FrameGraph& fg, bool
filament::Viewport const& vp, FrameGraphTexture::Descriptor const& outDesc,
backend::SamplerMagFilter filter) noexcept {

if (UTILS_LIKELY(!translucent && dsrOptions.quality == QualityLevel::LOW)) {
if (UTILS_LIKELY(!translucent && dsrOptions.quality == QualityLevel::LOW &&
mEngine.getDriverApi().getFeatureLevel() >= FeatureLevel::FEATURE_LEVEL_1)) {
return opaqueBlit(fg, input, vp, outDesc, filter);
}

Expand Down
6 changes: 3 additions & 3 deletions shaders/src/depth_main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void main() {
fragColor.zw = computeDepthMomentsVSM(-1.0 / depth); // requires at least RGBA16F
#elif defined(VARIANT_HAS_PICKING)
#if MATERIAL_FEATURE_LEVEL == 0
outPicking.a = float((object_uniforms_objectId / 65536) % 256) / 255.0;
outPicking.b = float((object_uniforms_objectId / 256) % 256) / 255.0;
outPicking.g = float( object_uniforms_objectId % 256) / 255.0;
outPicking.a = mod(float(object_uniforms_objectId / 65536), 256.0) / 255.0;
outPicking.b = mod(float(object_uniforms_objectId / 256), 256.0) / 255.0;
outPicking.g = mod(float(object_uniforms_objectId) , 256.0) / 255.0;
outPicking.r = vertex_position.z / vertex_position.w;
#else
outPicking.x = intBitsToFloat(object_uniforms_objectId);
Expand Down

0 comments on commit 766e4f2

Please sign in to comment.