hal/gles: fix buffer mapping

This commit is contained in:
Dzmitry Malyshau 2021-06-28 23:43:40 -04:00
parent 6025a8d25e
commit 3a796c2244
4 changed files with 31 additions and 38 deletions

View File

@ -306,16 +306,17 @@ impl crate::Device<super::Api> for super::Device {
glow::ARRAY_BUFFER glow::ARRAY_BUFFER
}; };
let mut map_flags = 0; let is_host_visible = desc
if desc
.usage .usage
.intersects(crate::BufferUse::MAP_READ | crate::BufferUse::MAP_WRITE) .intersects(crate::BufferUse::MAP_READ | crate::BufferUse::MAP_WRITE);
{ let is_coherent = desc
.memory_flags
.contains(crate::MemoryFlag::PREFER_COHERENT);
let mut map_flags = 0;
if is_host_visible {
map_flags |= glow::MAP_PERSISTENT_BIT; map_flags |= glow::MAP_PERSISTENT_BIT;
if desc if is_coherent {
.memory_flags
.contains(crate::MemoryFlag::PREFER_COHERENT)
{
map_flags |= glow::MAP_COHERENT_BIT; map_flags |= glow::MAP_COHERENT_BIT;
} }
} }
@ -335,6 +336,11 @@ impl crate::Device<super::Api> for super::Device {
gl.buffer_storage(target, raw_size, None, map_flags); gl.buffer_storage(target, raw_size, None, map_flags);
gl.bind_buffer(target, None); gl.bind_buffer(target, None);
if !is_coherent && desc.usage.contains(crate::BufferUse::MAP_WRITE) {
map_flags |= glow::MAP_FLUSH_EXPLICIT_BIT;
}
//TODO: do we need `glow::MAP_UNSYNCHRONIZED_BIT`?
if let Some(label) = desc.label { if let Some(label) = desc.label {
if gl.supports_debug() { if gl.supports_debug() {
gl.object_label(glow::BUFFER, raw, Some(label)); gl.object_label(glow::BUFFER, raw, Some(label));
@ -361,17 +367,13 @@ impl crate::Device<super::Api> for super::Device {
let gl = &self.shared.context; let gl = &self.shared.context;
let is_coherent = buffer.map_flags & glow::MAP_COHERENT_BIT != 0; let is_coherent = buffer.map_flags & glow::MAP_COHERENT_BIT != 0;
let mut flags = buffer.map_flags | glow::MAP_UNSYNCHRONIZED_BIT;
if !is_coherent {
flags |= glow::MAP_FLUSH_EXPLICIT_BIT;
}
gl.bind_buffer(buffer.target, Some(buffer.raw)); gl.bind_buffer(buffer.target, Some(buffer.raw));
let ptr = gl.map_buffer_range( let ptr = gl.map_buffer_range(
buffer.target, buffer.target,
range.start as i32, range.start as i32,
(range.end - range.start) as i32, (range.end - range.start) as i32,
flags, buffer.map_flags,
); );
gl.bind_buffer(buffer.target, None); gl.bind_buffer(buffer.target, None);
@ -401,19 +403,8 @@ impl crate::Device<super::Api> for super::Device {
); );
} }
} }
unsafe fn invalidate_mapped_ranges<I>(&self, buffer: &super::Buffer, ranges: I) unsafe fn invalidate_mapped_ranges<I>(&self, _buffer: &super::Buffer, _ranges: I) {
where //TODO: do we need to do anything?
I: Iterator<Item = crate::MemoryRange>,
{
let gl = &self.shared.context;
gl.bind_buffer(buffer.target, Some(buffer.raw));
for range in ranges {
gl.invalidate_buffer_sub_data(
buffer.target,
range.start as i32,
(range.end - range.start) as i32,
);
}
} }
unsafe fn create_texture( unsafe fn create_texture(
@ -592,11 +583,6 @@ impl crate::Device<super::Api> for super::Device {
let gl = &self.shared.context; let gl = &self.shared.context;
let raw = gl.create_sampler().unwrap(); let raw = gl.create_sampler().unwrap();
if let Some(label) = desc.label {
if gl.supports_debug() {
gl.object_label(glow::SAMPLER, raw, Some(label));
}
}
let (min, mag) = let (min, mag) =
conv::map_filter_modes(desc.min_filter, desc.mag_filter, desc.mipmap_filter); conv::map_filter_modes(desc.min_filter, desc.mag_filter, desc.mipmap_filter);
@ -652,6 +638,12 @@ impl crate::Device<super::Api> for super::Device {
); );
} }
if let Some(label) = desc.label {
if gl.supports_debug() {
gl.object_label(glow::SAMPLER, raw, Some(label));
}
}
Ok(super::Sampler { raw }) Ok(super::Sampler { raw })
} }
unsafe fn destroy_sampler(&self, sampler: super::Sampler) { unsafe fn destroy_sampler(&self, sampler: super::Sampler) {

View File

@ -287,10 +287,14 @@ impl super::Instance {
} }
} }
impl Drop for super::Instance { impl Drop for super::InstanceShared {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
self.shared.raw.destroy_instance(None); if let Some(du) = self.debug_utils.take() {
du.extension
.destroy_debug_utils_messenger(du.messenger, None);
}
self.raw.destroy_instance(None);
} }
} }
} }

View File

@ -48,7 +48,6 @@ impl crate::Api for Api {
struct DebugUtils { struct DebugUtils {
extension: ext::DebugUtils, extension: ext::DebugUtils,
#[allow(dead_code)]
messenger: vk::DebugUtilsMessengerEXT, messenger: vk::DebugUtilsMessengerEXT,
} }

View File

@ -41,8 +41,6 @@ fn main([[builtin(global_invocation_id)]] global_invocation_id: vec3<u32>) {
var cMassCount : i32 = 0; var cMassCount : i32 = 0;
var cVelCount : i32 = 0; var cVelCount : i32 = 0;
var pos : vec2<f32>;
var vel : vec2<f32>;
var i : u32 = 0u; var i : u32 = 0u;
loop { loop {
if (i >= total) { if (i >= total) {
@ -52,8 +50,8 @@ fn main([[builtin(global_invocation_id)]] global_invocation_id: vec3<u32>) {
continue; continue;
} }
pos = particlesSrc.particles[i].pos; let pos = particlesSrc.particles[i].pos;
vel = particlesSrc.particles[i].vel; let vel = particlesSrc.particles[i].vel;
if (distance(pos, vPos) < params.rule1Distance) { if (distance(pos, vPos) < params.rule1Distance) {
cMass = cMass + pos; cMass = cMass + pos;