diff --git a/.travis.yml b/.travis.yml index 33399f849..2266844a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,7 +69,7 @@ script: cmake --build . --target install && cd ../.. && export CMAKE_PREFIX_PATH=$GLFW3_INSTALL_DIR && - make examples-native VERBOSE=1; + make examples-compute example-triangle VERBOSE=1; fi - if [[ $TRAVIS_RUST_VERSION == "nightly" ]] && [[ $TRAVIS_OS_NAME != "windows" ]]; then make VERBOSE=1; fi # TODO: Temporarily only test building the gl backend, properly test when it is usable from C diff --git a/Makefile b/Makefile index 33bba5330..10e9b79d2 100644 --- a/Makefile +++ b/Makefile @@ -46,9 +46,9 @@ else endif endif -.PHONY: all check test doc clear lib-native lib-remote examples-native examples-remote +.PHONY: all check test doc clear lib-native lib-remote examples-compute example-triangle example-remote -all: examples-native examples-remote +all: examples-compute example-triangle example-remote check: cargo check --all @@ -69,10 +69,10 @@ lib-native: Cargo.lock wgpu-native/Cargo.toml $(WILDCARD_WGPU_NATIVE) lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE) cargo build --manifest-path wgpu-remote/Cargo.toml --features $(FEATURE_RUST) -ffi/wgpu.h: wgpu-native/cbindgen.toml $(WILDCARD_WGPU_NATIVE) +$(FFI_DIR)/wgpu.h: wgpu-native/cbindgen.toml $(WILDCARD_WGPU_NATIVE) rustup run nightly cbindgen wgpu-native > $(FFI_DIR)/wgpu.h -ffi/wgpu-remote.h: wgpu-remote/cbindgen.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE) +$(FFI_DIR)/wgpu-remote.h: wgpu-remote/cbindgen.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE) rustup run nightly cbindgen wgpu-remote > $(FFI_DIR)/wgpu-remote.h example-compute: lib-native $(FFI_DIR)/wgpu.h examples/compute/main.c @@ -82,4 +82,4 @@ example-triangle: lib-native $(FFI_DIR)/wgpu.h examples/triangle/main.c cd examples/triangle && $(CREATE_BUILD_DIR) && cd build && cmake .. -DBACKEND=$(FEATURE_RUST) $(GENERATOR_PLATFORM) && cmake --build . example-remote: lib-remote $(FFI_DIR)/wgpu-remote.h examples/remote/main.c - cd examples/remote && $(CREATE_BUILD_DIR) && cd build && cmake .. && cmake --build . \ No newline at end of file + cd examples/remote && $(CREATE_BUILD_DIR) && cd build && cmake .. && cmake --build . diff --git a/examples/framework.c b/examples/framework.c index 0fef04baa..812b87244 100644 --- a/examples/framework.c +++ b/examples/framework.c @@ -21,15 +21,16 @@ WGPUU32Array read_file(const char *name) { } void read_buffer_map( - WGPUBufferMapAsyncStatus status, - const uint8_t *data, + WGPUBufferMapAsyncStatus status, + const uint8_t *data, uint8_t *userdata) { + (void)userdata; if (status == WGPUBufferMapAsyncStatus_Success) { uint32_t *times = (uint32_t *) data; printf("Times: [%d, %d, %d, %d]", - times[0], - times[1], - times[2], + times[0], + times[1], + times[2], times[3]); } } diff --git a/ffi/wgpu-remote.h b/ffi/wgpu-remote.h index 643aaea25..e273e66dc 100644 --- a/ffi/wgpu-remote.h +++ b/ffi/wgpu-remote.h @@ -1,6 +1,6 @@ -/* Generated with cbindgen:0.8.7 */ +/* Generated with cbindgen:0.9.0 */ #include #include diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 2f537d912..37c871efa 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -431,7 +431,6 @@ typedef uint32_t WGPUBufferUsage; #define WGPUBufferUsage_STORAGE 128 #define WGPUBufferUsage_INDIRECT 256 #define WGPUBufferUsage_NONE 0 -#define WGPUBufferUsage_WRITE_ALL 2 + 8 + 128 typedef struct { WGPUBufferAddress size; @@ -575,7 +574,6 @@ typedef uint32_t WGPUTextureUsage; #define WGPUTextureUsage_STORAGE 8 #define WGPUTextureUsage_OUTPUT_ATTACHMENT 16 #define WGPUTextureUsage_NONE 0 -#define WGPUTextureUsage_WRITE_ALL 2 + 8 + 16 #define WGPUTextureUsage_UNINITIALIZED 65535 typedef struct { diff --git a/wgpu-native/src/resource.rs b/wgpu-native/src/resource.rs index dfe7530e1..d912adc08 100644 --- a/wgpu-native/src/resource.rs +++ b/wgpu-native/src/resource.rs @@ -31,7 +31,15 @@ bitflags! { const STORAGE = 128; const INDIRECT = 256; const NONE = 0; - const WRITE_ALL = 2 + 8 + 128; + /// The combination of all read-only usages. + const READ_ALL = Self::MAP_READ.bits | Self::TRANSFER_SRC.bits | + Self::INDEX.bits | Self::VERTEX.bits | Self::UNIFORM.bits | Self::INDIRECT.bits; + /// The combination of all write-only and read-write usages. + const WRITE_ALL = Self::MAP_WRITE.bits | Self::TRANSFER_DST.bits | Self::STORAGE.bits; + /// The combination of all usages that the are guaranteed to be be ordered by the hardware. + /// If a usage is not ordered, then even if it doesn't change between draw calls, there + /// still need to be pipeline barriers inserted for synchronization. + const ORDERED = Self::READ_ALL.bits; } } @@ -163,7 +171,14 @@ bitflags! { const STORAGE = 8; const OUTPUT_ATTACHMENT = 16; const NONE = 0; - const WRITE_ALL = 2 + 8 + 16; + /// The combination of all read-only usages. + const READ_ALL = Self::TRANSFER_SRC.bits | Self::SAMPLED.bits; + /// The combination of all write-only and read-write usages. + const WRITE_ALL = Self::TRANSFER_DST.bits | Self::STORAGE.bits | Self::OUTPUT_ATTACHMENT.bits; + /// The combination of all usages that the are guaranteed to be be ordered by the hardware. + /// If a usage is not ordered, then even if it doesn't change between draw calls, there + /// still need to be pipeline barriers inserted for synchronization. + const ORDERED = Self::READ_ALL.bits | Self::OUTPUT_ATTACHMENT.bits; const UNINITIALIZED = 0xFFFF; } } diff --git a/wgpu-native/src/track/buffer.rs b/wgpu-native/src/track/buffer.rs index b484f3fab..051f2d174 100644 --- a/wgpu-native/src/track/buffer.rs +++ b/wgpu-native/src/track/buffer.rs @@ -46,7 +46,7 @@ impl ResourceState for BufferState { output: Option<&mut Vec>>, ) -> Result<(), PendingTransition> { let old = self.last; - if usage != old { + if usage != old || !BufferUsage::ORDERED.contains(usage) { let pending = PendingTransition { id, selector: (), @@ -77,7 +77,7 @@ impl ResourceState for BufferState { ) -> Result<(), PendingTransition> { let old = self.last; let new = other.select(stitch); - self.last = if old == new { + self.last = if old == new && BufferUsage::ORDERED.contains(new) { other.last } else { let pending = PendingTransition { diff --git a/wgpu-native/src/track/texture.rs b/wgpu-native/src/track/texture.rs index d64186e36..a7e83a64b 100644 --- a/wgpu-native/src/track/texture.rs +++ b/wgpu-native/src/track/texture.rs @@ -123,7 +123,7 @@ impl ResourceState for TextureState { } let layers = plane_states.isolate(&selector.layers, Unit::new(usage)); for &mut (ref range, ref mut unit) in layers { - if unit.last == usage { + if unit.last == usage && TextureUsage::ORDERED.contains(usage) { continue } let pending = PendingTransition { @@ -175,7 +175,7 @@ impl ResourceState for TextureState { Range { start: None, end: Some(end) } => Unit::new(end.select(stitch)), Range { start: Some(start), end: Some(end) } => { let mut final_usage = end.select(stitch); - if start.last != final_usage { + if start.last != final_usage || !TextureUsage::ORDERED.contains(final_usage) { let pending = PendingTransition { id, selector: hal::image::SubresourceRange {