4
4
5
5
#![ cfg_attr( docsrs, feature( doc_cfg) ) ] // Allow doc(cfg(feature = "")) for showing in docs that something is feature gated.
6
6
#![ doc( html_logo_url = "https://raw.githubusercontent.com/gfx-rs/wgpu/master/logo.png" ) ]
7
- #![ warn( missing_docs) ]
7
+ #![ warn( missing_docs, unsafe_op_in_unsafe_fn ) ]
8
8
9
9
mod backend;
10
10
pub mod util;
@@ -1736,7 +1736,7 @@ impl Instance {
1736
1736
#[ cfg( any( not( target_arch = "wasm32" ) , feature = "emscripten" ) ) ]
1737
1737
pub unsafe fn from_hal < A : wgc:: hub:: HalApi > ( hal_instance : A :: Instance ) -> Self {
1738
1738
Self {
1739
- context : Arc :: new ( C :: from_hal_instance :: < A > ( hal_instance) ) ,
1739
+ context : Arc :: new ( unsafe { C :: from_hal_instance :: < A > ( hal_instance) } ) ,
1740
1740
}
1741
1741
}
1742
1742
@@ -1752,7 +1752,7 @@ impl Instance {
1752
1752
/// [`Instance`]: hal::Api::Instance
1753
1753
#[ cfg( any( not( target_arch = "wasm32" ) , feature = "webgl" ) ) ]
1754
1754
pub unsafe fn as_hal < A : wgc:: hub:: HalApi > ( & self ) -> Option < & A :: Instance > {
1755
- self . context . instance_as_hal :: < A > ( )
1755
+ unsafe { self . context . instance_as_hal :: < A > ( ) }
1756
1756
}
1757
1757
1758
1758
/// Create an new instance of wgpu from a wgpu-core instance.
@@ -1767,7 +1767,7 @@ impl Instance {
1767
1767
#[ cfg( any( not( target_arch = "wasm32" ) , feature = "webgl" ) ) ]
1768
1768
pub unsafe fn from_core ( core_instance : wgc:: instance:: Instance ) -> Self {
1769
1769
Self {
1770
- context : Arc :: new ( C :: from_core_instance ( core_instance) ) ,
1770
+ context : Arc :: new ( unsafe { C :: from_core_instance ( core_instance) } ) ,
1771
1771
}
1772
1772
}
1773
1773
@@ -1813,7 +1813,7 @@ impl Instance {
1813
1813
hal_adapter : hal:: ExposedAdapter < A > ,
1814
1814
) -> Adapter {
1815
1815
let context = Arc :: clone ( & self . context ) ;
1816
- let id = context. create_adapter_from_hal ( hal_adapter) ;
1816
+ let id = unsafe { context. create_adapter_from_hal ( hal_adapter) } ;
1817
1817
Adapter { context, id }
1818
1818
}
1819
1819
@@ -1853,7 +1853,7 @@ impl Instance {
1853
1853
& self ,
1854
1854
layer : * mut std:: ffi:: c_void ,
1855
1855
) -> Surface {
1856
- self . context . create_surface_from_core_animation_layer ( layer)
1856
+ unsafe { self . context . create_surface_from_core_animation_layer ( layer) }
1857
1857
}
1858
1858
1859
1859
/// Creates a surface from `IDCompositionVisual`.
@@ -1863,7 +1863,7 @@ impl Instance {
1863
1863
/// - visual must be a valid IDCompositionVisual to create a surface upon.
1864
1864
#[ cfg( target_os = "windows" ) ]
1865
1865
pub unsafe fn create_surface_from_visual ( & self , visual : * mut std:: ffi:: c_void ) -> Surface {
1866
- self . context . create_surface_from_visual ( visual)
1866
+ unsafe { self . context . create_surface_from_visual ( visual) }
1867
1867
}
1868
1868
1869
1869
/// Creates a surface from a `web_sys::HtmlCanvasElement`.
@@ -1976,20 +1976,22 @@ impl Adapter {
1976
1976
trace_path : Option < & std:: path:: Path > ,
1977
1977
) -> Result < ( Device , Queue ) , RequestDeviceError > {
1978
1978
let context = Arc :: clone ( & self . context ) ;
1979
- self . context
1980
- . create_device_from_hal ( & self . id , hal_device, desc, trace_path)
1981
- . map ( |( device_id, queue_id) | {
1982
- (
1983
- Device {
1984
- context : Arc :: clone ( & context) ,
1985
- id : device_id,
1986
- } ,
1987
- Queue {
1988
- context,
1989
- id : queue_id,
1990
- } ,
1991
- )
1992
- } )
1979
+ unsafe {
1980
+ self . context
1981
+ . create_device_from_hal ( & self . id , hal_device, desc, trace_path)
1982
+ }
1983
+ . map ( |( device_id, queue_id) | {
1984
+ (
1985
+ Device {
1986
+ context : Arc :: clone ( & context) ,
1987
+ id : device_id,
1988
+ } ,
1989
+ Queue {
1990
+ context,
1991
+ id : queue_id,
1992
+ } ,
1993
+ )
1994
+ } )
1993
1995
}
1994
1996
1995
1997
/// Apply a callback to this `Adapter`'s underlying backend adapter.
@@ -2016,8 +2018,10 @@ impl Adapter {
2016
2018
& self ,
2017
2019
hal_adapter_callback : F ,
2018
2020
) -> R {
2019
- self . context
2020
- . adapter_as_hal :: < A , F , R > ( self . id , hal_adapter_callback)
2021
+ unsafe {
2022
+ self . context
2023
+ . adapter_as_hal :: < A , F , R > ( self . id , hal_adapter_callback)
2024
+ }
2021
2025
}
2022
2026
2023
2027
/// Returns whether this adapter may present to the passed surface.
@@ -2117,12 +2121,14 @@ impl Device {
2117
2121
) -> ShaderModule {
2118
2122
ShaderModule {
2119
2123
context : Arc :: clone ( & self . context ) ,
2120
- id : Context :: device_create_shader_module (
2121
- & * self . context ,
2122
- & self . id ,
2123
- desc,
2124
- wgt:: ShaderBoundChecks :: unchecked ( ) ,
2125
- ) ,
2124
+ id : unsafe {
2125
+ Context :: device_create_shader_module (
2126
+ & * self . context ,
2127
+ & self . id ,
2128
+ desc,
2129
+ wgt:: ShaderBoundChecks :: unchecked ( ) ,
2130
+ )
2131
+ } ,
2126
2132
}
2127
2133
}
2128
2134
@@ -2140,7 +2146,9 @@ impl Device {
2140
2146
) -> ShaderModule {
2141
2147
ShaderModule {
2142
2148
context : Arc :: clone ( & self . context ) ,
2143
- id : Context :: device_create_shader_module_spirv ( & * self . context , & self . id , desc) ,
2149
+ id : unsafe {
2150
+ Context :: device_create_shader_module_spirv ( & * self . context , & self . id , desc)
2151
+ } ,
2144
2152
}
2145
2153
}
2146
2154
@@ -2250,9 +2258,10 @@ impl Device {
2250
2258
) -> Texture {
2251
2259
Texture {
2252
2260
context : Arc :: clone ( & self . context ) ,
2253
- id : self
2254
- . context
2255
- . create_texture_from_hal :: < A > ( hal_texture, & self . id , desc) ,
2261
+ id : unsafe {
2262
+ self . context
2263
+ . create_texture_from_hal :: < A > ( hal_texture, & self . id , desc)
2264
+ } ,
2256
2265
owned : true ,
2257
2266
}
2258
2267
}
@@ -2324,8 +2333,10 @@ impl Device {
2324
2333
& self ,
2325
2334
hal_device_callback : F ,
2326
2335
) -> R {
2327
- self . context
2328
- . device_as_hal :: < A , F , R > ( & self . id , hal_device_callback)
2336
+ unsafe {
2337
+ self . context
2338
+ . device_as_hal :: < A , F , R > ( & self . id , hal_device_callback)
2339
+ }
2329
2340
}
2330
2341
}
2331
2342
@@ -2635,8 +2646,10 @@ impl Texture {
2635
2646
& self ,
2636
2647
hal_texture_callback : F ,
2637
2648
) {
2638
- self . context
2639
- . texture_as_hal :: < A , F > ( & self . id , hal_texture_callback)
2649
+ unsafe {
2650
+ self . context
2651
+ . texture_as_hal :: < A , F > ( & self . id , hal_texture_callback)
2652
+ }
2640
2653
}
2641
2654
2642
2655
/// Creates a view of this texture.
0 commit comments