mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 01:23:57 +01:00
hal/gles: storage texture bindings
This commit is contained in:
1 parent
673ec60396
commit
c7356e124e
7 files changed
+97
-12
No files matched your search
@@ -190,6 +190,8 @@ impl super::Adapter {
|
||||
| wgt::DownlevelFlags::CUBE_ARRAY_TEXTURES
|
||||
| wgt::DownlevelFlags::COMPARISON_SAMPLERS;
|
||||
downlevel_flags.set(wgt::DownlevelFlags::COMPUTE_SHADERS, ver >= (3, 1));
|
||||
//Note: storage textures aren't supported atm, only buffers. See
|
||||
// https://github.com/grovesNL/glow/issues/174
|
||||
downlevel_flags.set(
|
||||
wgt::DownlevelFlags::FRAGMENT_WRITABLE_STORAGE,
|
||||
ver >= (3, 1),
|
||||
|
||||
@@ -495,6 +495,10 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
|
||||
size,
|
||||
});
|
||||
}
|
||||
super::RawBinding::Sampler(sampler) => {
|
||||
dirty_samplers |= 1 << slot;
|
||||
self.state.samplers[slot as usize] = Some(sampler);
|
||||
}
|
||||
super::RawBinding::Texture { raw, target } => {
|
||||
dirty_textures |= 1 << slot;
|
||||
self.state.texture_slots[slot as usize].tex_target = target;
|
||||
@@ -504,9 +508,11 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
|
||||
target,
|
||||
});
|
||||
}
|
||||
super::RawBinding::Sampler(sampler) => {
|
||||
dirty_samplers |= 1 << slot;
|
||||
self.state.samplers[slot as usize] = Some(sampler);
|
||||
super::RawBinding::Image(ref binding) => {
|
||||
self.cmd_buffer.commands.push(C::BindImage {
|
||||
slot,
|
||||
binding: binding.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,3 +313,11 @@ pub(super) fn map_blend(blend: &wgt::BlendState) -> super::BlendDesc {
|
||||
alpha: map_blend_component(&blend.alpha),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn map_storage_access(access: wgt::StorageTextureAccess) -> u32 {
|
||||
match access {
|
||||
wgt::StorageTextureAccess::ReadOnly => glow::READ_ONLY,
|
||||
wgt::StorageTextureAccess::WriteOnly => glow::WRITE_ONLY,
|
||||
wgt::StorageTextureAccess::ReadWrite => glow::READ_WRITE,
|
||||
}
|
||||
}
|
||||
@@ -455,6 +455,12 @@ impl crate::Device<super::Api> for super::Device {
|
||||
|
||||
Ok(super::Texture {
|
||||
inner,
|
||||
mip_level_count: desc.mip_level_count,
|
||||
array_layer_count: if desc.dimension == wgt::TextureDimension::D2 {
|
||||
desc.size.depth_or_array_layers
|
||||
} else {
|
||||
1
|
||||
},
|
||||
format: desc.format,
|
||||
format_desc,
|
||||
})
|
||||
@@ -476,6 +482,14 @@ impl crate::Device<super::Api> for super::Device {
|
||||
texture: &super::Texture,
|
||||
desc: &crate::TextureViewDescriptor,
|
||||
) -> Result<super::TextureView, crate::DeviceError> {
|
||||
let end_array_layer = match desc.range.array_layer_count {
|
||||
Some(count) => desc.range.base_array_layer + count.get(),
|
||||
None => texture.array_layer_count,
|
||||
};
|
||||
let end_mip_level = match desc.range.mip_level_count {
|
||||
Some(count) => desc.range.base_mip_level + count.get(),
|
||||
None => texture.mip_level_count,
|
||||
};
|
||||
Ok(super::TextureView {
|
||||
inner: match texture.inner {
|
||||
super::TextureInner::Renderbuffer { raw } => {
|
||||
@@ -489,8 +503,8 @@ impl crate::Device<super::Api> for super::Device {
|
||||
sample_type: texture.format.describe().sample_type,
|
||||
aspects: crate::FormatAspect::from(texture.format)
|
||||
& crate::FormatAspect::from(desc.range.aspect),
|
||||
base_mip_level: desc.range.base_mip_level,
|
||||
base_array_layer: desc.range.base_array_layer,
|
||||
mip_levels: desc.range.base_mip_level..end_mip_level,
|
||||
array_layers: desc.range.base_array_layer..end_array_layer,
|
||||
})
|
||||
}
|
||||
unsafe fn destroy_texture_view(&self, _view: super::TextureView) {}
|
||||
@@ -610,8 +624,9 @@ impl crate::Device<super::Api> for super::Device {
|
||||
let sampler = desc.samplers[entry.resource_index as usize];
|
||||
super::RawBinding::Sampler(sampler.raw)
|
||||
}
|
||||
wgt::BindingType::Texture { .. } | wgt::BindingType::StorageTexture { .. } => {
|
||||
match desc.textures[entry.resource_index as usize].view.inner {
|
||||
wgt::BindingType::Texture { .. } => {
|
||||
let view = desc.textures[entry.resource_index as usize].view;
|
||||
match view.inner {
|
||||
super::TextureInner::Renderbuffer { .. } => {
|
||||
panic!("Unable to use a renderbuffer in a group")
|
||||
}
|
||||
@@ -620,6 +635,32 @@ impl crate::Device<super::Api> for super::Device {
|
||||
}
|
||||
}
|
||||
}
|
||||
wgt::BindingType::StorageTexture {
|
||||
access,
|
||||
format,
|
||||
view_dimension,
|
||||
} => {
|
||||
let view = desc.textures[entry.resource_index as usize].view;
|
||||
let format_desc = self.shared.describe_texture_format(format);
|
||||
match view.inner {
|
||||
super::TextureInner::Renderbuffer { .. } => {
|
||||
panic!("Unable to use a renderbuffer in a group")
|
||||
}
|
||||
super::TextureInner::Texture { raw, .. } => {
|
||||
super::RawBinding::Image(super::ImageBinding {
|
||||
raw,
|
||||
mip_level: view.mip_levels.start,
|
||||
array_layer: match view_dimension {
|
||||
wgt::TextureViewDimension::D2Array
|
||||
| wgt::TextureViewDimension::CubeArray => None,
|
||||
_ => Some(view.array_layers.start),
|
||||
},
|
||||
access: conv::map_storage_access(access),
|
||||
format: format_desc.internal,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
contents.push(binding);
|
||||
}
|
||||
|
||||
@@ -683,6 +683,8 @@ impl crate::Surface<super::Api> for Surface {
|
||||
inner: super::TextureInner::Renderbuffer {
|
||||
raw: sc.renderbuffer,
|
||||
},
|
||||
array_layer_count: 1,
|
||||
mip_level_count: 1,
|
||||
format: sc.format,
|
||||
format_desc: sc.format_desc.clone(),
|
||||
};
|
||||
|
||||
@@ -224,6 +224,8 @@ impl TextureInner {
|
||||
#[derive(Debug)]
|
||||
pub struct Texture {
|
||||
inner: TextureInner,
|
||||
mip_level_count: u32,
|
||||
array_layer_count: u32,
|
||||
format: wgt::TextureFormat,
|
||||
format_desc: TextureFormatDesc,
|
||||
}
|
||||
@@ -233,8 +235,8 @@ pub struct TextureView {
|
||||
inner: TextureInner,
|
||||
sample_type: wgt::TextureSampleType,
|
||||
aspects: crate::FormatAspect,
|
||||
base_mip_level: u32,
|
||||
base_array_layer: u32,
|
||||
mip_levels: Range<u32>,
|
||||
array_layers: Range<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -285,7 +287,9 @@ enum RawBinding {
|
||||
Texture {
|
||||
raw: glow::Texture,
|
||||
target: BindTarget,
|
||||
//TODO: mip levels, array layers
|
||||
},
|
||||
Image(ImageBinding),
|
||||
Sampler(glow::Sampler),
|
||||
}
|
||||
|
||||
@@ -320,6 +324,15 @@ struct BufferBinding {
|
||||
offset: wgt::BufferAddress,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct ImageBinding {
|
||||
raw: glow::Texture,
|
||||
mip_level: u32,
|
||||
array_layer: Option<u32>,
|
||||
access: u32,
|
||||
format: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct VertexBufferDesc {
|
||||
step: wgt::InputStepMode,
|
||||
@@ -607,6 +620,10 @@ enum Command {
|
||||
texture: glow::Texture,
|
||||
target: BindTarget,
|
||||
},
|
||||
BindImage {
|
||||
slot: u32,
|
||||
binding: ImageBinding,
|
||||
},
|
||||
InsertDebugMarker(Range<u32>),
|
||||
PushDebugGroup(Range<u32>),
|
||||
PopDebugGroup,
|
||||
|
||||
@@ -346,8 +346,8 @@ impl super::Queue {
|
||||
glow::DRAW_FRAMEBUFFER,
|
||||
attachment,
|
||||
Some(raw),
|
||||
view.base_mip_level as i32,
|
||||
view.base_array_layer as i32,
|
||||
view.mip_levels.start as i32,
|
||||
view.array_layers.start as i32,
|
||||
);
|
||||
} else {
|
||||
gl.framebuffer_texture_2d(
|
||||
@@ -355,7 +355,7 @@ impl super::Queue {
|
||||
attachment,
|
||||
target,
|
||||
Some(raw),
|
||||
view.base_mip_level as i32,
|
||||
view.mip_levels.start as i32,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -602,6 +602,15 @@ impl super::Queue {
|
||||
gl.active_texture(glow::TEXTURE0 + slot);
|
||||
gl.bind_texture(target, Some(texture));
|
||||
}
|
||||
C::BindImage {
|
||||
slot: _,
|
||||
binding: _,
|
||||
} => {
|
||||
//TODO: https://github.com/grovesNL/glow/issues/174
|
||||
//gl.bind_image_texture(slot, Some(binding.raw), binding.mip_level as i32,
|
||||
// binding.array_layer.is_none(), binding.array_layer.unwrap_or_default(),
|
||||
// binding.access, binding.format);
|
||||
}
|
||||
C::InsertDebugMarker(ref range) => {
|
||||
let marker = extract_marker(data_bytes, range);
|
||||
gl.debug_message_insert(
|
||||
|
||||
Reference in new issue
Block a user