mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-25 00:41:07 +01:00
hal/gles: present, texture format caps
This commit is contained in:
1 parent
91f9806831
commit
24ff58c6c1
5 files changed
+151
-18
No files matched your search
@@ -304,7 +304,85 @@ impl crate::Adapter<super::Api> for super::Adapter {
|
||||
&self,
|
||||
format: wgt::TextureFormat,
|
||||
) -> crate::TextureFormatCapability {
|
||||
crate::TextureFormatCapability::empty() //TODO
|
||||
use crate::TextureFormatCapability as Tfc;
|
||||
use wgt::TextureFormat as Tf;
|
||||
// The storage types are sprinkled based on section
|
||||
// "TEXTURE IMAGE LOADS AND STORES" of GLES-3.2 spec.
|
||||
let unfiltered_color = Tfc::SAMPLED | Tfc::COLOR_ATTACHMENT;
|
||||
let filtered_color = unfiltered_color | Tfc::SAMPLED_LINEAR | Tfc::COLOR_ATTACHMENT_BLEND;
|
||||
match format {
|
||||
Tf::R8Unorm | Tf::R8Snorm => filtered_color,
|
||||
Tf::R8Uint | Tf::R8Sint | Tf::R16Uint | Tf::R16Sint => unfiltered_color,
|
||||
Tf::R16Float | Tf::Rg8Unorm | Tf::Rg8Snorm => filtered_color,
|
||||
Tf::Rg8Uint | Tf::Rg8Sint | Tf::R32Uint | Tf::R32Sint => {
|
||||
unfiltered_color | Tfc::STORAGE
|
||||
}
|
||||
Tf::R32Float => unfiltered_color,
|
||||
Tf::Rg16Uint | Tf::Rg16Sint => unfiltered_color,
|
||||
Tf::Rg16Float | Tf::Rgba8Unorm | Tf::Rgba8UnormSrgb => filtered_color | Tfc::STORAGE,
|
||||
Tf::Bgra8UnormSrgb | Tf::Rgba8Snorm | Tf::Bgra8Unorm => filtered_color,
|
||||
Tf::Rgba8Uint | Tf::Rgba8Sint => unfiltered_color | Tfc::STORAGE,
|
||||
Tf::Rgb10a2Unorm | Tf::Rg11b10Float => filtered_color,
|
||||
Tf::Rg32Uint | Tf::Rg32Sint => unfiltered_color,
|
||||
Tf::Rg32Float => unfiltered_color | Tfc::STORAGE,
|
||||
Tf::Rgba16Uint | Tf::Rgba16Sint => unfiltered_color | Tfc::STORAGE,
|
||||
Tf::Rgba16Float => filtered_color | Tfc::STORAGE,
|
||||
Tf::Rgba32Uint | Tf::Rgba32Sint => unfiltered_color | Tfc::STORAGE,
|
||||
Tf::Rgba32Float => unfiltered_color | Tfc::STORAGE,
|
||||
Tf::Depth32Float => Tfc::SAMPLED | Tfc::DEPTH_STENCIL_ATTACHMENT,
|
||||
Tf::Depth24Plus => Tfc::SAMPLED | Tfc::DEPTH_STENCIL_ATTACHMENT,
|
||||
Tf::Depth24PlusStencil8 => Tfc::SAMPLED | Tfc::DEPTH_STENCIL_ATTACHMENT,
|
||||
Tf::Bc1RgbaUnorm
|
||||
| Tf::Bc1RgbaUnormSrgb
|
||||
| Tf::Bc2RgbaUnorm
|
||||
| Tf::Bc2RgbaUnormSrgb
|
||||
| Tf::Bc3RgbaUnorm
|
||||
| Tf::Bc3RgbaUnormSrgb
|
||||
| Tf::Bc4RUnorm
|
||||
| Tf::Bc4RSnorm
|
||||
| Tf::Bc5RgUnorm
|
||||
| Tf::Bc5RgSnorm
|
||||
| Tf::Bc6hRgbSfloat
|
||||
| Tf::Bc6hRgbUfloat
|
||||
| Tf::Bc7RgbaUnorm
|
||||
| Tf::Bc7RgbaUnormSrgb
|
||||
| Tf::Etc2RgbUnorm
|
||||
| Tf::Etc2RgbUnormSrgb
|
||||
| Tf::Etc2RgbA1Unorm
|
||||
| Tf::Etc2RgbA1UnormSrgb
|
||||
| Tf::EacRUnorm
|
||||
| Tf::EacRSnorm
|
||||
| Tf::EtcRgUnorm
|
||||
| Tf::EtcRgSnorm
|
||||
| Tf::Astc4x4RgbaUnorm
|
||||
| Tf::Astc4x4RgbaUnormSrgb
|
||||
| Tf::Astc5x4RgbaUnorm
|
||||
| Tf::Astc5x4RgbaUnormSrgb
|
||||
| Tf::Astc5x5RgbaUnorm
|
||||
| Tf::Astc5x5RgbaUnormSrgb
|
||||
| Tf::Astc6x5RgbaUnorm
|
||||
| Tf::Astc6x5RgbaUnormSrgb
|
||||
| Tf::Astc6x6RgbaUnorm
|
||||
| Tf::Astc6x6RgbaUnormSrgb
|
||||
| Tf::Astc8x5RgbaUnorm
|
||||
| Tf::Astc8x5RgbaUnormSrgb
|
||||
| Tf::Astc8x6RgbaUnorm
|
||||
| Tf::Astc8x6RgbaUnormSrgb
|
||||
| Tf::Astc10x5RgbaUnorm
|
||||
| Tf::Astc10x5RgbaUnormSrgb
|
||||
| Tf::Astc10x6RgbaUnorm
|
||||
| Tf::Astc10x6RgbaUnormSrgb
|
||||
| Tf::Astc8x8RgbaUnorm
|
||||
| Tf::Astc8x8RgbaUnormSrgb
|
||||
| Tf::Astc10x8RgbaUnorm
|
||||
| Tf::Astc10x8RgbaUnormSrgb
|
||||
| Tf::Astc10x10RgbaUnorm
|
||||
| Tf::Astc10x10RgbaUnormSrgb
|
||||
| Tf::Astc12x10RgbaUnorm
|
||||
| Tf::Astc12x10RgbaUnormSrgb
|
||||
| Tf::Astc12x12RgbaUnorm
|
||||
| Tf::Astc12x12RgbaUnormSrgb => Tfc::SAMPLED | Tfc::SAMPLED_LINEAR,
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn surface_capabilities(
|
||||
|
||||
+17
-15
@@ -41,16 +41,18 @@ impl CompilationContext<'_> {
|
||||
}
|
||||
|
||||
for (name, mapping) in reflection_info.texture_mapping {
|
||||
let tex_br = module.global_variables[mapping.texture]
|
||||
.binding
|
||||
.as_ref()
|
||||
.unwrap();
|
||||
let var = &module.global_variables[mapping.texture];
|
||||
let register = if var.storage_access.is_empty() {
|
||||
super::BindingRegister::Textures
|
||||
} else {
|
||||
super::BindingRegister::Images
|
||||
};
|
||||
|
||||
let tex_br = var.binding.as_ref().unwrap();
|
||||
let texture_linear_index = self.layout.get_slot(tex_br);
|
||||
|
||||
self.name_binding_map.insert(
|
||||
name,
|
||||
(super::BindingRegister::Textures, texture_linear_index),
|
||||
);
|
||||
self.name_binding_map
|
||||
.insert(name, (register, texture_linear_index));
|
||||
if let Some(sampler_handle) = mapping.sampler {
|
||||
let sam_br = module.global_variables[sampler_handle]
|
||||
.binding
|
||||
@@ -205,10 +207,6 @@ impl super::Device {
|
||||
for (ref name, (register, slot)) in name_binding_map {
|
||||
log::trace!("Get binding {:?} from program {:?}", name, program);
|
||||
match register {
|
||||
super::BindingRegister::Textures => {
|
||||
let loc = gl.get_uniform_location(program, name).unwrap();
|
||||
gl.uniform_1_i32(Some(&loc), slot as _);
|
||||
}
|
||||
super::BindingRegister::UniformBuffers => {
|
||||
let index = gl.get_uniform_block_index(program, name).unwrap();
|
||||
gl.uniform_block_binding(program, index, slot as _);
|
||||
@@ -217,6 +215,10 @@ impl super::Device {
|
||||
let index = gl.get_shader_storage_block_index(program, name).unwrap();
|
||||
gl.shader_storage_block_binding(program, index, slot as _);
|
||||
}
|
||||
super::BindingRegister::Textures | super::BindingRegister::Images => {
|
||||
let loc = gl.get_uniform_location(program, name).unwrap();
|
||||
gl.uniform_1_i32(Some(&loc), slot as _);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -536,6 +538,7 @@ impl crate::Device<super::Api> for super::Device {
|
||||
let mut group_infos = Vec::with_capacity(desc.bind_group_layouts.len());
|
||||
let mut num_samplers = 0u8;
|
||||
let mut num_textures = 0u8;
|
||||
let mut num_images = 0u8;
|
||||
let mut num_uniform_buffers = 0u8;
|
||||
let mut num_storage_buffers = 0u8;
|
||||
|
||||
@@ -553,9 +556,8 @@ impl crate::Device<super::Api> for super::Device {
|
||||
for entry in bg_layout.entries.iter() {
|
||||
let counter = match entry.ty {
|
||||
wgt::BindingType::Sampler { .. } => &mut num_samplers,
|
||||
wgt::BindingType::Texture { .. } | wgt::BindingType::StorageTexture { .. } => {
|
||||
&mut num_textures
|
||||
}
|
||||
wgt::BindingType::Texture { .. } => &mut num_textures,
|
||||
wgt::BindingType::StorageTexture { .. } => &mut num_images,
|
||||
wgt::BindingType::Buffer {
|
||||
ty: wgt::BufferBindingType::Uniform,
|
||||
..
|
||||
|
||||
@@ -560,6 +560,57 @@ pub struct Surface {
|
||||
unsafe impl Send for Surface {}
|
||||
unsafe impl Sync for Surface {}
|
||||
|
||||
impl Surface {
|
||||
pub(super) unsafe fn present(
|
||||
&mut self,
|
||||
_suf_texture: super::Texture,
|
||||
gl: &glow::Context,
|
||||
) -> Result<(), crate::SurfaceError> {
|
||||
let sc = self.swapchain.as_ref().unwrap();
|
||||
|
||||
self.egl
|
||||
.make_current(
|
||||
self.display,
|
||||
Some(self.raw),
|
||||
Some(self.raw),
|
||||
Some(self.context),
|
||||
)
|
||||
.map_err(|e| {
|
||||
log::error!("make_current(surface) failed: {}", e);
|
||||
crate::SurfaceError::Lost
|
||||
})?;
|
||||
|
||||
gl.bind_framebuffer(glow::DRAW_FRAMEBUFFER, None);
|
||||
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(sc.framebuffer));
|
||||
gl.blit_framebuffer(
|
||||
0,
|
||||
0,
|
||||
sc.extent.width as i32,
|
||||
sc.extent.height as i32,
|
||||
0,
|
||||
0,
|
||||
sc.extent.width as i32,
|
||||
sc.extent.height as i32,
|
||||
glow::COLOR_BUFFER_BIT,
|
||||
glow::NEAREST,
|
||||
);
|
||||
gl.bind_framebuffer(glow::READ_FRAMEBUFFER, None);
|
||||
|
||||
self.egl.swap_buffers(self.display, self.raw).map_err(|e| {
|
||||
log::error!("swap_buffers failed: {}", e);
|
||||
crate::SurfaceError::Lost
|
||||
})?;
|
||||
self.egl
|
||||
.make_current(self.display, self.pbuffer, self.pbuffer, Some(self.context))
|
||||
.map_err(|e| {
|
||||
log::error!("make_current(null) failed: {}", e);
|
||||
crate::SurfaceError::Lost
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Surface<super::Api> for Surface {
|
||||
unsafe fn configure(
|
||||
&mut self,
|
||||
|
||||
@@ -266,9 +266,10 @@ impl PipelineLayout {
|
||||
|
||||
#[derive(Debug)]
|
||||
enum BindingRegister {
|
||||
Textures,
|
||||
UniformBuffers,
|
||||
StorageBuffers,
|
||||
Textures,
|
||||
Images,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -341,6 +341,7 @@ impl crate::Queue<super::Api> for super::Queue {
|
||||
surface: &mut super::Surface,
|
||||
texture: super::Texture,
|
||||
) -> Result<(), crate::SurfaceError> {
|
||||
Ok(())
|
||||
let gl = &self.shared.context;
|
||||
surface.present(texture, gl)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user