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
21 #include "wine/port.h"
23 #define NONAMELESSUNION
24 #include "d3d11_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d11
);
28 static HRESULT
set_dsv_desc_from_resource(D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
30 D3D11_RESOURCE_DIMENSION dimension
;
32 ID3D11Resource_GetType(resource
, &dimension
);
38 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
40 D3D11_TEXTURE1D_DESC texture_desc
;
41 ID3D11Texture1D
*texture
;
43 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
)))
45 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
49 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
50 ID3D11Texture1D_Release(texture
);
52 desc
->Format
= texture_desc
.Format
;
53 if (texture_desc
.ArraySize
== 1)
55 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE1D
;
56 desc
->u
.Texture1D
.MipSlice
= 0;
60 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE1DARRAY
;
61 desc
->u
.Texture1DArray
.MipSlice
= 0;
62 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
63 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
69 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
71 D3D11_TEXTURE2D_DESC texture_desc
;
72 ID3D11Texture2D
*texture
;
74 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
76 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
80 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
81 ID3D11Texture2D_Release(texture
);
83 desc
->Format
= texture_desc
.Format
;
84 if (texture_desc
.ArraySize
== 1)
86 if (texture_desc
.SampleDesc
.Count
== 1)
88 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2D
;
89 desc
->u
.Texture2D
.MipSlice
= 0;
93 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DMS
;
98 if (texture_desc
.SampleDesc
.Count
== 1)
100 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DARRAY
;
101 desc
->u
.Texture2DArray
.MipSlice
= 0;
102 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
103 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
107 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
;
108 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
109 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
117 ERR("Unhandled resource dimension %#x.\n", dimension
);
118 case D3D11_RESOURCE_DIMENSION_BUFFER
:
119 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
124 static HRESULT
normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
126 D3D11_RESOURCE_DIMENSION dimension
;
127 unsigned int layer_count
;
130 ID3D11Resource_GetType(resource
, &dimension
);
133 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
135 if (desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE1D
136 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE1DARRAY
)
138 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
142 FIXME("Unhandled 1D texture resource.\n");
146 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
148 const struct d3d_texture2d
*texture
;
150 if (desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2D
151 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DARRAY
152 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DMS
153 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
)
155 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
159 if (!(texture
= unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D
*)resource
)))
161 ERR("Cannot get implementation from ID3D11Texture2D.\n");
165 format
= texture
->desc
.Format
;
166 layer_count
= texture
->desc
.ArraySize
;
170 case D3D11_RESOURCE_DIMENSION_BUFFER
:
171 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
172 WARN("Invalid resource dimension %#x.\n", dimension
);
176 ERR("Unhandled resource dimension %#x.\n", dimension
);
180 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
181 desc
->Format
= format
;
183 switch (desc
->ViewDimension
)
185 case D3D11_DSV_DIMENSION_TEXTURE1DARRAY
:
186 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
187 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
190 case D3D11_DSV_DIMENSION_TEXTURE2DARRAY
:
191 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
192 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
195 case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
:
196 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
197 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
207 static HRESULT
set_rtv_desc_from_resource(D3D11_RENDER_TARGET_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
209 D3D11_RESOURCE_DIMENSION dimension
;
212 ID3D11Resource_GetType(resource
, &dimension
);
216 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
218 ID3D11Texture1D
*texture
;
219 D3D11_TEXTURE1D_DESC texture_desc
;
221 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
);
224 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D?\n");
228 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
229 ID3D11Texture1D_Release(texture
);
231 desc
->Format
= texture_desc
.Format
;
232 if (texture_desc
.ArraySize
== 1)
234 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE1D
;
235 desc
->u
.Texture1D
.MipSlice
= 0;
239 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE1DARRAY
;
240 desc
->u
.Texture1DArray
.MipSlice
= 0;
241 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
242 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
248 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
250 ID3D11Texture2D
*texture
;
251 D3D11_TEXTURE2D_DESC texture_desc
;
253 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
);
256 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D?\n");
260 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
261 ID3D11Texture2D_Release(texture
);
263 desc
->Format
= texture_desc
.Format
;
264 if (texture_desc
.ArraySize
== 1)
266 if (texture_desc
.SampleDesc
.Count
== 1)
268 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2D
;
269 desc
->u
.Texture2D
.MipSlice
= 0;
273 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DMS
;
278 if (texture_desc
.SampleDesc
.Count
== 1)
280 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DARRAY
;
281 desc
->u
.Texture2DArray
.MipSlice
= 0;
282 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
283 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
287 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
;
288 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
289 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
296 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
298 ID3D11Texture3D
*texture
;
299 D3D11_TEXTURE3D_DESC texture_desc
;
301 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
);
304 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D?\n");
308 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
309 ID3D11Texture3D_Release(texture
);
311 desc
->Format
= texture_desc
.Format
;
312 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE3D
;
313 desc
->u
.Texture3D
.MipSlice
= 0;
314 desc
->u
.Texture3D
.FirstWSlice
= 0;
315 desc
->u
.Texture3D
.WSize
= texture_desc
.Depth
;
321 FIXME("Unhandled resource dimension %#x.\n", dimension
);
326 static HRESULT
normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
328 D3D11_RESOURCE_DIMENSION dimension
;
329 unsigned int layer_count
;
332 ID3D11Resource_GetType(resource
, &dimension
);
335 case D3D11_RESOURCE_DIMENSION_BUFFER
:
337 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_BUFFER
)
339 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
345 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
347 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE1D
348 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE1DARRAY
)
350 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
354 FIXME("Unhandled 1D texture resource.\n");
358 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
360 const struct d3d_texture2d
*texture
;
362 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2D
363 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DARRAY
364 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DMS
365 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
)
367 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
371 if (!(texture
= unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D
*)resource
)))
373 ERR("Cannot get implementation from ID3D11Texture2D.\n");
377 format
= texture
->desc
.Format
;
378 layer_count
= texture
->desc
.ArraySize
;
382 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
384 const struct d3d_texture3d
*texture
;
386 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE3D
)
388 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
392 if (!(texture
= unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D
*)resource
)))
394 ERR("Cannot get implementation from ID3D11Texture3D.\n");
398 format
= texture
->desc
.Format
;
399 layer_count
= texture
->desc
.Depth
;
404 ERR("Unhandled resource dimension %#x.\n", dimension
);
408 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
409 desc
->Format
= format
;
411 switch (desc
->ViewDimension
)
413 case D3D11_RTV_DIMENSION_TEXTURE1DARRAY
:
414 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
415 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
418 case D3D11_RTV_DIMENSION_TEXTURE2DARRAY
:
419 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
420 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
423 case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
:
424 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
425 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
428 case D3D11_RTV_DIMENSION_TEXTURE3D
:
429 layer_count
= max(1, layer_count
>> desc
->u
.Texture3D
.MipSlice
);
430 if (desc
->u
.Texture3D
.WSize
== ~0u && desc
->u
.Texture3D
.FirstWSlice
< layer_count
)
431 desc
->u
.Texture3D
.WSize
= layer_count
- desc
->u
.Texture3D
.FirstWSlice
;
441 static HRESULT
set_srv_desc_from_resource(D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
443 D3D11_RESOURCE_DIMENSION dimension
;
445 ID3D11Resource_GetType(resource
, &dimension
);
449 case D3D11_RESOURCE_DIMENSION_BUFFER
:
451 D3D11_BUFFER_DESC buffer_desc
;
452 ID3D11Buffer
*buffer
;
454 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Buffer
, (void **)&buffer
)))
456 ERR("Resource of type BUFFER doesn't implement ID3D11Buffer.\n");
460 ID3D11Buffer_GetDesc(buffer
, &buffer_desc
);
461 ID3D11Buffer_Release(buffer
);
463 if (buffer_desc
.MiscFlags
& D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
)
465 desc
->Format
= DXGI_FORMAT_UNKNOWN
;
466 desc
->ViewDimension
= D3D11_SRV_DIMENSION_BUFFER
;
467 desc
->u
.Buffer
.u1
.FirstElement
= 0;
468 desc
->u
.Buffer
.u2
.NumElements
= buffer_desc
.ByteWidth
/ buffer_desc
.StructureByteStride
;
475 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
477 D3D11_TEXTURE1D_DESC texture_desc
;
478 ID3D11Texture1D
*texture
;
480 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
)))
482 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
486 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
487 ID3D11Texture1D_Release(texture
);
489 desc
->Format
= texture_desc
.Format
;
490 if (texture_desc
.ArraySize
== 1)
492 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE1D
;
493 desc
->u
.Texture1D
.MostDetailedMip
= 0;
494 desc
->u
.Texture1D
.MipLevels
= texture_desc
.MipLevels
;
498 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE1DARRAY
;
499 desc
->u
.Texture1DArray
.MostDetailedMip
= 0;
500 desc
->u
.Texture1DArray
.MipLevels
= texture_desc
.MipLevels
;
501 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
502 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
508 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
510 D3D11_TEXTURE2D_DESC texture_desc
;
511 ID3D11Texture2D
*texture
;
513 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
515 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
519 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
520 ID3D11Texture2D_Release(texture
);
522 desc
->Format
= texture_desc
.Format
;
523 if (texture_desc
.ArraySize
== 1)
525 if (texture_desc
.SampleDesc
.Count
== 1)
527 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2D
;
528 desc
->u
.Texture2D
.MostDetailedMip
= 0;
529 desc
->u
.Texture2D
.MipLevels
= texture_desc
.MipLevels
;
533 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DMS
;
538 if (texture_desc
.SampleDesc
.Count
== 1)
540 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DARRAY
;
541 desc
->u
.Texture2DArray
.MostDetailedMip
= 0;
542 desc
->u
.Texture2DArray
.MipLevels
= texture_desc
.MipLevels
;
543 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
544 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
548 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
;
549 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
550 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
557 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
559 D3D11_TEXTURE3D_DESC texture_desc
;
560 ID3D11Texture3D
*texture
;
562 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
)))
564 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D.\n");
568 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
569 ID3D11Texture3D_Release(texture
);
571 desc
->Format
= texture_desc
.Format
;
572 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE3D
;
573 desc
->u
.Texture3D
.MostDetailedMip
= 0;
574 desc
->u
.Texture3D
.MipLevels
= texture_desc
.MipLevels
;
580 ERR("Unhandled resource dimension %#x.\n", dimension
);
585 static HRESULT
normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
587 unsigned int miplevel_count
, layer_count
;
588 D3D11_RESOURCE_DIMENSION dimension
;
591 ID3D11Resource_GetType(resource
, &dimension
);
594 case D3D11_RESOURCE_DIMENSION_BUFFER
:
596 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_BUFFER
597 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_BUFFEREX
)
599 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
605 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
607 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE1D
608 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE1DARRAY
)
610 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
614 FIXME("Unhandled 1D texture resource.\n");
618 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
620 const struct d3d_texture2d
*texture
;
622 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2D
623 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DARRAY
624 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DMS
625 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
626 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURECUBE
627 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
)
629 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
633 if (!(texture
= unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D
*)resource
)))
635 ERR("Cannot get implementation from ID3D11Texture2D.\n");
639 format
= texture
->desc
.Format
;
640 miplevel_count
= texture
->desc
.MipLevels
;
641 layer_count
= texture
->desc
.ArraySize
;
645 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
647 const struct d3d_texture3d
*texture
;
649 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE3D
)
651 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
655 if (!(texture
= unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D
*)resource
)))
657 ERR("Cannot get implementation from ID3D11Texture3D.\n");
661 format
= texture
->desc
.Format
;
662 miplevel_count
= texture
->desc
.MipLevels
;
668 ERR("Unhandled resource dimension %#x.\n", dimension
);
672 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
673 desc
->Format
= format
;
675 switch (desc
->ViewDimension
)
677 case D3D11_SRV_DIMENSION_TEXTURE1D
:
678 if (desc
->u
.Texture1D
.MipLevels
== ~0u && desc
->u
.Texture1D
.MostDetailedMip
< miplevel_count
)
679 desc
->u
.Texture1D
.MipLevels
= miplevel_count
- desc
->u
.Texture1D
.MostDetailedMip
;
682 case D3D11_SRV_DIMENSION_TEXTURE1DARRAY
:
683 if (desc
->u
.Texture1DArray
.MipLevels
== ~0u && desc
->u
.Texture1DArray
.MostDetailedMip
< miplevel_count
)
684 desc
->u
.Texture1DArray
.MipLevels
= miplevel_count
- desc
->u
.Texture1DArray
.MostDetailedMip
;
685 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< miplevel_count
)
686 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
689 case D3D11_SRV_DIMENSION_TEXTURE2D
:
690 if (desc
->u
.Texture2D
.MipLevels
== ~0u && desc
->u
.Texture2D
.MostDetailedMip
< miplevel_count
)
691 desc
->u
.Texture2D
.MipLevels
= miplevel_count
- desc
->u
.Texture2D
.MostDetailedMip
;
694 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY
:
695 if (desc
->u
.Texture2DArray
.MipLevels
== ~0u && desc
->u
.Texture2DArray
.MostDetailedMip
< miplevel_count
)
696 desc
->u
.Texture2DArray
.MipLevels
= miplevel_count
- desc
->u
.Texture2DArray
.MostDetailedMip
;
697 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
698 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
701 case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
:
702 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
703 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
706 case D3D11_SRV_DIMENSION_TEXTURE3D
:
707 if (desc
->u
.Texture3D
.MipLevels
== ~0u && desc
->u
.Texture3D
.MostDetailedMip
< miplevel_count
)
708 desc
->u
.Texture3D
.MipLevels
= miplevel_count
- desc
->u
.Texture3D
.MostDetailedMip
;
711 case D3D11_SRV_DIMENSION_TEXTURECUBE
:
712 if (desc
->u
.TextureCube
.MipLevels
== ~0u && desc
->u
.TextureCube
.MostDetailedMip
< miplevel_count
)
713 desc
->u
.TextureCube
.MipLevels
= miplevel_count
- desc
->u
.TextureCube
.MostDetailedMip
;
716 case D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
:
717 if (desc
->u
.TextureCubeArray
.MipLevels
== ~0u && desc
->u
.TextureCubeArray
.MostDetailedMip
< miplevel_count
)
718 desc
->u
.TextureCubeArray
.MipLevels
= miplevel_count
- desc
->u
.TextureCubeArray
.MostDetailedMip
;
719 if (desc
->u
.TextureCubeArray
.NumCubes
== ~0u && desc
->u
.TextureCubeArray
.First2DArrayFace
< layer_count
)
720 desc
->u
.TextureCubeArray
.NumCubes
= (layer_count
- desc
->u
.TextureCubeArray
.First2DArrayFace
) / 6;
730 static HRESULT
set_uav_desc_from_resource(D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
732 D3D11_RESOURCE_DIMENSION dimension
;
734 ID3D11Resource_GetType(resource
, &dimension
);
738 case D3D11_RESOURCE_DIMENSION_BUFFER
:
740 D3D11_BUFFER_DESC buffer_desc
;
741 ID3D11Buffer
*buffer
;
743 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Buffer
, (void **)&buffer
)))
745 ERR("Resource of type BUFFER doesn't implement ID3D11Buffer.\n");
749 ID3D11Buffer_GetDesc(buffer
, &buffer_desc
);
750 ID3D11Buffer_Release(buffer
);
752 if (buffer_desc
.MiscFlags
& D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
)
754 desc
->Format
= DXGI_FORMAT_UNKNOWN
;
755 desc
->ViewDimension
= D3D11_UAV_DIMENSION_BUFFER
;
756 desc
->u
.Buffer
.FirstElement
= 0;
757 desc
->u
.Buffer
.NumElements
= buffer_desc
.ByteWidth
/ buffer_desc
.StructureByteStride
;
758 desc
->u
.Buffer
.Flags
= 0;
765 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
767 D3D11_TEXTURE2D_DESC texture_desc
;
768 ID3D11Texture2D
*texture
;
770 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
772 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
776 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
777 ID3D11Texture2D_Release(texture
);
779 if (texture_desc
.SampleDesc
.Count
!= 1)
781 WARN("Trying to create view for multisample texture.\n");
785 desc
->Format
= texture_desc
.Format
;
786 if (texture_desc
.ArraySize
== 1)
788 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE2D
;
789 desc
->u
.Texture2D
.MipSlice
= 0;
793 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE2DARRAY
;
794 desc
->u
.Texture2DArray
.MipSlice
= 0;
795 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
796 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
802 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
804 D3D11_TEXTURE3D_DESC texture_desc
;
805 ID3D11Texture3D
*texture
;
807 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
)))
809 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D.\n");
813 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
814 ID3D11Texture3D_Release(texture
);
816 desc
->Format
= texture_desc
.Format
;
817 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE3D
;
818 desc
->u
.Texture3D
.MipSlice
= 0;
819 desc
->u
.Texture3D
.FirstWSlice
= 0;
820 desc
->u
.Texture3D
.WSize
= texture_desc
.Depth
;
826 FIXME("Unhandled resource dimension %#x.\n", dimension
);
831 static HRESULT
normalize_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
833 D3D11_RESOURCE_DIMENSION dimension
;
834 unsigned int layer_count
;
837 ID3D11Resource_GetType(resource
, &dimension
);
840 case D3D11_RESOURCE_DIMENSION_BUFFER
:
842 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_BUFFER
)
844 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
850 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
852 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE1D
853 && desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE1DARRAY
)
855 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
859 FIXME("Unhandled 1D texture resource.\n");
863 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
865 const struct d3d_texture2d
*texture
;
867 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE2D
868 && desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE2DARRAY
)
870 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
874 if (!(texture
= unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D
*)resource
)))
876 ERR("Cannot get implementation from ID3D11Texture2D.\n");
880 format
= texture
->desc
.Format
;
881 layer_count
= texture
->desc
.ArraySize
;
885 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
887 const struct d3d_texture3d
*texture
;
889 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE3D
)
891 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
895 if (!(texture
= unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D
*)resource
)))
897 ERR("Cannot get implementation from ID3D11Texture3D.\n");
901 format
= texture
->desc
.Format
;
902 layer_count
= texture
->desc
.Depth
;
907 ERR("Unhandled resource dimension %#x.\n", dimension
);
911 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
912 desc
->Format
= format
;
914 switch (desc
->ViewDimension
)
916 case D3D11_UAV_DIMENSION_TEXTURE1DARRAY
:
917 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
918 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
921 case D3D11_UAV_DIMENSION_TEXTURE2DARRAY
:
922 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
923 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
926 case D3D11_UAV_DIMENSION_TEXTURE3D
:
927 layer_count
= max(1, layer_count
>> desc
->u
.Texture3D
.MipSlice
);
928 if (desc
->u
.Texture3D
.WSize
== ~0u && desc
->u
.Texture3D
.FirstWSlice
< layer_count
)
929 desc
->u
.Texture3D
.WSize
= layer_count
- desc
->u
.Texture3D
.FirstWSlice
;
939 /* ID3D11DepthStencilView methods */
941 static inline struct d3d_depthstencil_view
*impl_from_ID3D11DepthStencilView(ID3D11DepthStencilView
*iface
)
943 return CONTAINING_RECORD(iface
, struct d3d_depthstencil_view
, ID3D11DepthStencilView_iface
);
946 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_QueryInterface(ID3D11DepthStencilView
*iface
,
947 REFIID riid
, void **object
)
949 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
951 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
953 if (IsEqualGUID(riid
, &IID_ID3D11DepthStencilView
)
954 || IsEqualGUID(riid
, &IID_ID3D11View
)
955 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
956 || IsEqualGUID(riid
, &IID_IUnknown
))
958 ID3D11DepthStencilView_AddRef(iface
);
963 if (IsEqualGUID(riid
, &IID_ID3D10DepthStencilView
)
964 || IsEqualGUID(riid
, &IID_ID3D10View
)
965 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
967 ID3D10DepthStencilView_AddRef(&view
->ID3D10DepthStencilView_iface
);
968 *object
= &view
->ID3D10DepthStencilView_iface
;
972 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
975 return E_NOINTERFACE
;
978 static ULONG STDMETHODCALLTYPE
d3d11_depthstencil_view_AddRef(ID3D11DepthStencilView
*iface
)
980 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
981 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
983 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
988 static ULONG STDMETHODCALLTYPE
d3d11_depthstencil_view_Release(ID3D11DepthStencilView
*iface
)
990 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
991 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
993 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
997 wined3d_mutex_lock();
998 wined3d_rendertarget_view_decref(view
->wined3d_view
);
999 ID3D11Resource_Release(view
->resource
);
1000 ID3D11Device_Release(view
->device
);
1001 wined3d_private_store_cleanup(&view
->private_store
);
1002 wined3d_mutex_unlock();
1003 HeapFree(GetProcessHeap(), 0, view
);
1009 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetDevice(ID3D11DepthStencilView
*iface
,
1010 ID3D11Device
**device
)
1012 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1014 TRACE("iface %p, device %p.\n", iface
, device
);
1016 *device
= view
->device
;
1017 ID3D11Device_AddRef(*device
);
1020 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_GetPrivateData(ID3D11DepthStencilView
*iface
,
1021 REFGUID guid
, UINT
*data_size
, void *data
)
1023 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1025 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1027 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1030 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_SetPrivateData(ID3D11DepthStencilView
*iface
,
1031 REFGUID guid
, UINT data_size
, const void *data
)
1033 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1035 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1037 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1040 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_SetPrivateDataInterface(ID3D11DepthStencilView
*iface
,
1041 REFGUID guid
, const IUnknown
*data
)
1043 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1045 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1047 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1050 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetResource(ID3D11DepthStencilView
*iface
,
1051 ID3D11Resource
**resource
)
1053 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1055 TRACE("iface %p, resource %p.\n", iface
, resource
);
1057 *resource
= view
->resource
;
1058 ID3D11Resource_AddRef(*resource
);
1061 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetDesc(ID3D11DepthStencilView
*iface
,
1062 D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
1064 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1066 TRACE("iface %p, desc %p.\n", iface
, desc
);
1071 static const struct ID3D11DepthStencilViewVtbl d3d11_depthstencil_view_vtbl
=
1073 /* IUnknown methods */
1074 d3d11_depthstencil_view_QueryInterface
,
1075 d3d11_depthstencil_view_AddRef
,
1076 d3d11_depthstencil_view_Release
,
1077 /* ID3D11DeviceChild methods */
1078 d3d11_depthstencil_view_GetDevice
,
1079 d3d11_depthstencil_view_GetPrivateData
,
1080 d3d11_depthstencil_view_SetPrivateData
,
1081 d3d11_depthstencil_view_SetPrivateDataInterface
,
1082 /* ID3D11View methods */
1083 d3d11_depthstencil_view_GetResource
,
1084 /* ID3D11DepthStencilView methods */
1085 d3d11_depthstencil_view_GetDesc
,
1088 /* ID3D10DepthStencilView methods */
1090 static inline struct d3d_depthstencil_view
*impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView
*iface
)
1092 return CONTAINING_RECORD(iface
, struct d3d_depthstencil_view
, ID3D10DepthStencilView_iface
);
1095 /* IUnknown methods */
1097 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView
*iface
,
1098 REFIID riid
, void **object
)
1100 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1102 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1104 return d3d11_depthstencil_view_QueryInterface(&view
->ID3D11DepthStencilView_iface
, riid
, object
);
1107 static ULONG STDMETHODCALLTYPE
d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView
*iface
)
1109 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1111 TRACE("iface %p.\n", iface
);
1113 return d3d11_depthstencil_view_AddRef(&view
->ID3D11DepthStencilView_iface
);
1116 static ULONG STDMETHODCALLTYPE
d3d10_depthstencil_view_Release(ID3D10DepthStencilView
*iface
)
1118 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1120 TRACE("iface %p.\n", iface
);
1122 return d3d11_depthstencil_view_Release(&view
->ID3D11DepthStencilView_iface
);
1125 /* ID3D10DeviceChild methods */
1127 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView
*iface
, ID3D10Device
**device
)
1129 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1131 TRACE("iface %p, device %p.\n", iface
, device
);
1133 ID3D11Device_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
1136 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView
*iface
,
1137 REFGUID guid
, UINT
*data_size
, void *data
)
1139 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1141 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1142 iface
, debugstr_guid(guid
), data_size
, data
);
1144 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1147 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView
*iface
,
1148 REFGUID guid
, UINT data_size
, const void *data
)
1150 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1152 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1153 iface
, debugstr_guid(guid
), data_size
, data
);
1155 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1158 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView
*iface
,
1159 REFGUID guid
, const IUnknown
*data
)
1161 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1163 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1165 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1168 /* ID3D10View methods */
1170 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView
*iface
,
1171 ID3D10Resource
**resource
)
1173 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1175 TRACE("iface %p, resource %p.\n", iface
, resource
);
1177 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
1180 /* ID3D10DepthStencilView methods */
1182 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView
*iface
,
1183 D3D10_DEPTH_STENCIL_VIEW_DESC
*desc
)
1185 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1186 const D3D11_DEPTH_STENCIL_VIEW_DESC
*d3d11_desc
= &view
->desc
;
1188 TRACE("iface %p, desc %p.\n", iface
, desc
);
1190 desc
->Format
= d3d11_desc
->Format
;
1191 desc
->ViewDimension
= (D3D10_DSV_DIMENSION
)d3d11_desc
->ViewDimension
;
1192 memcpy(&desc
->u
, &d3d11_desc
->u
, sizeof(desc
->u
));
1195 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl
=
1197 /* IUnknown methods */
1198 d3d10_depthstencil_view_QueryInterface
,
1199 d3d10_depthstencil_view_AddRef
,
1200 d3d10_depthstencil_view_Release
,
1201 /* ID3D10DeviceChild methods */
1202 d3d10_depthstencil_view_GetDevice
,
1203 d3d10_depthstencil_view_GetPrivateData
,
1204 d3d10_depthstencil_view_SetPrivateData
,
1205 d3d10_depthstencil_view_SetPrivateDataInterface
,
1206 /* ID3D10View methods */
1207 d3d10_depthstencil_view_GetResource
,
1208 /* ID3D10DepthStencilView methods */
1209 d3d10_depthstencil_view_GetDesc
,
1212 static void wined3d_depth_stencil_view_desc_from_d3d11(struct wined3d_rendertarget_view_desc
*wined3d_desc
,
1213 const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
1215 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
1218 FIXME("Unhandled depth stencil view flags %#x.\n", desc
->Flags
);
1220 switch (desc
->ViewDimension
)
1222 case D3D11_DSV_DIMENSION_TEXTURE1D
:
1223 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MipSlice
;
1224 wined3d_desc
->u
.texture
.layer_idx
= 0;
1225 wined3d_desc
->u
.texture
.layer_count
= 1;
1228 case D3D11_DSV_DIMENSION_TEXTURE1DARRAY
:
1229 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MipSlice
;
1230 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
1231 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
1234 case D3D11_DSV_DIMENSION_TEXTURE2D
:
1235 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MipSlice
;
1236 wined3d_desc
->u
.texture
.layer_idx
= 0;
1237 wined3d_desc
->u
.texture
.layer_count
= 1;
1240 case D3D11_DSV_DIMENSION_TEXTURE2DARRAY
:
1241 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MipSlice
;
1242 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
1243 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
1246 case D3D11_DSV_DIMENSION_TEXTURE2DMS
:
1247 wined3d_desc
->u
.texture
.level_idx
= 0;
1248 wined3d_desc
->u
.texture
.layer_idx
= 0;
1249 wined3d_desc
->u
.texture
.layer_count
= 1;
1252 case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
:
1253 wined3d_desc
->u
.texture
.level_idx
= 0;
1254 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DMSArray
.FirstArraySlice
;
1255 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DMSArray
.ArraySize
;
1259 FIXME("Unhandled view dimension %#x.\n", desc
->ViewDimension
);
1260 wined3d_desc
->u
.texture
.level_idx
= 0;
1261 wined3d_desc
->u
.texture
.layer_idx
= 0;
1262 wined3d_desc
->u
.texture
.layer_count
= 1;
1267 static HRESULT
d3d_depthstencil_view_init(struct d3d_depthstencil_view
*view
, struct d3d_device
*device
,
1268 ID3D11Resource
*resource
, const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
1270 struct wined3d_rendertarget_view_desc wined3d_desc
;
1271 struct wined3d_resource
*wined3d_resource
;
1274 view
->ID3D11DepthStencilView_iface
.lpVtbl
= &d3d11_depthstencil_view_vtbl
;
1275 view
->ID3D10DepthStencilView_iface
.lpVtbl
= &d3d10_depthstencil_view_vtbl
;
1280 hr
= set_dsv_desc_from_resource(&view
->desc
, resource
);
1285 hr
= normalize_dsv_desc(&view
->desc
, resource
);
1290 wined3d_mutex_lock();
1291 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
1293 wined3d_mutex_unlock();
1294 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
1298 wined3d_depth_stencil_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
);
1299 if (FAILED(hr
= wined3d_rendertarget_view_create(&wined3d_desc
, wined3d_resource
,
1300 view
, &d3d_null_wined3d_parent_ops
, &view
->wined3d_view
)))
1302 wined3d_mutex_unlock();
1303 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr
);
1307 wined3d_private_store_init(&view
->private_store
);
1308 wined3d_mutex_unlock();
1309 view
->resource
= resource
;
1310 ID3D11Resource_AddRef(resource
);
1311 view
->device
= &device
->ID3D11Device_iface
;
1312 ID3D11Device_AddRef(view
->device
);
1317 HRESULT
d3d_depthstencil_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
1318 const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, struct d3d_depthstencil_view
**view
)
1320 struct d3d_depthstencil_view
*object
;
1323 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
1324 return E_OUTOFMEMORY
;
1326 if (FAILED(hr
= d3d_depthstencil_view_init(object
, device
, resource
, desc
)))
1328 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr
);
1329 HeapFree(GetProcessHeap(), 0, object
);
1333 TRACE("Created depthstencil view %p.\n", object
);
1339 struct d3d_depthstencil_view
*unsafe_impl_from_ID3D11DepthStencilView(ID3D11DepthStencilView
*iface
)
1343 assert(iface
->lpVtbl
== &d3d11_depthstencil_view_vtbl
);
1345 return impl_from_ID3D11DepthStencilView(iface
);
1348 struct d3d_depthstencil_view
*unsafe_impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView
*iface
)
1352 assert(iface
->lpVtbl
== &d3d10_depthstencil_view_vtbl
);
1354 return impl_from_ID3D10DepthStencilView(iface
);
1357 /* ID3D11RenderTargetView methods */
1359 static inline struct d3d_rendertarget_view
*impl_from_ID3D11RenderTargetView(ID3D11RenderTargetView
*iface
)
1361 return CONTAINING_RECORD(iface
, struct d3d_rendertarget_view
, ID3D11RenderTargetView_iface
);
1364 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_QueryInterface(ID3D11RenderTargetView
*iface
,
1365 REFIID riid
, void **object
)
1367 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1369 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1371 if (IsEqualGUID(riid
, &IID_ID3D11RenderTargetView
)
1372 || IsEqualGUID(riid
, &IID_ID3D11View
)
1373 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
1374 || IsEqualGUID(riid
, &IID_IUnknown
))
1376 ID3D11RenderTargetView_AddRef(iface
);
1381 if (IsEqualGUID(riid
, &IID_ID3D10RenderTargetView
)
1382 || IsEqualGUID(riid
, &IID_ID3D10View
)
1383 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
1385 ID3D10RenderTargetView_AddRef(&view
->ID3D10RenderTargetView_iface
);
1386 *object
= &view
->ID3D10RenderTargetView_iface
;
1390 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
1393 return E_NOINTERFACE
;
1396 static ULONG STDMETHODCALLTYPE
d3d11_rendertarget_view_AddRef(ID3D11RenderTargetView
*iface
)
1398 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1399 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
1401 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
1406 static ULONG STDMETHODCALLTYPE
d3d11_rendertarget_view_Release(ID3D11RenderTargetView
*iface
)
1408 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1409 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
1411 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
1415 wined3d_mutex_lock();
1416 wined3d_rendertarget_view_decref(view
->wined3d_view
);
1417 ID3D11Resource_Release(view
->resource
);
1418 ID3D11Device_Release(view
->device
);
1419 wined3d_private_store_cleanup(&view
->private_store
);
1420 wined3d_mutex_unlock();
1421 HeapFree(GetProcessHeap(), 0, view
);
1427 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetDevice(ID3D11RenderTargetView
*iface
,
1428 ID3D11Device
**device
)
1430 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1432 TRACE("iface %p, device %p.\n", iface
, device
);
1434 *device
= view
->device
;
1435 ID3D11Device_AddRef(*device
);
1438 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_GetPrivateData(ID3D11RenderTargetView
*iface
,
1439 REFGUID guid
, UINT
*data_size
, void *data
)
1441 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1443 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1445 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1448 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_SetPrivateData(ID3D11RenderTargetView
*iface
,
1449 REFGUID guid
, UINT data_size
, const void *data
)
1451 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1453 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1455 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1458 static HRESULT STDMETHODCALLTYPE
d3d11_rendertarget_view_SetPrivateDataInterface(ID3D11RenderTargetView
*iface
,
1459 REFGUID guid
, const IUnknown
*data
)
1461 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1463 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1465 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1468 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetResource(ID3D11RenderTargetView
*iface
,
1469 ID3D11Resource
**resource
)
1471 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1473 TRACE("iface %p, resource %p.\n", iface
, resource
);
1475 *resource
= view
->resource
;
1476 ID3D11Resource_AddRef(*resource
);
1479 static void STDMETHODCALLTYPE
d3d11_rendertarget_view_GetDesc(ID3D11RenderTargetView
*iface
,
1480 D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
1482 struct d3d_rendertarget_view
*view
= impl_from_ID3D11RenderTargetView(iface
);
1484 TRACE("iface %p, desc %p.\n", iface
, desc
);
1489 static const struct ID3D11RenderTargetViewVtbl d3d11_rendertarget_view_vtbl
=
1491 /* IUnknown methods */
1492 d3d11_rendertarget_view_QueryInterface
,
1493 d3d11_rendertarget_view_AddRef
,
1494 d3d11_rendertarget_view_Release
,
1495 /* ID3D11DeviceChild methods */
1496 d3d11_rendertarget_view_GetDevice
,
1497 d3d11_rendertarget_view_GetPrivateData
,
1498 d3d11_rendertarget_view_SetPrivateData
,
1499 d3d11_rendertarget_view_SetPrivateDataInterface
,
1500 /* ID3D11View methods */
1501 d3d11_rendertarget_view_GetResource
,
1502 /* ID3D11RenderTargetView methods */
1503 d3d11_rendertarget_view_GetDesc
,
1506 /* ID3D10RenderTargetView methods */
1508 static inline struct d3d_rendertarget_view
*impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView
*iface
)
1510 return CONTAINING_RECORD(iface
, struct d3d_rendertarget_view
, ID3D10RenderTargetView_iface
);
1513 /* IUnknown methods */
1515 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView
*iface
,
1516 REFIID riid
, void **object
)
1518 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1520 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1522 return d3d11_rendertarget_view_QueryInterface(&view
->ID3D11RenderTargetView_iface
, riid
, object
);
1525 static ULONG STDMETHODCALLTYPE
d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView
*iface
)
1527 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1529 TRACE("iface %p.\n", iface
);
1531 return d3d11_rendertarget_view_AddRef(&view
->ID3D11RenderTargetView_iface
);
1534 static ULONG STDMETHODCALLTYPE
d3d10_rendertarget_view_Release(ID3D10RenderTargetView
*iface
)
1536 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1538 TRACE("iface %p.\n", iface
);
1540 return d3d11_rendertarget_view_Release(&view
->ID3D11RenderTargetView_iface
);
1543 /* ID3D10DeviceChild methods */
1545 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView
*iface
, ID3D10Device
**device
)
1547 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1549 TRACE("iface %p, device %p.\n", iface
, device
);
1551 ID3D11Device_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
1554 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView
*iface
,
1555 REFGUID guid
, UINT
*data_size
, void *data
)
1557 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1559 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1560 iface
, debugstr_guid(guid
), data_size
, data
);
1562 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1565 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView
*iface
,
1566 REFGUID guid
, UINT data_size
, const void *data
)
1568 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1570 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1571 iface
, debugstr_guid(guid
), data_size
, data
);
1573 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1576 static HRESULT STDMETHODCALLTYPE
d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView
*iface
,
1577 REFGUID guid
, const IUnknown
*data
)
1579 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1581 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1583 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1586 /* ID3D10View methods */
1588 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView
*iface
,
1589 ID3D10Resource
**resource
)
1591 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1593 TRACE("iface %p, resource %p\n", iface
, resource
);
1595 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
1598 /* ID3D10RenderTargetView methods */
1600 static void STDMETHODCALLTYPE
d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView
*iface
,
1601 D3D10_RENDER_TARGET_VIEW_DESC
*desc
)
1603 struct d3d_rendertarget_view
*view
= impl_from_ID3D10RenderTargetView(iface
);
1605 TRACE("iface %p, desc %p\n", iface
, desc
);
1607 memcpy(desc
, &view
->desc
, sizeof(*desc
));
1610 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl
=
1612 /* IUnknown methods */
1613 d3d10_rendertarget_view_QueryInterface
,
1614 d3d10_rendertarget_view_AddRef
,
1615 d3d10_rendertarget_view_Release
,
1616 /* ID3D10DeviceChild methods */
1617 d3d10_rendertarget_view_GetDevice
,
1618 d3d10_rendertarget_view_GetPrivateData
,
1619 d3d10_rendertarget_view_SetPrivateData
,
1620 d3d10_rendertarget_view_SetPrivateDataInterface
,
1621 /* ID3D10View methods */
1622 d3d10_rendertarget_view_GetResource
,
1623 /* ID3D10RenderTargetView methods */
1624 d3d10_rendertarget_view_GetDesc
,
1627 static void wined3d_rendertarget_view_desc_from_d3d11(struct wined3d_rendertarget_view_desc
*wined3d_desc
,
1628 const D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
1630 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
1632 switch (desc
->ViewDimension
)
1634 case D3D11_RTV_DIMENSION_BUFFER
:
1635 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.Buffer
.u1
.FirstElement
;
1636 wined3d_desc
->u
.buffer
.count
= desc
->u
.Buffer
.u2
.NumElements
;
1639 case D3D11_RTV_DIMENSION_TEXTURE1D
:
1640 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MipSlice
;
1641 wined3d_desc
->u
.texture
.layer_idx
= 0;
1642 wined3d_desc
->u
.texture
.layer_count
= 1;
1645 case D3D11_RTV_DIMENSION_TEXTURE1DARRAY
:
1646 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MipSlice
;
1647 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
1648 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
1651 case D3D11_RTV_DIMENSION_TEXTURE2D
:
1652 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MipSlice
;
1653 wined3d_desc
->u
.texture
.layer_idx
= 0;
1654 wined3d_desc
->u
.texture
.layer_count
= 1;
1657 case D3D11_RTV_DIMENSION_TEXTURE2DARRAY
:
1658 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MipSlice
;
1659 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
1660 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
1663 case D3D11_RTV_DIMENSION_TEXTURE2DMS
:
1664 wined3d_desc
->u
.texture
.level_idx
= 0;
1665 wined3d_desc
->u
.texture
.layer_idx
= 0;
1666 wined3d_desc
->u
.texture
.layer_count
= 1;
1669 case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
:
1670 wined3d_desc
->u
.texture
.level_idx
= 0;
1671 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DMSArray
.FirstArraySlice
;
1672 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DMSArray
.ArraySize
;
1675 case D3D11_RTV_DIMENSION_TEXTURE3D
:
1676 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture3D
.MipSlice
;
1677 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture3D
.FirstWSlice
;
1678 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture3D
.WSize
;
1682 FIXME("Unhandled view dimension %#x.\n", desc
->ViewDimension
);
1683 wined3d_desc
->u
.texture
.level_idx
= 0;
1684 wined3d_desc
->u
.texture
.layer_idx
= 0;
1685 wined3d_desc
->u
.texture
.layer_count
= 1;
1690 static HRESULT
d3d_rendertarget_view_init(struct d3d_rendertarget_view
*view
, struct d3d_device
*device
,
1691 ID3D11Resource
*resource
, const D3D11_RENDER_TARGET_VIEW_DESC
*desc
)
1693 struct wined3d_rendertarget_view_desc wined3d_desc
;
1694 struct wined3d_resource
*wined3d_resource
;
1697 view
->ID3D11RenderTargetView_iface
.lpVtbl
= &d3d11_rendertarget_view_vtbl
;
1698 view
->ID3D10RenderTargetView_iface
.lpVtbl
= &d3d10_rendertarget_view_vtbl
;
1703 hr
= set_rtv_desc_from_resource(&view
->desc
, resource
);
1708 hr
= normalize_rtv_desc(&view
->desc
, resource
);
1713 wined3d_mutex_lock();
1714 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
1716 wined3d_mutex_unlock();
1717 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
1721 wined3d_rendertarget_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
);
1722 if (FAILED(hr
= wined3d_rendertarget_view_create(&wined3d_desc
, wined3d_resource
,
1723 view
, &d3d_null_wined3d_parent_ops
, &view
->wined3d_view
)))
1725 wined3d_mutex_unlock();
1726 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr
);
1730 wined3d_private_store_init(&view
->private_store
);
1731 wined3d_mutex_unlock();
1732 view
->resource
= resource
;
1733 ID3D11Resource_AddRef(resource
);
1734 view
->device
= &device
->ID3D11Device_iface
;
1735 ID3D11Device_AddRef(view
->device
);
1740 HRESULT
d3d_rendertarget_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
1741 const D3D11_RENDER_TARGET_VIEW_DESC
*desc
, struct d3d_rendertarget_view
**view
)
1743 struct d3d_rendertarget_view
*object
;
1746 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
1747 return E_OUTOFMEMORY
;
1749 if (FAILED(hr
= d3d_rendertarget_view_init(object
, device
, resource
, desc
)))
1751 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr
);
1752 HeapFree(GetProcessHeap(), 0, object
);
1756 TRACE("Created rendertarget view %p.\n", object
);
1762 struct d3d_rendertarget_view
*unsafe_impl_from_ID3D11RenderTargetView(ID3D11RenderTargetView
*iface
)
1766 assert(iface
->lpVtbl
== &d3d11_rendertarget_view_vtbl
);
1768 return impl_from_ID3D11RenderTargetView(iface
);
1771 struct d3d_rendertarget_view
*unsafe_impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView
*iface
)
1775 assert(iface
->lpVtbl
== &d3d10_rendertarget_view_vtbl
);
1777 return impl_from_ID3D10RenderTargetView(iface
);
1780 /* ID3D11ShaderResourceView methods */
1782 static inline struct d3d_shader_resource_view
*impl_from_ID3D11ShaderResourceView(ID3D11ShaderResourceView
*iface
)
1784 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D11ShaderResourceView_iface
);
1787 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_QueryInterface(ID3D11ShaderResourceView
*iface
,
1788 REFIID riid
, void **object
)
1790 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1792 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1794 if (IsEqualGUID(riid
, &IID_ID3D11ShaderResourceView
)
1795 || IsEqualGUID(riid
, &IID_ID3D11View
)
1796 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
1797 || IsEqualGUID(riid
, &IID_IUnknown
))
1799 ID3D11ShaderResourceView_AddRef(iface
);
1804 if (IsEqualGUID(riid
, &IID_ID3D10ShaderResourceView1
)
1805 || IsEqualGUID(riid
, &IID_ID3D10ShaderResourceView
)
1806 || IsEqualGUID(riid
, &IID_ID3D10View
)
1807 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
1809 ID3D10ShaderResourceView1_AddRef(&view
->ID3D10ShaderResourceView1_iface
);
1810 *object
= &view
->ID3D10ShaderResourceView1_iface
;
1814 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
1817 return E_NOINTERFACE
;
1820 static ULONG STDMETHODCALLTYPE
d3d11_shader_resource_view_AddRef(ID3D11ShaderResourceView
*iface
)
1822 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1823 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
1825 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
1830 static ULONG STDMETHODCALLTYPE
d3d11_shader_resource_view_Release(ID3D11ShaderResourceView
*iface
)
1832 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1833 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
1835 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
1839 wined3d_mutex_lock();
1840 wined3d_shader_resource_view_decref(view
->wined3d_view
);
1841 ID3D11Resource_Release(view
->resource
);
1842 ID3D11Device_Release(view
->device
);
1843 wined3d_private_store_cleanup(&view
->private_store
);
1844 wined3d_mutex_unlock();
1845 HeapFree(GetProcessHeap(), 0, view
);
1851 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetDevice(ID3D11ShaderResourceView
*iface
,
1852 ID3D11Device
**device
)
1854 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1856 TRACE("iface %p, device %p.\n", iface
, device
);
1858 *device
= view
->device
;
1859 ID3D11Device_AddRef(*device
);
1862 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_GetPrivateData(ID3D11ShaderResourceView
*iface
,
1863 REFGUID guid
, UINT
*data_size
, void *data
)
1865 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1867 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1869 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1872 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_SetPrivateData(ID3D11ShaderResourceView
*iface
,
1873 REFGUID guid
, UINT data_size
, const void *data
)
1875 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1877 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1879 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1882 static HRESULT STDMETHODCALLTYPE
d3d11_shader_resource_view_SetPrivateDataInterface(ID3D11ShaderResourceView
*iface
,
1883 REFGUID guid
, const IUnknown
*data
)
1885 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1887 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1889 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1892 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetResource(ID3D11ShaderResourceView
*iface
,
1893 ID3D11Resource
**resource
)
1895 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1897 TRACE("iface %p, resource %p.\n", iface
, resource
);
1899 *resource
= view
->resource
;
1900 ID3D11Resource_AddRef(*resource
);
1903 static void STDMETHODCALLTYPE
d3d11_shader_resource_view_GetDesc(ID3D11ShaderResourceView
*iface
,
1904 D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
)
1906 struct d3d_shader_resource_view
*view
= impl_from_ID3D11ShaderResourceView(iface
);
1908 TRACE("iface %p, desc %p.\n", iface
, desc
);
1913 static const struct ID3D11ShaderResourceViewVtbl d3d11_shader_resource_view_vtbl
=
1915 /* IUnknown methods */
1916 d3d11_shader_resource_view_QueryInterface
,
1917 d3d11_shader_resource_view_AddRef
,
1918 d3d11_shader_resource_view_Release
,
1919 /* ID3D11DeviceChild methods */
1920 d3d11_shader_resource_view_GetDevice
,
1921 d3d11_shader_resource_view_GetPrivateData
,
1922 d3d11_shader_resource_view_SetPrivateData
,
1923 d3d11_shader_resource_view_SetPrivateDataInterface
,
1924 /* ID3D11View methods */
1925 d3d11_shader_resource_view_GetResource
,
1926 /* ID3D11ShaderResourceView methods */
1927 d3d11_shader_resource_view_GetDesc
,
1930 /* ID3D10ShaderResourceView methods */
1932 static inline struct d3d_shader_resource_view
*impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView1
*iface
)
1934 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D10ShaderResourceView1_iface
);
1937 /* IUnknown methods */
1939 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView1
*iface
,
1940 REFIID riid
, void **object
)
1942 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1944 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1946 return d3d11_shader_resource_view_QueryInterface(&view
->ID3D11ShaderResourceView_iface
, riid
, object
);
1949 static ULONG STDMETHODCALLTYPE
d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView1
*iface
)
1951 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1953 TRACE("iface %p.\n", iface
);
1955 return d3d11_shader_resource_view_AddRef(&view
->ID3D11ShaderResourceView_iface
);
1958 static ULONG STDMETHODCALLTYPE
d3d10_shader_resource_view_Release(ID3D10ShaderResourceView1
*iface
)
1960 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1962 TRACE("iface %p.\n", iface
);
1964 return d3d11_shader_resource_view_Release(&view
->ID3D11ShaderResourceView_iface
);
1967 /* ID3D10DeviceChild methods */
1969 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView1
*iface
,
1970 ID3D10Device
**device
)
1972 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1974 TRACE("iface %p, device %p.\n", iface
, device
);
1976 ID3D11Device_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
1979 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView1
*iface
,
1980 REFGUID guid
, UINT
*data_size
, void *data
)
1982 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1984 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1985 iface
, debugstr_guid(guid
), data_size
, data
);
1987 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1990 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView1
*iface
,
1991 REFGUID guid
, UINT data_size
, const void *data
)
1993 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
1995 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1996 iface
, debugstr_guid(guid
), data_size
, data
);
1998 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
2001 static HRESULT STDMETHODCALLTYPE
d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView1
*iface
,
2002 REFGUID guid
, const IUnknown
*data
)
2004 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2006 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
2008 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
2011 /* ID3D10View methods */
2013 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView1
*iface
,
2014 ID3D10Resource
**resource
)
2016 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2018 TRACE("iface %p, resource %p.\n", iface
, resource
);
2020 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
2023 /* ID3D10ShaderResourceView methods */
2025 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView1
*iface
,
2026 D3D10_SHADER_RESOURCE_VIEW_DESC
*desc
)
2028 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2030 TRACE("iface %p, desc %p.\n", iface
, desc
);
2032 memcpy(desc
, &view
->desc
, sizeof(*desc
));
2035 static void STDMETHODCALLTYPE
d3d10_shader_resource_view_GetDesc1(ID3D10ShaderResourceView1
*iface
,
2036 D3D10_SHADER_RESOURCE_VIEW_DESC1
*desc
)
2038 struct d3d_shader_resource_view
*view
= impl_from_ID3D10ShaderResourceView(iface
);
2040 TRACE("iface %p, desc %p.\n", iface
, desc
);
2042 memcpy(desc
, &view
->desc
, sizeof(*desc
));
2045 static const struct ID3D10ShaderResourceView1Vtbl d3d10_shader_resource_view_vtbl
=
2047 /* IUnknown methods */
2048 d3d10_shader_resource_view_QueryInterface
,
2049 d3d10_shader_resource_view_AddRef
,
2050 d3d10_shader_resource_view_Release
,
2051 /* ID3D10DeviceChild methods */
2052 d3d10_shader_resource_view_GetDevice
,
2053 d3d10_shader_resource_view_GetPrivateData
,
2054 d3d10_shader_resource_view_SetPrivateData
,
2055 d3d10_shader_resource_view_SetPrivateDataInterface
,
2056 /* ID3D10View methods */
2057 d3d10_shader_resource_view_GetResource
,
2058 /* ID3D10ShaderResourceView methods */
2059 d3d10_shader_resource_view_GetDesc
,
2060 /* ID3D10ShaderResourceView1 methods */
2061 d3d10_shader_resource_view_GetDesc1
,
2064 static unsigned int wined3d_view_flags_from_d3d11_bufferex_flags(unsigned int d3d11_flags
)
2066 unsigned int wined3d_flags
= d3d11_flags
& WINED3D_VIEW_BUFFER_RAW
;
2068 if (d3d11_flags
!= wined3d_flags
)
2069 FIXME("Unhandled flags %#x.\n", d3d11_flags
& ~wined3d_flags
);
2071 return wined3d_flags
;
2074 static HRESULT
wined3d_shader_resource_view_desc_from_d3d11(struct wined3d_shader_resource_view_desc
*wined3d_desc
,
2075 const D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
)
2077 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
2078 wined3d_desc
->flags
= 0;
2080 switch (desc
->ViewDimension
)
2082 case D3D11_SRV_DIMENSION_BUFFER
:
2083 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.Buffer
.u1
.FirstElement
;
2084 wined3d_desc
->u
.buffer
.count
= desc
->u
.Buffer
.u2
.NumElements
;
2087 case D3D11_SRV_DIMENSION_TEXTURE1D
:
2088 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MostDetailedMip
;
2089 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture1D
.MipLevels
;
2090 wined3d_desc
->u
.texture
.layer_idx
= 0;
2091 wined3d_desc
->u
.texture
.layer_count
= 1;
2094 case D3D11_SRV_DIMENSION_TEXTURE1DARRAY
:
2095 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2096 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MostDetailedMip
;
2097 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture1DArray
.MipLevels
;
2098 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
2099 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
2102 case D3D11_SRV_DIMENSION_TEXTURE2D
:
2103 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MostDetailedMip
;
2104 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture2D
.MipLevels
;
2105 wined3d_desc
->u
.texture
.layer_idx
= 0;
2106 wined3d_desc
->u
.texture
.layer_count
= 1;
2109 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY
:
2110 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2111 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MostDetailedMip
;
2112 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture2DArray
.MipLevels
;
2113 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
2114 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
2117 case D3D11_SRV_DIMENSION_TEXTURE2DMS
:
2118 wined3d_desc
->u
.texture
.level_idx
= 0;
2119 wined3d_desc
->u
.texture
.level_count
= 1;
2120 wined3d_desc
->u
.texture
.layer_idx
= 0;
2121 wined3d_desc
->u
.texture
.layer_count
= 1;
2124 case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
:
2125 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2126 wined3d_desc
->u
.texture
.level_idx
= 0;
2127 wined3d_desc
->u
.texture
.level_count
= 1;
2128 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DMSArray
.FirstArraySlice
;
2129 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DMSArray
.ArraySize
;
2132 case D3D11_SRV_DIMENSION_TEXTURE3D
:
2133 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture3D
.MostDetailedMip
;
2134 wined3d_desc
->u
.texture
.level_count
= desc
->u
.Texture3D
.MipLevels
;
2135 wined3d_desc
->u
.texture
.layer_idx
= 0;
2136 wined3d_desc
->u
.texture
.layer_count
= 1;
2139 case D3D11_SRV_DIMENSION_TEXTURECUBE
:
2140 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_CUBE
;
2141 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.TextureCube
.MostDetailedMip
;
2142 wined3d_desc
->u
.texture
.level_count
= desc
->u
.TextureCube
.MipLevels
;
2143 wined3d_desc
->u
.texture
.layer_idx
= 0;
2144 wined3d_desc
->u
.texture
.layer_count
= 6;
2147 case D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
:
2148 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_CUBE
| WINED3D_VIEW_TEXTURE_ARRAY
;
2149 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.TextureCubeArray
.MostDetailedMip
;
2150 wined3d_desc
->u
.texture
.level_count
= desc
->u
.TextureCubeArray
.MipLevels
;
2151 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.TextureCubeArray
.First2DArrayFace
;
2152 wined3d_desc
->u
.texture
.layer_count
= 6 * desc
->u
.TextureCubeArray
.NumCubes
;
2155 case D3D11_SRV_DIMENSION_BUFFEREX
:
2156 wined3d_desc
->flags
= wined3d_view_flags_from_d3d11_bufferex_flags(desc
->u
.BufferEx
.Flags
);
2157 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.BufferEx
.FirstElement
;
2158 wined3d_desc
->u
.buffer
.count
= desc
->u
.BufferEx
.NumElements
;
2162 WARN("Unrecognized view dimension %#x.\n", desc
->ViewDimension
);
2169 static HRESULT
d3d_shader_resource_view_init(struct d3d_shader_resource_view
*view
, struct d3d_device
*device
,
2170 ID3D11Resource
*resource
, const D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
)
2172 struct wined3d_shader_resource_view_desc wined3d_desc
;
2173 struct wined3d_resource
*wined3d_resource
;
2176 view
->ID3D11ShaderResourceView_iface
.lpVtbl
= &d3d11_shader_resource_view_vtbl
;
2177 view
->ID3D10ShaderResourceView1_iface
.lpVtbl
= &d3d10_shader_resource_view_vtbl
;
2182 hr
= set_srv_desc_from_resource(&view
->desc
, resource
);
2187 hr
= normalize_srv_desc(&view
->desc
, resource
);
2192 if (FAILED(hr
= wined3d_shader_resource_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
)))
2195 wined3d_mutex_lock();
2196 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
2198 wined3d_mutex_unlock();
2199 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
2203 if (FAILED(hr
= wined3d_shader_resource_view_create(&wined3d_desc
, wined3d_resource
,
2204 view
, &d3d_null_wined3d_parent_ops
, &view
->wined3d_view
)))
2206 wined3d_mutex_unlock();
2207 WARN("Failed to create wined3d shader resource view, hr %#x.\n", hr
);
2211 wined3d_private_store_init(&view
->private_store
);
2212 wined3d_mutex_unlock();
2213 view
->resource
= resource
;
2214 ID3D11Resource_AddRef(resource
);
2215 view
->device
= &device
->ID3D11Device_iface
;
2216 ID3D11Device_AddRef(view
->device
);
2221 HRESULT
d3d_shader_resource_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
2222 const D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, struct d3d_shader_resource_view
**view
)
2224 struct d3d_shader_resource_view
*object
;
2227 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
2228 return E_OUTOFMEMORY
;
2230 if (FAILED(hr
= d3d_shader_resource_view_init(object
, device
, resource
, desc
)))
2232 WARN("Failed to initialize shader resource view, hr %#x.\n", hr
);
2233 HeapFree(GetProcessHeap(), 0, object
);
2237 TRACE("Created shader resource view %p.\n", object
);
2243 struct d3d_shader_resource_view
*unsafe_impl_from_ID3D11ShaderResourceView(ID3D11ShaderResourceView
*iface
)
2247 assert(iface
->lpVtbl
== &d3d11_shader_resource_view_vtbl
);
2248 return impl_from_ID3D11ShaderResourceView(iface
);
2251 struct d3d_shader_resource_view
*unsafe_impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView
*iface
)
2255 assert(iface
->lpVtbl
== (ID3D10ShaderResourceViewVtbl
*)&d3d10_shader_resource_view_vtbl
);
2256 return CONTAINING_RECORD(iface
, struct d3d_shader_resource_view
, ID3D10ShaderResourceView1_iface
);
2259 /* ID3D11UnorderedAccessView methods */
2261 static inline struct d3d11_unordered_access_view
*impl_from_ID3D11UnorderedAccessView(ID3D11UnorderedAccessView
*iface
)
2263 return CONTAINING_RECORD(iface
, struct d3d11_unordered_access_view
, ID3D11UnorderedAccessView_iface
);
2266 static HRESULT STDMETHODCALLTYPE
d3d11_unordered_access_view_QueryInterface(ID3D11UnorderedAccessView
*iface
,
2267 REFIID riid
, void **object
)
2269 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
2271 if (IsEqualGUID(riid
, &IID_ID3D11UnorderedAccessView
)
2272 || IsEqualGUID(riid
, &IID_ID3D11View
)
2273 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
2274 || IsEqualGUID(riid
, &IID_IUnknown
))
2276 ID3D11UnorderedAccessView_AddRef(*object
= iface
);
2280 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
2283 return E_NOINTERFACE
;
2286 static ULONG STDMETHODCALLTYPE
d3d11_unordered_access_view_AddRef(ID3D11UnorderedAccessView
*iface
)
2288 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2289 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
2291 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
2296 static ULONG STDMETHODCALLTYPE
d3d11_unordered_access_view_Release(ID3D11UnorderedAccessView
*iface
)
2298 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2299 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
2301 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
2305 wined3d_mutex_lock();
2306 wined3d_unordered_access_view_decref(view
->wined3d_view
);
2307 ID3D11Resource_Release(view
->resource
);
2308 ID3D11Device_Release(view
->device
);
2309 wined3d_private_store_cleanup(&view
->private_store
);
2310 wined3d_mutex_unlock();
2311 HeapFree(GetProcessHeap(), 0, view
);
2317 static void STDMETHODCALLTYPE
d3d11_unordered_access_view_GetDevice(ID3D11UnorderedAccessView
*iface
,
2318 ID3D11Device
**device
)
2320 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2322 TRACE("iface %p, device %p.\n", iface
, device
);
2324 ID3D11Device_AddRef(*device
= view
->device
);
2327 static HRESULT STDMETHODCALLTYPE
d3d11_unordered_access_view_GetPrivateData(ID3D11UnorderedAccessView
*iface
,
2328 REFGUID guid
, UINT
*data_size
, void *data
)
2330 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2332 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
2334 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
2337 static HRESULT STDMETHODCALLTYPE
d3d11_unordered_access_view_SetPrivateData(ID3D11UnorderedAccessView
*iface
,
2338 REFGUID guid
, UINT data_size
, const void *data
)
2340 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2342 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
2344 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
2347 static HRESULT STDMETHODCALLTYPE
d3d11_unordered_access_view_SetPrivateDataInterface(ID3D11UnorderedAccessView
*iface
,
2348 REFGUID guid
, const IUnknown
*data
)
2350 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2352 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
2354 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
2357 static void STDMETHODCALLTYPE
d3d11_unordered_access_view_GetResource(ID3D11UnorderedAccessView
*iface
,
2358 ID3D11Resource
**resource
)
2360 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2362 TRACE("iface %p, resource %p.\n", iface
, resource
);
2364 ID3D11Resource_AddRef(*resource
= view
->resource
);
2367 static void STDMETHODCALLTYPE
d3d11_unordered_access_view_GetDesc(ID3D11UnorderedAccessView
*iface
,
2368 D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
)
2370 struct d3d11_unordered_access_view
*view
= impl_from_ID3D11UnorderedAccessView(iface
);
2372 TRACE("iface %p, desc %p.\n", iface
, desc
);
2377 static const struct ID3D11UnorderedAccessViewVtbl d3d11_unordered_access_view_vtbl
=
2379 /* IUnknown methods */
2380 d3d11_unordered_access_view_QueryInterface
,
2381 d3d11_unordered_access_view_AddRef
,
2382 d3d11_unordered_access_view_Release
,
2383 /* ID3D11DeviceChild methods */
2384 d3d11_unordered_access_view_GetDevice
,
2385 d3d11_unordered_access_view_GetPrivateData
,
2386 d3d11_unordered_access_view_SetPrivateData
,
2387 d3d11_unordered_access_view_SetPrivateDataInterface
,
2388 /* ID3D11View methods */
2389 d3d11_unordered_access_view_GetResource
,
2390 /* ID3D11UnorderedAccessView methods */
2391 d3d11_unordered_access_view_GetDesc
,
2394 static unsigned int wined3d_view_flags_from_d3d11_buffer_uav_flags(unsigned int d3d11_flags
)
2396 unsigned int wined3d_flags
= d3d11_flags
& (WINED3D_VIEW_BUFFER_RAW
2397 | WINED3D_VIEW_BUFFER_APPEND
| WINED3D_VIEW_BUFFER_COUNTER
);
2399 if (d3d11_flags
!= wined3d_flags
)
2400 FIXME("Unhandled flags %#x.\n", d3d11_flags
& ~wined3d_flags
);
2402 return wined3d_flags
;
2405 static HRESULT
wined3d_unordered_access_view_desc_from_d3d11(struct wined3d_unordered_access_view_desc
*wined3d_desc
,
2406 const D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
)
2408 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
2409 wined3d_desc
->flags
= 0;
2411 switch (desc
->ViewDimension
)
2413 case D3D11_UAV_DIMENSION_BUFFER
:
2414 wined3d_desc
->flags
= wined3d_view_flags_from_d3d11_buffer_uav_flags(desc
->u
.Buffer
.Flags
);
2415 wined3d_desc
->u
.buffer
.start_idx
= desc
->u
.Buffer
.FirstElement
;
2416 wined3d_desc
->u
.buffer
.count
= desc
->u
.Buffer
.NumElements
;
2419 case D3D11_UAV_DIMENSION_TEXTURE1D
:
2420 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1D
.MipSlice
;
2421 wined3d_desc
->u
.texture
.layer_idx
= 0;
2422 wined3d_desc
->u
.texture
.layer_count
= 1;
2425 case D3D11_UAV_DIMENSION_TEXTURE1DARRAY
:
2426 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2427 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture1DArray
.MipSlice
;
2428 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture1DArray
.FirstArraySlice
;
2429 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture1DArray
.ArraySize
;
2432 case D3D11_UAV_DIMENSION_TEXTURE2D
:
2433 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2D
.MipSlice
;
2434 wined3d_desc
->u
.texture
.layer_idx
= 0;
2435 wined3d_desc
->u
.texture
.layer_count
= 1;
2438 case D3D11_UAV_DIMENSION_TEXTURE2DARRAY
:
2439 wined3d_desc
->flags
= WINED3D_VIEW_TEXTURE_ARRAY
;
2440 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture2DArray
.MipSlice
;
2441 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture2DArray
.FirstArraySlice
;
2442 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture2DArray
.ArraySize
;
2445 case D3D11_UAV_DIMENSION_TEXTURE3D
:
2446 wined3d_desc
->u
.texture
.level_idx
= desc
->u
.Texture3D
.MipSlice
;
2447 wined3d_desc
->u
.texture
.layer_idx
= desc
->u
.Texture3D
.FirstWSlice
;
2448 wined3d_desc
->u
.texture
.layer_count
= desc
->u
.Texture3D
.WSize
;
2452 WARN("Unrecognized view dimension %#x.\n", desc
->ViewDimension
);
2459 static HRESULT
d3d11_unordered_access_view_init(struct d3d11_unordered_access_view
*view
,
2460 struct d3d_device
*device
, ID3D11Resource
*resource
, const D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
)
2462 struct wined3d_unordered_access_view_desc wined3d_desc
;
2463 struct wined3d_resource
*wined3d_resource
;
2466 view
->ID3D11UnorderedAccessView_iface
.lpVtbl
= &d3d11_unordered_access_view_vtbl
;
2471 hr
= set_uav_desc_from_resource(&view
->desc
, resource
);
2476 hr
= normalize_uav_desc(&view
->desc
, resource
);
2481 if (FAILED(hr
= wined3d_unordered_access_view_desc_from_d3d11(&wined3d_desc
, &view
->desc
)))
2484 wined3d_mutex_lock();
2485 if (!(wined3d_resource
= wined3d_resource_from_d3d11_resource(resource
)))
2487 wined3d_mutex_unlock();
2488 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource
);
2492 if (FAILED(hr
= wined3d_unordered_access_view_create(&wined3d_desc
, wined3d_resource
,
2493 view
, &d3d_null_wined3d_parent_ops
, &view
->wined3d_view
)))
2495 wined3d_mutex_unlock();
2496 WARN("Failed to create wined3d unordered access view, hr %#x.\n", hr
);
2500 wined3d_private_store_init(&view
->private_store
);
2501 wined3d_mutex_unlock();
2502 ID3D11Resource_AddRef(view
->resource
= resource
);
2503 ID3D11Device_AddRef(view
->device
= &device
->ID3D11Device_iface
);
2508 HRESULT
d3d11_unordered_access_view_create(struct d3d_device
*device
, ID3D11Resource
*resource
,
2509 const D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
, struct d3d11_unordered_access_view
**view
)
2511 struct d3d11_unordered_access_view
*object
;
2514 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
2515 return E_OUTOFMEMORY
;
2517 if (FAILED(hr
= d3d11_unordered_access_view_init(object
, device
, resource
, desc
)))
2519 WARN("Failed to initialize unordered access view, hr %#x.\n", hr
);
2520 HeapFree(GetProcessHeap(), 0, object
);
2524 TRACE("Created unordered access view %p.\n", object
);