Skip to content

Commit

Permalink
Merge #2071 #2164 #2166
Browse files Browse the repository at this point in the history
2071: Remaping descriptor sets in the gl backend r=kvark a=ZeGentzy

I'll rebase off master when I'm done.

Uniforms in gl only have a bindings field, not a set one. This means that for shaders that use multiple sets to work, we must change where we are binding them.

See page 14 for what I mean: https://www.khronos.org/assets/uploads/developers/library/2016-vulkan-devday-uk/4-Using-spir-v-with-spirv-cross.pdf

PR checklist:
- [ ] `make` succeeds (on *nix)
- [ ] `make reftests` succeeds
- [ ] tested examples with the following backends:


2164: [mtl] Borrowed commands r=grovesNL a=kvark

PR checklist:
- [ ] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [x] tested examples with the following backends:

r? @gfx-rs/metallists 

This PR attempts to have lightweight software commands that don't take any heap space or own ObjC objects. In most cases, where a command list is live-recorded and executed once, this should reduce the amount of work we do per command, which is especially important if those commands are thrown away (e.g. because we are not inside a render pass).

My expectation would be to see an improvement in #2161 due to us doing less work. The actual results are somewhat shocking: with v-sync enabled I'm getting the same 59-60 fps as usual. With v-sync OFF, I'm getting between 25 and 50 fps now (which is lower than the previous 50-70). Not sure what's going on, the instrumental profile doesn't give a clue. Please check out the code.

2166: Update example instructions in README.md r=kvark a=king6cong



Co-authored-by: Hal Gentz <[email protected]>
Co-authored-by: Dzmitry Malyshau <[email protected]>
Co-authored-by: king6cong <[email protected]>
  • Loading branch information
4 people committed Jun 22, 2018
4 parents 0e1c915 + d7e0676 + 90fd193 + 4c7a4ac commit 05a4566
Show file tree
Hide file tree
Showing 13 changed files with 1,716 additions and 871 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ To run an example, simply use `cargo run` and specify the backend with `--featur

```bash
git clone https://github.com/gfx-rs/gfx
cd gfx/examples/hal
cd gfx/examples
# macOS
cargo run --bin quad --features metal
# vulkan
cargo run --bin quad --features vulkan
# Windows
cargo run --bin compute --features dx12 1 2 3 4
```

Expand Down
2 changes: 1 addition & 1 deletion src/backend/gl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ gfx_gl = "0.5"
gfx-hal = { path = "../../hal", version = "0.1" }
smallvec = "0.6"
glutin = { version = "0.16", optional = true }
spirv_cross = "0.8"
spirv_cross = "0.9.2"
53 changes: 48 additions & 5 deletions src/backend/gl/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ pub enum Command {
CopySurfaceToBuffer(n::Surface, n::RawBuffer, command::BufferImageCopy),
CopyImageToTexture(n::ImageKind, n::Texture, command::ImageCopy),
CopyImageToSurface(n::ImageKind, n::Surface, command::ImageCopy),

BindBufferRange(gl::types::GLenum, gl::types::GLuint, n::RawBuffer, gl::types::GLintptr, gl::types::GLsizeiptr),
BindTexture(gl::types::GLenum, n::Texture),
BindSampler(gl::types::GLuint, n::Texture),
}

pub type FrameBufferTarget = gl::types::GLenum;
Expand Down Expand Up @@ -862,17 +866,56 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {

fn bind_graphics_descriptor_sets<I, J>(
&mut self,
_layout: &n::PipelineLayout,
_first_set: usize,
_sets: I,
_offsets: J,
layout: &n::PipelineLayout,
first_set: usize,
sets: I,
offsets: J,
) where
I: IntoIterator,
I::Item: Borrow<n::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<command::DescriptorSetOffset>,
{
// TODO
assert!(offsets.into_iter().next().is_none()); // TODO: offsets unsupported

let mut set = first_set as _;
let drd = &*layout.desc_remap_data.read().unwrap();

for desc_set in sets {
let desc_set = desc_set.borrow();
for new_binding in &*desc_set.bindings.lock().unwrap() {
match new_binding {
n::DescSetBindings::Buffer {ty: btype, binding, buffer, offset, size} => {
for binding in drd.get_binding(n::BindingTypes::UniformBuffers, set, *binding).unwrap() {
self.push_cmd(Command::BindBufferRange(
gl::UNIFORM_BUFFER,
*binding,
*buffer,
*offset,
*size,
))
}
}
n::DescSetBindings::Texture(binding, texture) => {
for binding in drd.get_binding(n::BindingTypes::Images, set, *binding).unwrap() {
self.push_cmd(Command::BindTexture(
*binding,
*texture,
))
}
}
n::DescSetBindings::Sampler(binding, sampler) => {
for binding in drd.get_binding(n::BindingTypes::Images, set, *binding).unwrap() {
self.push_cmd(Command::BindSampler(
*binding,
*sampler,
))
}
}
}
}
set += 1;
}
}

fn bind_compute_pipeline(&mut self, pipeline: &n::ComputePipeline) {
Expand Down
Loading

0 comments on commit 05a4566

Please sign in to comment.