Skip to content

Commit

Permalink
Handle the immutable format in cached textures
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jan 17, 2018
1 parent 22767fa commit 4584032
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
19 changes: 1 addition & 18 deletions webrender/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ use std::ptr;
use std::rc::Rc;
use std::thread;

// Apparently, in some cases calling `glTexImage3D` with
// similar parameters that the texture already has confuses
// Angle when running with optimizations.
const WORK_AROUND_TEX_IMAGE: bool = cfg!(windows);

#[derive(Debug, Copy, Clone, PartialEq, Ord, Eq, PartialOrd)]
#[cfg_attr(feature = "capture", derive(Deserialize, Serialize))]
Expand Down Expand Up @@ -1038,7 +1034,7 @@ impl Device {
is_resized: bool,
pixels: Option<&[u8]>,
) {
assert!(texture.layer_count > 0);
assert!(texture.layer_count > 0 || texture.width + texture.height == 0);

let needed_layer_count = texture.layer_count - texture.fbo_ids.len() as i32;
let allocate_color = needed_layer_count != 0 || is_resized || pixels.is_some();
Expand All @@ -1047,19 +1043,6 @@ impl Device {
let desc = gl_describe_format(self.gl(), texture.format);
match texture.target {
gl::TEXTURE_2D_ARRAY => {
if WORK_AROUND_TEX_IMAGE {
// reset the contents before resizing
self.gl.tex_image_3d(
texture.target,
0,
gl::RGBA32F as _,
2, 2, 1,
0,
gl::RGBA,
gl::FLOAT,
None,
)
}
self.gl.tex_image_3d(
texture.target,
0,
Expand Down
5 changes: 4 additions & 1 deletion webrender/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4985,7 +4985,10 @@ impl Renderer {
};

for ExternalCaptureImage { short_path, external, descriptor } in renderer.external_images {
let target = get_external_image_target(external.image_type).unwrap();
let target = match get_external_image_target(external.image_type) {
Some(target) => target,
None => continue,
};
//TODO: provide a way to query both the layer count and the filter from external images
let (layer_count, filter) = (1, TextureFilter::Linear);
let plain = PlainTexture {
Expand Down
33 changes: 17 additions & 16 deletions webrender/src/texture_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use device::TextureFilter;
use frame::FrameId;
use freelist::{FreeList, FreeListHandle, UpsertResult, WeakFreeListHandle};
use gpu_cache::{GpuCache, GpuCacheHandle};
use internal_types::{CacheTextureId, TextureUpdateList, TextureUpdateSource};
use internal_types::{CacheTextureId, FastHashMap, TextureUpdateList, TextureUpdateSource};
use internal_types::{RenderTargetInfo, SourceTexture, TextureUpdate, TextureUpdateOp};
use profiler::{ResourceProfileCounter, TextureCacheProfileCounters};
use resource_cache::CacheItem;
Expand All @@ -31,33 +31,34 @@ const TEXTURE_REGION_DIMENSIONS: u32 = 512;
// to real API-specific texture IDs in the renderer.
#[cfg_attr(feature = "capture", derive(Deserialize, Serialize))]
struct CacheTextureIdList {
free_list: Vec<CacheTextureId>,
free_lists: FastHashMap<ImageFormat, Vec<CacheTextureId>>,
next_id: usize,
}

impl CacheTextureIdList {
fn new() -> Self {
CacheTextureIdList {
next_id: 0,
free_list: Vec::new(),
free_lists: FastHashMap::default(),
}
}

fn allocate(&mut self) -> CacheTextureId {
fn allocate(&mut self, format: ImageFormat) -> CacheTextureId {
// If nothing on the free list of texture IDs,
// allocate a new one.
match self.free_list.pop() {
Some(id) => id,
None => {
let id = CacheTextureId(self.next_id);
self.free_lists.get_mut(&format)
.and_then(|fl| fl.pop())
.unwrap_or_else(|| {
self.next_id += 1;
id
}
}
CacheTextureId(self.next_id - 1)
})
}

fn free(&mut self, id: CacheTextureId) {
self.free_list.push(id);
fn free(&mut self, id: CacheTextureId, format: ImageFormat) {
self.free_lists
.entry(format)
.or_insert(Vec::new())
.push(id);
}
}

Expand Down Expand Up @@ -553,7 +554,7 @@ impl TextureCache {
id: entry.texture_id,
op: TextureUpdateOp::Free,
});
self.cache_textures.free(entry.texture_id);
self.cache_textures.free(entry.texture_id, entry.format);
None
}
EntryKind::Cache {
Expand Down Expand Up @@ -592,7 +593,7 @@ impl TextureCache {

// Lazy initialize this texture array if required.
if texture_array.texture_id.is_none() {
let texture_id = self.cache_textures.allocate();
let texture_id = self.cache_textures.allocate(descriptor.format);

let update_op = TextureUpdate {
id: texture_id,
Expand Down Expand Up @@ -686,7 +687,7 @@ impl TextureCache {
// will just have to be in a unique texture. This hurts batching but should
// only occur on a small number of images (or pathological test cases!).
if new_cache_entry.is_none() {
let texture_id = self.cache_textures.allocate();
let texture_id = self.cache_textures.allocate(descriptor.format);

// Create an update operation to allocate device storage
// of the right size / format.
Expand Down

0 comments on commit 4584032

Please sign in to comment.