Implement mipmap views on the OpenGL backend (#4278)

This commit is contained in:
Zoxc 2023-11-01 21:57:24 +01:00 committed by GitHub
parent a411861f48
commit 3f80ee785c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 7 deletions

View File

@ -514,8 +514,7 @@ static TEST: wgpu_example::framework::ExampleTestParams =
width: 1024,
height: 768,
optional_features: wgpu::Features::default(),
base_test_parameters: wgpu_test::TestParameters::default()
.expect_fail(wgpu_test::FailureCase::backend(wgpu::Backends::GL)),
base_test_parameters: wgpu_test::TestParameters::default(),
comparisons: &[wgpu_test::ComparisonType::Mean(0.02)],
_phantom: std::marker::PhantomData::<Example>,
};
@ -529,8 +528,7 @@ static TEST_QUERY: wgpu_example::framework::ExampleTestParams =
width: 1024,
height: 768,
optional_features: QUERY_FEATURES,
base_test_parameters: wgpu_test::TestParameters::default()
.expect_fail(wgpu_test::FailureCase::backend(wgpu::Backends::GL)),
base_test_parameters: wgpu_test::TestParameters::default(),
comparisons: &[wgpu_test::ComparisonType::Mean(0.025)],
_phantom: std::marker::PhantomData::<Example>,
};

View File

@ -701,6 +701,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
raw,
target,
aspects,
ref mip_levels,
} => {
dirty_textures |= 1 << slot;
self.state.texture_slots[slot as usize].tex_target = target;
@ -709,6 +710,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
texture: raw,
target,
aspects,
mip_levels: mip_levels.clone(),
});
}
super::RawBinding::Image(ref binding) => {

View File

@ -1158,8 +1158,8 @@ impl crate::Device<super::Api> for super::Device {
}
wgt::BindingType::Texture { .. } => {
let view = desc.textures[entry.resource_index as usize].view;
if view.mip_levels.start != 0 || view.array_layers.start != 0 {
log::error!("Unable to create a sampled texture binding for non-zero mipmap level or array layer.\n{}",
if view.array_layers.start != 0 {
log::error!("Unable to create a sampled texture binding for non-zero array layer.\n{}",
"This is an implementation problem of wgpu-hal/gles backend.")
}
let (raw, target) = view.inner.as_native();
@ -1167,6 +1167,7 @@ impl crate::Device<super::Api> for super::Device {
raw,
target,
aspects: view.aspects,
mip_levels: view.mip_levels.clone(),
}
}
wgt::BindingType::StorageTexture {

View File

@ -426,7 +426,8 @@ enum RawBinding {
raw: glow::Texture,
target: BindTarget,
aspects: crate::FormatAspects,
//TODO: mip levels, array layers
mip_levels: Range<u32>,
//TODO: array layers
},
Image(ImageBinding),
Sampler(glow::Sampler),
@ -871,6 +872,7 @@ enum Command {
texture: glow::Texture,
target: BindTarget,
aspects: crate::FormatAspects,
mip_levels: Range<u32>,
},
BindImage {
slot: u32,

View File

@ -127,6 +127,7 @@ impl super::Queue {
};
} else {
unsafe {
assert_eq!(view.mip_levels.len(), 1);
gl.framebuffer_texture_2d(
fbo_target,
attachment,
@ -1346,10 +1347,22 @@ impl super::Queue {
texture,
target,
aspects,
ref mip_levels,
} => {
unsafe { gl.active_texture(glow::TEXTURE0 + slot) };
unsafe { gl.bind_texture(target, Some(texture)) };
unsafe {
gl.tex_parameter_i32(target, glow::TEXTURE_BASE_LEVEL, mip_levels.start as i32)
};
unsafe {
gl.tex_parameter_i32(
target,
glow::TEXTURE_MAX_LEVEL,
(mip_levels.end - 1) as i32,
)
};
let version = gl.version();
let is_min_es_3_1 = version.is_embedded && (version.major, version.minor) >= (3, 1);
let is_min_4_3 = !version.is_embedded && (version.major, version.minor) >= (4, 3);