2 * Copyright 2009 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define NONAMELESSUNION
21 #define WINE_NO_NAMELESS_EXTENSION
22 #include "d3d11_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d11
);
26 static HRESULT
get_resource_properties(ID3D11Resource
*resource
, D3D11_RESOURCE_DIMENSION
*dimension
,
27 DXGI_FORMAT
*format
, unsigned int *miplevel_count
, unsigned int *layer_count
)
29 ID3D11Resource_GetType(resource
, dimension
);
32 case D3D11_RESOURCE_DIMENSION_BUFFER
:
35 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
37 const struct d3d_texture1d
*texture
;
39 if (!(texture
= unsafe_impl_from_ID3D11Texture1D((ID3D11Texture1D
*)resource
)))
41 ERR("Cannot get implementation from ID3D11Texture1D.\n");
45 *format
= texture
->desc
.Format
;
47 *miplevel_count
= texture
->desc
.MipLevels
;
48 *layer_count
= texture
->desc
.ArraySize
;
52 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
54 const struct d3d_texture2d
*texture
;
56 if (!(texture
= unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D
*)resource
)))
58 ERR("Cannot get implementation from ID3D11Texture2D.\n");
62 *format
= texture
->desc
.Format
;
64 *miplevel_count
= texture
->desc
.MipLevels
;
65 *layer_count
= texture
->desc
.ArraySize
;
69 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
71 const struct d3d_texture3d
*texture
;
73 if (!(texture
= unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D
*)resource
)))
75 ERR("Cannot get implementation from ID3D11Texture3D.\n");
79 *format
= texture
->desc
.Format
;
81 *miplevel_count
= texture
->desc
.MipLevels
;
82 *layer_count
= texture
->desc
.Depth
;
87 WARN("Invalid resource dimension %#x.\n", *dimension
);
94 static HRESULT
set_dsv_desc_from_resource(D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
96 D3D11_RESOURCE_DIMENSION dimension
;
98 ID3D11Resource_GetType(resource
, &dimension
);
104 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
106 D3D11_TEXTURE1D_DESC texture_desc
;
107 ID3D11Texture1D
*texture
;
109 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
)))
111 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
115 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
116 ID3D11Texture1D_Release(texture
);
118 desc
->Format
= texture_desc
.Format
;
119 if (texture_desc
.ArraySize
== 1)
121 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE1D
;
122 desc
->u
.Texture1D
.MipSlice
= 0;
126 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE1DARRAY
;
127 desc
->u
.Texture1DArray
.MipSlice
= 0;
128 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
129 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
135 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
137 D3D11_TEXTURE2D_DESC texture_desc
;
138 ID3D11Texture2D
*texture
;
140 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
142 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
146 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
147 ID3D11Texture2D_Release(texture
);
149 desc
->Format
= texture_desc
.Format
;
150 if (texture_desc
.ArraySize
== 1)
152 if (texture_desc
.SampleDesc
.Count
== 1)
154 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2D
;
155 desc
->u
.Texture2D
.MipSlice
= 0;
159 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DMS
;
164 if (texture_desc
.SampleDesc
.Count
== 1)
166 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DARRAY
;
167 desc
->u
.Texture2DArray
.MipSlice
= 0;
168 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
169 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
173 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
;
174 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
175 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
182 case D3D11_RESOURCE_DIMENSION_BUFFER
:
183 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
185 WARN("Invalid resource dimension %#x.\n", dimension
);
190 static HRESULT
normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
192 D3D11_RESOURCE_DIMENSION dimension
;
193 unsigned int layer_count
;
197 if (FAILED(hr
= get_resource_properties(resource
, &dimension
, &format
, NULL
, &layer_count
)))
201 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
202 if (desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE1D
203 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE1DARRAY
)
205 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
210 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
211 if (desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2D
212 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DARRAY
213 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DMS
214 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
)
216 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
221 case D3D11_RESOURCE_DIMENSION_BUFFER
:
222 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
224 WARN("Invalid resource dimension %#x.\n", dimension
);
228 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
229 desc
->Format
= format
;
231 switch (desc
->ViewDimension
)
233 case D3D11_DSV_DIMENSION_TEXTURE1DARRAY
:
234 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
235 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
238 case D3D11_DSV_DIMENSION_TEXTURE2DARRAY
:
239 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
240 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
243 case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
:
244 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
245 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
255 static HRESULT
set_rtv_desc_from_resource(D3D11_RENDER_TARGET_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
257 D3D11_RESOURCE_DIMENSION dimension
;
260 ID3D11Resource_GetType(resource
, &dimension
);
264 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
266 ID3D11Texture1D
*texture
;
267 D3D11_TEXTURE1D_DESC texture_desc
;
269 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
);
272 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D?\n");
276 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
277 ID3D11Texture1D_Release(texture
);
279 desc
->Format
= texture_desc
.Format
;
280 if (texture_desc
.ArraySize
== 1)
282 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE1D
;
283 desc
->u
.Texture1D
.MipSlice
= 0;
287 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE1DARRAY
;
288 desc
->u
.Texture1DArray
.MipSlice
= 0;
289 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
290 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
296 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
298 ID3D11Texture2D
*texture
;
299 D3D11_TEXTURE2D_DESC texture_desc
;
301 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
);
304 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D?\n");
308 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
309 ID3D11Texture2D_Release(texture
);
311 desc
->Format
= texture_desc
.Format
;
312 if (texture_desc
.ArraySize
== 1)
314 if (texture_desc
.SampleDesc
.Count
== 1)
316 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2D
;
317 desc
->u
.Texture2D
.MipSlice
= 0;
321 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DMS
;
326 if (texture_desc
.SampleDesc
.Count
== 1)
328 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DARRAY
;
329 desc
->u
.Texture2DArray
.MipSlice
= 0;
330 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
331 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
335 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
;
336 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
337 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
344 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
346 ID3D11Texture3D
*texture
;
347 D3D11_TEXTURE3D_DESC texture_desc
;
349 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
);
352 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D?\n");
356 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
357 ID3D11Texture3D_Release(texture
);
359 desc
->Format
= texture_desc
.Format
;
360 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE3D
;
361 desc
->u
.Texture3D
.MipSlice
= 0;
362 desc
->u
.Texture3D
.FirstWSlice
= 0;
363 desc
->u
.Texture3D
.WSize
= texture_desc
.Depth
;
369 FIXME("Unhandled resource dimension %#x.\n", dimension
);
374 static HRESULT
normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
376 D3D11_RESOURCE_DIMENSION dimension
;
377 unsigned int layer_count
;
381 if (FAILED(hr
= get_resource_properties(resource
, &dimension
, &format
, NULL
, &layer_count
)))
385 case D3D11_RESOURCE_DIMENSION_BUFFER
:
386 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_BUFFER
)
388 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
393 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
394 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE1D
395 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE1DARRAY
)
397 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
402 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
403 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2D
404 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DARRAY
405 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DMS
406 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
)
408 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
413 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
414 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE3D
)
416 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
422 WARN("Invalid resource dimension %#x.\n", dimension
);
426 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
427 desc
->Format
= format
;
429 switch (desc
->ViewDimension
)
431 case D3D11_RTV_DIMENSION_TEXTURE1DARRAY
:
432 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
433 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
436 case D3D11_RTV_DIMENSION_TEXTURE2DARRAY
:
437 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
438 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
441 case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
:
442 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
443 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
446 case D3D11_RTV_DIMENSION_TEXTURE3D
:
447 layer_count
= max(1, layer_count
>> desc
->u
.Texture3D
.MipSlice
);
448 if (desc
->u
.Texture3D
.WSize
== ~0u && desc
->u
.Texture3D
.FirstWSlice
< layer_count
)
449 desc
->u
.Texture3D
.WSize
= layer_count
- desc
->u
.Texture3D
.FirstWSlice
;
459 static HRESULT
set_srv_desc_from_resource(D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
461 D3D11_RESOURCE_DIMENSION dimension
;
463 ID3D11Resource_GetType(resource
, &dimension
);
467 case D3D11_RESOURCE_DIMENSION_BUFFER
:
469 D3D11_BUFFER_DESC buffer_desc
;
470 ID3D11Buffer
*buffer
;
472 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Buffer
, (void **)&buffer
)))
474 ERR("Resource of type BUFFER doesn't implement ID3D11Buffer.\n");
478 ID3D11Buffer_GetDesc(buffer
, &buffer_desc
);
479 ID3D11Buffer_Release(buffer
);
481 if (buffer_desc
.MiscFlags
& D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
)
483 desc
->Format
= DXGI_FORMAT_UNKNOWN
;
484 desc
->ViewDimension
= D3D11_SRV_DIMENSION_BUFFER
;
485 desc
->u
.Buffer
.u1
.FirstElement
= 0;
486 desc
->u
.Buffer
.u2
.NumElements
= buffer_desc
.ByteWidth
/ buffer_desc
.StructureByteStride
;
493 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
495 D3D11_TEXTURE1D_DESC texture_desc
;
496 ID3D11Texture1D
*texture
;
498 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
)))
500 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
504 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
505 ID3D11Texture1D_Release(texture
);
507 desc
->Format
= texture_desc
.Format
;
508 if (texture_desc
.ArraySize
== 1)
510 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE1D
;
511 desc
->u
.Texture1D
.MostDetailedMip
= 0;
512 desc
->u
.Texture1D
.MipLevels
= texture_desc
.MipLevels
;
516 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE1DARRAY
;
517 desc
->u
.Texture1DArray
.MostDetailedMip
= 0;
518 desc
->u
.Texture1DArray
.MipLevels
= texture_desc
.MipLevels
;
519 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
520 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
526 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
528 D3D11_TEXTURE2D_DESC texture_desc
;
529 ID3D11Texture2D
*texture
;
531 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
533 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
537 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
538 ID3D11Texture2D_Release(texture
);
540 desc
->Format
= texture_desc
.Format
;
541 if (texture_desc
.MiscFlags
& D3D11_RESOURCE_MISC_TEXTURECUBE
)
543 if (texture_desc
.ArraySize
>= 12)
545 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
;
546 desc
->u
.TextureCubeArray
.MostDetailedMip
= 0;
547 desc
->u
.TextureCubeArray
.MipLevels
= texture_desc
.MipLevels
;
548 desc
->u
.TextureCubeArray
.First2DArrayFace
= 0;
549 desc
->u
.TextureCubeArray
.NumCubes
= texture_desc
.ArraySize
/ 6;
553 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURECUBE
;
554 desc
->u
.TextureCube
.MostDetailedMip
= 0;
555 desc
->u
.TextureCube
.MipLevels
= texture_desc
.MipLevels
;
558 else if (texture_desc
.ArraySize
== 1)
560 if (texture_desc
.SampleDesc
.Count
== 1)
562 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2D
;
563 desc
->u
.Texture2D
.MostDetailedMip
= 0;
564 desc
->u
.Texture2D
.MipLevels
= texture_desc
.MipLevels
;
568 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DMS
;
573 if (texture_desc
.SampleDesc
.Count
== 1)
575 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DARRAY
;
576 desc
->u
.Texture2DArray
.MostDetailedMip
= 0;
577 desc
->u
.Texture2DArray
.MipLevels
= texture_desc
.MipLevels
;
578 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
579 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
583 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
;
584 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
585 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
592 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
594 D3D11_TEXTURE3D_DESC texture_desc
;
595 ID3D11Texture3D
*texture
;
597 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
)))
599 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D.\n");
603 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
604 ID3D11Texture3D_Release(texture
);
606 desc
->Format
= texture_desc
.Format
;
607 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE3D
;
608 desc
->u
.Texture3D
.MostDetailedMip
= 0;
609 desc
->u
.Texture3D
.MipLevels
= texture_desc
.MipLevels
;
615 WARN("Invalid resource dimension %#x.\n", dimension
);
620 static HRESULT
normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
622 unsigned int miplevel_count
, layer_count
;
623 D3D11_RESOURCE_DIMENSION dimension
;
627 if (FAILED(hr
= get_resource_properties(resource
, &dimension
, &format
, &miplevel_count
, &layer_count
)))
631 case D3D11_RESOURCE_DIMENSION_BUFFER
:
632 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_BUFFER
633 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_BUFFEREX
)
635 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
638 if (!desc
->u
.Buffer
.u2
.NumElements
)
640 WARN("Zero sized buffer view.\n");
645 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
646 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE1D
647 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE1DARRAY
)
649 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
654 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
655 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2D
656 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DARRAY
657 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DMS
658 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
659 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURECUBE
660 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
)
662 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
667 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
668 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE3D
)
670 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
676 WARN("Invalid resource dimension %#x.\n", dimension
);
680 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
681 desc
->Format
= format
;
683 switch (desc
->ViewDimension
)
685 case D3D11_SRV_DIMENSION_TEXTURE1D
:
686 if (desc
->u
.Texture1D
.MipLevels
== ~0u && desc
->u
.Texture1D
.MostDetailedMip
< miplevel_count
)
687 desc
->u
.Texture1D
.MipLevels
= miplevel_count
- desc
->u
.Texture1D
.MostDetailedMip
;
690 case D3D11_SRV_DIMENSION_TEXTURE1DARRAY
:
691 if (desc
->u
.Texture1DArray
.MipLevels
== ~0u && desc
->u
.Texture1DArray
.MostDetailedMip
< miplevel_count
)
692 desc
->u
.Texture1DArray
.MipLevels
= miplevel_count
- desc
->u
.Texture1DArray
.MostDetailedMip
;
693 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< miplevel_count
)
694 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
697 case D3D11_SRV_DIMENSION_TEXTURE2D
:
698 if (desc
->u
.Texture2D
.MipLevels
== ~0u && desc
->u
.Texture2D
.MostDetailedMip
< miplevel_count
)
699 desc
->u
.Texture2D
.MipLevels
= miplevel_count
- desc
->u
.Texture2D
.MostDetailedMip
;
702 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY
:
703 if (desc
->u
.Texture2DArray
.MipLevels
== ~0u && desc
->u
.Texture2DArray
.MostDetailedMip
< miplevel_count
)
704 desc
->u
.Texture2DArray
.MipLevels
= miplevel_count
- desc
->u
.Texture2DArray
.MostDetailedMip
;
705 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
706 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
709 case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
:
710 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
711 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
714 case D3D11_SRV_DIMENSION_TEXTURE3D
:
715 if (desc
->u
.Texture3D
.MipLevels
== ~0u && desc
->u
.Texture3D
.MostDetailedMip
< miplevel_count
)
716 desc
->u
.Texture3D
.MipLevels
= miplevel_count
- desc
->u
.Texture3D
.MostDetailedMip
;
719 case D3D11_SRV_DIMENSION_TEXTURECUBE
:
720 if (desc
->u
.TextureCube
.MipLevels
== ~0u && desc
->u
.TextureCube
.MostDetailedMip
< miplevel_count
)
721 desc
->u
.TextureCube
.MipLevels
= miplevel_count
- desc
->u
.TextureCube
.MostDetailedMip
;
724 case D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
:
725 if (desc
->u
.TextureCubeArray
.MipLevels
== ~0u && desc
->u
.TextureCubeArray
.MostDetailedMip
< miplevel_count
)
726 desc
->u
.TextureCubeArray
.MipLevels
= miplevel_count
- desc
->u
.TextureCubeArray
.MostDetailedMip
;
727 if (desc
->u
.TextureCubeArray
.NumCubes
== ~0u && desc
->u
.TextureCubeArray
.First2DArrayFace
< layer_count
)
728 desc
->u
.TextureCubeArray
.NumCubes
= (layer_count
- desc
->u
.TextureCubeArray
.First2DArrayFace
) / 6;
738 static HRESULT
set_uav_desc_from_resource(D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
740 D3D11_RESOURCE_DIMENSION dimension
;
742 ID3D11Resource_GetType(resource
, &dimension
);
746 case D3D11_RESOURCE_DIMENSION_BUFFER
:
748 D3D11_BUFFER_DESC buffer_desc
;
749 ID3D11Buffer
*buffer
;
751 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Buffer
, (void **)&buffer
)))
753 ERR("Resource of type BUFFER doesn't implement ID3D11Buffer.\n");
757 ID3D11Buffer_GetDesc(buffer
, &buffer_desc
);
758 ID3D11Buffer_Release(buffer
);
760 if (buffer_desc
.MiscFlags
& D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
)
762 desc
->Format
= DXGI_FORMAT_UNKNOWN
;
763 desc
->ViewDimension
= D3D11_UAV_DIMENSION_BUFFER
;
764 desc
->u
.Buffer
.FirstElement
= 0;
765 desc
->u
.Buffer
.NumElements
= buffer_desc
.ByteWidth
/ buffer_desc
.StructureByteStride
;
766 desc
->u
.Buffer
.Flags
= 0;
773 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
775 D3D11_TEXTURE2D_DESC texture_desc
;
776 ID3D11Texture2D
*texture
;
778 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
780 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
784 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
785 ID3D11Texture2D_Release(texture
);
787 if (texture_desc
.SampleDesc
.Count
!= 1)
789 WARN("Trying to create view for multisample texture.\n");
793 desc
->Format
= texture_desc
.Format
;
794 if (texture_desc
.ArraySize
== 1)
796 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE2D
;
797 desc
->u
.Texture2D
.MipSlice
= 0;
801 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE2DARRAY
;
802 desc
->u
.Texture2DArray
.MipSlice
= 0;
803 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
804 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
810 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
812 D3D11_TEXTURE3D_DESC texture_desc
;
813 ID3D11Texture3D
*texture
;
815 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
)))
817 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D.\n");
821 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
822 ID3D11Texture3D_Release(texture
);
824 desc
->Format
= texture_desc
.Format
;
825 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE3D
;
826 desc
->u
.Texture3D
.MipSlice
= 0;
827 desc
->u
.Texture3D
.FirstWSlice
= 0;
828 desc
->u
.Texture3D
.WSize
= texture_desc
.Depth
;
834 FIXME("Unhandled resource dimension %#x.\n", dimension
);
839 static HRESULT
normalize_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
841 D3D11_RESOURCE_DIMENSION dimension
;
842 unsigned int layer_count
;
846 if (FAILED(hr
= get_resource_properties(resource
, &dimension
, &format
, NULL
, &layer_count
)))
850 case D3D11_RESOURCE_DIMENSION_BUFFER
:
851 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_BUFFER
)
853 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
858 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
859 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE1D
860 && desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE1DARRAY
)
862 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
867 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
868 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE2D
869 && desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE2DARRAY
)
871 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
876 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
877 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE3D
)
879 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
885 WARN("Invalid resource dimension %#x.\n", dimension
);
889 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
890 desc
->Format
= format
;
892 switch (desc
->ViewDimension
)
894 case D3D11_UAV_DIMENSION_TEXTURE1DARRAY
:
895 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
896 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
899 case D3D11_UAV_DIMENSION_TEXTURE2DARRAY
:
900 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
901 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
904 case D3D11_UAV_DIMENSION_TEXTURE3D
:
905 layer_count
= max(1, layer_count
>> desc
->u
.Texture3D
.MipSlice
);
906 if (desc
->u
.Texture3D
.WSize
== ~0u && desc
->u
.Texture3D
.FirstWSlice
< layer_count
)
907 desc
->u
.Texture3D
.WSize
= layer_count
- desc
->u
.Texture3D
.FirstWSlice
;
917 /* ID3D11DepthStencilView methods */
919 static inline struct d3d_depthstencil_view
*impl_from_ID3D11DepthStencilView(ID3D11DepthStencilView
*iface
)
921 return CONTAINING_RECORD(iface
, struct d3d_depthstencil_view
, ID3D11DepthStencilView_iface
);
924 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_QueryInterface(ID3D11DepthStencilView
*iface
,
925 REFIID riid
, void **object
)
927 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
929 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
931 if (IsEqualGUID(riid
, &IID_ID3D11DepthStencilView
)
932 || IsEqualGUID(riid
, &IID_ID3D11View
)
933 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
934 || IsEqualGUID(riid
, &IID_IUnknown
))
936 ID3D11DepthStencilView_AddRef(iface
);
941 if (IsEqualGUID(riid
, &IID_ID3D10DepthStencilView
)
942 || IsEqualGUID(riid
, &IID_ID3D10View
)
943 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
945 ID3D10DepthStencilView_AddRef(&view
->ID3D10DepthStencilView_iface
);
946 *object
= &view
->ID3D10DepthStencilView_iface
;
950 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
953 return E_NOINTERFACE
;
956 static ULONG STDMETHODCALLTYPE
d3d11_depthstencil_view_AddRef(ID3D11DepthStencilView
*iface
)
958 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
959 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
961 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
965 ID3D11Device2_AddRef(view
->device
);
966 wined3d_mutex_lock();
967 wined3d_rendertarget_view_incref(view
->wined3d_view
);
968 wined3d_mutex_unlock();
974 static ULONG STDMETHODCALLTYPE
d3d11_depthstencil_view_Release(ID3D11DepthStencilView
*iface
)
976 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
977 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
979 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
983 ID3D11Device2
*device
= view
->device
;
985 wined3d_mutex_lock();
986 wined3d_rendertarget_view_decref(view
->wined3d_view
);
987 wined3d_mutex_unlock();
989 ID3D11Device2_Release(device
);
995 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetDevice(ID3D11DepthStencilView
*iface
,
996 ID3D11Device
**device
)
998 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1000 TRACE("iface %p, device %p.\n", iface
, device
);
1002 *device
= (ID3D11Device
*)view
->device
;
1003 ID3D11Device_AddRef(*device
);
1006 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_GetPrivateData(ID3D11DepthStencilView
*iface
,
1007 REFGUID guid
, UINT
*data_size
, void *data
)
1009 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1011 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1013 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1016 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_SetPrivateData(ID3D11DepthStencilView
*iface
,
1017 REFGUID guid
, UINT data_size
, const void *data
)
1019 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1021 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1023 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1026 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_SetPrivateDataInterface(ID3D11DepthStencilView
*iface
,
1027 REFGUID guid
, const IUnknown
*data
)
1029 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1031 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1033 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1036 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetResource(ID3D11DepthStencilView
*iface
,
1037 ID3D11Resource
**resource
)
1039 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1041 TRACE("iface %p, resource %p.\n", iface
, resource
);
1043 *resource
= view
->resource
;
1044 ID3D11Resource_AddRef(*resource
);
1047 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetDesc(ID3D11DepthStencilView
*iface
,
1048 D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
1050 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1052 TRACE("iface %p, desc %p.\n", iface
, desc
);
1057 static const struct ID3D11DepthStencilViewVtbl d3d11_depthstencil_view_vtbl
=
1059 /* IUnknown methods */
1060 d3d11_depthstencil_view_QueryInterface
,
1061 d3d11_depthstencil_view_AddRef
,
1062 d3d11_depthstencil_view_Release
,
1063 /* ID3D11DeviceChild methods */
1064 d3d11_depthstencil_view_GetDevice
,
1065 d3d11_depthstencil_view_GetPrivateData
,
1066 d3d11_depthstencil_view_SetPrivateData
,
1067 d3d11_depthstencil_view_SetPrivateDataInterface
,
1068 /* ID3D11View methods */
1069 d3d11_depthstencil_view_GetResource
,
1070 /* ID3D11DepthStencilView methods */
1071 d3d11_depthstencil_view_GetDesc
,
1074 /* ID3D10DepthStencilView methods */
1076 static inline struct d3d_depthstencil_view
*impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView
*iface
)
1078 return CONTAINING_RECORD(iface
, struct d3d_depthstencil_view
, ID3D10DepthStencilView_iface
);
1081 /* IUnknown methods */
1083 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView
*iface
,
1084 REFIID riid
, void **object
)
1086 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1088 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1090 return d3d11_depthstencil_view_QueryInterface(&view
->ID3D11DepthStencilView_iface
, riid
, object
);
1093 static ULONG STDMETHODCALLTYPE
d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView
*iface
)
1095 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1097 TRACE("iface %p.\n", iface
);
1099 return d3d11_depthstencil_view_AddRef(&view
->ID3D11DepthStencilView_iface
);
1102 static ULONG STDMETHODCALLTYPE
d3d10_depthstencil_view_Release(ID3D10DepthStencilView
*iface
)
1104 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1106 TRACE("iface %p.\n", iface
);
1108 return d3d11_depthstencil_view_Release(&view
->ID3D11DepthStencilView_iface
);
1111 /* ID3D10DeviceChild methods */
1113 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView
*iface
, ID3D10Device
**device
)
1115 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1117 TRACE("iface %p, device %p.\n", iface
, device
);
1119 ID3D11Device2_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
1122 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView
*iface
,
1123 REFGUID guid
, UINT
*data_size
, void *data
)
1125 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1127 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1128 iface
, debugstr_guid(guid
), data_size
, data
);
1130 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1133 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView
*iface
,
1134 REFGUID guid
, UINT data_size
, const void *data
)
1136 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1138 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1139 iface
, debugstr_guid(guid
), data_size
, data
);
1141 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1144 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView
*iface
,
1145 REFGUID guid
, const IUnknown
*data
)
1147 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1149 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1151 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1154 /* ID3D10View methods */
1156 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView
*iface
,
1157 ID3D10Resource
**resource
)
1159 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1161 TRACE("iface %p, resource %p.\n", iface
, resource
);
1163 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
1166 /* ID3D10DepthStencilView methods */
1168 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView
*iface
,
1169 D3D10_DEPTH_STENCIL_VIEW_DESC
*desc
)
1171 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1172 const D3D11_DEPTH_STENCIL_VIEW_DESC
*d3d11_desc
= &view
->desc
;
1174 TRACE("iface %p, desc %p.\n", iface
, desc
);
1176 desc
->Format
= d3d11_desc
->Format
;
1177 desc
->ViewDimension
= (D3D10_DSV_DIMENSION
)d3d11_desc
->ViewDimension
;
1178 memcpy(&desc
->u
, &d3d11_desc
->u
, sizeof(desc
->u
));
1181 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl
=
1183 /* IUnknown methods */
1184 d3d10_depthstencil_view_QueryInterface
,
1185 d3d10_depthstencil_view_AddRef
,
1186 d3d10_depthstencil_view_Release
,
1187 /* ID3D10DeviceChild methods */
1188 d3d10_depthstencil_view_GetDevice
,
1189 d3d10_depthstencil_view_GetPrivateData
,
1190 d3d10_depthstencil_view_SetPrivateData
,
1191 d3d10_depthstencil_view_SetPrivateDataInterface
,
1192 /* ID3D10View methods */
1193 d3d10_depthstencil_view_GetResource
,
1194 /* ID3D10DepthStencilView methods */
1195 d3d10_depthstencil_view_GetDesc
,
1198 static void STDMETHODCALLTYPE
d3d_depth_stencil_view_wined3d_object_destroyed(void *parent
)
1200 struct d3d_depthstencil_view
*view
= parent
;
1202 wined3d_private_store_cleanup(&view
->private_store
);
1206 static const struct wined3d_parent_ops d3d_depth_stencil_view_wined3d_parent_ops
=
1208 d3d_depth_stencil_view_wined3d_object_destroyed
,
1211 static void wined3d_depth_stencil_view_desc_from_d3d11(struct wined3d_view_desc
*wined3d_desc
,
1212 const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
1214 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
1216 wined3d_desc
->flags
= 0;
1217 if (desc
->Flags
& D3D11_DSV_READ_ONLY_DEPTH
)
1218 wined3d_desc
->flags
|= WINED3D_VIEW_READ_ONLY_DEPTH
;
1219 if (desc
->Flags
& D3D11_DSV_READ_ONLY_STENCIL
)
1220 wined3d_desc
->flags
|= WINED3D_VIEW_READ_ONLY_STENCIL
;
1222 wined3d_desc
->u
.texture
.level_count
= 1;
1223 switch (desc
->ViewDimension
)
1225 case D3D11_DSV_DIMENSION_TEXTURE1D
:
1226 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MipSlice
;
1227 wined3d_desc
->u
.texture
.layer_idx
= 0;
1228 wined3d_desc
->u
.texture
.layer_count
= 1;
1231 case D3D11_DSV_DIMENSION_TEXTURE1DARRAY
:
1232 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
1233 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MipSlice
;
1234 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
1235 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
1238 case D3D11_DSV_DIMENSION_TEXTURE2D
:
1239 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MipSlice
;
1240 wined3d_desc
->u
.texture
.layer_idx
= 0;
1241 wined3d_desc
->u
.texture
.layer_count
= 1;
1244 case D3D11_DSV_DIMENSION_TEXTURE2DARRAY
:
1245 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
1246 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MipSlice
;
1247 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
1248 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
1251 case D3D11_DSV_DIMENSION_TEXTURE2DMS
:
1252 wined3d_desc
->u
.texture
.level_idx
= 0;
1253 wined3d_desc
->u
.texture
.layer_idx
= 0;
1254 wined3d_desc
->u
.texture
.layer_count
= 1;
1257 case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
:
1258 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
1259 wined3d_desc
->u
.texture
.level_idx
= 0;
1260 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DMSArray
.FirstArraySlice
;
1261 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DMSArray
.ArraySize
;
1265 FIXME("Unhandled view dimension %#x.\n", desc
->ViewDimension
);
1266 wined3d_desc
->u
.texture
.level_idx
= 0;
1267 wined3d_desc
->u
.texture
.layer_idx
= 0;
1268 wined3d_desc
->u
.texture
.layer_count
= 1;
1273 static HRESULT
d3d_depthstencil_view_init(struct d3d_depthstencil_view
*view
, struct d3d_device
*device
,
1274 ID3D11Resource
*resource
, const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
1276 struct wined3d_resource
*wined3d_resource
;
1277 struct wined3d_view_desc wined3d_desc
;
1280 view
->ID3D11DepthStencilView_iface
.lpVtbl
= &d3d11_depthstencil_view_vtbl
;
1281 view
->ID3D10DepthStencilView_iface
.lpVtbl
= &d3d10_depthstencil_view_vtbl
;
1286 hr
= set_dsv_desc_from_resource(&view
->desc
, resource
);
1291 hr
= normalize_dsv_desc(&view
->desc
, resource
);
1296 wined3d_mutex_lock();
1297 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
1299 wined3d_mutex_unlock();
1300 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
1304 wined3d_depth_stencil_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
);
1305 if (FAILED(hr
= wined3d_rendertarget_view_create(&wined3d_desc
, wined3d_resource
,
1306 view
, &d3d_depth_stencil_view_wined3d_parent_ops
, &view
->wined3d_view
)))
1308 wined3d_mutex_unlock();
1309 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr
);
1313 wined3d_private_store_init(&view
->private_store
);
1314 wined3d_mutex_unlock();
1315 view
->resource
= resource
;
1316 ID3D11Device2_AddRef(view
->device
= &device
->ID3D11Device2_iface
);
1321 HRESULT
d3d_depthstencil_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
1322 const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, struct d3d_depthstencil_view
**view
)
1324 struct d3d_depthstencil_view
*object
;
1327 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1328 return E_OUTOFMEMORY
;
1330 if (FAILED(hr
= d3d_depthstencil_view_init(object
, device
, resource
, desc
)))
1332 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr
);
1337 TRACE("Created depthstencil view %p.\n", object
);
1343 struct d3d_depthstencil_view
*unsafe_impl_from_ID3D11DepthStencilView(ID3D11DepthStencilView
*iface
)
1347 assert(iface
->lpVtbl
== &d3d11_depthstencil_view_vtbl
);
1349 return impl_from_ID3D11DepthStencilView(iface
);
1352 struct d3d_depthstencil_view
*unsafe_impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView
*iface
)
1356 assert(iface
->lpVtbl
== &d3d10_depthstencil_view_vtbl
);
1358 return impl_from_ID3D10DepthStencilView(iface
);
1361 /* ID3D11RenderTargetView methods */
1363 static inline struct d3d_rendertarget_view
*impl_from_ID3D11RenderTargetView(ID3D11RenderTargetView
*iface
)
1365 return CONTAINING_RECORD(iface
, struct d3d_rendertarget_view
, ID3D11RenderTargetView_iface
);
1368 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_QueryInterface(ID3D11RenderTargetView
*iface
,
1369 REFIID riid
, void **object
)
1371 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1373 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1375 if (IsEqualGUID(riid
, &IID_ID3D11RenderTargetView
)
1376 || IsEqualGUID(riid
, &IID_ID3D11View
)
1377 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
1378 || IsEqualGUID(riid
, &IID_IUnknown
))
1380 ID3D11RenderTargetView_AddRef(iface
);
1385 if (IsEqualGUID(riid
, &IID_ID3D10RenderTargetView
)
1386 || IsEqualGUID(riid
, &IID_ID3D10View
)
1387 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
1389 ID3D10RenderTargetView_AddRef(&view
->ID3D10RenderTargetView_iface
);
1390 *object
= &view
->ID3D10RenderTargetView_iface
;
1394 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
1397 return E_NOINTERFACE
;
1400 static ULONG STDMETHODCALLTYPE
d3d11_rendertarget_view_AddRef(ID3D11RenderTargetView
*iface
)
1402 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1403 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
1405 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
1409 ID3D11Device2_AddRef(view
->device
);
1410 wined3d_mutex_lock();
1411 wined3d_rendertarget_view_incref(view
->wined3d_view
);
1412 wined3d_mutex_unlock();
1418 static ULONG STDMETHODCALLTYPE
d3d11_rendertarget_view_Release(ID3D11RenderTargetView
*iface
)
1420 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1421 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
1423 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
1427 ID3D11Device2
*device
= view
->device
;
1429 wined3d_mutex_lock();
1430 wined3d_rendertarget_view_decref(view
->wined3d_view
);
1431 wined3d_mutex_unlock();
1433 ID3D11Device2_Release(device
);
1439 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetDevice(ID3D11RenderTargetView
*iface
,
1440 ID3D11Device
**device
)
1442 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1444 TRACE("iface %p, device %p.\n", iface
, device
);
1446 *device
= (ID3D11Device
*)view
->device
;
1447 ID3D11Device_AddRef(*device
);
1450 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_GetPrivateData(ID3D11RenderTargetView
*iface
,
1451 REFGUID guid
, UINT
*data_size
, void *data
)
1453 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1455 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1457 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1460 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_SetPrivateData(ID3D11RenderTargetView
*iface
,
1461 REFGUID guid
, UINT data_size
, const void *data
)
1463 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1465 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1467 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1470 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_SetPrivateDataInterface(ID3D11RenderTargetView
*iface
,
1471 REFGUID guid
, const IUnknown
*data
)
1473 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1475 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1477 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1480 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetResource(ID3D11RenderTargetView
*iface
,
1481 ID3D11Resource
**resource
)
1483 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1485 TRACE("iface %p, resource %p.\n", iface
, resource
);
1487 *resource
= view
->resource
;
1488 ID3D11Resource_AddRef(*resource
);
1491 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetDesc(ID3D11RenderTargetView
*iface
,
1492 D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
1494 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1496 TRACE("iface %p, desc %p.\n", iface
, desc
);
1501 static const struct ID3D11RenderTargetViewVtbl d3d11_rendertarget_view_vtbl
=
1503 /* IUnknown methods */
1504 d3d11_rendertarget_view_QueryInterface
,
1505 d3d11_rendertarget_view_AddRef
,
1506 d3d11_rendertarget_view_Release
,
1507 /* ID3D11DeviceChild methods */
1508 d3d11_rendertarget_view_GetDevice
,
1509 d3d11_rendertarget_view_GetPrivateData
,
1510 d3d11_rendertarget_view_SetPrivateData
,
1511 d3d11_rendertarget_view_SetPrivateDataInterface
,
1512 /* ID3D11View methods */
1513 d3d11_rendertarget_view_GetResource
,
1514 /* ID3D11RenderTargetView methods */
1515 d3d11_rendertarget_view_GetDesc
,
1518 /* ID3D10RenderTargetView methods */
1520 static inline struct d3d_rendertarget_view
*impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView
*iface
)
1522 return CONTAINING_RECORD(iface
, struct d3d_rendertarget_view
, ID3D10RenderTargetView_iface
);
1525 /* IUnknown methods */
1527 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView
*iface
,
1528 REFIID riid
, void **object
)
1530 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1532 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1534 return d3d11_rendertarget_view_QueryInterface(&view
->ID3D11RenderTargetView_iface
, riid
, object
);
1537 static ULONG STDMETHODCALLTYPE
d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView
*iface
)
1539 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1541 TRACE("iface %p.\n", iface
);
1543 return d3d11_rendertarget_view_AddRef(&view
->ID3D11RenderTargetView_iface
);
1546 static ULONG STDMETHODCALLTYPE
d3d10_rendertarget_view_Release(ID3D10RenderTargetView
*iface
)
1548 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1550 TRACE("iface %p.\n", iface
);
1552 return d3d11_rendertarget_view_Release(&view
->ID3D11RenderTargetView_iface
);
1555 /* ID3D10DeviceChild methods */
1557 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView
*iface
, ID3D10Device
**device
)
1559 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1561 TRACE("iface %p, device %p.\n", iface
, device
);
1563 ID3D11Device2_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
1566 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView
*iface
,
1567 REFGUID guid
, UINT
*data_size
, void *data
)
1569 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1571 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1572 iface
, debugstr_guid(guid
), data_size
, data
);
1574 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1577 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView
*iface
,
1578 REFGUID guid
, UINT data_size
, const void *data
)
1580 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1582 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1583 iface
, debugstr_guid(guid
), data_size
, data
);
1585 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1588 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView
*iface
,
1589 REFGUID guid
, const IUnknown
*data
)
1591 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1593 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1595 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1598 /* ID3D10View methods */
1600 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView
*iface
,
1601 ID3D10Resource
**resource
)
1603 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1605 TRACE("iface %p, resource %p\n", iface
, resource
);
1607 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
1610 /* ID3D10RenderTargetView methods */
1612 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView
*iface
,
1613 D3D10_RENDER_TARGET_VIEW_DESC
*desc
)
1615 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1617 TRACE("iface %p, desc %p\n", iface
, desc
);
1619 memcpy(desc
, &view
->desc
, sizeof(*desc
));
1622 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl
=
1624 /* IUnknown methods */
1625 d3d10_rendertarget_view_QueryInterface
,
1626 d3d10_rendertarget_view_AddRef
,
1627 d3d10_rendertarget_view_Release
,
1628 /* ID3D10DeviceChild methods */
1629 d3d10_rendertarget_view_GetDevice
,
1630 d3d10_rendertarget_view_GetPrivateData
,
1631 d3d10_rendertarget_view_SetPrivateData
,
1632 d3d10_rendertarget_view_SetPrivateDataInterface
,
1633 /* ID3D10View methods */
1634 d3d10_rendertarget_view_GetResource
,
1635 /* ID3D10RenderTargetView methods */
1636 d3d10_rendertarget_view_GetDesc
,
1639 static void STDMETHODCALLTYPE
d3d_render_target_view_wined3d_object_destroyed(void *parent
)
1641 struct d3d_rendertarget_view
*view
= parent
;
1643 wined3d_private_store_cleanup(&view
->private_store
);
1647 static const struct wined3d_parent_ops d3d_render_target_view_wined3d_parent_ops
=
1649 d3d_render_target_view_wined3d_object_destroyed
,
1652 static void wined3d_rendertarget_view_desc_from_d3d11(struct wined3d_view_desc
*wined3d_desc
,
1653 const D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
1655 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
1657 wined3d_desc
->flags
= 0;
1658 wined3d_desc
->u
.texture
.level_count
= 1;
1659 switch (desc
->ViewDimension
)
1661 case D3D11_RTV_DIMENSION_BUFFER
:
1662 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.Buffer
.u1
.FirstElement
;
1663 wined3d_desc
->u
.buffer
.count
= desc
->u
.Buffer
.u2
.NumElements
;
1666 case D3D11_RTV_DIMENSION_TEXTURE1D
:
1667 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MipSlice
;
1668 wined3d_desc
->u
.texture
.layer_idx
= 0;
1669 wined3d_desc
->u
.texture
.layer_count
= 1;
1672 case D3D11_RTV_DIMENSION_TEXTURE1DARRAY
:
1673 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
1674 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MipSlice
;
1675 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
1676 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
1679 case D3D11_RTV_DIMENSION_TEXTURE2D
:
1680 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MipSlice
;
1681 wined3d_desc
->u
.texture
.layer_idx
= 0;
1682 wined3d_desc
->u
.texture
.layer_count
= 1;
1685 case D3D11_RTV_DIMENSION_TEXTURE2DARRAY
:
1686 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
1687 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MipSlice
;
1688 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
1689 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
1692 case D3D11_RTV_DIMENSION_TEXTURE2DMS
:
1693 wined3d_desc
->u
.texture
.level_idx
= 0;
1694 wined3d_desc
->u
.texture
.layer_idx
= 0;
1695 wined3d_desc
->u
.texture
.layer_count
= 1;
1698 case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
:
1699 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
1700 wined3d_desc
->u
.texture
.level_idx
= 0;
1701 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DMSArray
.FirstArraySlice
;
1702 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DMSArray
.ArraySize
;
1705 case D3D11_RTV_DIMENSION_TEXTURE3D
:
1706 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture3D
.MipSlice
;
1707 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture3D
.FirstWSlice
;
1708 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture3D
.WSize
;
1712 FIXME("Unhandled view dimension %#x.\n", desc
->ViewDimension
);
1713 wined3d_desc
->u
.texture
.level_idx
= 0;
1714 wined3d_desc
->u
.texture
.layer_idx
= 0;
1715 wined3d_desc
->u
.texture
.layer_count
= 1;
1720 static HRESULT
d3d_rendertarget_view_init(struct d3d_rendertarget_view
*view
, struct d3d_device
*device
,
1721 ID3D11Resource
*resource
, const D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
1723 struct wined3d_resource
*wined3d_resource
;
1724 struct wined3d_view_desc wined3d_desc
;
1727 view
->ID3D11RenderTargetView_iface
.lpVtbl
= &d3d11_rendertarget_view_vtbl
;
1728 view
->ID3D10RenderTargetView_iface
.lpVtbl
= &d3d10_rendertarget_view_vtbl
;
1733 hr
= set_rtv_desc_from_resource(&view
->desc
, resource
);
1738 hr
= normalize_rtv_desc(&view
->desc
, resource
);
1743 wined3d_mutex_lock();
1744 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
1746 wined3d_mutex_unlock();
1747 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
1751 wined3d_rendertarget_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
);
1752 if (FAILED(hr
= wined3d_rendertarget_view_create(&wined3d_desc
, wined3d_resource
,
1753 view
, &d3d_render_target_view_wined3d_parent_ops
, &view
->wined3d_view
)))
1755 wined3d_mutex_unlock();
1756 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr
);
1760 wined3d_private_store_init(&view
->private_store
);
1761 wined3d_mutex_unlock();
1762 view
->resource
= resource
;
1763 ID3D11Device2_AddRef(view
->device
= &device
->ID3D11Device2_iface
);
1768 HRESULT
d3d_rendertarget_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
1769 const D3D11_RENDER_TARGET_VIEW_DESC
*desc
, struct d3d_rendertarget_view
**view
)
1771 struct d3d_rendertarget_view
*object
;
1774 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1775 return E_OUTOFMEMORY
;
1777 if (FAILED(hr
= d3d_rendertarget_view_init(object
, device
, resource
, desc
)))
1779 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr
);
1784 TRACE("Created rendertarget view %p.\n", object
);
1790 struct d3d_rendertarget_view
*unsafe_impl_from_ID3D11RenderTargetView(ID3D11RenderTargetView
*iface
)
1794 assert(iface
->lpVtbl
== &d3d11_rendertarget_view_vtbl
);
1796 return impl_from_ID3D11RenderTargetView(iface
);
1799 struct d3d_rendertarget_view
*unsafe_impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView
*iface
)
1803 assert(iface
->lpVtbl
== &d3d10_rendertarget_view_vtbl
);
1805 return impl_from_ID3D10RenderTargetView(iface
);
1808 /* ID3D11ShaderResourceView methods */
1810 static inline struct d3d_shader_resource_view
*impl_from_ID3D11ShaderResourceView(ID3D11ShaderResourceView
*iface
)
1812 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D11ShaderResourceView_iface
);
1815 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_QueryInterface(ID3D11ShaderResourceView
*iface
,
1816 REFIID riid
, void **object
)
1818 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1820 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1822 if (IsEqualGUID(riid
, &IID_ID3D11ShaderResourceView
)
1823 || IsEqualGUID(riid
, &IID_ID3D11View
)
1824 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
1825 || IsEqualGUID(riid
, &IID_IUnknown
))
1827 ID3D11ShaderResourceView_AddRef(iface
);
1832 if (IsEqualGUID(riid
, &IID_ID3D10ShaderResourceView1
)
1833 || IsEqualGUID(riid
, &IID_ID3D10ShaderResourceView
)
1834 || IsEqualGUID(riid
, &IID_ID3D10View
)
1835 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
1837 ID3D10ShaderResourceView1_AddRef(&view
->ID3D10ShaderResourceView1_iface
);
1838 *object
= &view
->ID3D10ShaderResourceView1_iface
;
1842 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
1845 return E_NOINTERFACE
;
1848 static ULONG STDMETHODCALLTYPE
d3d11_shader_resource_view_AddRef(ID3D11ShaderResourceView
*iface
)
1850 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1851 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
1853 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
1857 ID3D11Device2_AddRef(view
->device
);
1858 wined3d_mutex_lock();
1859 wined3d_shader_resource_view_incref(view
->wined3d_view
);
1860 wined3d_mutex_unlock();
1866 static ULONG STDMETHODCALLTYPE
d3d11_shader_resource_view_Release(ID3D11ShaderResourceView
*iface
)
1868 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1869 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
1871 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
1875 ID3D11Device2
*device
= view
->device
;
1877 wined3d_mutex_lock();
1878 wined3d_shader_resource_view_decref(view
->wined3d_view
);
1879 wined3d_mutex_unlock();
1881 ID3D11Device2_Release(device
);
1887 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetDevice(ID3D11ShaderResourceView
*iface
,
1888 ID3D11Device
**device
)
1890 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1892 TRACE("iface %p, device %p.\n", iface
, device
);
1894 *device
= (ID3D11Device
*)view
->device
;
1895 ID3D11Device_AddRef(*device
);
1898 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_GetPrivateData(ID3D11ShaderResourceView
*iface
,
1899 REFGUID guid
, UINT
*data_size
, void *data
)
1901 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1903 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1905 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1908 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_SetPrivateData(ID3D11ShaderResourceView
*iface
,
1909 REFGUID guid
, UINT data_size
, const void *data
)
1911 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1913 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1915 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1918 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_SetPrivateDataInterface(ID3D11ShaderResourceView
*iface
,
1919 REFGUID guid
, const IUnknown
*data
)
1921 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1923 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1925 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1928 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetResource(ID3D11ShaderResourceView
*iface
,
1929 ID3D11Resource
**resource
)
1931 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1933 TRACE("iface %p, resource %p.\n", iface
, resource
);
1935 *resource
= view
->resource
;
1936 ID3D11Resource_AddRef(*resource
);
1939 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetDesc(ID3D11ShaderResourceView
*iface
,
1940 D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
)
1942 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1944 TRACE("iface %p, desc %p.\n", iface
, desc
);
1949 static const struct ID3D11ShaderResourceViewVtbl d3d11_shader_resource_view_vtbl
=
1951 /* IUnknown methods */
1952 d3d11_shader_resource_view_QueryInterface
,
1953 d3d11_shader_resource_view_AddRef
,
1954 d3d11_shader_resource_view_Release
,
1955 /* ID3D11DeviceChild methods */
1956 d3d11_shader_resource_view_GetDevice
,
1957 d3d11_shader_resource_view_GetPrivateData
,
1958 d3d11_shader_resource_view_SetPrivateData
,
1959 d3d11_shader_resource_view_SetPrivateDataInterface
,
1960 /* ID3D11View methods */
1961 d3d11_shader_resource_view_GetResource
,
1962 /* ID3D11ShaderResourceView methods */
1963 d3d11_shader_resource_view_GetDesc
,
1966 /* ID3D10ShaderResourceView methods */
1968 static inline struct d3d_shader_resource_view
*impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView1
*iface
)
1970 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D10ShaderResourceView1_iface
);
1973 /* IUnknown methods */
1975 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView1
*iface
,
1976 REFIID riid
, void **object
)
1978 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1980 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1982 return d3d11_shader_resource_view_QueryInterface(&view
->ID3D11ShaderResourceView_iface
, riid
, object
);
1985 static ULONG STDMETHODCALLTYPE
d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView1
*iface
)
1987 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1989 TRACE("iface %p.\n", iface
);
1991 return d3d11_shader_resource_view_AddRef(&view
->ID3D11ShaderResourceView_iface
);
1994 static ULONG STDMETHODCALLTYPE
d3d10_shader_resource_view_Release(ID3D10ShaderResourceView1
*iface
)
1996 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1998 TRACE("iface %p.\n", iface
);
2000 return d3d11_shader_resource_view_Release(&view
->ID3D11ShaderResourceView_iface
);
2003 /* ID3D10DeviceChild methods */
2005 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView1
*iface
,
2006 ID3D10Device
**device
)
2008 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2010 TRACE("iface %p, device %p.\n", iface
, device
);
2012 ID3D11Device2_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
2015 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView1
*iface
,
2016 REFGUID guid
, UINT
*data_size
, void *data
)
2018 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2020 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
2021 iface
, debugstr_guid(guid
), data_size
, data
);
2023 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
2026 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView1
*iface
,
2027 REFGUID guid
, UINT data_size
, const void *data
)
2029 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2031 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
2032 iface
, debugstr_guid(guid
), data_size
, data
);
2034 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
2037 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView1
*iface
,
2038 REFGUID guid
, const IUnknown
*data
)
2040 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2042 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
2044 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
2047 /* ID3D10View methods */
2049 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView1
*iface
,
2050 ID3D10Resource
**resource
)
2052 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2054 TRACE("iface %p, resource %p.\n", iface
, resource
);
2056 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
2059 /* ID3D10ShaderResourceView methods */
2061 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView1
*iface
,
2062 D3D10_SHADER_RESOURCE_VIEW_DESC
*desc
)
2064 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2066 TRACE("iface %p, desc %p.\n", iface
, desc
);
2068 memcpy(desc
, &view
->desc
, sizeof(*desc
));
2071 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetDesc1(ID3D10ShaderResourceView1
*iface
,
2072 D3D10_SHADER_RESOURCE_VIEW_DESC1
*desc
)
2074 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2076 TRACE("iface %p, desc %p.\n", iface
, desc
);
2078 memcpy(desc
, &view
->desc
, sizeof(*desc
));
2081 static const struct ID3D10ShaderResourceView1Vtbl d3d10_shader_resource_view_vtbl
=
2083 /* IUnknown methods */
2084 d3d10_shader_resource_view_QueryInterface
,
2085 d3d10_shader_resource_view_AddRef
,
2086 d3d10_shader_resource_view_Release
,
2087 /* ID3D10DeviceChild methods */
2088 d3d10_shader_resource_view_GetDevice
,
2089 d3d10_shader_resource_view_GetPrivateData
,
2090 d3d10_shader_resource_view_SetPrivateData
,
2091 d3d10_shader_resource_view_SetPrivateDataInterface
,
2092 /* ID3D10View methods */
2093 d3d10_shader_resource_view_GetResource
,
2094 /* ID3D10ShaderResourceView methods */
2095 d3d10_shader_resource_view_GetDesc
,
2096 /* ID3D10ShaderResourceView1 methods */
2097 d3d10_shader_resource_view_GetDesc1
,
2100 static void STDMETHODCALLTYPE
d3d_shader_resource_view_wined3d_object_destroyed(void *parent
)
2102 struct d3d_shader_resource_view
*view
= parent
;
2104 wined3d_private_store_cleanup(&view
->private_store
);
2108 static const struct wined3d_parent_ops d3d_shader_resource_view_wined3d_parent_ops
=
2110 d3d_shader_resource_view_wined3d_object_destroyed
,
2113 static unsigned int wined3d_view_flags_from_d3d11_bufferex_flags(unsigned int d3d11_flags
)
2115 unsigned int wined3d_flags
= d3d11_flags
& WINED3D_VIEW_BUFFER_RAW
;
2117 if (d3d11_flags
!= wined3d_flags
)
2118 FIXME("Unhandled flags %#x.\n", d3d11_flags
& ~wined3d_flags
);
2120 return wined3d_flags
;
2123 static HRESULT
wined3d_shader_resource_view_desc_from_d3d11(struct wined3d_view_desc
*wined3d_desc
,
2124 const D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
)
2126 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
2127 wined3d_desc
->flags
= 0;
2129 switch (desc
->ViewDimension
)
2131 case D3D11_SRV_DIMENSION_BUFFER
:
2132 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.Buffer
.u1
.FirstElement
;
2133 wined3d_desc
->u
.buffer
.count
= desc
->u
.Buffer
.u2
.NumElements
;
2136 case D3D11_SRV_DIMENSION_TEXTURE1D
:
2137 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MostDetailedMip
;
2138 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture1D
.MipLevels
;
2139 wined3d_desc
->u
.texture
.layer_idx
= 0;
2140 wined3d_desc
->u
.texture
.layer_count
= 1;
2143 case D3D11_SRV_DIMENSION_TEXTURE1DARRAY
:
2144 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2145 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MostDetailedMip
;
2146 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture1DArray
.MipLevels
;
2147 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
2148 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
2151 case D3D11_SRV_DIMENSION_TEXTURE2D
:
2152 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MostDetailedMip
;
2153 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture2D
.MipLevels
;
2154 wined3d_desc
->u
.texture
.layer_idx
= 0;
2155 wined3d_desc
->u
.texture
.layer_count
= 1;
2158 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY
:
2159 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2160 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MostDetailedMip
;
2161 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture2DArray
.MipLevels
;
2162 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
2163 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
2166 case D3D11_SRV_DIMENSION_TEXTURE2DMS
:
2167 wined3d_desc
->u
.texture
.level_idx
= 0;
2168 wined3d_desc
->u
.texture
.level_count
= 1;
2169 wined3d_desc
->u
.texture
.layer_idx
= 0;
2170 wined3d_desc
->u
.texture
.layer_count
= 1;
2173 case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
:
2174 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2175 wined3d_desc
->u
.texture
.level_idx
= 0;
2176 wined3d_desc
->u
.texture
.level_count
= 1;
2177 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DMSArray
.FirstArraySlice
;
2178 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DMSArray
.ArraySize
;
2181 case D3D11_SRV_DIMENSION_TEXTURE3D
:
2182 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture3D
.MostDetailedMip
;
2183 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture3D
.MipLevels
;
2184 wined3d_desc
->u
.texture
.layer_idx
= 0;
2185 wined3d_desc
->u
.texture
.layer_count
= 1;
2188 case D3D11_SRV_DIMENSION_TEXTURECUBE
:
2189 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_CUBE
;
2190 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.TextureCube
.MostDetailedMip
;
2191 wined3d_desc
->u
.texture
.level_count
= desc
->u
.TextureCube
.MipLevels
;
2192 wined3d_desc
->u
.texture
.layer_idx
= 0;
2193 wined3d_desc
->u
.texture
.layer_count
= 6;
2196 case D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
:
2197 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_CUBE
| WINED3D_VIEW_TEXTURE_ARRAY
;
2198 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.TextureCubeArray
.MostDetailedMip
;
2199 wined3d_desc
->u
.texture
.level_count
= desc
->u
.TextureCubeArray
.MipLevels
;
2200 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.TextureCubeArray
.First2DArrayFace
;
2201 wined3d_desc
->u
.texture
.layer_count
= 6 * desc
->u
.TextureCubeArray
.NumCubes
;
2204 case D3D11_SRV_DIMENSION_BUFFEREX
:
2205 wined3d_desc
->flags
= wined3d_view_flags_from_d3d11_bufferex_flags(desc
->u
.BufferEx
.Flags
);
2206 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.BufferEx
.FirstElement
;
2207 wined3d_desc
->u
.buffer
.count
= desc
->u
.BufferEx
.NumElements
;
2211 WARN("Unrecognized view dimension %#x.\n", desc
->ViewDimension
);
2218 static HRESULT
d3d_shader_resource_view_init(struct d3d_shader_resource_view
*view
, struct d3d_device
*device
,
2219 ID3D11Resource
*resource
, const D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
)
2221 struct wined3d_resource
*wined3d_resource
;
2222 struct wined3d_view_desc wined3d_desc
;
2225 view
->ID3D11ShaderResourceView_iface
.lpVtbl
= &d3d11_shader_resource_view_vtbl
;
2226 view
->ID3D10ShaderResourceView1_iface
.lpVtbl
= &d3d10_shader_resource_view_vtbl
;
2231 hr
= set_srv_desc_from_resource(&view
->desc
, resource
);
2236 hr
= normalize_srv_desc(&view
->desc
, resource
);
2241 if (FAILED(hr
= wined3d_shader_resource_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
)))
2244 wined3d_mutex_lock();
2245 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
2247 wined3d_mutex_unlock();
2248 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
2252 if (FAILED(hr
= wined3d_shader_resource_view_create(&wined3d_desc
, wined3d_resource
,
2253 view
, &d3d_shader_resource_view_wined3d_parent_ops
, &view
->wined3d_view
)))
2255 wined3d_mutex_unlock();
2256 WARN("Failed to create wined3d shader resource view, hr %#x.\n", hr
);
2260 wined3d_private_store_init(&view
->private_store
);
2261 wined3d_mutex_unlock();
2262 view
->resource
= resource
;
2263 ID3D11Device2_AddRef(view
->device
= &device
->ID3D11Device2_iface
);
2268 HRESULT
d3d_shader_resource_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
2269 const D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, struct d3d_shader_resource_view
**view
)
2271 struct d3d_shader_resource_view
*object
;
2274 if (!(object
= heap_alloc_zero(sizeof(*object
))))
2275 return E_OUTOFMEMORY
;
2277 if (FAILED(hr
= d3d_shader_resource_view_init(object
, device
, resource
, desc
)))
2279 WARN("Failed to initialize shader resource view, hr %#x.\n", hr
);
2284 TRACE("Created shader resource view %p.\n", object
);
2290 struct d3d_shader_resource_view
*unsafe_impl_from_ID3D11ShaderResourceView(ID3D11ShaderResourceView
*iface
)
2294 assert(iface
->lpVtbl
== &d3d11_shader_resource_view_vtbl
);
2295 return impl_from_ID3D11ShaderResourceView(iface
);
2298 struct d3d_shader_resource_view
*unsafe_impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView
*iface
)
2302 assert(iface
->lpVtbl
== (ID3D10ShaderResourceViewVtbl
*)&d3d10_shader_resource_view_vtbl
);
2303 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D10ShaderResourceView1_iface
);
2306 /* ID3D11UnorderedAccessView methods */
2308 static inline struct d3d11_unordered_access_view
*impl_from_ID3D11UnorderedAccessView(ID3D11UnorderedAccessView
*iface
)
2310 return CONTAINING_RECORD(iface
, struct d3d11_unordered_access_view
, ID3D11UnorderedAccessView_iface
);
2313 static HRESULT STDMETHODCALLTYPE
d3d11_unordered_access_view_QueryInterface(ID3D11UnorderedAccessView
*iface
,
2314 REFIID riid
, void **object
)
2316 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
2318 if (IsEqualGUID(riid
, &IID_ID3D11UnorderedAccessView
)
2319 || IsEqualGUID(riid
, &IID_ID3D11View
)
2320 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
2321 || IsEqualGUID(riid
, &IID_IUnknown
))
2323 ID3D11UnorderedAccessView_AddRef(*object
= iface
);
2327 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
2330 return E_NOINTERFACE
;
2333 static ULONG STDMETHODCALLTYPE
d3d11_unordered_access_view_AddRef(ID3D11UnorderedAccessView
*iface
)
2335 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2336 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
2338 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
2342 ID3D11Device2_AddRef(view
->device
);
2343 wined3d_mutex_lock();
2344 wined3d_unordered_access_view_incref(view
->wined3d_view
);
2345 wined3d_mutex_unlock();
2351 static ULONG STDMETHODCALLTYPE
d3d11_unordered_access_view_Release(ID3D11UnorderedAccessView
*iface
)
2353 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2354 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
2356 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
2360 ID3D11Device2
*device
= view
->device
;
2362 wined3d_mutex_lock();
2363 wined3d_unordered_access_view_decref(view
->wined3d_view
);
2364 wined3d_mutex_unlock();
2366 ID3D11Device2_Release(device
);
2372 static void STDMETHODCALLTYPE
d3d11_unordered_access_view_GetDevice(ID3D11UnorderedAccessView
*iface
,
2373 ID3D11Device
**device
)
2375 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2377 TRACE("iface %p, device %p.\n", iface
, device
);
2379 ID3D11Device_AddRef(*device
= (ID3D11Device
*)view
->device
);
2382 static HRESULT STDMETHODCALLTYPE
d3d11_unordered_access_view_GetPrivateData(ID3D11UnorderedAccessView
*iface
,
2383 REFGUID guid
, UINT
*data_size
, void *data
)
2385 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2387 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
2389 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
2392 static HRESULT STDMETHODCALLTYPE
d3d11_unordered_access_view_SetPrivateData(ID3D11UnorderedAccessView
*iface
,
2393 REFGUID guid
, UINT data_size
, const void *data
)
2395 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2397 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
2399 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
2402 static HRESULT STDMETHODCALLTYPE
d3d11_unordered_access_view_SetPrivateDataInterface(ID3D11UnorderedAccessView
*iface
,
2403 REFGUID guid
, const IUnknown
*data
)
2405 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2407 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
2409 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
2412 static void STDMETHODCALLTYPE
d3d11_unordered_access_view_GetResource(ID3D11UnorderedAccessView
*iface
,
2413 ID3D11Resource
**resource
)
2415 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2417 TRACE("iface %p, resource %p.\n", iface
, resource
);
2419 ID3D11Resource_AddRef(*resource
= view
->resource
);
2422 static void STDMETHODCALLTYPE
d3d11_unordered_access_view_GetDesc(ID3D11UnorderedAccessView
*iface
,
2423 D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
)
2425 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2427 TRACE("iface %p, desc %p.\n", iface
, desc
);
2432 static const struct ID3D11UnorderedAccessViewVtbl d3d11_unordered_access_view_vtbl
=
2434 /* IUnknown methods */
2435 d3d11_unordered_access_view_QueryInterface
,
2436 d3d11_unordered_access_view_AddRef
,
2437 d3d11_unordered_access_view_Release
,
2438 /* ID3D11DeviceChild methods */
2439 d3d11_unordered_access_view_GetDevice
,
2440 d3d11_unordered_access_view_GetPrivateData
,
2441 d3d11_unordered_access_view_SetPrivateData
,
2442 d3d11_unordered_access_view_SetPrivateDataInterface
,
2443 /* ID3D11View methods */
2444 d3d11_unordered_access_view_GetResource
,
2445 /* ID3D11UnorderedAccessView methods */
2446 d3d11_unordered_access_view_GetDesc
,
2449 static void STDMETHODCALLTYPE
d3d11_unordered_access_view_wined3d_object_destroyed(void *parent
)
2451 struct d3d11_unordered_access_view
*view
= parent
;
2453 wined3d_private_store_cleanup(&view
->private_store
);
2457 static const struct wined3d_parent_ops d3d11_unordered_access_view_wined3d_parent_ops
=
2459 d3d11_unordered_access_view_wined3d_object_destroyed
,
2462 static unsigned int wined3d_view_flags_from_d3d11_buffer_uav_flags(unsigned int d3d11_flags
)
2464 unsigned int wined3d_flags
= d3d11_flags
& (WINED3D_VIEW_BUFFER_RAW
2465 | WINED3D_VIEW_BUFFER_APPEND
| WINED3D_VIEW_BUFFER_COUNTER
);
2467 if (d3d11_flags
!= wined3d_flags
)
2468 FIXME("Unhandled flags %#x.\n", d3d11_flags
& ~wined3d_flags
);
2470 return wined3d_flags
;
2473 static HRESULT
wined3d_unordered_access_view_desc_from_d3d11(struct wined3d_view_desc
*wined3d_desc
,
2474 const D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
)
2476 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
2478 wined3d_desc
->flags
= 0;
2479 wined3d_desc
->u
.texture
.level_count
= 1;
2480 switch (desc
->ViewDimension
)
2482 case D3D11_UAV_DIMENSION_BUFFER
:
2483 wined3d_desc
->flags
= wined3d_view_flags_from_d3d11_buffer_uav_flags(desc
->u
.Buffer
.Flags
);
2484 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.Buffer
.FirstElement
;
2485 wined3d_desc
->u
.buffer
.count
= desc
->u
.Buffer
.NumElements
;
2488 case D3D11_UAV_DIMENSION_TEXTURE1D
:
2489 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MipSlice
;
2490 wined3d_desc
->u
.texture
.layer_idx
= 0;
2491 wined3d_desc
->u
.texture
.layer_count
= 1;
2494 case D3D11_UAV_DIMENSION_TEXTURE1DARRAY
:
2495 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2496 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MipSlice
;
2497 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
2498 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
2501 case D3D11_UAV_DIMENSION_TEXTURE2D
:
2502 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MipSlice
;
2503 wined3d_desc
->u
.texture
.layer_idx
= 0;
2504 wined3d_desc
->u
.texture
.layer_count
= 1;
2507 case D3D11_UAV_DIMENSION_TEXTURE2DARRAY
:
2508 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2509 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MipSlice
;
2510 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
2511 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
2514 case D3D11_UAV_DIMENSION_TEXTURE3D
:
2515 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture3D
.MipSlice
;
2516 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture3D
.FirstWSlice
;
2517 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture3D
.WSize
;
2521 WARN("Unrecognized view dimension %#x.\n", desc
->ViewDimension
);
2528 static HRESULT
d3d11_unordered_access_view_init(struct d3d11_unordered_access_view
*view
,
2529 struct d3d_device
*device
, ID3D11Resource
*resource
, const D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
)
2531 struct wined3d_resource
*wined3d_resource
;
2532 struct wined3d_view_desc wined3d_desc
;
2535 view
->ID3D11UnorderedAccessView_iface
.lpVtbl
= &d3d11_unordered_access_view_vtbl
;
2540 hr
= set_uav_desc_from_resource(&view
->desc
, resource
);
2545 hr
= normalize_uav_desc(&view
->desc
, resource
);
2550 if (FAILED(hr
= wined3d_unordered_access_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
)))
2553 wined3d_mutex_lock();
2554 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
2556 wined3d_mutex_unlock();
2557 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
2561 if (FAILED(hr
= wined3d_unordered_access_view_create(&wined3d_desc
, wined3d_resource
,
2562 view
, &d3d11_unordered_access_view_wined3d_parent_ops
, &view
->wined3d_view
)))
2564 wined3d_mutex_unlock();
2565 WARN("Failed to create wined3d unordered access view, hr %#x.\n", hr
);
2569 wined3d_private_store_init(&view
->private_store
);
2570 wined3d_mutex_unlock();
2571 view
->resource
= resource
;
2572 ID3D11Device2_AddRef(view
->device
= &device
->ID3D11Device2_iface
);
2577 HRESULT
d3d11_unordered_access_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
2578 const D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
, struct d3d11_unordered_access_view
**view
)
2580 struct d3d11_unordered_access_view
*object
;
2583 if (!(object
= heap_alloc_zero(sizeof(*object
))))
2584 return E_OUTOFMEMORY
;
2586 if (FAILED(hr
= d3d11_unordered_access_view_init(object
, device
, resource
, desc
)))
2588 WARN("Failed to initialize unordered access view, hr %#x.\n", hr
);
2593 TRACE("Created unordered access view %p.\n", object
);
2599 struct d3d11_unordered_access_view
*unsafe_impl_from_ID3D11UnorderedAccessView(ID3D11UnorderedAccessView
*iface
)
2603 assert(iface
->lpVtbl
== &d3d11_unordered_access_view_vtbl
);
2605 return impl_from_ID3D11UnorderedAccessView(iface
);