Skip to content

Commit f03b110

Browse files
committed
[vk] descriptor layout init
1 parent 2f1891c commit f03b110

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ gfx_window_dxgi = { path = "src/window/dxgi", version = "0.2" }
4040
gfx_device_dx11 = { path = "src/backend/dx11", version = "0.2" }
4141
gfx_window_dxgi = { path = "src/window/dxgi", version = "0.2" }
4242

43-
[[example]]
44-
name = "vk"
45-
4643
[[example]]
4744
name = "blend"
4845
path = "examples/blend/main.rs"

examples/triangle/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#[macro_use]
1616
extern crate gfx;
1717
extern crate gfx_window_glutin;
18-
extern crate gfx_device_gl;
1918
extern crate glutin;
2019

2120
use gfx::traits::FactoryExt;

src/backend/gl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl d::Resources for Resources {
7777

7878
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
7979
pub struct BufferElement {
80-
pub desc: d::pso::BufferDesc,
80+
pub desc: d::pso::VertexBufferDesc,
8181
pub elem: d::pso::Element<d::format::Format>,
8282
}
8383

src/backend/vulkan/src/data.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use gfx_core::factory::{Bind, MapAccess, Usage, LayerError};
1616
use gfx_core::format::{SurfaceType, ChannelType, Swizzle, ChannelSource};
1717
use gfx_core::pso::ColorInfo;
1818
use gfx_core::tex::{FilterMethod, Kind, Layer, PackedColor, WrapMode};
19-
use gfx_core::{state, Primitive};
19+
use gfx_core::{shade, state, Primitive};
2020
use vk;
2121

2222

@@ -410,3 +410,9 @@ pub fn map_blend(ci: &ColorInfo) -> vk::PipelineColorBlendAttachmentState {
410410
if ci.mask.contains(state::ALPHA) {vk::COLOR_COMPONENT_A_BIT} else {0},
411411
}
412412
}
413+
414+
pub fn map_stage(usage: shade::Usage) -> vk::ShaderStageFlags {
415+
(if usage.contains(shade::VERTEX) { vk::SHADER_STAGE_VERTEX_BIT } else { 0 }) |
416+
(if usage.contains(shade::GEOMETRY) { vk::SHADER_STAGE_GEOMETRY_BIT } else { 0 }) |
417+
(if usage.contains(shade::PIXEL) { vk::SHADER_STAGE_FRAGMENT_BIT } else { 0 })
418+
}

src/backend/vulkan/src/factory.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,57 @@ impl core::Factory<R> for Factory {
393393
let (dev, vk) = self.share.get_device();
394394

395395
let set_layout = {
396+
let mut bindings = Vec::new();
397+
for (i, cb) in desc.constant_buffers.iter().enumerate() {
398+
if let &Some(usage) = cb {
399+
bindings.push(vk::DescriptorSetLayoutBinding {
400+
binding: i as u32,
401+
descriptorType: vk::DESCRIPTOR_TYPE_UNIFORM_BUFFER,
402+
descriptorCount: 1,
403+
stageFlags: data::map_stage(usage),
404+
pImmutableSamplers: ptr::null(),
405+
});
406+
}
407+
}
408+
for (i, srv) in desc.resource_views.iter().enumerate() {
409+
if let &Some(usage) = srv {
410+
bindings.push(vk::DescriptorSetLayoutBinding {
411+
binding: i as u32,
412+
descriptorType: vk::DESCRIPTOR_TYPE_SAMPLED_IMAGE,
413+
descriptorCount: 1,
414+
stageFlags: data::map_stage(usage),
415+
pImmutableSamplers: ptr::null(),
416+
});
417+
}
418+
}
419+
for (i, uav) in desc.unordered_views.iter().enumerate() {
420+
if let &Some(usage) = uav {
421+
bindings.push(vk::DescriptorSetLayoutBinding {
422+
binding: i as u32,
423+
descriptorType: vk::DESCRIPTOR_TYPE_STORAGE_IMAGE, //TODO: buffer views
424+
descriptorCount: 1,
425+
stageFlags: data::map_stage(usage),
426+
pImmutableSamplers: ptr::null(),
427+
});
428+
}
429+
}
430+
for (i, sam) in desc.samplers.iter().enumerate() {
431+
if let &Some(usage) = sam {
432+
bindings.push(vk::DescriptorSetLayoutBinding {
433+
binding: i as u32,
434+
descriptorType: vk::DESCRIPTOR_TYPE_SAMPLER,
435+
descriptorCount: 1,
436+
stageFlags: data::map_stage(usage),
437+
pImmutableSamplers: ptr::null(),
438+
});
439+
}
440+
}
396441
let info = vk::DescriptorSetLayoutCreateInfo {
397442
sType: vk::STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
398443
pNext: ptr::null(),
399444
flags: 0,
400-
bindingCount: 0,
401-
pBindings: ptr::null(), //TODO
445+
bindingCount: bindings.len() as u32,
446+
pBindings: bindings.as_ptr(),
402447
};
403448
let mut out = 0;
404449
assert_eq!(vk::SUCCESS, unsafe {

0 commit comments

Comments
 (0)