Welcome to mirror list, hosted at ThFree Co, Russian Federation.

d3d11_resource.h « d3d11 « src - github.com/doitsujin/dxvk.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c459ca3104501959ea7458715bed9ce8d26cc8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#pragma once

#include "d3d11_include.h"

namespace dxvk {

  /**
   * \brief Common resource description
   * 
   * Stores the usage and bind flags of a resource
   * Can be used to quickly determine whether it is
   * legal to create a view for a given resource.
   */
  struct D3D11_COMMON_RESOURCE_DESC {
    D3D11_RESOURCE_DIMENSION  Dim;
    DXGI_FORMAT               Format;
    D3D11_USAGE               Usage;
    UINT                      BindFlags;
    UINT                      CPUAccessFlags;
    UINT                      MiscFlags;
    UINT                      DxgiUsage;
  };
  

  /**
   * \brief IDXGIKeyedMutex implementation
   */
  class D3D11DXGIKeyedMutex : public IDXGIKeyedMutex {

  public:

    D3D11DXGIKeyedMutex(
            ID3D11Resource*         pResource);

    ~D3D11DXGIKeyedMutex();

    ULONG STDMETHODCALLTYPE AddRef();

    ULONG STDMETHODCALLTYPE Release();

    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                  riid,
            void**                  ppvObject);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                 Name,
            UINT*                   pDataSize,
            void*                   pData);

    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                 Name,
            UINT                    DataSize,
      const void*                   pData);

    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                 Name,
      const IUnknown*               pUnknown);

    HRESULT STDMETHODCALLTYPE GetParent(
            REFIID                  riid,
            void**                  ppParent);

    HRESULT STDMETHODCALLTYPE GetDevice(
            REFIID                  riid,
            void**                  ppDevice);

    HRESULT STDMETHODCALLTYPE AcquireSync(
            UINT64                  Key,
            DWORD                   dwMilliseconds);

    HRESULT STDMETHODCALLTYPE ReleaseSync(
            UINT64                  Key);

  private:

    ID3D11Resource* m_resource;
    bool m_warned = false;
  };


  /**
   * \brief IDXGIResource implementation for D3D11 resources
   */
  class D3D11DXGIResource : public IDXGIResource1 {

  public:
    
    D3D11DXGIResource(
            ID3D11Resource*         pResource);

    ~D3D11DXGIResource();

    ULONG STDMETHODCALLTYPE AddRef();
    
    ULONG STDMETHODCALLTYPE Release();
    
    HRESULT STDMETHODCALLTYPE QueryInterface(
            REFIID                  riid,
            void**                  ppvObject);

    HRESULT STDMETHODCALLTYPE GetPrivateData(
            REFGUID                 Name,
            UINT*                   pDataSize,
            void*                   pData);
    
    HRESULT STDMETHODCALLTYPE SetPrivateData(
            REFGUID                 Name,
            UINT                    DataSize,
      const void*                   pData);
    
    HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
            REFGUID                 Name,
      const IUnknown*               pUnknown);
    
    HRESULT STDMETHODCALLTYPE GetParent(
            REFIID                  riid,
            void**                  ppParent);
    
    HRESULT STDMETHODCALLTYPE GetDevice(
            REFIID                  riid,
            void**                  ppDevice);

    HRESULT STDMETHODCALLTYPE GetEvictionPriority(
            UINT*                   pEvictionPriority);

    HRESULT STDMETHODCALLTYPE GetSharedHandle(
            HANDLE*                 pSharedHandle);

    HRESULT STDMETHODCALLTYPE GetUsage(
            DXGI_USAGE*             pUsage);

    HRESULT STDMETHODCALLTYPE SetEvictionPriority(
            UINT                    EvictionPriority);

    HRESULT STDMETHODCALLTYPE CreateSharedHandle(
      const SECURITY_ATTRIBUTES*    pAttributes,
            DWORD                   dwAccess,
            LPCWSTR                 lpName,
            HANDLE*                 pHandle);

    HRESULT STDMETHODCALLTYPE CreateSubresourceSurface(
            UINT                    index,
            IDXGISurface2**         ppSurface);

    HRESULT GetKeyedMutex(void **ppvObject);

  private:

    ID3D11Resource* m_resource;
    D3D11DXGIKeyedMutex m_keyedMutex;

  };


  /**
   * \brief Queries D3D11on12 resource info
   *
   * \param [in] pResource The resource to query
   * \param [out] p11on12Info 11on12 info
   * \returns \c S_OK on success, or \c E_INVALIDARG
   */
  HRESULT GetResource11on12Info(
          ID3D11Resource*             pResource,
          D3D11_ON_12_RESOURCE_INFO*  p11on12Info);

  /**
   * \brief Queries common resource description
   * 
   * \param [in] pResource The resource to query
   * \param [out] pDesc Resource description
   * \returns \c S_OK on success, or \c E_INVALIDARG
   */
  HRESULT GetCommonResourceDesc(
          ID3D11Resource*             pResource,
          D3D11_COMMON_RESOURCE_DESC* pDesc);

  /**
   * \brief Checks whether a format can be used to view a resource
   * 
   * Depending on whether the resource is a buffer or a
   * texture, certain restrictions apply on which formats
   * can be used to view the resource.
   * \param [in] pResource The resource to check
   * \param [in] BindFlags Bind flags required for the view
   * \param [in] Format The desired view format
   * \param [in] Plane Plane slice for planar formats
   * \returns \c true if the format is compatible
   */
  BOOL CheckResourceViewCompatibility(
          ID3D11Resource*             pResource,
          UINT                        BindFlags,
          DXGI_FORMAT                 Format,
          UINT                        Plane);

  /**
   * \brief Queries paged resource from resource pointer
   *
   * \param [in] resource The resource
   * \returns Paged resource object
   */
  Rc<DxvkPagedResource> GetPagedResource(
          ID3D11Resource*             pResource);

  /**
   * \brief Increments private reference count of a resource
   * 
   * Helper method that figures out the exact type of
   * the resource and calls its \c AddRefPrivate method.
   * \param [in] pResource The resource to reference
   * \param [in] Type Resource type
   * \returns \c S_OK, or \c E_INVALIDARG for an invalid resource
   */
  HRESULT ResourceAddRefPrivate(
          ID3D11Resource*             pResource,
          D3D11_RESOURCE_DIMENSION    Type);
  
  HRESULT ResourceAddRefPrivate(
          ID3D11Resource*             pResource);

  /**
   * \brief Decrements private reference count of a resource
   * 
   * Helper method that figures out the exact type of
   * the resource and calls its \c ReleasePrivate method.
   * \param [in] pResource The resource to reference
   * \param [in] Type Resource type
   * \returns \c S_OK, or \c E_INVALIDARG for an invalid resource
   */
  HRESULT ResourceReleasePrivate(
          ID3D11Resource*             pResource,
          D3D11_RESOURCE_DIMENSION    Type);

  HRESULT ResourceReleasePrivate(
          ID3D11Resource*             pResource);

  /**
   * \brief Typed private resource pointer
   *
   * Stores a resource and its type, in order to avoid
   * unnecessary GetType calls. Also optionally stores
   * a subresource index to avoid struct padding.
   */
  class D3D11ResourceRef {

  public:

    D3D11ResourceRef()
    : m_type(D3D11_RESOURCE_DIMENSION_UNKNOWN),
      m_subresource(0), m_resource(nullptr) { }

    D3D11ResourceRef(ID3D11Resource* pResource)
    : D3D11ResourceRef(pResource, 0) { }

    D3D11ResourceRef(ID3D11Resource* pResource, UINT Subresource)
    : m_type(D3D11_RESOURCE_DIMENSION_UNKNOWN),
      m_subresource(Subresource), m_resource(pResource) {
      if (m_resource) {
        m_resource->GetType(&m_type);
        ResourceAddRefPrivate(m_resource, m_type);
      }
    }

    D3D11ResourceRef(ID3D11Resource* pResource, UINT Subresource, D3D11_RESOURCE_DIMENSION Type)
    : m_type(Type), m_subresource(Subresource), m_resource(pResource) {
      if (m_resource)
        ResourceAddRefPrivate(m_resource, m_type);
    }

    D3D11ResourceRef(D3D11ResourceRef&& other)
    : m_type(other.m_type), m_subresource(other.m_subresource), m_resource(other.m_resource) {
      other.m_type = D3D11_RESOURCE_DIMENSION_UNKNOWN;
      other.m_subresource = 0;
      other.m_resource = nullptr;
    }

    D3D11ResourceRef(const D3D11ResourceRef& other)
    : m_type(other.m_type), m_subresource(other.m_subresource), m_resource(other.m_resource) {
      if (m_resource)
        ResourceAddRefPrivate(m_resource, m_type);
    }

    ~D3D11ResourceRef() {
      if (m_resource)
        ResourceReleasePrivate(m_resource, m_type);
    }

    D3D11ResourceRef& operator = (D3D11ResourceRef&& other) {
      if (m_resource)
        ResourceReleasePrivate(m_resource, m_type);

      m_type = other.m_type;
      m_subresource = other.m_subresource;
      m_resource = other.m_resource;

      other.m_type = D3D11_RESOURCE_DIMENSION_UNKNOWN;
      other.m_subresource = 0;
      other.m_resource = nullptr;
      return *this;
    }

    D3D11ResourceRef& operator = (const D3D11ResourceRef& other) {
      if (other.m_resource)
        ResourceAddRefPrivate(other.m_resource, other.m_type);

      if (m_resource)
        ResourceReleasePrivate(m_resource, m_type);

      m_type = other.m_type;
      m_subresource = other.m_subresource;
      m_resource = other.m_resource;
      return *this;
    }

    D3D11_RESOURCE_DIMENSION GetType() const {
      return m_type;
    }

    UINT GetSubresource() const {
      return m_subresource;
    }

    ID3D11Resource* Get() const {
      return m_resource;
    }

  private:

    D3D11_RESOURCE_DIMENSION  m_type;
    UINT                      m_subresource;
    ID3D11Resource*           m_resource;

  };

}