Skip to content
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

More as_hal() methods #3966

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
32311fe
WIP More hal exposures
JMS55 Jan 13, 2023
32ec118
Finish CommandEncoder::as_hal_mut()
JMS55 Jan 13, 2023
b3f2afb
Add raw_handle methods
JMS55 Jan 13, 2023
493db92
Add Adapter::texture_format_as_hal()
JMS55 Jan 13, 2023
f6bc72f
Add changelog
JMS55 Jan 13, 2023
84f5bd1
Type fixes
JMS55 Jan 13, 2023
d8ab000
Another type fix
JMS55 Jan 13, 2023
2ea6293
Fix unused warning on wasm
JMS55 Jan 13, 2023
101a392
Fixes
JMS55 Jan 16, 2023
f979162
Change hal command encoder
JMS55 Jan 17, 2023
d7dcc9b
Make public more things
JMS55 Jan 17, 2023
0548dfb
Fix command encoder as_hal_mut
JMS55 Jan 19, 2023
a937666
Expose raw
JMS55 Jan 19, 2023
c429170
Merge commit 'c5851275c59b1d5d949b142d6aa973d0bb638181'
JMS55 Jan 20, 2023
e3e895a
Ensure a command buffer is active
JMS55 Jan 20, 2023
e31b764
Setup hacky command_encoder_transition_textures
JMS55 Jan 21, 2023
28d6dac
Extremely hacky transition_textures
JMS55 Jan 21, 2023
eb19bfc
Misc
JMS55 Jan 21, 2023
e722de8
Merge commit '98ea3500fd2cfb4b51d5454c662d8eefd940156a'
JMS55 Jan 30, 2023
2fb314d
Merge remote-tracking branch 'wgpu/master'
JMS55 Feb 3, 2023
108d63c
Fix
JMS55 Feb 27, 2023
f4f6fca
Merge commit '9dc834a0ac694d576a584a89f72733a0bb2f4485'
JMS55 Feb 27, 2023
9b85135
Remove hacky transition textures
JMS55 Feb 27, 2023
765cb02
Misc cleanup
JMS55 Feb 27, 2023
e439a83
Misc
JMS55 Feb 27, 2023
894a161
Add back stuff
JMS55 Feb 27, 2023
020f343
Add back TextureView::raw_handle()
JMS55 Feb 27, 2023
5d98a86
Add back TextureView::raw_handle()
JMS55 Feb 28, 2023
c9444a0
Merge branch 'master' of https://github.com/JMS55/wgpu
JMS55 Feb 28, 2023
93ca2c2
Misc
JMS55 Feb 28, 2023
94730d4
Merge commit '54e4c8654d85eb28262db0a24d07e4c6db612b38'
JMS55 Mar 6, 2023
13ab6a8
Merge commit '7198d60f6820af15d12a3762de9ab0d484c4e827'
JMS55 Jul 22, 2023
4bf5751
Merge commit '2a77bbd80d23e14175c801d7cc3d109d9d47d8ca'
JMS55 Jul 23, 2023
63f127c
Add missing imports
JMS55 Jul 23, 2023
644306d
Misc fix
JMS55 Jul 23, 2023
88152f8
Fix
JMS55 Jul 23, 2023
e4c90ba
Mark fn as pub
JMS55 Jul 23, 2023
1b2a072
Mark import as pub
JMS55 Jul 23, 2023
1a38694
Merge commit '09b010b26af6876ce84991576a168a572172f08d'
JMS55 Aug 1, 2023
480ba76
Change naga version
JMS55 Aug 1, 2023
9d1e574
Misc
JMS55 Aug 1, 2023
7a326e8
Revert "Change naga version"
JMS55 Aug 4, 2023
1880d89
Merge commit '5b4c6b8ae4afa88358be6135b36e9d2b54808611'
JMS55 Aug 4, 2023
221d2cb
Misc
JMS55 Aug 4, 2023
a98eacb
Merge commit '359e39232239d2f5d0ac1dadde7c3d874d3cf29e'
JMS55 Aug 4, 2023
31c67e0
Merge commit '40cc2ee88a5c9bf281395547375e279ca30aedc0'
JMS55 Sep 15, 2023
04b7bdd
Merge branch 'trunk' into master
cwfitzgerald Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ path = "./wgpu-hal"
version = "0.17"

[workspace.dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "bac2d82a430fbfcf100ee22b7c3bc12f3d593079"
# git = "https://github.com/gfx-rs/naga"
# rev = "bac2d82a430fbfcf100ee22b7c3bc12f3d593079"
version = "0.13.0"

[workspace.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ smallvec = "1"
thiserror = "1"

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "bac2d82a430fbfcf100ee22b7c3bc12f3d593079"
# git = "https://github.com/gfx-rs/naga"
# rev = "bac2d82a430fbfcf100ee22b7c3bc12f3d593079"
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
version = "0.13.0"
features = ["clone", "span", "validate"]

Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum CommandEncoderStatus {
Error,
}

struct CommandEncoder<A: hal::Api> {
pub struct CommandEncoder<A: hal::Api> {
raw: A::CommandEncoder,
list: Vec<A::CommandBuffer>,
is_open: bool,
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<A: hal::Api> CommandEncoder<A> {
}
}

fn open(&mut self) -> &mut A::CommandEncoder {
pub fn open(&mut self) -> &mut A::CommandEncoder {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I need to make this method public, and CommandBuffer.encoder pub(crate)? Not sure.

if !self.is_open {
self.is_open = true;
let label = self.label.as_deref();
Expand All @@ -106,7 +106,7 @@ pub(crate) struct DestroyedBufferError(pub id::BufferId);
pub(crate) struct DestroyedTextureError(pub id::TextureId);

pub struct CommandBuffer<A: HalApi> {
encoder: CommandEncoder<A>,
pub(crate) encoder: CommandEncoder<A>,
status: CommandEncoderStatus,
pub(crate) device_id: Stored<id::DeviceId>,
pub(crate) trackers: Tracker<A>,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ flagged as errors as well.
[`IdentityHandlerFactory<I>`]: crate::identity::IdentityHandlerFactory
*/

pub use crate::hal_api::HalApi;
use crate::{
binding_model::{BindGroup, BindGroupLayout, PipelineLayout},
command::{CommandBuffer, RenderBundle},
device::Device,
hal_api::HalApi,
id,
identity::GlobalIdentityHandlerFactory,
instance::{Adapter, HalSurface, Instance, Surface},
Expand Down
69 changes: 65 additions & 4 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
global::Global,
hal_api::HalApi,
hub::Token,
id::{AdapterId, DeviceId, SurfaceId, TextureId, Valid},
id::{AdapterId, CommandEncoderId, DeviceId, SurfaceId, TextureId, TextureViewId, Valid},
identity::GlobalIdentityHandlerFactory,
init_tracker::{BufferInitTracker, TextureInitTracker},
track::TextureSelector,
Expand Down Expand Up @@ -426,11 +426,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
/// # Safety
///
/// - The raw texture handle must not be manually destroyed
pub unsafe fn texture_as_hal<A: HalApi, F: FnOnce(Option<&A::Texture>)>(
pub unsafe fn texture_as_hal<A: HalApi, F: FnOnce(Option<&A::Texture>) -> R, R>(
&self,
id: TextureId,
hal_texture_callback: F,
) {
) -> R {
profiling::scope!("Texture::as_hal");

let hub = A::hub(self);
Expand All @@ -439,7 +439,26 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let texture = guard.try_get(id).ok().flatten();
let hal_texture = texture.and_then(|tex| tex.inner.as_raw());

hal_texture_callback(hal_texture);
hal_texture_callback(hal_texture)
}

/// # Safety
///
/// - The raw texture view handle must not be manually destroyed
pub unsafe fn texture_view_as_hal<A: HalApi, F: FnOnce(Option<&A::TextureView>) -> R, R>(
&self,
id: TextureViewId,
hal_texture_view_callback: F,
) -> R {
profiling::scope!("TextureView::as_hal");

let hub = A::hub(self);
let mut token = Token::root();
let (guard, _) = hub.texture_views.read(&mut token);
let texture_view = guard.try_get(id).ok().flatten();
let hal_texture_view = texture_view.map(|tex| &tex.raw);

hal_texture_view_callback(hal_texture_view)
}

/// # Safety
Expand All @@ -462,6 +481,26 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hal_adapter_callback(hal_adapter)
}

#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub fn texture_format_as_hal<A: HalApi>(
&self,
adapter: AdapterId,
texture_format: wgt::TextureFormat,
) -> Option<A::TextureFormat> {
use hal::Adapter;

profiling::scope!("TextureFormat::as_hal");

let hub = A::hub(self);
let mut token = Token::root();

let (guard, _) = hub.adapters.read(&mut token);
let adapter = guard.try_get(adapter).ok().flatten();
let hal_adapter = adapter.map(|adapter| &adapter.raw.adapter);

hal_adapter.map(|hal_adapter| hal_adapter.texture_format_as_hal(texture_format))
}

/// # Safety
///
/// - The raw device handle must not be manually destroyed
Expand Down Expand Up @@ -499,6 +538,28 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

hal_surface_callback(hal_surface)
}

/// # Safety
/// - The raw command encoder handle must not be manually destroyed
pub unsafe fn command_encoder_as_hal_mut<
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to add the not wasm #cfg's here, and in a few other places?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should

A: HalApi,
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
R,
>(
&self,
id: CommandEncoderId,
hal_command_encoder_callback: F,
) -> R {
profiling::scope!("CommandEncoder::as_hal_mut");

let hub = A::hub(self);
let mut token = Token::root();
let (mut guard, _) = hub.command_buffers.write(&mut token);
let command_encoder = guard.get_mut(id).ok();
let hal_command_encoder = command_encoder.map(|encoder| encoder.encoder.open());

hal_command_encoder_callback(hal_command_encoder)
}
}

#[derive(Clone, Copy, Debug)]
Expand Down
5 changes: 2 additions & 3 deletions wgpu-core/src/track/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ use thiserror::Error;
pub(crate) use buffer::{BufferBindGroupState, BufferTracker, BufferUsageScope};
use metadata::{ResourceMetadata, ResourceMetadataProvider};
pub(crate) use stateless::{StatelessBindGroupSate, StatelessTracker};
pub(crate) use texture::{
TextureBindGroupState, TextureSelector, TextureTracker, TextureUsageScope,
};
pub use texture::TextureSelector;
pub(crate) use texture::{TextureBindGroupState, TextureTracker, TextureUsageScope};
use wgt::strict_assert_ne;

/// A structure containing all the information about a particular resource
Expand Down
8 changes: 4 additions & 4 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ libc = "0.2"
android_system_properties = "0.1.1"

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "bac2d82a430fbfcf100ee22b7c3bc12f3d593079"
# git = "https://github.com/gfx-rs/naga"
# rev = "bac2d82a430fbfcf100ee22b7c3bc12f3d593079"
version = "0.13.0"
features = ["clone"]

# DEV dependencies
[dev-dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "bac2d82a430fbfcf100ee22b7c3bc12f3d593079"
# git = "https://github.com/gfx-rs/naga"
# rev = "bac2d82a430fbfcf100ee22b7c3bc12f3d593079"
version = "0.13.0"
features = ["wgsl-in"]

Expand Down
7 changes: 7 additions & 0 deletions wgpu-hal/src/dx11/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp {
todo!()
}

fn texture_format_as_hal(
&self,
texture_format: wgt::TextureFormat,
) -> <crate::dx11::Api as crate::Api>::TextureFormat {
todo!()
}
}

impl super::Adapter {
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/dx11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl crate::Api for Api {
type ShaderModule = ShaderModule;
type RenderPipeline = RenderPipeline;
type ComputePipeline = ComputePipeline;

type TextureFormat = ();
}

pub struct Instance {
Expand Down
9 changes: 8 additions & 1 deletion wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
auxil::{self, dxgi::result::HResult as _},
auxil::{self, dxgi::conv::map_texture_format, dxgi::result::HResult as _},
dx12::SurfaceTarget,
};
use std::{mem, ptr, sync::Arc, thread};
Expand Down Expand Up @@ -613,4 +613,11 @@ impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp {
wgt::PresentationTimestamp(self.presentation_timer.get_timestamp_ns())
}

fn texture_format_as_hal(
&self,
texture_format: wgt::TextureFormat,
) -> <crate::dx12::Api as crate::Api>::TextureFormat {
map_texture_format(texture_format)
}
}
4 changes: 3 additions & 1 deletion wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use arrayvec::ArrayVec;
use parking_lot::Mutex;
use std::{ffi, fmt, mem, num::NonZeroU32, sync::Arc};
use winapi::{
shared::{dxgi, dxgi1_4, dxgitype, windef, winerror},
shared::{dxgi, dxgi1_4, dxgiformat, dxgitype, windef, winerror},
um::{d3d12 as d3d12_ty, dcomp, synchapi, winbase, winnt},
Interface as _,
};
Expand Down Expand Up @@ -82,6 +82,8 @@ impl crate::Api for Api {
type ShaderModule = ShaderModule;
type RenderPipeline = RenderPipeline;
type ComputePipeline = ComputePipeline;

type TextureFormat = dxgiformat::DXGI_FORMAT;
}

// Limited by D3D12's root signature size of 64. Each element takes 1 or 2 entries.
Expand Down
9 changes: 9 additions & 0 deletions wgpu-hal/src/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ impl crate::Api for Api {
type ShaderModule = Resource;
type RenderPipeline = Resource;
type ComputePipeline = Resource;

type TextureFormat = Resource;
}

impl crate::Instance<Api> for Context {
Expand Down Expand Up @@ -97,6 +99,13 @@ impl crate::Adapter<Api> for Context {
unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp {
wgt::PresentationTimestamp::INVALID_TIMESTAMP
}

fn texture_format_as_hal(
&self,
texture_format: wgt::TextureFormat,
) -> <Api as crate::Api>::TextureFormat {
Resource
}
}

impl crate::Queue<Api> for Context {
Expand Down
7 changes: 7 additions & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,13 @@ impl crate::Adapter<super::Api> for super::Adapter {
unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp {
wgt::PresentationTimestamp::INVALID_TIMESTAMP
}

fn texture_format_as_hal(
&self,
_texture_format: wgt::TextureFormat,
) -> <super::Api as crate::Api>::TextureFormat {
todo!()
}
}

impl super::AdapterShared {
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ impl crate::Api for Api {
type ShaderModule = ShaderModule;
type RenderPipeline = RenderPipeline;
type ComputePipeline = ComputePipeline;

type TextureFormat = ();
}

bitflags::bitflags! {
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub trait Api: Clone + Sized {
type ShaderModule: fmt::Debug + WasmNotSend + WasmNotSync;
type RenderPipeline: WasmNotSend + WasmNotSync;
type ComputePipeline: WasmNotSend + WasmNotSync;

type TextureFormat;
}

pub trait Instance<A: Api>: Sized + WasmNotSend + WasmNotSync {
Expand Down Expand Up @@ -239,6 +241,9 @@ pub trait Adapter<A: Api>: WasmNotSend + WasmNotSync {
///
/// [`PresentationTimestamp`]: wgt::PresentationTimestamp
unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp;

// Returns the hal texture format.
fn texture_format_as_hal(&self, texture_format: wgt::TextureFormat) -> A::TextureFormat;
}

pub trait Device<A: Api>: WasmNotSend + WasmNotSync {
Expand Down
7 changes: 7 additions & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ impl crate::Adapter<super::Api> for super::Adapter {

wgt::PresentationTimestamp(timestamp)
}

fn texture_format_as_hal(
&self,
texture_format: wgt::TextureFormat,
) -> <crate::metal::Api as crate::Api>::TextureFormat {
self.shared.private_caps.map_format(texture_format)
}
}

const RESOURCE_HEAP_SUPPORT: &[MTLFeatureSet] = &[
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ impl crate::Api for Api {
type ShaderModule = ShaderModule;
type RenderPipeline = RenderPipeline;
type ComputePipeline = ComputePipeline;

type TextureFormat = metal::MTLPixelFormat;
}

pub struct Instance {
Expand Down
7 changes: 7 additions & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,13 @@ impl crate::Adapter<super::Api> for super::Adapter {
wgt::PresentationTimestamp::INVALID_TIMESTAMP
}
}

fn texture_format_as_hal(
&self,
texture_format: wgt::TextureFormat,
) -> <super::Api as crate::Api>::TextureFormat {
self.private_caps.map_texture_format(texture_format)
}
}

fn is_format_16bit_norm_supported(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
Expand Down
Loading