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

Basic depth output handling #986

Merged
merged 2 commits into from
Jun 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/dx11/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ gfx_core = { path = "../../core", version = "0.3" }
d3d11-sys = "0.2"
d3dcompiler-sys = "0.2"
dxguid-sys = "0.2"
winapi = "0.2"
winapi = "0.2.7"
2 changes: 1 addition & 1 deletion src/backend/dx11/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::ptr;
use winapi::{FLOAT, INT, UINT, UINT8, DXGI_FORMAT,
DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R32_UINT,
DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R32_UINT,
D3D11_CLEAR_FLAG, D3D11_PRIMITIVE_TOPOLOGY, D3D11_VIEWPORT, D3D11_RECT,
ID3D11RasterizerState, ID3D11DepthStencilState, ID3D11BlendState};
use gfx_core::{draw, pso, shade, state, target, tex};
Expand Down
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