Skip to content

Commit

Permalink
Handling of the output pixel depth
Browse files Browse the repository at this point in the history
  • Loading branch information
sectopod committed Jun 2, 2016
1 parent 8a32e86 commit fc81cf3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/backend/dx11/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ impl core::Factory<R> for Factory {
unordereds: Vec::new(),
samplers: Vec::new(),
outputs: Vec::new(),
output_depth: false,
knows_outputs: true,
};
let fh = &mut self.frame_handles;
Expand Down
23 changes: 13 additions & 10 deletions src/backend/dx11/src/mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,19 @@ pub fn populate_info(info: &mut s::ProgramInfo, stage: s::Stage,
let name = convert_str(desc.SemanticName);
debug!("Output {}, system type {:?}, mask {}, read-write mask {}",
name, desc.SystemValueType, desc.Mask, desc.ReadWriteMask);
if desc.SystemValueType == winapi::D3D_NAME_TARGET {
info.outputs.push(s::OutputVar {
name: format!("Target{}", desc.SemanticIndex), //care!
slot: desc.Register as core::ColorSlot,
base_type: map_base_type_from_component(desc.ComponentType),
container: mask_to_vector(desc.Mask),
});
}else
if desc.SystemValueType == winapi::D3D_NAME_UNDEFINED {
warn!("Custom PS output semantic is ignored: {}", name)
match desc.SystemValueType {
winapi::D3D_NAME_TARGET =>
info.outputs.push(s::OutputVar {
name: format!("Target{}", desc.SemanticIndex), //care!
slot: desc.Register as core::ColorSlot,
base_type: map_base_type_from_component(desc.ComponentType),
container: mask_to_vector(desc.Mask),
}),
winapi::D3D_NAME_DEPTH => info.output_depth = true,
winapi::D3D_NAME_UNDEFINED =>
warn!("Custom PS output semantic is ignored: {}", name),
_ =>
warn!("Unhandled PS output semantic {} of type {:?}", name, desc.SystemValueType),
}
}
}
Expand Down
26 changes: 18 additions & 8 deletions src/backend/gl/src/shade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ fn query_parameters(gl: &gl::Gl, caps: &d::Capabilities, prog: super::Program, u
(uniforms, textures, samplers)
}

fn query_outputs(gl: &gl::Gl, prog: super::Program) -> Vec<s::OutputVar> {
fn query_outputs(gl: &gl::Gl, prog: super::Program) -> (Vec<s::OutputVar>, bool) {
use std::ptr;

let mut out_depth = false;
let mut num_slots = 0;
unsafe {
gl.GetProgramInterfaceiv(prog, gl::PROGRAM_OUTPUT, gl::ACTIVE_RESOURCES, &mut num_slots);
Expand Down Expand Up @@ -379,11 +380,17 @@ fn query_outputs(gl: &gl::Gl, prog: super::Program) -> Vec<s::OutputVar> {

// special index reported for GLSL 120 to 140 shaders
if index == !0 {
assert!(name.starts_with("gl_Frag"));
index = if name.starts_with("gl_FragData") {
(name.chars().nth(12).unwrap() as i32) - ('0' as i32)
}else { 0 };
name = format!("Target{}", index);
if name.starts_with("gl_FragData") {
let index = (name.chars().nth(12).unwrap() as i32) - ('0' as i32);
name = format!("Target{}", index);
}else
if &name == "gl_FragDepth" {
out_depth = true;
continue;
}else {
warn!("Unhandled GLSL built-in: {}", name);
continue;
}
}

if let StorageType::Var(base, container) = StorageType::new(type_ as u32) {
Expand All @@ -395,7 +402,7 @@ fn query_outputs(gl: &gl::Gl, prog: super::Program) -> Vec<s::OutputVar> {
});
}
}
out
(out, out_depth)
}

pub fn get_program_log(gl: &gl::Gl, name: super::Program) -> String {
Expand Down Expand Up @@ -441,10 +448,13 @@ pub fn create_program(gl: &gl::Gl, caps: &d::Capabilities, private: &PrivateCaps
unordereds: Vec::new(), //TODO
samplers: samplers,
outputs: Vec::new(),
output_depth: false,
knows_outputs: false,
};
if private.program_interface_supported {
info.outputs = query_outputs(gl, name);
let (outs, od) = query_outputs(gl, name);
info.outputs = outs;
info.output_depth = od;
info.knows_outputs = true;
}
debug!("Program {} reflection: {:?}", name, info);
Expand Down
2 changes: 2 additions & 0 deletions src/core/src/shade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ pub struct ProgramInfo {
pub samplers: Vec<SamplerVar>,
/// Output targets in the program
pub outputs: Vec<OutputVar>,
/// A flag indicating that the pixel shader manually assigns the depth.
pub output_depth: bool,
/// A hacky flag to make sure the clients know we are
/// unable to actually get the output variable info
pub knows_outputs: bool,
Expand Down

0 comments on commit fc81cf3

Please sign in to comment.