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
get_resource_properties(ID3D11Resource
*resource
, D3D11_RESOURCE_DIMENSION
*dimension
,
29 DXGI_FORMAT
*format
, unsigned int *miplevel_count
, unsigned int *layer_count
)
31 ID3D11Resource_GetType(resource
, dimension
);
34 case D3D11_RESOURCE_DIMENSION_BUFFER
:
37 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
39 const struct d3d_texture1d
*texture
;
41 if (!(texture
= unsafe_impl_from_ID3D11Texture1D((ID3D11Texture1D
*)resource
)))
43 ERR("Cannot get implementation from ID3D11Texture1D.\n");
47 *format
= texture
->desc
.Format
;
49 *miplevel_count
= texture
->desc
.MipLevels
;
50 *layer_count
= texture
->desc
.ArraySize
;
54 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
56 const struct d3d_texture2d
*texture
;
58 if (!(texture
= unsafe_impl_from_ID3D11Texture2D((ID3D11Texture2D
*)resource
)))
60 ERR("Cannot get implementation from ID3D11Texture2D.\n");
64 *format
= texture
->desc
.Format
;
66 *miplevel_count
= texture
->desc
.MipLevels
;
67 *layer_count
= texture
->desc
.ArraySize
;
71 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
73 const struct d3d_texture3d
*texture
;
75 if (!(texture
= unsafe_impl_from_ID3D11Texture3D((ID3D11Texture3D
*)resource
)))
77 ERR("Cannot get implementation from ID3D11Texture3D.\n");
81 *format
= texture
->desc
.Format
;
83 *miplevel_count
= texture
->desc
.MipLevels
;
84 *layer_count
= texture
->desc
.Depth
;
89 WARN("Invalid resource dimension %#x.\n", *dimension
);
96 static HRESULT
set_dsv_desc_from_resource(D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
98 D3D11_RESOURCE_DIMENSION dimension
;
100 ID3D11Resource_GetType(resource
, &dimension
);
106 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
108 D3D11_TEXTURE1D_DESC texture_desc
;
109 ID3D11Texture1D
*texture
;
111 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
)))
113 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
117 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
118 ID3D11Texture1D_Release(texture
);
120 desc
->Format
= texture_desc
.Format
;
121 if (texture_desc
.ArraySize
== 1)
123 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE1D
;
124 desc
->u
.Texture1D
.MipSlice
= 0;
128 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE1DARRAY
;
129 desc
->u
.Texture1DArray
.MipSlice
= 0;
130 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
131 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
137 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
139 D3D11_TEXTURE2D_DESC texture_desc
;
140 ID3D11Texture2D
*texture
;
142 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
144 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
148 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
149 ID3D11Texture2D_Release(texture
);
151 desc
->Format
= texture_desc
.Format
;
152 if (texture_desc
.ArraySize
== 1)
154 if (texture_desc
.SampleDesc
.Count
== 1)
156 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2D
;
157 desc
->u
.Texture2D
.MipSlice
= 0;
161 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DMS
;
166 if (texture_desc
.SampleDesc
.Count
== 1)
168 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DARRAY
;
169 desc
->u
.Texture2DArray
.MipSlice
= 0;
170 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
171 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
175 desc
->ViewDimension
= D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
;
176 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
177 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
184 case D3D11_RESOURCE_DIMENSION_BUFFER
:
185 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
187 WARN("Invalid resource dimension %#x.\n", dimension
);
192 static HRESULT
normalize_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
194 D3D11_RESOURCE_DIMENSION dimension
;
195 unsigned int layer_count
;
199 if (FAILED(hr
= get_resource_properties(resource
, &dimension
, &format
, NULL
, &layer_count
)))
203 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
204 if (desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE1D
205 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE1DARRAY
)
207 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
212 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
213 if (desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2D
214 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DARRAY
215 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DMS
216 && desc
->ViewDimension
!= D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
)
218 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
223 case D3D11_RESOURCE_DIMENSION_BUFFER
:
224 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
226 WARN("Invalid resource dimension %#x.\n", dimension
);
230 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
231 desc
->Format
= format
;
233 switch (desc
->ViewDimension
)
235 case D3D11_DSV_DIMENSION_TEXTURE1DARRAY
:
236 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
237 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
240 case D3D11_DSV_DIMENSION_TEXTURE2DARRAY
:
241 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
242 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
245 case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
:
246 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
247 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
257 static HRESULT
set_rtv_desc_from_resource(D3D11_RENDER_TARGET_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
259 D3D11_RESOURCE_DIMENSION dimension
;
262 ID3D11Resource_GetType(resource
, &dimension
);
266 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
268 ID3D11Texture1D
*texture
;
269 D3D11_TEXTURE1D_DESC texture_desc
;
271 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
);
274 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D?\n");
278 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
279 ID3D11Texture1D_Release(texture
);
281 desc
->Format
= texture_desc
.Format
;
282 if (texture_desc
.ArraySize
== 1)
284 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE1D
;
285 desc
->u
.Texture1D
.MipSlice
= 0;
289 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE1DARRAY
;
290 desc
->u
.Texture1DArray
.MipSlice
= 0;
291 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
292 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
298 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
300 ID3D11Texture2D
*texture
;
301 D3D11_TEXTURE2D_DESC texture_desc
;
303 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
);
306 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D?\n");
310 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
311 ID3D11Texture2D_Release(texture
);
313 desc
->Format
= texture_desc
.Format
;
314 if (texture_desc
.ArraySize
== 1)
316 if (texture_desc
.SampleDesc
.Count
== 1)
318 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2D
;
319 desc
->u
.Texture2D
.MipSlice
= 0;
323 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DMS
;
328 if (texture_desc
.SampleDesc
.Count
== 1)
330 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DARRAY
;
331 desc
->u
.Texture2DArray
.MipSlice
= 0;
332 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
333 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
337 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
;
338 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
339 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
346 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
348 ID3D11Texture3D
*texture
;
349 D3D11_TEXTURE3D_DESC texture_desc
;
351 hr
= ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
);
354 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D?\n");
358 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
359 ID3D11Texture3D_Release(texture
);
361 desc
->Format
= texture_desc
.Format
;
362 desc
->ViewDimension
= D3D11_RTV_DIMENSION_TEXTURE3D
;
363 desc
->u
.Texture3D
.MipSlice
= 0;
364 desc
->u
.Texture3D
.FirstWSlice
= 0;
365 desc
->u
.Texture3D
.WSize
= texture_desc
.Depth
;
371 FIXME("Unhandled resource dimension %#x.\n", dimension
);
376 static HRESULT
normalize_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
378 D3D11_RESOURCE_DIMENSION dimension
;
379 unsigned int layer_count
;
383 if (FAILED(hr
= get_resource_properties(resource
, &dimension
, &format
, NULL
, &layer_count
)))
387 case D3D11_RESOURCE_DIMENSION_BUFFER
:
388 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_BUFFER
)
390 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
395 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
396 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE1D
397 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE1DARRAY
)
399 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
404 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
405 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2D
406 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DARRAY
407 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DMS
408 && desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
)
410 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
415 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
416 if (desc
->ViewDimension
!= D3D11_RTV_DIMENSION_TEXTURE3D
)
418 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
424 WARN("Invalid resource dimension %#x.\n", dimension
);
428 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
429 desc
->Format
= format
;
431 switch (desc
->ViewDimension
)
433 case D3D11_RTV_DIMENSION_TEXTURE1DARRAY
:
434 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
435 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
438 case D3D11_RTV_DIMENSION_TEXTURE2DARRAY
:
439 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
440 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
443 case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
:
444 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
445 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
448 case D3D11_RTV_DIMENSION_TEXTURE3D
:
449 layer_count
= max(1, layer_count
>> desc
->u
.Texture3D
.MipSlice
);
450 if (desc
->u
.Texture3D
.WSize
== ~0u && desc
->u
.Texture3D
.FirstWSlice
< layer_count
)
451 desc
->u
.Texture3D
.WSize
= layer_count
- desc
->u
.Texture3D
.FirstWSlice
;
461 static HRESULT
set_srv_desc_from_resource(D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
463 D3D11_RESOURCE_DIMENSION dimension
;
465 ID3D11Resource_GetType(resource
, &dimension
);
469 case D3D11_RESOURCE_DIMENSION_BUFFER
:
471 D3D11_BUFFER_DESC buffer_desc
;
472 ID3D11Buffer
*buffer
;
474 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Buffer
, (void **)&buffer
)))
476 ERR("Resource of type BUFFER doesn't implement ID3D11Buffer.\n");
480 ID3D11Buffer_GetDesc(buffer
, &buffer_desc
);
481 ID3D11Buffer_Release(buffer
);
483 if (buffer_desc
.MiscFlags
& D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
)
485 desc
->Format
= DXGI_FORMAT_UNKNOWN
;
486 desc
->ViewDimension
= D3D11_SRV_DIMENSION_BUFFER
;
487 desc
->u
.Buffer
.u1
.FirstElement
= 0;
488 desc
->u
.Buffer
.u2
.NumElements
= buffer_desc
.ByteWidth
/ buffer_desc
.StructureByteStride
;
495 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
497 D3D11_TEXTURE1D_DESC texture_desc
;
498 ID3D11Texture1D
*texture
;
500 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture1D
, (void **)&texture
)))
502 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
506 ID3D11Texture1D_GetDesc(texture
, &texture_desc
);
507 ID3D11Texture1D_Release(texture
);
509 desc
->Format
= texture_desc
.Format
;
510 if (texture_desc
.ArraySize
== 1)
512 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE1D
;
513 desc
->u
.Texture1D
.MostDetailedMip
= 0;
514 desc
->u
.Texture1D
.MipLevels
= texture_desc
.MipLevels
;
518 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE1DARRAY
;
519 desc
->u
.Texture1DArray
.MostDetailedMip
= 0;
520 desc
->u
.Texture1DArray
.MipLevels
= texture_desc
.MipLevels
;
521 desc
->u
.Texture1DArray
.FirstArraySlice
= 0;
522 desc
->u
.Texture1DArray
.ArraySize
= texture_desc
.ArraySize
;
528 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
530 D3D11_TEXTURE2D_DESC texture_desc
;
531 ID3D11Texture2D
*texture
;
533 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
535 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
539 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
540 ID3D11Texture2D_Release(texture
);
542 desc
->Format
= texture_desc
.Format
;
543 if (texture_desc
.MiscFlags
& D3D11_RESOURCE_MISC_TEXTURECUBE
)
545 if (texture_desc
.ArraySize
>= 12)
547 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
;
548 desc
->u
.TextureCubeArray
.MostDetailedMip
= 0;
549 desc
->u
.TextureCubeArray
.MipLevels
= texture_desc
.MipLevels
;
550 desc
->u
.TextureCubeArray
.First2DArrayFace
= 0;
551 desc
->u
.TextureCubeArray
.NumCubes
= texture_desc
.ArraySize
/ 6;
555 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURECUBE
;
556 desc
->u
.TextureCube
.MostDetailedMip
= 0;
557 desc
->u
.TextureCube
.MipLevels
= texture_desc
.MipLevels
;
560 else if (texture_desc
.ArraySize
== 1)
562 if (texture_desc
.SampleDesc
.Count
== 1)
564 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2D
;
565 desc
->u
.Texture2D
.MostDetailedMip
= 0;
566 desc
->u
.Texture2D
.MipLevels
= texture_desc
.MipLevels
;
570 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DMS
;
575 if (texture_desc
.SampleDesc
.Count
== 1)
577 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DARRAY
;
578 desc
->u
.Texture2DArray
.MostDetailedMip
= 0;
579 desc
->u
.Texture2DArray
.MipLevels
= texture_desc
.MipLevels
;
580 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
581 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
585 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
;
586 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
587 desc
->u
.Texture2DMSArray
.ArraySize
= texture_desc
.ArraySize
;
594 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
596 D3D11_TEXTURE3D_DESC texture_desc
;
597 ID3D11Texture3D
*texture
;
599 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
)))
601 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D.\n");
605 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
606 ID3D11Texture3D_Release(texture
);
608 desc
->Format
= texture_desc
.Format
;
609 desc
->ViewDimension
= D3D11_SRV_DIMENSION_TEXTURE3D
;
610 desc
->u
.Texture3D
.MostDetailedMip
= 0;
611 desc
->u
.Texture3D
.MipLevels
= texture_desc
.MipLevels
;
617 WARN("Invalid resource dimension %#x.\n", dimension
);
622 static HRESULT
normalize_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
624 unsigned int miplevel_count
, layer_count
;
625 D3D11_RESOURCE_DIMENSION dimension
;
629 if (FAILED(hr
= get_resource_properties(resource
, &dimension
, &format
, &miplevel_count
, &layer_count
)))
633 case D3D11_RESOURCE_DIMENSION_BUFFER
:
634 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_BUFFER
635 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_BUFFEREX
)
637 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
640 if (!desc
->u
.Buffer
.u2
.NumElements
)
642 WARN("Zero sized buffer view.\n");
647 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
648 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE1D
649 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE1DARRAY
)
651 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
656 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
657 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2D
658 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DARRAY
659 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DMS
660 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
661 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURECUBE
662 && desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
)
664 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
669 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
670 if (desc
->ViewDimension
!= D3D11_SRV_DIMENSION_TEXTURE3D
)
672 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
678 WARN("Invalid resource dimension %#x.\n", dimension
);
682 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
683 desc
->Format
= format
;
685 switch (desc
->ViewDimension
)
687 case D3D11_SRV_DIMENSION_TEXTURE1D
:
688 if (desc
->u
.Texture1D
.MipLevels
== ~0u && desc
->u
.Texture1D
.MostDetailedMip
< miplevel_count
)
689 desc
->u
.Texture1D
.MipLevels
= miplevel_count
- desc
->u
.Texture1D
.MostDetailedMip
;
692 case D3D11_SRV_DIMENSION_TEXTURE1DARRAY
:
693 if (desc
->u
.Texture1DArray
.MipLevels
== ~0u && desc
->u
.Texture1DArray
.MostDetailedMip
< miplevel_count
)
694 desc
->u
.Texture1DArray
.MipLevels
= miplevel_count
- desc
->u
.Texture1DArray
.MostDetailedMip
;
695 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< miplevel_count
)
696 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
699 case D3D11_SRV_DIMENSION_TEXTURE2D
:
700 if (desc
->u
.Texture2D
.MipLevels
== ~0u && desc
->u
.Texture2D
.MostDetailedMip
< miplevel_count
)
701 desc
->u
.Texture2D
.MipLevels
= miplevel_count
- desc
->u
.Texture2D
.MostDetailedMip
;
704 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY
:
705 if (desc
->u
.Texture2DArray
.MipLevels
== ~0u && desc
->u
.Texture2DArray
.MostDetailedMip
< miplevel_count
)
706 desc
->u
.Texture2DArray
.MipLevels
= miplevel_count
- desc
->u
.Texture2DArray
.MostDetailedMip
;
707 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
708 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
711 case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
:
712 if (desc
->u
.Texture2DMSArray
.ArraySize
== ~0u && desc
->u
.Texture2DMSArray
.FirstArraySlice
< layer_count
)
713 desc
->u
.Texture2DMSArray
.ArraySize
= layer_count
- desc
->u
.Texture2DMSArray
.FirstArraySlice
;
716 case D3D11_SRV_DIMENSION_TEXTURE3D
:
717 if (desc
->u
.Texture3D
.MipLevels
== ~0u && desc
->u
.Texture3D
.MostDetailedMip
< miplevel_count
)
718 desc
->u
.Texture3D
.MipLevels
= miplevel_count
- desc
->u
.Texture3D
.MostDetailedMip
;
721 case D3D11_SRV_DIMENSION_TEXTURECUBE
:
722 if (desc
->u
.TextureCube
.MipLevels
== ~0u && desc
->u
.TextureCube
.MostDetailedMip
< miplevel_count
)
723 desc
->u
.TextureCube
.MipLevels
= miplevel_count
- desc
->u
.TextureCube
.MostDetailedMip
;
726 case D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
:
727 if (desc
->u
.TextureCubeArray
.MipLevels
== ~0u && desc
->u
.TextureCubeArray
.MostDetailedMip
< miplevel_count
)
728 desc
->u
.TextureCubeArray
.MipLevels
= miplevel_count
- desc
->u
.TextureCubeArray
.MostDetailedMip
;
729 if (desc
->u
.TextureCubeArray
.NumCubes
== ~0u && desc
->u
.TextureCubeArray
.First2DArrayFace
< layer_count
)
730 desc
->u
.TextureCubeArray
.NumCubes
= (layer_count
- desc
->u
.TextureCubeArray
.First2DArrayFace
) / 6;
740 static HRESULT
set_uav_desc_from_resource(D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
742 D3D11_RESOURCE_DIMENSION dimension
;
744 ID3D11Resource_GetType(resource
, &dimension
);
748 case D3D11_RESOURCE_DIMENSION_BUFFER
:
750 D3D11_BUFFER_DESC buffer_desc
;
751 ID3D11Buffer
*buffer
;
753 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Buffer
, (void **)&buffer
)))
755 ERR("Resource of type BUFFER doesn't implement ID3D11Buffer.\n");
759 ID3D11Buffer_GetDesc(buffer
, &buffer_desc
);
760 ID3D11Buffer_Release(buffer
);
762 if (buffer_desc
.MiscFlags
& D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
)
764 desc
->Format
= DXGI_FORMAT_UNKNOWN
;
765 desc
->ViewDimension
= D3D11_UAV_DIMENSION_BUFFER
;
766 desc
->u
.Buffer
.FirstElement
= 0;
767 desc
->u
.Buffer
.NumElements
= buffer_desc
.ByteWidth
/ buffer_desc
.StructureByteStride
;
768 desc
->u
.Buffer
.Flags
= 0;
775 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
777 D3D11_TEXTURE2D_DESC texture_desc
;
778 ID3D11Texture2D
*texture
;
780 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture2D
, (void **)&texture
)))
782 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
786 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
787 ID3D11Texture2D_Release(texture
);
789 if (texture_desc
.SampleDesc
.Count
!= 1)
791 WARN("Trying to create view for multisample texture.\n");
795 desc
->Format
= texture_desc
.Format
;
796 if (texture_desc
.ArraySize
== 1)
798 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE2D
;
799 desc
->u
.Texture2D
.MipSlice
= 0;
803 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE2DARRAY
;
804 desc
->u
.Texture2DArray
.MipSlice
= 0;
805 desc
->u
.Texture2DArray
.FirstArraySlice
= 0;
806 desc
->u
.Texture2DArray
.ArraySize
= texture_desc
.ArraySize
;
812 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
814 D3D11_TEXTURE3D_DESC texture_desc
;
815 ID3D11Texture3D
*texture
;
817 if (FAILED(ID3D11Resource_QueryInterface(resource
, &IID_ID3D11Texture3D
, (void **)&texture
)))
819 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D.\n");
823 ID3D11Texture3D_GetDesc(texture
, &texture_desc
);
824 ID3D11Texture3D_Release(texture
);
826 desc
->Format
= texture_desc
.Format
;
827 desc
->ViewDimension
= D3D11_UAV_DIMENSION_TEXTURE3D
;
828 desc
->u
.Texture3D
.MipSlice
= 0;
829 desc
->u
.Texture3D
.FirstWSlice
= 0;
830 desc
->u
.Texture3D
.WSize
= texture_desc
.Depth
;
836 FIXME("Unhandled resource dimension %#x.\n", dimension
);
841 static HRESULT
normalize_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC
*desc
, ID3D11Resource
*resource
)
843 D3D11_RESOURCE_DIMENSION dimension
;
844 unsigned int layer_count
;
848 if (FAILED(hr
= get_resource_properties(resource
, &dimension
, &format
, NULL
, &layer_count
)))
852 case D3D11_RESOURCE_DIMENSION_BUFFER
:
853 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_BUFFER
)
855 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
860 case D3D11_RESOURCE_DIMENSION_TEXTURE1D
:
861 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE1D
862 && desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE1DARRAY
)
864 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
869 case D3D11_RESOURCE_DIMENSION_TEXTURE2D
:
870 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE2D
871 && desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE2DARRAY
)
873 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
878 case D3D11_RESOURCE_DIMENSION_TEXTURE3D
:
879 if (desc
->ViewDimension
!= D3D11_UAV_DIMENSION_TEXTURE3D
)
881 WARN("Incompatible dimensions %#x, %#x.\n", dimension
, desc
->ViewDimension
);
887 WARN("Invalid resource dimension %#x.\n", dimension
);
891 if (desc
->Format
== DXGI_FORMAT_UNKNOWN
)
892 desc
->Format
= format
;
894 switch (desc
->ViewDimension
)
896 case D3D11_UAV_DIMENSION_TEXTURE1DARRAY
:
897 if (desc
->u
.Texture1DArray
.ArraySize
== ~0u && desc
->u
.Texture1DArray
.FirstArraySlice
< layer_count
)
898 desc
->u
.Texture1DArray
.ArraySize
= layer_count
- desc
->u
.Texture1DArray
.FirstArraySlice
;
901 case D3D11_UAV_DIMENSION_TEXTURE2DARRAY
:
902 if (desc
->u
.Texture2DArray
.ArraySize
== ~0u && desc
->u
.Texture2DArray
.FirstArraySlice
< layer_count
)
903 desc
->u
.Texture2DArray
.ArraySize
= layer_count
- desc
->u
.Texture2DArray
.FirstArraySlice
;
906 case D3D11_UAV_DIMENSION_TEXTURE3D
:
907 layer_count
= max(1, layer_count
>> desc
->u
.Texture3D
.MipSlice
);
908 if (desc
->u
.Texture3D
.WSize
== ~0u && desc
->u
.Texture3D
.FirstWSlice
< layer_count
)
909 desc
->u
.Texture3D
.WSize
= layer_count
- desc
->u
.Texture3D
.FirstWSlice
;
919 /* ID3D11DepthStencilView methods */
921 static inline struct d3d_depthstencil_view
*impl_from_ID3D11DepthStencilView(ID3D11DepthStencilView
*iface
)
923 return CONTAINING_RECORD(iface
, struct d3d_depthstencil_view
, ID3D11DepthStencilView_iface
);
926 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_QueryInterface(ID3D11DepthStencilView
*iface
,
927 REFIID riid
, void **object
)
929 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
931 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
933 if (IsEqualGUID(riid
, &IID_ID3D11DepthStencilView
)
934 || IsEqualGUID(riid
, &IID_ID3D11View
)
935 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
936 || IsEqualGUID(riid
, &IID_IUnknown
))
938 ID3D11DepthStencilView_AddRef(iface
);
943 if (IsEqualGUID(riid
, &IID_ID3D10DepthStencilView
)
944 || IsEqualGUID(riid
, &IID_ID3D10View
)
945 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
947 ID3D10DepthStencilView_AddRef(&view
->ID3D10DepthStencilView_iface
);
948 *object
= &view
->ID3D10DepthStencilView_iface
;
952 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
955 return E_NOINTERFACE
;
958 static ULONG STDMETHODCALLTYPE
d3d11_depthstencil_view_AddRef(ID3D11DepthStencilView
*iface
)
960 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
961 ULONG refcount
= InterlockedIncrement(&view
->refcount
);
963 TRACE("%p increasing refcount to %u.\n", view
, refcount
);
967 ID3D11Device2_AddRef(view
->device
);
968 wined3d_mutex_lock();
969 wined3d_rendertarget_view_incref(view
->wined3d_view
);
970 wined3d_mutex_unlock();
976 static ULONG STDMETHODCALLTYPE
d3d11_depthstencil_view_Release(ID3D11DepthStencilView
*iface
)
978 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
979 ULONG refcount
= InterlockedDecrement(&view
->refcount
);
981 TRACE("%p decreasing refcount to %u.\n", view
, refcount
);
985 ID3D11Device2
*device
= view
->device
;
987 wined3d_mutex_lock();
988 wined3d_rendertarget_view_decref(view
->wined3d_view
);
989 wined3d_mutex_unlock();
991 ID3D11Device2_Release(device
);
997 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetDevice(ID3D11DepthStencilView
*iface
,
998 ID3D11Device
**device
)
1000 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1002 TRACE("iface %p, device %p.\n", iface
, device
);
1004 *device
= (ID3D11Device
*)view
->device
;
1005 ID3D11Device_AddRef(*device
);
1008 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_GetPrivateData(ID3D11DepthStencilView
*iface
,
1009 REFGUID guid
, UINT
*data_size
, void *data
)
1011 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1013 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1015 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1018 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_SetPrivateData(ID3D11DepthStencilView
*iface
,
1019 REFGUID guid
, UINT data_size
, const void *data
)
1021 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1023 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
1025 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1028 static HRESULT STDMETHODCALLTYPE
d3d11_depthstencil_view_SetPrivateDataInterface(ID3D11DepthStencilView
*iface
,
1029 REFGUID guid
, const IUnknown
*data
)
1031 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1033 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1035 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1038 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetResource(ID3D11DepthStencilView
*iface
,
1039 ID3D11Resource
**resource
)
1041 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1043 TRACE("iface %p, resource %p.\n", iface
, resource
);
1045 *resource
= view
->resource
;
1046 ID3D11Resource_AddRef(*resource
);
1049 static void STDMETHODCALLTYPE
d3d11_depthstencil_view_GetDesc(ID3D11DepthStencilView
*iface
,
1050 D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
1052 struct d3d_depthstencil_view
*view
= impl_from_ID3D11DepthStencilView(iface
);
1054 TRACE("iface %p, desc %p.\n", iface
, desc
);
1059 static const struct ID3D11DepthStencilViewVtbl d3d11_depthstencil_view_vtbl
=
1061 /* IUnknown methods */
1062 d3d11_depthstencil_view_QueryInterface
,
1063 d3d11_depthstencil_view_AddRef
,
1064 d3d11_depthstencil_view_Release
,
1065 /* ID3D11DeviceChild methods */
1066 d3d11_depthstencil_view_GetDevice
,
1067 d3d11_depthstencil_view_GetPrivateData
,
1068 d3d11_depthstencil_view_SetPrivateData
,
1069 d3d11_depthstencil_view_SetPrivateDataInterface
,
1070 /* ID3D11View methods */
1071 d3d11_depthstencil_view_GetResource
,
1072 /* ID3D11DepthStencilView methods */
1073 d3d11_depthstencil_view_GetDesc
,
1076 /* ID3D10DepthStencilView methods */
1078 static inline struct d3d_depthstencil_view
*impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView
*iface
)
1080 return CONTAINING_RECORD(iface
, struct d3d_depthstencil_view
, ID3D10DepthStencilView_iface
);
1083 /* IUnknown methods */
1085 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView
*iface
,
1086 REFIID riid
, void **object
)
1088 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1090 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1092 return d3d11_depthstencil_view_QueryInterface(&view
->ID3D11DepthStencilView_iface
, riid
, object
);
1095 static ULONG STDMETHODCALLTYPE
d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView
*iface
)
1097 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1099 TRACE("iface %p.\n", iface
);
1101 return d3d11_depthstencil_view_AddRef(&view
->ID3D11DepthStencilView_iface
);
1104 static ULONG STDMETHODCALLTYPE
d3d10_depthstencil_view_Release(ID3D10DepthStencilView
*iface
)
1106 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1108 TRACE("iface %p.\n", iface
);
1110 return d3d11_depthstencil_view_Release(&view
->ID3D11DepthStencilView_iface
);
1113 /* ID3D10DeviceChild methods */
1115 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView
*iface
, ID3D10Device
**device
)
1117 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1119 TRACE("iface %p, device %p.\n", iface
, device
);
1121 ID3D11Device2_QueryInterface(view
->device
, &IID_ID3D10Device
, (void **)device
);
1124 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView
*iface
,
1125 REFGUID guid
, UINT
*data_size
, void *data
)
1127 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1129 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1130 iface
, debugstr_guid(guid
), data_size
, data
);
1132 return d3d_get_private_data(&view
->private_store
, guid
, data_size
, data
);
1135 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView
*iface
,
1136 REFGUID guid
, UINT data_size
, const void *data
)
1138 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1140 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1141 iface
, debugstr_guid(guid
), data_size
, data
);
1143 return d3d_set_private_data(&view
->private_store
, guid
, data_size
, data
);
1146 static HRESULT STDMETHODCALLTYPE
d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView
*iface
,
1147 REFGUID guid
, const IUnknown
*data
)
1149 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1151 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
1153 return d3d_set_private_data_interface(&view
->private_store
, guid
, data
);
1156 /* ID3D10View methods */
1158 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView
*iface
,
1159 ID3D10Resource
**resource
)
1161 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1163 TRACE("iface %p, resource %p.\n", iface
, resource
);
1165 ID3D11Resource_QueryInterface(view
->resource
, &IID_ID3D10Resource
, (void **)resource
);
1168 /* ID3D10DepthStencilView methods */
1170 static void STDMETHODCALLTYPE
d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView
*iface
,
1171 D3D10_DEPTH_STENCIL_VIEW_DESC
*desc
)
1173 struct d3d_depthstencil_view
*view
= impl_from_ID3D10DepthStencilView(iface
);
1174 const D3D11_DEPTH_STENCIL_VIEW_DESC
*d3d11_desc
= &view
->desc
;
1176 TRACE("iface %p, desc %p.\n", iface
, desc
);
1178 desc
->Format
= d3d11_desc
->Format
;
1179 desc
->ViewDimension
= (D3D10_DSV_DIMENSION
)d3d11_desc
->ViewDimension
;
1180 memcpy(&desc
->u
, &d3d11_desc
->u
, sizeof(desc
->u
));
1183 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl
=
1185 /* IUnknown methods */
1186 d3d10_depthstencil_view_QueryInterface
,
1187 d3d10_depthstencil_view_AddRef
,
1188 d3d10_depthstencil_view_Release
,
1189 /* ID3D10DeviceChild methods */
1190 d3d10_depthstencil_view_GetDevice
,
1191 d3d10_depthstencil_view_GetPrivateData
,
1192 d3d10_depthstencil_view_SetPrivateData
,
1193 d3d10_depthstencil_view_SetPrivateDataInterface
,
1194 /* ID3D10View methods */
1195 d3d10_depthstencil_view_GetResource
,
1196 /* ID3D10DepthStencilView methods */
1197 d3d10_depthstencil_view_GetDesc
,
1200 static void STDMETHODCALLTYPE
d3d_depth_stencil_view_wined3d_object_destroyed(void *parent
)
1202 struct d3d_depthstencil_view
*view
= parent
;
1204 wined3d_private_store_cleanup(&view
->private_store
);
1208 static const struct wined3d_parent_ops d3d_depth_stencil_view_wined3d_parent_ops
=
1210 d3d_depth_stencil_view_wined3d_object_destroyed
,
1213 static void wined3d_depth_stencil_view_desc_from_d3d11(struct wined3d_view_desc
*wined3d_desc
,
1214 const D3D11_DEPTH_STENCIL_VIEW_DESC
*desc
)
1216 wined3d_desc
->format_id
= wined3dformat_from_dxgi_format(desc
->Format
);
1219 FIXME("Unhandled depth stencil view flags %#x.\n", desc
->Flags
);
1221 wined3d_desc
->flags
= 0;
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
);