@@ -2,9 +2,9 @@ use windows::{
22 core:: { Interface , Result } ,
33 Win32 :: Graphics :: {
44 Direct3D11 :: {
5- ID3D11Device , ID3D11DeviceContext , ID3D11Resource , ID3D11Texture2D , D3D11_BIND_FLAG ,
6- D3D11_CPU_ACCESS_READ , D3D11_MAPPED_SUBRESOURCE , D3D11_MAP_READ ,
7- D3D11_RESOURCE_MISC_FLAG , D3D11_TEXTURE2D_DESC , D3D11_USAGE_STAGING ,
5+ ID3D11Device , ID3D11DeviceContext , ID3D11Resource , ID3D11Texture2D ,
6+ D3D11_CPU_ACCESS_READ , D3D11_MAPPED_SUBRESOURCE , D3D11_MAP_READ , D3D11_TEXTURE2D_DESC ,
7+ D3D11_USAGE_STAGING ,
88 } ,
99 Dxgi :: Common :: { DXGI_FORMAT , DXGI_SAMPLE_DESC } ,
1010 } ,
@@ -33,15 +33,21 @@ impl StagingTexture {
3333 Count : 1 ,
3434 Quality : 0 ,
3535 } ,
36- BindFlags : D3D11_BIND_FLAG ( 0 ) ,
37- MiscFlags : D3D11_RESOURCE_MISC_FLAG ( 0 ) ,
36+ BindFlags : 0 ,
37+ MiscFlags : 0 ,
3838 Usage : D3D11_USAGE_STAGING ,
39- CPUAccessFlags : D3D11_CPU_ACCESS_READ ,
39+ CPUAccessFlags : D3D11_CPU_ACCESS_READ . 0 as u32 ,
4040 } ;
4141
42- let texture = unsafe { device. CreateTexture2D ( & desc, None ) ? } ;
42+ let mut texture = None ;
43+ unsafe {
44+ device. CreateTexture2D ( & desc, None , Some ( & mut texture) ) ?;
45+ }
4346
44- Ok ( Self { texture, desc } )
47+ Ok ( Self {
48+ texture : texture. expect ( "CreateTexture2D" ) ,
49+ desc,
50+ } )
4551 }
4652
4753 pub fn as_resource ( & self ) -> Result < ID3D11Resource > {
@@ -50,8 +56,16 @@ impl StagingTexture {
5056
5157 pub fn as_mapped ( & self , context : & ID3D11DeviceContext ) -> Result < D3D11_MAPPED_SUBRESOURCE > {
5258 let staging_texture_ptr: ID3D11Resource = self . texture . cast ( ) ?;
53- let mapped_texture =
54- unsafe { context. Map ( Some ( & staging_texture_ptr) , 0 , D3D11_MAP_READ , 0 ) ? } ;
59+ let mut mapped_texture = D3D11_MAPPED_SUBRESOURCE :: default ( ) ;
60+ unsafe {
61+ context. Map (
62+ Some ( & staging_texture_ptr) ,
63+ 0 ,
64+ D3D11_MAP_READ ,
65+ 0 ,
66+ Some ( & mut mapped_texture) ,
67+ ) ?;
68+ }
5569 // we can instantly unmap because the texture is staging, and will be still accessible by CPU
5670 // TODO there should be a way to do this by queueing a fence (we only need to wait copies) or something like that,
5771 // which would probably be more correct solution rather than map-unmap
0 commit comments