Diligent Engine API Reference: D:/GitHub/DiligentEngine/DiligentCore/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h Source File

Diligent Engine API Reference

D3D11TypeConversions.h
1 /* Copyright 2015-2018 Egor Yusov
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12 *
13 * In no event and under no legal theory, whether in tort (including negligence),
14 * contract, or otherwise, unless required by applicable law (such as deliberate
15 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16 * liable for any damages, including any direct, indirect, special, incidental,
17 * or consequential damages of any character arising as a result of this License or
18 * out of the use or inability to use the software (including but not limited to damages
19 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20 * all other commercial damages or losses), even if such Contributor has been advised
21 * of the possibility of such damages.
22 */
23
24 #pragma once
25
28
29 #include "GraphicsTypes.h"
30 #include "DXGITypeConversions.h"
31
32 namespace Diligent
33 {
34
35 inline UINT BindFlagsToD3D11BindFlags(Uint32 BindFlags)
36 {
37 UINT D3D11BindFlags = 0;
38 D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_VERTEX_BUFFER) ? D3D11_BIND_VERTEX_BUFFER : 0);
39 D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_INDEX_BUFFER) ? D3D11_BIND_INDEX_BUFFER : 0);
40 D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNIFORM_BUFFER) ? D3D11_BIND_CONSTANT_BUFFER : 0);
41 D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_SHADER_RESOURCE) ? D3D11_BIND_SHADER_RESOURCE : 0);
42 D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_STREAM_OUTPUT) ? D3D11_BIND_STREAM_OUTPUT : 0);
43 D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_RENDER_TARGET) ? D3D11_BIND_RENDER_TARGET : 0);
44 D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_DEPTH_STENCIL) ? D3D11_BIND_DEPTH_STENCIL : 0);
45 D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNORDERED_ACCESS) ? D3D11_BIND_UNORDERED_ACCESS : 0);
46 return D3D11BindFlags;
47 }
48
49 inline Uint32 D3D11BindFlagsToBindFlags(UINT D3D11BindFlags)
50 {
51 Uint32 BindFlags = 0;
52 BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_VERTEX_BUFFER) ? BIND_VERTEX_BUFFER : 0);
53 BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_INDEX_BUFFER) ? BIND_INDEX_BUFFER : 0);
54 BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_CONSTANT_BUFFER) ? BIND_UNIFORM_BUFFER : 0);
55 BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_SHADER_RESOURCE) ? BIND_SHADER_RESOURCE : 0);
56 BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_STREAM_OUTPUT) ? BIND_STREAM_OUTPUT : 0);
57 BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_RENDER_TARGET) ? BIND_RENDER_TARGET : 0);
58 BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_DEPTH_STENCIL) ? BIND_DEPTH_STENCIL : 0);
59 BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_UNORDERED_ACCESS) ? BIND_UNORDERED_ACCESS : 0);
60 VERIFY_EXPR( (D3D11BindFlags &
61 (D3D11_BIND_VERTEX_BUFFER|D3D11_BIND_INDEX_BUFFER|D3D11_BIND_CONSTANT_BUFFER|
62 D3D11_BIND_SHADER_RESOURCE|D3D11_BIND_STREAM_OUTPUT|D3D11_BIND_RENDER_TARGET|
63 D3D11_BIND_DEPTH_STENCIL|D3D11_BIND_UNORDERED_ACCESS)) == BindFlagsToD3D11BindFlags(BindFlags));
64 return BindFlags;
65 }
66
67 D3D11_PRIMITIVE_TOPOLOGY TopologyToD3D11Topology(PRIMITIVE_TOPOLOGY Topology);
68
69 inline D3D11_USAGE UsageToD3D11Usage(USAGE Usage)
70 {
71 switch(Usage)
72 {
73 case USAGE_STATIC: return D3D11_USAGE_IMMUTABLE;
74 case USAGE_DEFAULT: return D3D11_USAGE_DEFAULT;
75 case USAGE_DYNAMIC: return D3D11_USAGE_DYNAMIC;
76 case USAGE_CPU_ACCESSIBLE: return D3D11_USAGE_STAGING;
77 default: UNEXPECTED("Unknow usage" ); return D3D11_USAGE_DEFAULT;
78 }
79 }
80
81 inline USAGE D3D11UsageToUsage(D3D11_USAGE D3D11Usage)
82 {
83 switch(D3D11Usage)
84 {
85 case D3D11_USAGE_IMMUTABLE: return USAGE_STATIC;
86 case D3D11_USAGE_DEFAULT: return USAGE_DEFAULT;
87 case D3D11_USAGE_DYNAMIC: return USAGE_DYNAMIC;
88 case D3D11_USAGE_STAGING: return USAGE_CPU_ACCESSIBLE;
89 default: UNEXPECTED("Unknow D3D11 usage" ); return USAGE_DEFAULT;
90 }
91 }
92
93 inline void MapParamsToD3D11MapParams(MAP_TYPE MapType, Uint32 MapFlags, D3D11_MAP &d3d11MapType, UINT d3d11MapFlags)
94 {
95 d3d11MapType = static_cast<D3D11_MAP>(0);
96 switch(MapType)
97 {
98 case MAP_READ:
99 d3d11MapType = D3D11_MAP_READ;
100 break;
101
102 case MAP_WRITE:
103 if(MapFlags & MAP_FLAG_DISCARD)
104 d3d11MapType = D3D11_MAP_WRITE_DISCARD;
105 else if(MapFlags & MAP_FLAG_DO_NOT_SYNCHRONIZE)
106 d3d11MapType = D3D11_MAP_WRITE_NO_OVERWRITE;
107 else
108 d3d11MapType = D3D11_MAP_WRITE;
109 break;
110
111 case MAP_READ_WRITE:
112 d3d11MapType = D3D11_MAP_READ_WRITE;
113 break;
114
115 default:
116 UNEXPECTED( "Unknown map type" );
117 }
118
119 d3d11MapFlags = 0;
120 d3d11MapFlags |= (MapFlags & MAP_FLAG_DO_NOT_WAIT) ? D3D11_MAP_FLAG_DO_NOT_WAIT : 0;
121 }
122
123 inline UINT MapFlagsToD3D11MapFlags(Uint32 MapFlags)
124 {
125 }
126
127 inline UINT CPUAccessFlagsToD3D11CPUAccessFlags(Uint32 Flags)
128 {
129 UINT D3D11CPUAccessFlags = 0;
130 D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_READ) ? D3D11_CPU_ACCESS_READ : 0;
131 D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_WRITE) ? D3D11_CPU_ACCESS_WRITE : 0;
132 return D3D11CPUAccessFlags;
133 }
134
135 inline Uint32 D3D11CPUAccessFlagsToCPUAccessFlags(UINT D3D11CPUAccessFlags)
136 {
137 Uint32 CPUAccessFlags = 0;
138 CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_READ) ? CPU_ACCESS_READ : 0;
139 CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) ? CPU_ACCESS_WRITE : 0;
140 VERIFY_EXPR(D3D11CPUAccessFlags == CPUAccessFlagsToD3D11CPUAccessFlags(CPUAccessFlags));
141 return CPUAccessFlags;
142 }
143
144 inline UINT MiscTextureFlagsToD3D11Flags(Uint32 Flags)
145 {
146 UINT D3D11MiscFlags = 0;
147 D3D11MiscFlags |= (Flags & MISC_TEXTURE_FLAG_GENERATE_MIPS) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0;
148 return D3D11MiscFlags;
149 }
150
151 inline Uint32 D3D11MiscFlagsToMiscTextureFlags(UINT D3D11MiscFlags)
152 {
153 Uint32 MiscFlags = 0;
154 MiscFlags |= (D3D11MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS) ? MISC_TEXTURE_FLAG_GENERATE_MIPS : 0;
155 return MiscFlags;
156 }
157
158 D3D11_FILTER FilterTypeToD3D11Filter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter);
159 D3D11_TEXTURE_ADDRESS_MODE TexAddressModeToD3D11AddressMode(TEXTURE_ADDRESS_MODE Mode);
160
161 D3D11_COMPARISON_FUNC ComparisonFuncToD3D11ComparisonFunc(COMPARISON_FUNCTION Func);
162 void DepthStencilStateDesc_To_D3D11_DEPTH_STENCIL_DESC(const DepthStencilStateDesc &DepthStencilDesc, D3D11_DEPTH_STENCIL_DESC &d3d11DSSDesc);
163 void RasterizerStateDesc_To_D3D11_RASTERIZER_DESC(const RasterizerStateDesc &RasterizerDesc, D3D11_RASTERIZER_DESC &d3d11RSDesc);
164 void BlendStateDesc_To_D3D11_BLEND_DESC(const BlendStateDesc &BSDesc, D3D11_BLEND_DESC &D3D11BSDesc);
165 void LayoutElements_To_D3D11_INPUT_ELEMENT_DESCs(const std::vector<LayoutElement, STDAllocatorRawMem<LayoutElement> > &LayoutElements,
166 std::vector<D3D11_INPUT_ELEMENT_DESC, STDAllocatorRawMem<D3D11_INPUT_ELEMENT_DESC> > &D3D11InputElements);
167
168 void TextureViewDesc_to_D3D11_SRV_DESC(const TextureViewDesc& TexViewDesc, D3D11_SHADER_RESOURCE_VIEW_DESC &D3D11SRVDesc, Uint32 SampleCount);
169 void TextureViewDesc_to_D3D11_RTV_DESC(const TextureViewDesc& TexViewDesc, D3D11_RENDER_TARGET_VIEW_DESC &D3D11RTVDesc, Uint32 SampleCount);
170 void TextureViewDesc_to_D3D11_DSV_DESC(const TextureViewDesc& TexViewDesc, D3D11_DEPTH_STENCIL_VIEW_DESC &D3D11DSVDesc, Uint32 SampleCount);
171 void TextureViewDesc_to_D3D11_UAV_DESC(const TextureViewDesc& TexViewDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC &D3D11UAVDesc);
172
173 void BufferViewDesc_to_D3D11_SRV_DESC(const BufferDesc &BuffDesc, const BufferViewDesc& SRVDesc, D3D11_SHADER_RESOURCE_VIEW_DESC &D3D11SRVDesc);
174 void BufferViewDesc_to_D3D11_UAV_DESC(const BufferDesc &BuffDesc, const BufferViewDesc& UAVDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC &D3D11UAVDesc);
175
176 }
Diligent::BIND_RENDER_TARGET
A texture can be bound as a render target.
Definition: GraphicsTypes.h:71
Diligent::PRIMITIVE_TOPOLOGY
PRIMITIVE_TOPOLOGY
Input primitive topology.
Definition: DeviceContext.h:56
Diligent::BIND_SHADER_RESOURCE
A buffer or a texture can be bound as a shader resource.
Definition: GraphicsTypes.h:68
Diligent
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Diligent::BIND_INDEX_BUFFER
A buffer can be bound as an index buffer.
Definition: GraphicsTypes.h:65
Diligent::TEXTURE_ADDRESS_MODE
TEXTURE_ADDRESS_MODE
Texture address mode.
Definition: GraphicsTypes.h:805
Diligent::MAP_FLAG_DISCARD
Previous contents of the resource will be undefined. This flag is only compatible with MAP_WRITE D3D...
Definition: GraphicsTypes.h:158
Diligent::BIND_VERTEX_BUFFER
A buffer can be bound as a vertex buffer.
Definition: GraphicsTypes.h:64
Diligent::CPU_ACCESS_READ
A resource can be mapped for reading.
Definition: GraphicsTypes.h:114
Diligent::BIND_DEPTH_STENCIL
A texture can be bound as a depth-stencil target.
Definition: GraphicsTypes.h:72
Diligent::USAGE_DEFAULT
A resource that requires read and write access by the GPU and can also be occasionally written by the...
Definition: GraphicsTypes.h:95
Diligent::MAP_FLAG_DO_NOT_SYNCHRONIZE
The system will not synchronize pending operations before mapping the buffer. It is responsibility of...
Definition: GraphicsTypes.h:164
Diligent::USAGE_STATIC
A resource that can only be read by the GPU. It cannot be written by the GPU, and cannot be accessed ...
Definition: GraphicsTypes.h:90
Diligent::MAP_FLAG_DO_NOT_WAIT
Specifies that map operation should not wait until previous command that using the same resource comp...
Definition: GraphicsTypes.h:153
Diligent::MAP_WRITE
Resource is mapped for writing. D3D11 counterpart: D3D11_MAP_WRITE. OpenGL counterpart: GL_MAP_WRIT...
Definition: GraphicsTypes.h:133
Diligent::USAGE_CPU_ACCESSIBLE
A resource that facilitates transferring data from GPU to CPU. D3D11 Counterpart: D3D11_USAGE_STAGI...
Definition: GraphicsTypes.h:103
Diligent::MAP_READ
Resource is mapped for reading. D3D11 counterpart: D3D11_MAP_READ. OpenGL counterpart: GL_MAP_READ_...
Definition: GraphicsTypes.h:129
Diligent::USAGE
USAGE
Resource usage.
Definition: GraphicsTypes.h:84
Diligent::MISC_TEXTURE_FLAG_GENERATE_MIPS
Allow automatic mipmap generation with ITextureView::GenerateMips()
Definition: GraphicsTypes.h:896
Diligent::BIND_UNORDERED_ACCESS
A buffer or a texture can be bound as an unordered access view.
Definition: GraphicsTypes.h:73
Diligent::BIND_STREAM_OUTPUT
A buffer can be bound as a target for stream output stage.
Definition: GraphicsTypes.h:70
Diligent::BIND_UNIFORM_BUFFER
A buffer can be bound as a uniform buffer.
Definition: GraphicsTypes.h:66
Diligent::FILTER_TYPE
FILTER_TYPE
Filter type.
Definition: GraphicsTypes.h:780
Diligent::CPU_ACCESS_WRITE
A resource can be mapped for writing.
Definition: GraphicsTypes.h:115
Diligent::COMPARISON_FUNCTION
COMPARISON_FUNCTION
Comparison function.
Definition: GraphicsTypes.h:847
Diligent::MAP_READ_WRITE
Resource is mapped for reading and writing. D3D11 counterpart: D3D11_MAP_READ_WRITE. OpenGL counterpart: GL_MAP_WRITE_BIT | GL_MAP_READ_BIT.
Definition: GraphicsTypes.h:137
Diligent::MAP_TYPE
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:125
Diligent::USAGE_DYNAMIC
A resource that can be read by the GPU and written at least once per frame by the CPU...
Definition: GraphicsTypes.h:99