Skip to content

Commit

Permalink
UploadMethod configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Dec 1, 2017
1 parent 597cf22 commit 83ee20d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
39 changes: 25 additions & 14 deletions webrender/src/device.rs
Expand Up @@ -118,6 +118,17 @@ enum FBOTarget {
Draw,
}

/// Method of uploading texel data from CPU to GPU.
#[derive(Debug, Clone)]
pub enum UploadMethod {
/// Just call `glTexSubImage` directly with the CPU data pointer
Immediate,
/// Copy to PBO with STATIC usage first before transferring to a texture.
StaticPbo,
/// Copy to PBO with STREAM usage first before transferring to a texture.
StreamPbo,
}

pub fn get_gl_format_bgra(gl: &gl::Gl) -> gl::GLuint {
match gl.get_type() {
gl::GlType::Gl => GL_FORMAT_BGRA_GL,
Expand Down Expand Up @@ -589,7 +600,8 @@ pub struct Device {
default_read_fbo: gl::GLuint,
default_draw_fbo: gl::GLuint,

pub device_pixel_ratio: f32,
device_pixel_ratio: f32,
upload_method: UploadMethod,

// HW or API capabilties
capabilities: Capabilities,
Expand All @@ -613,6 +625,7 @@ impl Device {
pub fn new(
gl: Rc<gl::Gl>,
resource_override_path: Option<PathBuf>,
upload_method: UploadMethod,
_file_changed_handler: Box<FileWatcherHandler>,
cached_programs: Option<Rc<ProgramCache>>,
) -> Device {
Expand All @@ -622,9 +635,10 @@ impl Device {
Device {
gl,
resource_override_path,
// This is initialized to 1 by default, but it is set
// every frame by the call to begin_frame().
// This is initialized to 1 by default, but it is reset
// at the beginning of each frame in `Renderer::bind_frame_data`.
device_pixel_ratio: 1.0,
upload_method,
inside_frame: false,

capabilities: Capabilities {
Expand Down Expand Up @@ -654,6 +668,10 @@ impl Device {
&self.gl
}

pub fn set_device_pixel_ratio(&mut self, ratio: f32) {
self.device_pixel_ratio = ratio;
}

pub fn update_program_cache(&mut self, cached_programs: Rc<ProgramCache>) {
self.cached_programs = Some(cached_programs);
}
Expand Down Expand Up @@ -1328,25 +1346,18 @@ impl Device {
debug_assert!(self.inside_frame);
self.bind_texture(DEFAULT_TEXTURE, texture);

enum UploadStyle {
Immediate,
StaticPbo,
StreamPbo,
}
let style = UploadStyle::StreamPbo;

let target = UploadTarget {
gl: &*self.gl,
texture,
};
let usage = match style {
UploadStyle::Immediate => return TextureUploader {
let usage = match self.upload_method {
UploadMethod::Immediate => return TextureUploader {
target,
buffer: None,
marker: PhantomData,
},
UploadStyle::StaticPbo => gl::STATIC_DRAW,
UploadStyle::StreamPbo => gl::STREAM_DRAW,
UploadMethod::StaticPbo => gl::STATIC_DRAW,
UploadMethod::StreamPbo => gl::STREAM_DRAW,
};

self.gl.bind_buffer(gl::PIXEL_UNPACK_BUFFER, pbo.id);
Expand Down
10 changes: 8 additions & 2 deletions webrender/src/renderer.rs
Expand Up @@ -25,7 +25,7 @@ use debug_colors;
use debug_render::DebugRenderer;
#[cfg(feature = "debugger")]
use debug_server::{self, DebugServer};
use device::{DepthFunction, Device, FrameId, Program, Texture,
use device::{DepthFunction, Device, FrameId, Program, UploadMethod, Texture,
VertexDescriptor, PBO};
use device::{get_gl_format_bgra, ExternalTexture, FBOId, TextureSlot, VertexAttribute,
VertexAttributeKind};
Expand Down Expand Up @@ -1485,6 +1485,7 @@ impl Renderer {
let mut device = Device::new(
gl,
options.resource_override_path.clone(),
options.upload_method,
Box::new(file_watch_handler),
options.cached_programs,
);
Expand Down Expand Up @@ -3756,7 +3757,7 @@ impl Renderer {

fn bind_frame_data(&mut self, frame: &mut Frame) {
let _timer = self.gpu_profile.start_timer(GPU_TAG_SETUP_DATA);
self.device.device_pixel_ratio = frame.device_pixel_ratio;
self.device.set_device_pixel_ratio(frame.device_pixel_ratio);

// Some of the textures are already assigned by `prepare_frame`.
// Now re-allocate the space for the rest of the target textures.
Expand Down Expand Up @@ -4229,6 +4230,7 @@ pub struct RendererOptions {
pub clear_color: Option<ColorF>,
pub enable_clear_scissor: bool,
pub max_texture_size: Option<u32>,
pub upload_method: UploadMethod,
pub workers: Option<Arc<ThreadPool>>,
pub blob_image_renderer: Option<Box<BlobImageRenderer>>,
pub recorder: Option<Box<ApiRecordingReceiver>>,
Expand Down Expand Up @@ -4256,6 +4258,10 @@ impl Default for RendererOptions {
clear_color: Some(ColorF::new(1.0, 1.0, 1.0, 1.0)),
enable_clear_scissor: true,
max_texture_size: None,
#[cfg(windows)]
upload_method: UploadMethod::Immediate,
#[cfg(not(windows))]
upload_method: UploadMethod::StreamPbo,
workers: None,
blob_image_renderer: None,
recorder: None,
Expand Down

0 comments on commit 83ee20d

Please sign in to comment.