Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Hal Gentz <[email protected]>
  • Loading branch information
goddessfreya committed May 31, 2018
1 parent 032593c commit 1c070cb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/backend/gl/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,9 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {

for desc_set in sets {
let desc_set = desc_set.borrow();
for new_binding in desc_set.bindings.read().unwrap().iter() {
for new_binding in desc_set.bindings.borrow() {
match new_binding {
n::DescSetBindings::Buffer(btype, binding, buffer, offset, size) => {
n::DescSetBindings::Buffer {ty: btype, binding, buffer, offset, size} => {
self.push_cmd(Command::BindBufferRange(
gl::UNIFORM_BUFFER,
*layout.desc_remap_data.read().unwrap().get_binding(*btype, set, *binding).unwrap(),
Expand Down
28 changes: 12 additions & 16 deletions src/backend/gl/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ impl Device {
for res in all_res {
let set = ast.get_decoration(res.id, spirv::Decoration::DescriptorSet).unwrap();
let binding = ast.get_decoration(res.id, spirv::Decoration::Binding).unwrap();
let mut new_binding = desc_remap_data.get_binding_insert(btype, set, binding);
desc_remap_data.associate_name(res.name.clone(), btype, set, binding);
let mut new_binding = desc_remap_data.insert_missing_binding(btype, set as _, binding);
desc_remap_data.associate_name(res.name.clone(), btype, set as _, binding);

if self.share.legacy_features.contains(LegacyFeatures::NO_EXPLICIT_LAYOUTS_IN_SHADER) {
debug!("Next remap is going to be to zero because explicit layouts in shaders aren't supported prior to OpenGL4.2");
Expand Down Expand Up @@ -1061,6 +1061,7 @@ impl d::Device<B> for Device {
{
for mut write in writes {
let set = &mut write.set;
let mut bindings = set.bindings.borrow_mut();
let binding = write.binding;
let mut offset = write.array_offset as _;

Expand All @@ -1071,33 +1072,28 @@ impl d::Device<B> for Device {
let end = range.end.unwrap_or(buffer.size);
let size = (end - start) as _;

set.bindings
.write()
.unwrap()
.push(n::DescSetBindings::Buffer(
n::BindingTypes::UniformBuffers,
bindings
.push(n::DescSetBindings::Buffer {
ty: n::BindingTypes::UniformBuffers,
binding,
buffer.raw,
buffer: buffer.raw,
offset,
size,
));
});

offset += size;
}
pso::Descriptor::CombinedImageSampler(view, layout, sampler) => {
match view {
n::ImageView::Texture(tex, _)
| n::ImageView::TextureLayer(tex, _, _) => set
.bindings
.write()
.unwrap()
| n::ImageView::TextureLayer(tex, _, _) =>
bindings
.push(n::DescSetBindings::Texture(binding, *tex)),
n::ImageView::Surface(_) => unimplemented!(),
}
match sampler {
n::FatSampler::Sampler(sampler) => set.bindings
.write()
.unwrap()
n::FatSampler::Sampler(sampler) =>
bindings
.push(n::DescSetBindings::Sampler(binding, *sampler)),
n::FatSampler::Info(_) => unimplemented!(),
}
Expand Down
78 changes: 30 additions & 48 deletions src/backend/gl/src/native.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::cell::Cell;
use std::cell::{Cell, RefCell};
use std::sync::{Arc, RwLock};

use hal::{format, image as i, pass, pso};
Expand All @@ -17,8 +17,6 @@ pub type FrameBuffer = gl::types::GLuint;
pub type Surface = gl::types::GLuint;
pub type Texture = gl::types::GLuint;
pub type Sampler = gl::types::GLuint;
pub(crate) type SetID = gl::types::GLuint;
pub(crate) type BindingID = gl::types::GLuint;

pub const DEFAULT_FRAMEBUFFER: FrameBuffer = 0;

Expand All @@ -44,7 +42,7 @@ impl Fence {
}

#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub(crate) enum BindingTypes {
pub enum BindingTypes {
UniformBuffers,
StorageBuffers,
StorageImages,
Expand All @@ -55,63 +53,41 @@ pub(crate) enum BindingTypes {
}

#[derive(Clone, Debug)]
pub(crate) struct DescRemapData {
bindings: HashMap<BindingTypes, HashMap<SetID, HashMap<BindingID, BindingID>>>,
names: HashMap<String, (BindingTypes, SetID, BindingID)>,
next_binding: BindingID,
pub struct DescRemapData {
bindings: HashMap<(BindingTypes, pso::DescriptorSetIndex, pso::DescriptorBinding), pso::DescriptorBinding>,
names: HashMap<String, (BindingTypes, pso::DescriptorSetIndex, pso::DescriptorBinding)>,
next_binding: pso::DescriptorBinding,
}

/// Stores where the descriptor bindings have been remaped too.
///
/// OpenGL doesn't support sets, so we have to flatten out the bindings.
impl DescRemapData {
pub(crate) fn new() -> Self {
pub fn new() -> Self {
DescRemapData {
bindings: HashMap::new(),
names: HashMap::new(),
next_binding: 0,
}
}

pub(crate) fn get_binding_insert(&mut self, btype: BindingTypes, set: SetID, binding: BindingID) -> BindingID {
if !self.bindings.contains_key(&btype) {
self.bindings.insert(btype, HashMap::new());
}

let bindings = self.bindings.get_mut(&btype).unwrap();
if !bindings.contains_key(&set) {
bindings.insert(set, HashMap::new());
}

let set_map = bindings.get_mut(&set).unwrap();
if !set_map.contains_key(&binding) {
set_map.insert(binding, self.next_binding);
self.next_binding += 1;
}

*set_map.get(&binding).unwrap()
pub fn insert_missing_binding(&mut self, btype: BindingTypes, set: pso::DescriptorSetIndex, binding: pso::DescriptorBinding) -> pso::DescriptorBinding {
let nb = &mut self.next_binding;
*self.bindings.entry((btype, set, binding)).or_insert_with(|| {
*nb += 1;
*nb - 1
})
}

pub(crate) fn get_binding(&self, btype: BindingTypes, set: SetID, binding: BindingID) -> Option<&BindingID> {
if !self.bindings.contains_key(&btype) {
return None
}

let bindings = self.bindings.get(&btype).unwrap();
if !bindings.contains_key(&set) {
return None
}

let set_map = bindings.get(&set).unwrap();
if !set_map.contains_key(&binding) {
return None
}

set_map.get(&binding)
pub fn get_binding(&self, btype: BindingTypes, set: pso::DescriptorSetIndex, binding: pso::DescriptorBinding) -> Option<&pso::DescriptorBinding> {
self.bindings.get(&(btype, set, binding))
}

pub(crate) fn associate_name(&mut self, name: String, btype: BindingTypes, set: SetID, binding: BindingID) {
pub fn associate_name(&mut self, name: String, btype: BindingTypes, set: pso::DescriptorSetIndex, binding: pso::DescriptorBinding) {
self.names.insert(name, (btype, set, binding));
}

pub(crate) fn get_names_and_data(&self) -> hash_map::Iter<String, (BindingTypes, SetID, BindingID)> {
pub fn get_names_and_data(&self) -> hash_map::Iter<String, (BindingTypes, pso::DescriptorSetIndex, pso::DescriptorBinding)> {
self.names.iter()
}
}
Expand Down Expand Up @@ -161,15 +137,21 @@ pub enum ImageView {

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub(crate) enum DescSetBindings {
Buffer(BindingTypes, BindingID, RawBuffer, gl::types::GLintptr, gl::types::GLsizeiptr),
Texture(BindingID, Texture),
Sampler(BindingID, Sampler),
Buffer {
ty: BindingTypes,
binding: pso::DescriptorBinding,
buffer: RawBuffer,
offset: gl::types::GLintptr,
size: gl::types::GLsizeiptr
},
Texture(pso::DescriptorBinding, Texture),
Sampler(pso::DescriptorBinding, Sampler),
}

#[derive(Clone, Debug)]
pub struct DescriptorSet {
layout: Vec<pso::DescriptorSetLayoutBinding>,
pub(crate) bindings: Arc<RwLock<Vec<DescSetBindings>>>,
pub(crate) bindings: RefCell<Vec<DescSetBindings>>,
}

#[derive(Debug)]
Expand Down

0 comments on commit 1c070cb

Please sign in to comment.