1 | use super::{ID3D12Resource, D3D12_RESOURCE_STATES, DXGI_FORMAT}; |
2 | use crate::{gpu, prelude::*}; |
3 | use skia_bindings::{ |
4 | GrD3DAlloc, GrD3DMemoryAllocator, GrD3DSurfaceInfo, GrD3DTextureResourceInfo, SkRefCntBase, |
5 | }; |
6 | use std::{fmt, os::raw::c_uint}; |
7 | use windows::Win32::Graphics::{ |
8 | Direct3D12::{ID3D12Fence, D3D12_RESOURCE_STATE_COMMON}, |
9 | Dxgi::Common::{DXGI_FORMAT_UNKNOWN, DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN}, |
10 | }; |
11 | |
12 | // TODO: add remaining cp functions to ComPtr via traits (get, reset, retain). |
13 | |
14 | pub type Alloc = RCHandle<GrD3DAlloc>; |
15 | unsafe_send_sync!(Alloc); |
16 | |
17 | impl NativeRefCountedBase for GrD3DAlloc { |
18 | type Base = SkRefCntBase; |
19 | } |
20 | |
21 | impl fmt::Debug for Alloc { |
22 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
23 | f.debug_struct(name:"Alloc" ).finish() |
24 | } |
25 | } |
26 | |
27 | // TODO: support the implementation of custom D3D memory allocator's |
28 | // virtual createResource() and createAliasingResource() functions. |
29 | pub type MemoryAllocator = RCHandle<GrD3DMemoryAllocator>; |
30 | unsafe_send_sync!(MemoryAllocator); |
31 | |
32 | impl NativeRefCountedBase for GrD3DMemoryAllocator { |
33 | type Base = SkRefCntBase; |
34 | } |
35 | |
36 | impl fmt::Debug for MemoryAllocator { |
37 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
38 | f.debug_struct(name:"MemoryAllocator" ).finish() |
39 | } |
40 | } |
41 | |
42 | #[repr (C)] |
43 | #[derive (Clone, Debug)] |
44 | pub struct TextureResourceInfo { |
45 | pub resource: ID3D12Resource, |
46 | pub alloc: Option<Alloc>, |
47 | pub resource_state: D3D12_RESOURCE_STATES, |
48 | pub format: DXGI_FORMAT, |
49 | pub sample_count: u32, |
50 | pub level_count: u32, |
51 | pub sample_quality_pattern: std::os::raw::c_uint, |
52 | pub protected: gpu::Protected, |
53 | } |
54 | unsafe_send_sync!(TextureResourceInfo); |
55 | |
56 | impl TextureResourceInfo { |
57 | pub fn from_resource(resource: ID3D12Resource) -> Self { |
58 | Self { |
59 | resource, |
60 | alloc: None, |
61 | resource_state: D3D12_RESOURCE_STATE_COMMON, |
62 | format: DXGI_FORMAT_UNKNOWN, |
63 | sample_count: 1, |
64 | level_count: 0, |
65 | sample_quality_pattern: DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN, |
66 | protected: gpu::Protected::No, |
67 | } |
68 | } |
69 | |
70 | #[must_use ] |
71 | pub fn with_state(self, resource_state: D3D12_RESOURCE_STATES) -> Self { |
72 | Self { |
73 | resource_state, |
74 | ..self |
75 | } |
76 | } |
77 | } |
78 | |
79 | impl From<ID3D12Resource> for TextureResourceInfo { |
80 | fn from(resource: ID3D12Resource) -> Self { |
81 | Self::from_resource(resource) |
82 | } |
83 | } |
84 | |
85 | native_transmutable!( |
86 | GrD3DTextureResourceInfo, |
87 | TextureResourceInfo, |
88 | texture_resource_info_layout |
89 | ); |
90 | |
91 | #[repr (C)] |
92 | #[derive (Clone, Debug)] |
93 | pub struct FenceInfo { |
94 | pub fence: ID3D12Fence, |
95 | pub value: u64, |
96 | } |
97 | |
98 | unsafe_send_sync!(FenceInfo); |
99 | |
100 | #[derive (Copy, Clone, PartialEq, Eq, Debug)] |
101 | #[repr (C)] |
102 | pub struct SurfaceInfo { |
103 | pub sample_count: u32, |
104 | pub level_count: u32, |
105 | pub protected: gpu::Protected, |
106 | |
107 | pub format: DXGI_FORMAT, |
108 | pub sample_quality_pattern: c_uint, |
109 | } |
110 | |
111 | native_transmutable!(GrD3DSurfaceInfo, SurfaceInfo, surface_info_layout); |
112 | |
113 | impl Default for SurfaceInfo { |
114 | fn default() -> Self { |
115 | Self { |
116 | sample_count: 1, |
117 | level_count: 0, |
118 | protected: gpu::Protected::No, |
119 | format: DXGI_FORMAT_UNKNOWN, |
120 | sample_quality_pattern: DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN, |
121 | } |
122 | } |
123 | } |
124 | |