-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for transient textures on Vulkan and Metal #8247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
opstic
wants to merge
59
commits into
gfx-rs:trunk
Choose a base branch
from
opstic:transient
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+380
−11
Open
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
56d648a
Preliminary implementation
opstic 8c7dace
Merge branch 'gfx-rs:trunk' into transient
opstic 598259c
oops
opstic 9ec9242
Better implementation
opstic 2185cd8
Add entry in `CHANGELOG.md`
opstic 625bf3b
Remove `Feature::TRANSIENT_ATTACHMENTS` and add validation
opstic 5644cd2
Remove `#[cfg(windows)]` from `find_memory_type_index`
opstic 6c3d11b
Tries to find a memory type that contains `MemoryPropertyFlags::LAZIL…
opstic a16ec0c
Merge branch 'trunk' into transient
opstic aafa05e
`cargo fmt`
opstic 703bf26
Add check in Metal for `MTLStorageMode::Memoryless` support
opstic 02201f4
Apply `TextureUsages::TRANSIENT` to relevant examples
opstic c1c04ec
Improve documentation by @cwfitzgerald
opstic 77bf9af
Improve error message by @cwfitzgerald
opstic faea1c3
Move `TextureUses::TRANSIENT` to `1 << 12`
opstic 56b3956
Improve `TextureUsages` docs
opstic 15ded86
Better wording
opstic e0280d9
Add `StoreOp` requirement
opstic 01776c8
Allow `TextureUsages::TRANSIENT` in `guaranteed_format_features`
opstic 607ed01
Improve error message
opstic ef922ef
Add `TextureUses::TRANSIENT` to GL backend's `render_usage`
opstic 54c4cc0
Improve docs
opstic f50b098
Add validation tests
opstic df228e0
Fix `TextureUsages::TRANSIENT` docs formatting
opstic f6f2de8
Add `supports_transient` flag in `AdapterInfo`
opstic e30db54
Merge branch 'trunk' into transient
opstic c28ea1a
oops
opstic cb248c5
📎
opstic 1a09f3c
Formatting
opstic 0e72950
Fix WebGPU compile
opstic 3d063d7
Add simple transient test case
opstic 69d8110
Actually use the transient flag in test
opstic 5b0eb92
Merge branch 'trunk' into transient
opstic 4598ebd
Well that was a nice demonstration of validation
opstic dfb60de
Update `CHANGELOG.md`
opstic 8182e41
Use proper formatting for documentation
opstic 0124879
Merge branch 'trunk' into transient
opstic 7af040e
Merge branch 'trunk' into transient
opstic b6e05b1
Improve validation usage filtering by @cwfitzgerald
opstic 1332b31
Improve documentation by @cwfitzgerald
opstic 88b5cd4
Improve documentation by @cwfitzgerald
opstic 99ff738
Limit `supports_memoryless_storage` to Apple Silicon
opstic 126e45b
Merge remote-tracking branch 'fork/transient' into transient
opstic 305a8fa
`cargo fmt`
opstic a3d8e86
Move `TextureUsages::TRANSIENT` in `guaranteed_format_features`
opstic 584f4f7
Merge branch 'trunk' into transient
opstic 193a138
Remove unnecessary `mut`
opstic 440964f
`MTLGPUFamily::Metal4` doesn't exist yet in the version on `metal` we…
opstic 59118fb
Improve transient support hint naming
opstic d711c11
Correct `AdapterInfo` for `noop` backend
opstic 146806b
Merge branch 'trunk' into transient
opstic 64a7e32
Fix compile
opstic b1b9bb5
`cargo fmt`
opstic 75ce4ad
Merge branch 'trunk' into transient
opstic 052ba98
Allow `TextureUsages::TRANSIENT` along with `TextureUsages::RENDER_AT…
opstic d3701bc
Disallow `TextureUsages::TRANSIENT` if `TextureUsages::RENDER_ATTACHM…
opstic 653e1a2
Update docs
opstic 48b76ff
Update validation test
opstic bbfb1eb
`cargo fmt`
opstic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
use wgpu_test::{gpu_test, GpuTestConfiguration, GpuTestInitializer, TestParameters}; | ||
|
||
pub fn all_tests(vec: &mut Vec<GpuTestInitializer>) { | ||
vec.push(RESOLVE_WITH_TRANSIENT); | ||
} | ||
|
||
#[gpu_test] | ||
static RESOLVE_WITH_TRANSIENT: GpuTestConfiguration = GpuTestConfiguration::new() | ||
.parameters(TestParameters::default()) | ||
.run_async(|ctx| async move { | ||
const SIZE: wgpu::Extent3d = wgpu::Extent3d { | ||
width: 256, | ||
height: 256, | ||
depth_or_array_layers: 1, | ||
}; | ||
|
||
let shader_src = " | ||
@vertex | ||
fn vs_main(@builtin(vertex_index) index: u32) -> @builtin(position) vec4f { | ||
let positions: array<vec2f, 3> = array<vec2f, 3>( | ||
vec2f(-1.0, -1.0), | ||
vec2f(-1.0, 3.0), | ||
vec2f(3.0, -1.0) | ||
); | ||
return vec4f(positions[index], 0.0, 1.0); | ||
} | ||
|
||
@fragment | ||
fn fs_main() -> @location(0) vec4f { | ||
return vec4f(1.0); | ||
} | ||
"; | ||
|
||
let shader = ctx | ||
.device | ||
.create_shader_module(wgpu::ShaderModuleDescriptor { | ||
label: None, | ||
source: wgpu::ShaderSource::Wgsl(shader_src.into()), | ||
}); | ||
|
||
let pipeline_desc = wgpu::RenderPipelineDescriptor { | ||
label: None, | ||
layout: None, | ||
vertex: wgpu::VertexState { | ||
buffers: &[], | ||
module: &shader, | ||
entry_point: Some("vs_main"), | ||
compilation_options: Default::default(), | ||
}, | ||
primitive: wgpu::PrimitiveState::default(), | ||
depth_stencil: None, | ||
multisample: wgpu::MultisampleState { | ||
count: 4, | ||
mask: !0, | ||
alpha_to_coverage_enabled: false, | ||
}, | ||
fragment: Some(wgpu::FragmentState { | ||
module: &shader, | ||
entry_point: Some("fs_main"), | ||
compilation_options: Default::default(), | ||
targets: &[Some(wgpu::ColorTargetState { | ||
format: wgpu::TextureFormat::Rgba8Unorm, | ||
blend: None, | ||
write_mask: wgpu::ColorWrites::ALL, | ||
})], | ||
}), | ||
multiview: None, | ||
cache: None, | ||
}; | ||
let pipeline = ctx.device.create_render_pipeline(&pipeline_desc); | ||
|
||
let transient_texture = ctx.device.create_texture(&wgpu::TextureDescriptor { | ||
label: None, | ||
size: SIZE, | ||
mip_level_count: 1, | ||
sample_count: 4, | ||
dimension: wgpu::TextureDimension::D2, | ||
format: wgpu::TextureFormat::Rgba8Unorm, | ||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TRANSIENT, | ||
view_formats: &[], | ||
}); | ||
|
||
let target_texture = ctx.device.create_texture(&wgpu::TextureDescriptor { | ||
label: None, | ||
size: SIZE, | ||
mip_level_count: 1, | ||
sample_count: 1, | ||
dimension: wgpu::TextureDimension::D2, | ||
format: wgpu::TextureFormat::Rgba8Unorm, | ||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, | ||
view_formats: &[], | ||
}); | ||
|
||
let readback_buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor { | ||
label: None, | ||
size: 256 * 256 * 4, | ||
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, | ||
mapped_at_creation: false, | ||
}); | ||
|
||
let mut encoder = ctx | ||
.device | ||
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); | ||
|
||
{ | ||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { | ||
label: None, | ||
color_attachments: &[Some(wgpu::RenderPassColorAttachment { | ||
view: &transient_texture.create_view(&wgpu::TextureViewDescriptor::default()), | ||
depth_slice: None, | ||
resolve_target: Some( | ||
&target_texture.create_view(&wgpu::TextureViewDescriptor::default()), | ||
), | ||
ops: wgpu::Operations { | ||
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), | ||
store: wgpu::StoreOp::Discard, | ||
}, | ||
})], | ||
depth_stencil_attachment: None, | ||
timestamp_writes: None, | ||
occlusion_query_set: None, | ||
}); | ||
|
||
rpass.set_pipeline(&pipeline); | ||
rpass.draw(0..3, 0..1); | ||
} | ||
|
||
encoder.copy_texture_to_buffer( | ||
wgpu::TexelCopyTextureInfo { | ||
texture: &target_texture, | ||
mip_level: 0, | ||
origin: wgpu::Origin3d { x: 0, y: 0, z: 0 }, | ||
aspect: wgpu::TextureAspect::All, | ||
}, | ||
wgpu::TexelCopyBufferInfo { | ||
buffer: &readback_buffer, | ||
layout: wgpu::TexelCopyBufferLayout { | ||
offset: 0, | ||
bytes_per_row: Some(256 * 4), | ||
rows_per_image: Some(256), | ||
}, | ||
}, | ||
SIZE, | ||
); | ||
|
||
ctx.queue.submit([encoder.finish()]); | ||
|
||
let slice = readback_buffer.slice(..); | ||
slice.map_async(wgpu::MapMode::Read, |_| ()); | ||
|
||
ctx.async_poll(wgpu::PollType::wait_indefinitely()) | ||
.await | ||
.unwrap(); | ||
|
||
let data = slice.get_mapped_range(); | ||
let succeeded = data.iter().all(|b| *b == u8::MAX); | ||
assert!(succeeded); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.