Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/blit_command_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ std::string BlitGenerateMipmapCommandGLES::GetLabel() const {

bool BlitGenerateMipmapCommandGLES::Encode(const ReactorGLES& reactor) const {
auto texture_gles = TextureGLES::Cast(texture.get());
if (!texture_gles->GenerateMipmaps()) {
if (!texture_gles->GenerateMipmap()) {
return false;
}

Expand Down
9 changes: 9 additions & 0 deletions impeller/renderer/backend/gles/sampler_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// found in the LICENSE file.

#include "impeller/renderer/backend/gles/sampler_gles.h"

#include <iostream>

#include "impeller/base/validation.h"
#include "impeller/renderer/backend/gles/formats_gles.h"
#include "impeller/renderer/backend/gles/proc_table_gles.h"
#include "impeller/renderer/backend/gles/texture_gles.h"
Expand Down Expand Up @@ -69,6 +71,13 @@ bool SamplerGLES::ConfigureBoundTexture(const TextureGLES& texture,
return false;
}

if (texture.NeedsMipmapGeneration()) {
VALIDATION_LOG
<< "Texture mip count is > 1, but the mipmap has not been generated. "
"Texture can not be sampled safely.";
return false;
}

auto target = ToTextureTarget(texture.GetTextureDescriptor().type);

if (!target.has_value()) {
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/backend/gles/texture_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ bool TextureGLES::Bind() const {
return true;
}

bool TextureGLES::GenerateMipmaps() const {
bool TextureGLES::GenerateMipmap() {
if (!IsValid()) {
return false;
}
Expand Down Expand Up @@ -453,6 +453,7 @@ bool TextureGLES::GenerateMipmaps() const {

const auto& gl = reactor_->GetProcTable();
gl.GenerateMipmap(ToTextureType(type));
mipmap_generated_ = true;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/texture_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TextureGLES final : public Texture,

[[nodiscard]] bool Bind() const;

[[nodiscard]] bool GenerateMipmaps() const;
[[nodiscard]] bool GenerateMipmap();

enum class AttachmentPoint {
kColor0,
Expand Down
9 changes: 1 addition & 8 deletions impeller/renderer/backend/metal/blit_command_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,7 @@

bool BlitGenerateMipmapCommandMTL::Encode(
id<MTLBlitCommandEncoder> encoder) const {
auto texture_mtl = TextureMTL::Cast(*texture).GetMTLTexture();
if (!texture_mtl) {
return false;
}

[encoder generateMipmapsForTexture:texture_mtl];

return true;
return TextureMTL::Cast(*texture).GenerateMipmap(encoder);
};

} // namespace impeller
7 changes: 7 additions & 0 deletions impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ static bool Bind(PassBindingsCache& pass,
return false;
}

if (texture.NeedsMipmapGeneration()) {
VALIDATION_LOG
<< "Texture at binding index " << bind_index
<< " has a mip count > 1, but the mipmap has not been generated.";
return false;
}

return pass.SetTexture(stage, bind_index,
TextureMTL::Cast(texture).GetMTLTexture());
}
Expand Down
2 changes: 2 additions & 0 deletions impeller/renderer/backend/metal/texture_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class TextureMTL final : public Texture,

bool IsWrapped() const;

bool GenerateMipmap(id<MTLBlitCommandEncoder> encoder);

private:
id<MTLTexture> texture_ = nullptr;
bool is_valid_ = false;
Expand Down
11 changes: 11 additions & 0 deletions impeller/renderer/backend/metal/texture_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,15 @@
return is_wrapped_;
}

bool TextureMTL::GenerateMipmap(id<MTLBlitCommandEncoder> encoder) {
if (!texture_) {
return false;
}

[encoder generateMipmapsForTexture:texture_];
mipmap_generated_ = true;

return true;
}

} // namespace impeller
3 changes: 2 additions & 1 deletion impeller/renderer/backend/vulkan/blit_command_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void InsertImageMemoryBarrier(const vk::CommandBuffer& cmd,
}

bool BlitGenerateMipmapCommandVK::Encode(CommandEncoderVK& encoder) const {
const auto& src = TextureVK::Cast(*texture);
auto& src = TextureVK::Cast(*texture);

const auto size = src.GetTextureDescriptor().size;
uint32_t mip_count = src.GetTextureDescriptor().mip_count;
Expand Down Expand Up @@ -249,6 +249,7 @@ bool BlitGenerateMipmapCommandVK::Encode(CommandEncoderVK& encoder) const {
// state so it doesn't try to perform redundant transitions under the hood.
src.SetLayoutWithoutEncoding(vk::ImageLayout::eShaderReadOnlyOptimal);

src.SetMipmapGenerated();
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions impeller/renderer/backend/vulkan/render_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ static bool UpdateDescriptorSets(vk::Device device,
}

auto texture = bindings.textures.at(index).resource;
if (texture->NeedsMipmapGeneration()) {
VALIDATION_LOG
<< "Texture at binding index " << index
<< " has a mip count > 1, but the mipmap has not been generated.";
return false;
}
const auto& texture_vk = TextureVK::Cast(*texture);
const SamplerVK& sampler = SamplerVK::Cast(*sampler_handle.resource);

Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/texture_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ vk::ImageLayout TextureVK::GetLayout() const {
return layout_;
}

void TextureVK::SetMipmapGenerated() {
mipmap_generated_ = true;
}

vk::ImageLayout TextureVK::SetLayoutWithoutEncoding(
vk::ImageLayout layout) const {
WriterLock lock(layout_mutex_);
Expand Down
2 changes: 2 additions & 0 deletions impeller/renderer/backend/vulkan/texture_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class TextureVK final : public Texture, public BackendCast<TextureVK, Texture> {

vk::ImageLayout GetLayout() const;

void SetMipmapGenerated();

private:
std::weak_ptr<Context> context_;
std::shared_ptr<TextureSourceVK> source_;
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ Scalar Texture::GetYCoordScale() const {
return 1.0;
}

bool Texture::NeedsMipmapGeneration() const {
return !mipmap_generated_ && desc_.mip_count > 1;
}

} // namespace impeller
4 changes: 4 additions & 0 deletions impeller/renderer/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Texture {

virtual Scalar GetYCoordScale() const;

bool NeedsMipmapGeneration() const;

protected:
explicit Texture(TextureDescriptor desc);

Expand All @@ -52,6 +54,8 @@ class Texture {
std::shared_ptr<const fml::Mapping> mapping,
size_t slice) = 0;

bool mipmap_generated_ = false;

private:
TextureIntent intent_ = TextureIntent::kRenderToTexture;
const TextureDescriptor desc_;
Expand Down