Skip to content

Commit

Permalink
Support Limits::max_bind_groups (gfx-rs#348)
Browse files Browse the repository at this point in the history
* Pass max_bind_count down into Binder.
* Use the existing hub.
* Remove accidental newline.
  • Loading branch information
terrence2 authored and kvark committed Oct 15, 2019
1 parent 5ba923c commit 78fbbba
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wgpu-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ raw-window-handle = "0.3"
rendy-memory = { git = "https://github.com/amethyst/rendy", rev = "e8ffcabc2bc74fbb282d4f71fa55c28d0ec31c86" }
rendy-descriptor = { git = "https://github.com/amethyst/rendy", rev = "e8ffcabc2bc74fbb282d4f71fa55c28d0ec31c86" }
serde = { version = "1.0", features = ["serde_derive"], optional = true }
smallvec = "0.6"
vec_map = "0.8"

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
Expand Down
18 changes: 13 additions & 5 deletions wgpu-native/src/command/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ use crate::{
};

use log::trace;
use smallvec::{smallvec, SmallVec};

use std::convert::identity;

pub const MAX_BIND_GROUPS: usize = 4;
pub const DEFAULT_BIND_GROUPS: usize = 4;
type BindGroupMask = u8;

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct BindGroupPair {
layout_id: BindGroupLayoutId,
group_id: Stored<BindGroupId>,
Expand Down Expand Up @@ -53,7 +54,7 @@ where
}
}

#[derive(Default, Debug)]
#[derive(Clone, Default, Debug)]
pub struct BindGroupEntry {
expected_layout_id: Option<BindGroupLayoutId>,
provided: Option<BindGroupPair>,
Expand Down Expand Up @@ -140,10 +141,17 @@ impl BindGroupEntry {
#[derive(Default, Debug)]
pub struct Binder {
pub(crate) pipeline_layout_id: Option<PipelineLayoutId>, //TODO: strongly `Stored`
pub(crate) entries: [BindGroupEntry; MAX_BIND_GROUPS],
pub(crate) entries: SmallVec<[BindGroupEntry; DEFAULT_BIND_GROUPS]>,
}

impl Binder {
pub(crate) fn new(max_bind_groups: u32) -> Self {
Self {
pipeline_layout_id: None,
entries: smallvec![Default::default(); max_bind_groups as usize]
}
}

pub(crate) fn reset_expectations(&mut self, length: usize) {
for entry in self.entries[length ..].iter_mut() {
entry.expected_layout_id = None;
Expand Down Expand Up @@ -175,7 +183,7 @@ impl Binder {
let compatible_count = self.compatible_count();
if index < compatible_count {
let end = compatible_count
.min(if was_compatible { index + 1 } else { MAX_BIND_GROUPS });
.min(if was_compatible { index + 1 } else { self.entries.len() });
trace!("\t\tbinding up to {}", end);
Some((
self.pipeline_layout_id?,
Expand Down
1 change: 1 addition & 0 deletions wgpu-native/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ pub fn command_encoder_begin_render_pass<B: GfxBackend>(
},
context,
sample_count,
cmb.features.max_bind_groups,
)
};
hub.render_passes.register_identity(id_in, pass, &mut token)
Expand Down
3 changes: 2 additions & 1 deletion wgpu-native/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ impl<B: GfxBackend> RenderPass<B> {
cmb_id: Stored<CommandBufferId>,
context: RenderPassContext,
sample_count: u8,
max_bind_groups: u32,
) -> Self {
RenderPass {
raw,
cmb_id,
context,
binder: Binder::default(),
binder: Binder::new(max_bind_groups),
trackers: TrackerSet::new(B::VARIANT),
blend_color_status: OptionalState::Unused,
stencil_reference_status: OptionalState::Unused,
Expand Down
2 changes: 2 additions & 0 deletions wgpu-native/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ impl<B: GfxBackend> Device<B> {
queue_group: hal::queue::QueueGroup<B>,
mem_props: hal::adapter::MemoryProperties,
supports_texture_d24_s8: bool,
max_bind_groups: u32,
) -> Self {
// don't start submission index at zero
let life_guard = LifeGuard::new();
Expand Down Expand Up @@ -559,6 +560,7 @@ impl<B: GfxBackend> Device<B> {
ready_to_map: Vec::new(),
}),
features: Features {
max_bind_groups,
supports_texture_d24_s8,
}
}
Expand Down
7 changes: 6 additions & 1 deletion wgpu-native/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ pub extern "C" fn wgpu_request_adapter(desc: Option<&RequestAdapterOptions>) ->

pub fn adapter_request_device<B: GfxBackend>(
adapter_id: AdapterId,
_desc: &DeviceDescriptor,
desc: &DeviceDescriptor,
id_in: Input<DeviceId>,
) -> Output<DeviceId> {
let hub = B::hub();
Expand Down Expand Up @@ -462,6 +462,10 @@ pub fn adapter_request_device<B: GfxBackend>(
BIND_BUFFER_ALIGNMENT % limits.min_uniform_buffer_offset_alignment,
"Adapter uniform buffer offset alignment not compatible with WGPU"
);
assert!(
u32::from(limits.max_bound_descriptor_sets) >= desc.limits.max_bind_groups,
"Adapter does not support the requested max_bind_groups"
);

let mem_props = adapter.physical_device.memory_properties();

Expand All @@ -477,6 +481,7 @@ pub fn adapter_request_device<B: GfxBackend>(
gpu.queue_groups.swap_remove(0),
mem_props,
supports_texture_d24_s8,
desc.limits.max_bind_groups,
)
};

Expand Down
1 change: 1 addition & 0 deletions wgpu-native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,6 @@ macro_rules! gfx_select {

#[derive(Clone, Copy, Debug)]
pub(crate) struct Features {
pub max_bind_groups: u32,
pub supports_texture_d24_s8: bool,
}

0 comments on commit 78fbbba

Please sign in to comment.