Bug 1692250 - Remove ImageSourceHandle. r=gw

Replaced with RenderTaskId or Option<RenderTaskId> depending on context.

Differential Revision: https://phabricator.services.mozilla.com/D105984
This commit is contained in:
Nicolas Silva 2021-02-24 10:32:25 +00:00
Родитель 0e6dc9d100
Коммит 94ed405587
5 изменённых файлов: 54 добавлений и 92 удалений

Просмотреть файл

@ -35,7 +35,6 @@ use smallvec::SmallVec;
use std::{f32, i32, usize};
use crate::util::{project_rect, MaxRect, TransformedRectKind};
use crate::segment::EdgeAaSegmentMask;
use crate::image_source::resolve_render_task;
// Special sentinel value recognized by the shader. It is considered to be
// a dummy task that doesn't mask out anything.
@ -1079,7 +1078,7 @@ impl BatchBuilder {
// task for each valid edge / corner of the border.
for task_id in task_ids {
if let Some((uv_rect_address, texture)) = resolve_render_task(*task_id, render_tasks, gpu_cache) {
if let Some((uv_rect_address, texture)) = render_tasks.resolve_location(*task_id, gpu_cache) {
segment_data.push(
SegmentInstanceData {
textures: TextureSet::prim_textured(texture),
@ -1391,7 +1390,7 @@ impl BatchBuilder {
let (batch_kind, textures, prim_user_data, specific_resource_address) = match render_task {
Some(task_id) => {
let (uv_rect_address, texture) = resolve_render_task(*task_id, render_tasks, gpu_cache).unwrap();
let (uv_rect_address, texture) = render_tasks.resolve_location(*task_id, gpu_cache).unwrap();
let textures = BatchTextures::prim_textured(
texture,
clip_mask_texture_id,
@ -2191,7 +2190,7 @@ impl BatchBuilder {
let common_data = &prim_data.common;
let border_data = &prim_data.kind;
let (uv_rect_address, texture) = match border_data.src_color.resolve(render_tasks, gpu_cache) {
let (uv_rect_address, texture) = match render_tasks.resolve_location(border_data.src_color, gpu_cache) {
Some(src) => src,
None => {
return;
@ -2336,7 +2335,7 @@ impl BatchBuilder {
debug_assert!(channel_count <= 3);
for channel in 0 .. channel_count {
let src_channel = yuv_image_data.src_yuv[channel].resolve(render_tasks, gpu_cache);
let src_channel = render_tasks.resolve_location(yuv_image_data.src_yuv[channel], gpu_cache);
let (uv_rect_address, texture_source) = match src_channel {
Some(src) => src,
@ -2467,7 +2466,7 @@ impl BatchBuilder {
}
}
let src_color = image_instance.src_color.resolve(render_tasks, gpu_cache);
let src_color = render_tasks.resolve_location(image_instance.src_color, gpu_cache);
let (uv_rect_address, texture_source) = match src_color {
Some(src) => src,
@ -2563,7 +2562,7 @@ impl BatchBuilder {
let prim_header_index = prim_headers.push(&prim_header, z_id, prim_user_data);
for (i, tile) in chunk.iter().enumerate() {
let (uv_rect_address, texture) = match tile.src_color.resolve(render_tasks, gpu_cache) {
let (uv_rect_address, texture) = match render_tasks.resolve_location(tile.src_color, gpu_cache) {
Some(result) => result,
None => {
return;
@ -2622,9 +2621,8 @@ impl BatchBuilder {
if !gradient.cache_segments.is_empty() {
for segment in &gradient.cache_segments {
let (uv_rect_address, texture) = match resolve_render_task(
let (uv_rect_address, texture) = match render_tasks.resolve_location(
segment.render_task,
render_tasks,
gpu_cache
) {
Some(resolved) => resolved,
@ -3604,7 +3602,7 @@ impl ClipBatcher {
let task_id = source
.render_task
.expect("bug: render task handle not allocated");
let (uv_rect_address, texture) = resolve_render_task(task_id, render_tasks, gpu_cache).unwrap();
let (uv_rect_address, texture) = render_tasks.resolve_location(task_id, gpu_cache).unwrap();
self.get_batch_list(is_first_clip)
.box_shadows

Просмотреть файл

@ -4,8 +4,8 @@
use api::units::*;
use api::ImageFormat;
use crate::gpu_cache::GpuCache;
use crate::internal_types::{CacheTextureId, FastHashMap, FastHashSet};
use crate::gpu_cache::{GpuCache, GpuCacheAddress};
use crate::internal_types::{TextureSource, CacheTextureId, FastHashMap, FastHashSet};
use crate::render_backend::FrameId;
use crate::render_task_graph::{RenderTaskId};
use crate::render_task::{StaticRenderTaskSurface, RenderTaskLocation, RenderTask};
@ -636,6 +636,32 @@ impl FrameGraph {
}
}
pub fn resolve_location(
&self,
task_id: impl Into<Option<RenderTaskId>>,
gpu_cache: &GpuCache,
) -> Option<(GpuCacheAddress, TextureSource)> {
self.resolve_impl(task_id.into()?, gpu_cache)
}
fn resolve_impl(
&self,
task_id: RenderTaskId,
gpu_cache: &GpuCache,
) -> Option<(GpuCacheAddress, TextureSource)> {
let task = &self[task_id];
let texture_source = task.get_texture_source();
if let TextureSource::Invalid = texture_source {
return None;
}
let uv_address = task.get_texture_address(gpu_cache);
Some((uv_address, texture_source))
}
/// Return the surface and texture counts, used for testing
#[cfg(test)]
pub fn surface_counts(&self) -> (usize, usize) {

Просмотреть файл

@ -11,50 +11,13 @@
use crate::api::ExternalImageType;
use crate::api::units::*;
use crate::gpu_cache::{GpuCache, GpuCacheAddress};
use crate::gpu_cache::GpuCache;
use crate::prim_store::DeferredResolve;
use crate::renderer::BLOCKS_PER_UV_RECT;
use crate::render_task_graph::{RenderTaskId, RenderTaskGraph};
use crate::render_task_cache::RenderTaskCacheEntryHandle;
use crate::resource_cache::{ResourceCache, ImageRequest, CacheItem};
use crate::internal_types::{TextureSource, DeferredResolveIndex};
/// The different ways a primitive can refer to a source image, if any.
///
/// This information is eventually turned into a texture source the uv rect's
/// gpu cache handle.
///
/// TODO: ImageSourceHandle is now basically an Option<RenderTaskId>. The next patch
/// will remove it in favor of manipulating render task ids directly instead.
#[derive(Debug)]
#[derive(MallocSizeOf)]
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub enum ImageSourceHandle {
RenderTask(RenderTaskId),
None,
}
impl ImageSourceHandle {
/// Resolve this handle into a TextureSource and the uv rect's gpu cache address (if any).
///
/// Called during batching.
pub fn resolve(
&self,
render_tasks: &RenderTaskGraph,
gpu_cache: &mut GpuCache,
) -> Option<(GpuCacheAddress, TextureSource)> {
return match self {
ImageSourceHandle::None => {
None
}
ImageSourceHandle::RenderTask(task_id) => {
resolve_render_task(*task_id, render_tasks, gpu_cache)
},
}
}
}
/// Resolve a resource cache's imagre request into a texture cache item.
pub fn resolve_image(
request: ImageRequest,
@ -130,20 +93,3 @@ pub fn resolve_cached_render_task(
resource_cache.get_texture_cache_item(&rt_cache_entry.handle)
}
pub fn resolve_render_task(
task_id: RenderTaskId,
render_tasks: &RenderTaskGraph,
gpu_cache: &GpuCache,
) -> Option<(GpuCacheAddress, TextureSource)> {
let task = &render_tasks[task_id];
let texture_source = task.get_texture_source();
if let TextureSource::Invalid = texture_source {
return None;
}
let uv_address = task.get_texture_address(gpu_cache);
Some((uv_address, texture_source))
}

Просмотреть файл

@ -18,8 +18,8 @@ use crate::prim_store::{
PrimitiveStore, InternablePrimitive,
};
use crate::resource_cache::ImageRequest;
use crate::image_source::ImageSourceHandle;
use crate::render_task::RenderTask;
use crate::render_task_graph::RenderTaskId;
use crate::render_backend::FrameId;
use super::storage;
@ -232,7 +232,7 @@ pub struct ImageBorderData {
#[ignore_malloc_size_of = "Arc"]
pub request: ImageRequest,
pub brush_segments: Vec<BrushSegment>,
pub src_color: ImageSourceHandle,
pub src_color: Option<RenderTaskId>,
pub frame_id: FrameId,
pub is_opaque: bool,
}
@ -265,7 +265,7 @@ impl ImageBorderData {
RenderTask::new_image(size, self.request)
);
self.src_color = ImageSourceHandle::RenderTask(task_id);
self.src_color = Some(task_id);
let image_properties = frame_state
.resource_cache
@ -323,7 +323,7 @@ impl From<ImageBorderKey> for ImageBorderTemplate {
kind: ImageBorderData {
request: key.kind.request,
brush_segments,
src_color: ImageSourceHandle::None,
src_color: None,
frame_id: FrameId::INVALID,
is_opaque: false,
}

Просмотреть файл

@ -21,13 +21,13 @@ use crate::prim_store::{
SizeKey, InternablePrimitive,
};
use crate::render_target::RenderTargetKind;
use crate::render_task_graph::RenderTaskId;
use crate::render_task::RenderTask;
use crate::render_task_cache::{
RenderTaskCacheKey, RenderTaskCacheKeyKind, RenderTaskParent
};
use crate::resource_cache::{ImageRequest, ImageProperties, ResourceCache};
use crate::util::pack_as_float;
use crate::image_source::ImageSourceHandle;
use crate::visibility::{PrimitiveVisibility, compute_conservative_visible_rect};
use crate::spatial_tree::SpatialNodeIndex;
use crate::image_tiling;
@ -36,7 +36,7 @@ use crate::image_tiling;
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct VisibleImageTile {
pub src_color: ImageSourceHandle,
pub src_color: RenderTaskId,
pub edge_flags: EdgeAaSegmentMask,
pub local_rect: LayoutRect,
pub local_clip_rect: LayoutRect,
@ -70,7 +70,7 @@ pub struct ImageInstance {
pub segment_instance_index: SegmentInstanceIndex,
pub tight_local_clip_rect: LayoutRect,
pub visible_tiles: Vec<VisibleImageTile>,
pub src_color: ImageSourceHandle,
pub src_color: Option<RenderTaskId>,
}
#[cfg_attr(feature = "capture", derive(Serialize))]
@ -187,7 +187,7 @@ impl ImageData {
// evicted from the texture cache.
if self.tile_spacing == LayoutSize::zero() {
// Most common case.
image_instance.src_color = ImageSourceHandle::RenderTask(task_id);
image_instance.src_color = Some(task_id);
} else {
let padding = DeviceIntSideOffsets::new(
0,
@ -248,13 +248,13 @@ impl ImageData {
}
);
image_instance.src_color = ImageSourceHandle::RenderTask(cached_task_handle);
image_instance.src_color = Some(cached_task_handle);
}
}
// Tiled image path.
Some(ImageProperties { tiling: Some(tile_size), visible_rect, .. }) => {
// we'll have a source handle per visible tile instead.
image_instance.src_color = ImageSourceHandle::None;
image_instance.src_color = None;
image_instance.visible_tiles.clear();
// TODO: rename the blob's visible_rect into something that doesn't conflict
@ -318,7 +318,7 @@ impl ImageData {
);
image_instance.visible_tiles.push(VisibleImageTile {
src_color: ImageSourceHandle::RenderTask(task_id),
src_color: task_id,
edge_flags: tile.edge_flags & edge_flags,
local_rect: tile.rect,
local_clip_rect: tight_clip_rect,
@ -332,7 +332,7 @@ impl ImageData {
}
}
None => {
image_instance.src_color = ImageSourceHandle::None;
image_instance.src_color = None;
}
}
@ -411,7 +411,7 @@ impl InternablePrimitive for Image {
segment_instance_index: SegmentInstanceIndex::INVALID,
tight_local_clip_rect: LayoutRect::zero(),
visible_tiles: Vec::new(),
src_color: ImageSourceHandle::None,
src_color: None,
});
PrimitiveInstanceKind::Image {
@ -482,7 +482,7 @@ impl InternDebug for YuvImageKey {}
pub struct YuvImageData {
pub color_depth: ColorDepth,
pub yuv_key: [ApiImageKey; 3],
pub src_yuv: [ImageSourceHandle; 3],
pub src_yuv: [Option<RenderTaskId>; 3],
pub format: YuvFormat,
pub color_space: YuvColorSpace,
pub color_range: ColorRange,
@ -494,11 +494,7 @@ impl From<YuvImage> for YuvImageData {
YuvImageData {
color_depth: image.color_depth,
yuv_key: image.yuv_key,
src_yuv: [
ImageSourceHandle::None,
ImageSourceHandle::None,
ImageSourceHandle::None,
],
src_yuv: [None, None, None],
format: image.format,
color_space: image.color_space,
color_range: image.color_range,
@ -518,11 +514,7 @@ impl YuvImageData {
frame_state: &mut FrameBuildingState,
) {
self.src_yuv = [
ImageSourceHandle::None,
ImageSourceHandle::None,
ImageSourceHandle::None,
];
self.src_yuv = [ None, None, None ];
let channel_num = self.format.get_plane_num();
debug_assert!(channel_num <= 3);
@ -542,7 +534,7 @@ impl YuvImageData {
RenderTask::new_image(size, request)
);
self.src_yuv[channel] = ImageSourceHandle::RenderTask(task_id);
self.src_yuv[channel] = Some(task_id);
}
if let Some(mut request) = frame_state.gpu_cache.request(&mut common.gpu_cache_handle) {