Skip to content

Commit 05a4566

Browse files
bors[bot]goddessfreyakvarkking6cong
committed
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]>
4 parents 0e1c915 + d7e0676 + 90fd193 + 4c7a4ac commit 05a4566

File tree

13 files changed

+1716
-871
lines changed

13 files changed

+1716
-871
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ To run an example, simply use `cargo run` and specify the backend with `--featur
3636

3737
```bash
3838
git clone https://github.com/gfx-rs/gfx
39-
cd gfx/examples/hal
39+
cd gfx/examples
40+
# macOS
41+
cargo run --bin quad --features metal
42+
# vulkan
4043
cargo run --bin quad --features vulkan
44+
# Windows
4145
cargo run --bin compute --features dx12 1 2 3 4
4246
```
4347

src/backend/gl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ gfx_gl = "0.5"
2424
gfx-hal = { path = "../../hal", version = "0.1" }
2525
smallvec = "0.6"
2626
glutin = { version = "0.16", optional = true }
27-
spirv_cross = "0.8"
27+
spirv_cross = "0.9.2"

src/backend/gl/src/command.rs

+48-5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ pub enum Command {
108108
CopySurfaceToBuffer(n::Surface, n::RawBuffer, command::BufferImageCopy),
109109
CopyImageToTexture(n::ImageKind, n::Texture, command::ImageCopy),
110110
CopyImageToSurface(n::ImageKind, n::Surface, command::ImageCopy),
111+
112+
BindBufferRange(gl::types::GLenum, gl::types::GLuint, n::RawBuffer, gl::types::GLintptr, gl::types::GLsizeiptr),
113+
BindTexture(gl::types::GLenum, n::Texture),
114+
BindSampler(gl::types::GLuint, n::Texture),
111115
}
112116

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

863867
fn bind_graphics_descriptor_sets<I, J>(
864868
&mut self,
865-
_layout: &n::PipelineLayout,
866-
_first_set: usize,
867-
_sets: I,
868-
_offsets: J,
869+
layout: &n::PipelineLayout,
870+
first_set: usize,
871+
sets: I,
872+
offsets: J,
869873
) where
870874
I: IntoIterator,
871875
I::Item: Borrow<n::DescriptorSet>,
872876
J: IntoIterator,
873877
J::Item: Borrow<command::DescriptorSetOffset>,
874878
{
875-
// TODO
879+
assert!(offsets.into_iter().next().is_none()); // TODO: offsets unsupported
880+
881+
let mut set = first_set as _;
882+
let drd = &*layout.desc_remap_data.read().unwrap();
883+
884+
for desc_set in sets {
885+
let desc_set = desc_set.borrow();
886+
for new_binding in &*desc_set.bindings.lock().unwrap() {
887+
match new_binding {
888+
n::DescSetBindings::Buffer {ty: btype, binding, buffer, offset, size} => {
889+
for binding in drd.get_binding(n::BindingTypes::UniformBuffers, set, *binding).unwrap() {
890+
self.push_cmd(Command::BindBufferRange(
891+
gl::UNIFORM_BUFFER,
892+
*binding,
893+
*buffer,
894+
*offset,
895+
*size,
896+
))
897+
}
898+
}
899+
n::DescSetBindings::Texture(binding, texture) => {
900+
for binding in drd.get_binding(n::BindingTypes::Images, set, *binding).unwrap() {
901+
self.push_cmd(Command::BindTexture(
902+
*binding,
903+
*texture,
904+
))
905+
}
906+
}
907+
n::DescSetBindings::Sampler(binding, sampler) => {
908+
for binding in drd.get_binding(n::BindingTypes::Images, set, *binding).unwrap() {
909+
self.push_cmd(Command::BindSampler(
910+
*binding,
911+
*sampler,
912+
))
913+
}
914+
}
915+
}
916+
}
917+
set += 1;
918+
}
876919
}
877920

878921
fn bind_compute_pipeline(&mut self, pipeline: &n::ComputePipeline) {

0 commit comments

Comments
 (0)