Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix render target cache. #229

Merged
merged 1 commit into from Mar 9, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Fix render target cache.

Ensure that the render target cache doesn't return a render target that was allocated on this frame.

Fixes #185.
  • Loading branch information
gw3583 committed Mar 9, 2016
commit 320826167cbeb8b03e4b1eb6cdc9a3ebdbca5ffd
@@ -142,7 +142,8 @@ impl RenderTarget {
width: f32,
height: f32,
device_pixel_ratio: f32,
resource_cache: &mut ResourceCache) -> (Point2D<f32>, TextureId) {
resource_cache: &mut ResourceCache,
frame_id: FrameId) -> (Point2D<f32>, TextureId) {
// If the target is more than 512x512 (an arbitrary choice), assign it
// to an exact sized render target - assuming that there probably aren't
// many of them. This minimises GPU memory wastage if there are just a small
@@ -156,7 +157,8 @@ impl RenderTarget {

let texture_id = resource_cache.allocate_render_target(device_pixel_size,
device_pixel_size,
ImageFormat::RGBA8);
ImageFormat::RGBA8,
frame_id);
self.texture_id_list.push(texture_id);
self.page_allocator = Some(TexturePage::new(texture_id, texture_size));
}
@@ -180,7 +182,8 @@ impl RenderTarget {

let texture_id = resource_cache.allocate_render_target(device_pixel_width,
device_pixel_height,
ImageFormat::RGBA8);
ImageFormat::RGBA8,
frame_id);
self.texture_id_list.push(texture_id);

(Point2D::zero(), texture_id)
@@ -1107,7 +1110,8 @@ impl Frame {
target.allocate_target_rect(target_rect.size.width,
target_rect.size.height,
context.device_pixel_ratio,
context.resource_cache);
context.resource_cache,
self.id);

let mut new_target = RenderTarget::new(render_target_id,
origin,
@@ -705,8 +705,6 @@ impl Renderer {
let zero_point = Point2D::new(0.0, 0.0);
let zero_size = Size2D::new(0.0, 0.0);

let device_pixel_ratio = self.device_pixel_ratio;

self.add_rect_to_raster_batch(update.id,
TextureId(0),
border_program_id,
@@ -381,9 +381,13 @@ impl ResourceCache {
pub fn allocate_render_target(&mut self,
width: u32,
height: u32,
format: ImageFormat)
format: ImageFormat,
frame_id: FrameId)
-> TextureId {
self.texture_cache.allocate_render_target(width, height, format)
self.texture_cache.allocate_render_target(width,
height,
format,
frame_id)
}

pub fn free_old_render_targets(&mut self) {
@@ -6,6 +6,7 @@ use app_units::Au;
use device::{MAX_TEXTURE_SIZE, TextureId, TextureFilter};
use euclid::{Point2D, Rect, Size2D};
use fnv::FnvHasher;
use frame::FrameId;
use freelist::{FreeList, FreeListItem, FreeListItemId};
use internal_types::{TextureUpdate, TextureUpdateOp, TextureUpdateDetails};
use internal_types::{RasterItem, RenderTargetMode, TextureImage, TextureUpdateList};
@@ -673,21 +674,24 @@ impl TextureCache {
pub fn allocate_render_target(&mut self,
width: u32,
height: u32,
format: ImageFormat)
format: ImageFormat,
frame_id: FrameId)
-> TextureId {
let mut cached_render_target_index = None;
for (i, cached_render_target) in self.cached_render_targets.iter().enumerate() {
if cached_render_target.width == width &&
cached_render_target.height == height &&
cached_render_target.format == format {
cached_render_target.format == format &&
cached_render_target.frame_id != frame_id {
cached_render_target_index = Some(i);
break
}
}
if let Some(cached_render_target_index) = cached_render_target_index {
// Push to the end to mark as recently used.
let cached_render_target = self.cached_render_targets
.remove(cached_render_target_index);
let mut cached_render_target = self.cached_render_targets
.remove(cached_render_target_index);
cached_render_target.frame_id = frame_id;
self.cached_render_targets.push(cached_render_target);
return cached_render_target.texture_id
}
@@ -714,6 +718,7 @@ impl TextureCache {
width: width,
height: height,
format: format,
frame_id: frame_id,
});

texture_id
@@ -891,7 +896,7 @@ impl TextureCache {
pub fn insert_raster_op(&mut self,
image_id: TextureCacheItemId,
item: &RasterItem,
device_pixel_ratio: f32) {
_device_pixel_ratio: f32) {
let update_op = match item {
&RasterItem::BorderRadius(ref op) => {
let rect = Rect::new(Point2D::zero(),
@@ -1275,5 +1280,6 @@ pub struct CachedRenderTarget {
width: u32,
height: u32,
format: ImageFormat,
frame_id: FrameId,
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.