mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 23:04:07 +00:00
hal/gles: fix buffer mapping
This commit is contained in:
parent
6025a8d25e
commit
3a796c2244
@ -306,16 +306,17 @@ impl crate::Device<super::Api> for super::Device {
|
||||
glow::ARRAY_BUFFER
|
||||
};
|
||||
|
||||
let mut map_flags = 0;
|
||||
if desc
|
||||
let is_host_visible = desc
|
||||
.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;
|
||||
if desc
|
||||
.memory_flags
|
||||
.contains(crate::MemoryFlag::PREFER_COHERENT)
|
||||
{
|
||||
if is_coherent {
|
||||
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.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 gl.supports_debug() {
|
||||
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 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));
|
||||
let ptr = gl.map_buffer_range(
|
||||
buffer.target,
|
||||
range.start as i32,
|
||||
(range.end - range.start) as i32,
|
||||
flags,
|
||||
buffer.map_flags,
|
||||
);
|
||||
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)
|
||||
where
|
||||
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 invalidate_mapped_ranges<I>(&self, _buffer: &super::Buffer, _ranges: I) {
|
||||
//TODO: do we need to do anything?
|
||||
}
|
||||
|
||||
unsafe fn create_texture(
|
||||
@ -592,11 +583,6 @@ impl crate::Device<super::Api> for super::Device {
|
||||
let gl = &self.shared.context;
|
||||
|
||||
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) =
|
||||
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 })
|
||||
}
|
||||
unsafe fn destroy_sampler(&self, sampler: super::Sampler) {
|
||||
|
@ -287,10 +287,14 @@ impl super::Instance {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for super::Instance {
|
||||
impl Drop for super::InstanceShared {
|
||||
fn drop(&mut self) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ impl crate::Api for Api {
|
||||
|
||||
struct DebugUtils {
|
||||
extension: ext::DebugUtils,
|
||||
#[allow(dead_code)]
|
||||
messenger: vk::DebugUtilsMessengerEXT,
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,6 @@ fn main([[builtin(global_invocation_id)]] global_invocation_id: vec3<u32>) {
|
||||
var cMassCount : i32 = 0;
|
||||
var cVelCount : i32 = 0;
|
||||
|
||||
var pos : vec2<f32>;
|
||||
var vel : vec2<f32>;
|
||||
var i : u32 = 0u;
|
||||
loop {
|
||||
if (i >= total) {
|
||||
@ -52,8 +50,8 @@ fn main([[builtin(global_invocation_id)]] global_invocation_id: vec3<u32>) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pos = particlesSrc.particles[i].pos;
|
||||
vel = particlesSrc.particles[i].vel;
|
||||
let pos = particlesSrc.particles[i].pos;
|
||||
let vel = particlesSrc.particles[i].vel;
|
||||
|
||||
if (distance(pos, vPos) < params.rule1Distance) {
|
||||
cMass = cMass + pos;
|
||||
|
Loading…
Reference in New Issue
Block a user