shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2 | // |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 3 | // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // Renderer11.cpp: Implements a back-end specific class for the D3D11 renderer. |
| 9 | |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 10 | #include "libGLESv2/main.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 11 | #include "libGLESv2/utilities.h" |
daniel@transgaming.com | 18adad0 | 2012-11-28 21:04:03 +0000 | [diff] [blame] | 12 | #include "libGLESv2/Buffer.h" |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 13 | #include "libGLESv2/ProgramBinary.h" |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 14 | #include "libGLESv2/Framebuffer.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 15 | #include "libGLESv2/RenderBuffer.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 16 | #include "libGLESv2/renderer/Renderer11.h" |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 17 | #include "libGLESv2/renderer/RenderTarget11.h" |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 18 | #include "libGLESv2/renderer/renderer11_utils.h" |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 19 | #include "libGLESv2/renderer/ShaderExecutable11.h" |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 20 | #include "libGLESv2/renderer/SwapChain11.h" |
daniel@transgaming.com | a8aac67 | 2012-12-20 21:08:00 +0000 | [diff] [blame] | 21 | #include "libGLESv2/renderer/Image11.h" |
daniel@transgaming.com | 2c4d070 | 2012-12-20 21:08:51 +0000 | [diff] [blame] | 22 | #include "libGLESv2/renderer/VertexBuffer11.h" |
daniel@transgaming.com | 11c2af5 | 2012-12-20 21:10:01 +0000 | [diff] [blame] | 23 | #include "libGLESv2/renderer/IndexBuffer11.h" |
shannon.woods@transgaming.com | 4e52b63 | 2013-02-28 23:08:01 +0000 | [diff] [blame] | 24 | #include "libGLESv2/renderer/BufferStorage11.h" |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 25 | #include "libGLESv2/renderer/VertexDataManager.h" |
| 26 | #include "libGLESv2/renderer/IndexDataManager.h" |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 27 | #include "libGLESv2/renderer/TextureStorage11.h" |
shannon.woods@transgaming.com | 8b7606a | 2013-02-28 23:03:47 +0000 | [diff] [blame] | 28 | #include "libGLESv2/renderer/Query11.h" |
shannon.woods@transgaming.com | be58aa0 | 2013-02-28 23:03:55 +0000 | [diff] [blame] | 29 | #include "libGLESv2/renderer/Fence11.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 30 | |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 31 | #include "libGLESv2/renderer/shaders/compiled/passthrough11vs.h" |
| 32 | #include "libGLESv2/renderer/shaders/compiled/passthroughrgba11ps.h" |
| 33 | #include "libGLESv2/renderer/shaders/compiled/passthroughrgb11ps.h" |
| 34 | #include "libGLESv2/renderer/shaders/compiled/passthroughlum11ps.h" |
| 35 | #include "libGLESv2/renderer/shaders/compiled/passthroughlumalpha11ps.h" |
| 36 | |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 37 | #include "libGLESv2/renderer/shaders/compiled/clear11vs.h" |
| 38 | #include "libGLESv2/renderer/shaders/compiled/clear11ps.h" |
| 39 | |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 40 | #include "libEGL/Display.h" |
| 41 | |
shannon.woods@transgaming.com | 236be77 | 2013-02-28 23:18:15 +0000 | [diff] [blame] | 42 | #ifdef _DEBUG |
| 43 | // this flag enables suppressing some spurious warnings that pop up in certain WebGL samples |
| 44 | // and conformance tests. to enable all warnings, remove this define. |
| 45 | #define ANGLE_SUPPRESS_D3D11_HAZARD_WARNINGS 1 |
| 46 | #endif |
| 47 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 48 | namespace rx |
| 49 | { |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 50 | static const DXGI_FORMAT RenderTargetFormats[] = |
| 51 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 52 | DXGI_FORMAT_B8G8R8A8_UNORM, |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 53 | DXGI_FORMAT_R8G8B8A8_UNORM |
| 54 | }; |
| 55 | |
| 56 | static const DXGI_FORMAT DepthStencilFormats[] = |
| 57 | { |
shannon.woods@transgaming.com | eec5c63 | 2013-02-28 23:04:21 +0000 | [diff] [blame] | 58 | DXGI_FORMAT_UNKNOWN, |
| 59 | DXGI_FORMAT_D24_UNORM_S8_UINT, |
| 60 | DXGI_FORMAT_D16_UNORM |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 61 | }; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 62 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 63 | enum |
| 64 | { |
| 65 | MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16 |
| 66 | }; |
| 67 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 68 | Renderer11::Renderer11(egl::Display *display, HDC hDc) : Renderer(display), mDc(hDc) |
| 69 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 70 | mVertexDataManager = NULL; |
| 71 | mIndexDataManager = NULL; |
| 72 | |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 73 | mLineLoopIB = NULL; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 74 | mTriangleFanIB = NULL; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 75 | |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 76 | mCopyResourcesInitialized = false; |
| 77 | mCopyVB = NULL; |
| 78 | mCopySampler = NULL; |
| 79 | mCopyIL = NULL; |
| 80 | mCopyVS = NULL; |
| 81 | mCopyRGBAPS = NULL; |
| 82 | mCopyRGBPS = NULL; |
| 83 | mCopyLumPS = NULL; |
| 84 | mCopyLumAlphaPS = NULL; |
| 85 | |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 86 | mClearResourcesInitialized = false; |
| 87 | mClearVB = NULL; |
| 88 | mClearIL = NULL; |
| 89 | mClearVS = NULL; |
| 90 | mClearPS = NULL; |
| 91 | mClearScissorRS = NULL; |
| 92 | mClearNoScissorRS = NULL; |
| 93 | |
daniel@transgaming.com | bdf787f | 2013-02-01 03:20:36 +0000 | [diff] [blame] | 94 | mSyncQuery = NULL; |
| 95 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 96 | mD3d11Module = NULL; |
| 97 | mDxgiModule = NULL; |
| 98 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 99 | mDeviceLost = false; |
| 100 | |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 101 | mMaxSupportedSamples = 0; |
| 102 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 103 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 104 | mDeviceContext = NULL; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 105 | mDxgiAdapter = NULL; |
| 106 | mDxgiFactory = NULL; |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 107 | |
| 108 | mDriverConstantBufferVS = NULL; |
| 109 | mDriverConstantBufferPS = NULL; |
shannon.woods@transgaming.com | bec04bf | 2013-01-25 21:53:52 +0000 | [diff] [blame] | 110 | |
| 111 | mBGRATextureSupport = false; |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 112 | |
| 113 | mIsGeometryShaderActive = false; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | Renderer11::~Renderer11() |
| 117 | { |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 118 | release(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 119 | } |
| 120 | |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 121 | Renderer11 *Renderer11::makeRenderer11(Renderer *renderer) |
| 122 | { |
apatrick@chromium.org | 8b400b1 | 2013-01-30 21:53:40 +0000 | [diff] [blame] | 123 | ASSERT(HAS_DYNAMIC_TYPE(rx::Renderer11*, renderer)); |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 124 | return static_cast<rx::Renderer11*>(renderer); |
| 125 | } |
| 126 | |
shannon.woods%transgaming.com@gtempaccount.com | f9686c2 | 2013-04-13 03:33:45 +0000 | [diff] [blame] | 127 | #ifndef __d3d11_1_h__ |
| 128 | #define D3D11_MESSAGE_ID_DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET ((D3D11_MESSAGE_ID)3146081) |
| 129 | #endif |
| 130 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 131 | EGLint Renderer11::initialize() |
| 132 | { |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 133 | if (!initializeCompiler()) |
| 134 | { |
| 135 | return EGL_NOT_INITIALIZED; |
| 136 | } |
| 137 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 138 | mDxgiModule = LoadLibrary(TEXT("dxgi.dll")); |
| 139 | mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 140 | |
| 141 | if (mD3d11Module == NULL || mDxgiModule == NULL) |
| 142 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 143 | ERR("Could not load D3D11 or DXGI library - aborting!\n"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 144 | return EGL_NOT_INITIALIZED; |
| 145 | } |
| 146 | |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 147 | // create the D3D11 device |
| 148 | ASSERT(mDevice == NULL); |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 149 | PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 150 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 151 | if (D3D11CreateDevice == NULL) |
| 152 | { |
| 153 | ERR("Could not retrieve D3D11CreateDevice address - aborting!\n"); |
| 154 | return EGL_NOT_INITIALIZED; |
| 155 | } |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 156 | |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 157 | D3D_FEATURE_LEVEL featureLevels[] = |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 158 | { |
| 159 | D3D_FEATURE_LEVEL_11_0, |
| 160 | D3D_FEATURE_LEVEL_10_1, |
| 161 | D3D_FEATURE_LEVEL_10_0, |
| 162 | }; |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 163 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 164 | HRESULT result = D3D11CreateDevice(NULL, |
| 165 | D3D_DRIVER_TYPE_HARDWARE, |
| 166 | NULL, |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 167 | #if defined(_DEBUG) |
| 168 | D3D11_CREATE_DEVICE_DEBUG, |
| 169 | #else |
| 170 | 0, |
| 171 | #endif |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 172 | featureLevels, |
| 173 | ArraySize(featureLevels), |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 174 | D3D11_SDK_VERSION, |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 175 | &mDevice, |
| 176 | &mFeatureLevel, |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 177 | &mDeviceContext); |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 178 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 179 | if (!mDevice || FAILED(result)) |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 180 | { |
| 181 | ERR("Could not create D3D11 device - aborting!\n"); |
| 182 | return EGL_NOT_INITIALIZED; // Cleanup done by destructor through glDestroyRenderer |
| 183 | } |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 184 | |
| 185 | IDXGIDevice *dxgiDevice = NULL; |
| 186 | result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); |
| 187 | |
| 188 | if (FAILED(result)) |
| 189 | { |
| 190 | ERR("Could not query DXGI device - aborting!\n"); |
| 191 | return EGL_NOT_INITIALIZED; |
| 192 | } |
| 193 | |
| 194 | result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&mDxgiAdapter); |
| 195 | |
| 196 | if (FAILED(result)) |
| 197 | { |
| 198 | ERR("Could not retrieve DXGI adapter - aborting!\n"); |
| 199 | return EGL_NOT_INITIALIZED; |
| 200 | } |
| 201 | |
| 202 | dxgiDevice->Release(); |
| 203 | |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 204 | mDxgiAdapter->GetDesc(&mAdapterDescription); |
| 205 | memset(mDescription, 0, sizeof(mDescription)); |
| 206 | wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1); |
| 207 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 208 | result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&mDxgiFactory); |
| 209 | |
| 210 | if (!mDxgiFactory || FAILED(result)) |
| 211 | { |
| 212 | ERR("Could not create DXGI factory - aborting!\n"); |
| 213 | return EGL_NOT_INITIALIZED; |
| 214 | } |
| 215 | |
shannon.woods@transgaming.com | 236be77 | 2013-02-28 23:18:15 +0000 | [diff] [blame] | 216 | // Disable some spurious D3D11 debug warnings to prevent them from flooding the output log |
| 217 | #if defined(ANGLE_SUPPRESS_D3D11_HAZARD_WARNINGS) && defined(_DEBUG) |
| 218 | ID3D11InfoQueue *infoQueue; |
| 219 | result = mDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void **)&infoQueue); |
| 220 | |
| 221 | if (SUCCEEDED(result)) |
| 222 | { |
| 223 | D3D11_MESSAGE_ID hideMessages[] = |
| 224 | { |
| 225 | D3D11_MESSAGE_ID_DEVICE_OMSETRENDERTARGETS_HAZARD, |
shannon.woods%transgaming.com@gtempaccount.com | f9686c2 | 2013-04-13 03:33:45 +0000 | [diff] [blame] | 226 | D3D11_MESSAGE_ID_DEVICE_PSSETSHADERRESOURCES_HAZARD, |
| 227 | D3D11_MESSAGE_ID_DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET |
shannon.woods@transgaming.com | 236be77 | 2013-02-28 23:18:15 +0000 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | D3D11_INFO_QUEUE_FILTER filter = {0}; |
| 231 | filter.DenyList.NumIDs = ArraySize(hideMessages); |
| 232 | filter.DenyList.pIDList = hideMessages; |
| 233 | |
| 234 | infoQueue->AddStorageFilterEntries(&filter); |
| 235 | |
| 236 | infoQueue->Release(); |
| 237 | } |
| 238 | #endif |
| 239 | |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 240 | unsigned int maxSupportedSamples = 0; |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 241 | unsigned int rtFormatCount = ArraySize(RenderTargetFormats); |
| 242 | unsigned int dsFormatCount = ArraySize(DepthStencilFormats); |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 243 | for (unsigned int i = 0; i < rtFormatCount + dsFormatCount; ++i) |
| 244 | { |
| 245 | DXGI_FORMAT format = (i < rtFormatCount) ? RenderTargetFormats[i] : DepthStencilFormats[i - rtFormatCount]; |
| 246 | if (format != DXGI_FORMAT_UNKNOWN) |
| 247 | { |
| 248 | UINT formatSupport; |
| 249 | result = mDevice->CheckFormatSupport(format, &formatSupport); |
| 250 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET)) |
| 251 | { |
| 252 | MultisampleSupportInfo supportInfo; |
| 253 | |
| 254 | for (unsigned int j = 1; j <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; j++) |
| 255 | { |
| 256 | result = mDevice->CheckMultisampleQualityLevels(format, j, &supportInfo.qualityLevels[j - 1]); |
| 257 | if (SUCCEEDED(result) && supportInfo.qualityLevels[j - 1] > 0) |
| 258 | { |
| 259 | maxSupportedSamples = std::max(j, maxSupportedSamples); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | supportInfo.qualityLevels[j - 1] = 0; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | mMultisampleSupportMap.insert(std::make_pair(format, supportInfo)); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | mMaxSupportedSamples = maxSupportedSamples; |
| 272 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 273 | initializeDevice(); |
| 274 | |
shannon.woods@transgaming.com | bec04bf | 2013-01-25 21:53:52 +0000 | [diff] [blame] | 275 | // BGRA texture support is optional in feature levels 10 and 10_1 |
| 276 | UINT formatSupport; |
| 277 | result = mDevice->CheckFormatSupport(DXGI_FORMAT_B8G8R8A8_UNORM, &formatSupport); |
| 278 | if (FAILED(result)) |
| 279 | { |
| 280 | ERR("Error checking BGRA format support: 0x%08X", result); |
| 281 | } |
| 282 | else |
| 283 | { |
| 284 | const int flags = (D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_RENDER_TARGET); |
| 285 | mBGRATextureSupport = (formatSupport & flags) == flags; |
| 286 | } |
| 287 | |
shannon.woods@transgaming.com | 9cdced6 | 2013-02-28 23:07:31 +0000 | [diff] [blame] | 288 | // Check floating point texture support |
| 289 | static const unsigned int requiredTextureFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURECUBE; |
| 290 | static const unsigned int requiredRenderableFlags = D3D11_FORMAT_SUPPORT_RENDER_TARGET; |
| 291 | static const unsigned int requiredFilterFlags = D3D11_FORMAT_SUPPORT_SHADER_SAMPLE; |
| 292 | |
| 293 | DXGI_FORMAT float16Formats[] = |
| 294 | { |
| 295 | DXGI_FORMAT_R16_FLOAT, |
| 296 | DXGI_FORMAT_R16G16_FLOAT, |
| 297 | DXGI_FORMAT_R16G16B16A16_FLOAT, |
| 298 | }; |
| 299 | |
| 300 | DXGI_FORMAT float32Formats[] = |
| 301 | { |
| 302 | DXGI_FORMAT_R32_FLOAT, |
| 303 | DXGI_FORMAT_R32G32_FLOAT, |
| 304 | DXGI_FORMAT_R32G32B32_FLOAT, |
| 305 | DXGI_FORMAT_R32G32B32A32_FLOAT, |
| 306 | }; |
| 307 | |
| 308 | mFloat16TextureSupport = true; |
| 309 | mFloat16FilterSupport = true; |
| 310 | mFloat16RenderSupport = true; |
| 311 | for (unsigned int i = 0; i < ArraySize(float16Formats); i++) |
| 312 | { |
| 313 | if (SUCCEEDED(mDevice->CheckFormatSupport(float16Formats[i], &formatSupport))) |
| 314 | { |
| 315 | mFloat16TextureSupport = mFloat16TextureSupport && (formatSupport & requiredTextureFlags) == requiredTextureFlags; |
| 316 | mFloat16FilterSupport = mFloat16FilterSupport && (formatSupport & requiredFilterFlags) == requiredFilterFlags; |
| 317 | mFloat16RenderSupport = mFloat16RenderSupport && (formatSupport & requiredRenderableFlags) == requiredRenderableFlags; |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | mFloat16TextureSupport = false; |
| 322 | mFloat16RenderSupport = false; |
| 323 | mFloat16FilterSupport = false; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | mFloat32TextureSupport = true; |
| 328 | mFloat32FilterSupport = true; |
| 329 | mFloat32RenderSupport = true; |
| 330 | for (unsigned int i = 0; i < ArraySize(float32Formats); i++) |
| 331 | { |
| 332 | if (SUCCEEDED(mDevice->CheckFormatSupport(float32Formats[i], &formatSupport))) |
| 333 | { |
| 334 | mFloat32TextureSupport = mFloat32TextureSupport && (formatSupport & requiredTextureFlags) == requiredTextureFlags; |
| 335 | mFloat32FilterSupport = mFloat32FilterSupport && (formatSupport & requiredFilterFlags) == requiredFilterFlags; |
| 336 | mFloat32RenderSupport = mFloat32RenderSupport && (formatSupport & requiredRenderableFlags) == requiredRenderableFlags; |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | mFloat32TextureSupport = false; |
| 341 | mFloat32FilterSupport = false; |
| 342 | mFloat32RenderSupport = false; |
| 343 | } |
| 344 | } |
| 345 | |
shannon.woods@transgaming.com | 09f326b | 2013-02-28 23:13:34 +0000 | [diff] [blame] | 346 | // Check compressed texture support |
| 347 | const unsigned int requiredCompressedTextureFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D; |
| 348 | |
| 349 | if (SUCCEEDED(mDevice->CheckFormatSupport(DXGI_FORMAT_BC1_UNORM, &formatSupport))) |
| 350 | { |
| 351 | mDXT1TextureSupport = (formatSupport & requiredCompressedTextureFlags) == requiredCompressedTextureFlags; |
| 352 | } |
| 353 | else |
| 354 | { |
| 355 | mDXT1TextureSupport = false; |
| 356 | } |
| 357 | |
| 358 | if (SUCCEEDED(mDevice->CheckFormatSupport(DXGI_FORMAT_BC3_UNORM, &formatSupport))) |
| 359 | { |
| 360 | mDXT3TextureSupport = (formatSupport & requiredCompressedTextureFlags) == requiredCompressedTextureFlags; |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | mDXT3TextureSupport = false; |
| 365 | } |
| 366 | |
| 367 | if (SUCCEEDED(mDevice->CheckFormatSupport(DXGI_FORMAT_BC5_UNORM, &formatSupport))) |
| 368 | { |
| 369 | mDXT5TextureSupport = (formatSupport & requiredCompressedTextureFlags) == requiredCompressedTextureFlags; |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | mDXT5TextureSupport = false; |
| 374 | } |
| 375 | |
shannon.woods@transgaming.com | cf103f3 | 2013-02-28 23:18:45 +0000 | [diff] [blame] | 376 | // Check depth texture support |
| 377 | DXGI_FORMAT depthTextureFormats[] = |
| 378 | { |
| 379 | DXGI_FORMAT_D16_UNORM, |
| 380 | DXGI_FORMAT_D24_UNORM_S8_UINT, |
| 381 | }; |
| 382 | |
| 383 | static const unsigned int requiredDepthTextureFlags = D3D11_FORMAT_SUPPORT_DEPTH_STENCIL | |
| 384 | D3D11_FORMAT_SUPPORT_TEXTURE2D; |
| 385 | |
| 386 | mDepthTextureSupport = true; |
| 387 | for (unsigned int i = 0; i < ArraySize(depthTextureFormats); i++) |
| 388 | { |
| 389 | if (SUCCEEDED(mDevice->CheckFormatSupport(depthTextureFormats[i], &formatSupport))) |
| 390 | { |
| 391 | mDepthTextureSupport = mDepthTextureSupport && ((formatSupport & requiredDepthTextureFlags) == requiredDepthTextureFlags); |
| 392 | } |
| 393 | else |
| 394 | { |
| 395 | mDepthTextureSupport = false; |
| 396 | } |
| 397 | } |
| 398 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 399 | return EGL_SUCCESS; |
| 400 | } |
| 401 | |
| 402 | // do any one-time device initialization |
| 403 | // NOTE: this is also needed after a device lost/reset |
| 404 | // to reset the scene status and ensure the default states are reset. |
| 405 | void Renderer11::initializeDevice() |
| 406 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 407 | mStateCache.initialize(mDevice); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 408 | mInputLayoutCache.initialize(mDevice, mDeviceContext); |
| 409 | |
| 410 | ASSERT(!mVertexDataManager && !mIndexDataManager); |
| 411 | mVertexDataManager = new VertexDataManager(this); |
| 412 | mIndexDataManager = new IndexDataManager(this); |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 413 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 414 | markAllStateDirty(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 415 | } |
| 416 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 417 | int Renderer11::generateConfigs(ConfigDesc **configDescList) |
| 418 | { |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 419 | unsigned int numRenderFormats = ArraySize(RenderTargetFormats); |
| 420 | unsigned int numDepthFormats = ArraySize(DepthStencilFormats); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 421 | (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; |
| 422 | int numConfigs = 0; |
| 423 | |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 424 | for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 425 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 426 | for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 427 | { |
| 428 | DXGI_FORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; |
| 429 | |
| 430 | UINT formatSupport = 0; |
| 431 | HRESULT result = mDevice->CheckFormatSupport(renderTargetFormat, &formatSupport); |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 432 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 433 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) |
| 434 | { |
| 435 | DXGI_FORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; |
| 436 | |
shannon.woods@transgaming.com | eec5c63 | 2013-02-28 23:04:21 +0000 | [diff] [blame] | 437 | bool depthStencilFormatOK = true; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 438 | |
shannon.woods@transgaming.com | eec5c63 | 2013-02-28 23:04:21 +0000 | [diff] [blame] | 439 | if (depthStencilFormat != DXGI_FORMAT_UNKNOWN) |
| 440 | { |
| 441 | UINT formatSupport = 0; |
| 442 | result = mDevice->CheckFormatSupport(depthStencilFormat, &formatSupport); |
| 443 | depthStencilFormatOK = SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL); |
| 444 | } |
| 445 | |
| 446 | if (depthStencilFormatOK) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 447 | { |
| 448 | ConfigDesc newConfig; |
| 449 | newConfig.renderTargetFormat = d3d11_gl::ConvertBackBufferFormat(renderTargetFormat); |
| 450 | newConfig.depthStencilFormat = d3d11_gl::ConvertDepthStencilFormat(depthStencilFormat); |
| 451 | newConfig.multiSample = 0; // FIXME: enumerate multi-sampling |
| 452 | newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast |
shannon.woods%transgaming.com@gtempaccount.com | dcf33d5 | 2013-04-13 03:33:11 +0000 | [diff] [blame] | 453 | newConfig.es3Capable = true; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 454 | |
| 455 | (*configDescList)[numConfigs++] = newConfig; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | return numConfigs; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void Renderer11::deleteConfigs(ConfigDesc *configDescList) |
| 465 | { |
| 466 | delete [] (configDescList); |
| 467 | } |
| 468 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 469 | void Renderer11::sync(bool block) |
| 470 | { |
daniel@transgaming.com | bdf787f | 2013-02-01 03:20:36 +0000 | [diff] [blame] | 471 | if (block) |
| 472 | { |
| 473 | HRESULT result; |
| 474 | |
| 475 | if (!mSyncQuery) |
| 476 | { |
| 477 | D3D11_QUERY_DESC queryDesc; |
| 478 | queryDesc.Query = D3D11_QUERY_EVENT; |
| 479 | queryDesc.MiscFlags = 0; |
| 480 | |
| 481 | result = mDevice->CreateQuery(&queryDesc, &mSyncQuery); |
| 482 | ASSERT(SUCCEEDED(result)); |
| 483 | } |
| 484 | |
| 485 | mDeviceContext->End(mSyncQuery); |
| 486 | mDeviceContext->Flush(); |
| 487 | |
| 488 | do |
| 489 | { |
| 490 | result = mDeviceContext->GetData(mSyncQuery, NULL, 0, D3D11_ASYNC_GETDATA_DONOTFLUSH); |
| 491 | |
| 492 | // Keep polling, but allow other threads to do something useful first |
| 493 | Sleep(0); |
| 494 | |
| 495 | if (testDeviceLost(true)) |
| 496 | { |
| 497 | return; |
| 498 | } |
| 499 | } |
| 500 | while (result == S_FALSE); |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | mDeviceContext->Flush(); |
| 505 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 506 | } |
| 507 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 508 | SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) |
| 509 | { |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 510 | return new rx::SwapChain11(this, window, shareHandle, backBufferFormat, depthBufferFormat); |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 511 | } |
| 512 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 513 | void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) |
| 514 | { |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 515 | if (type == gl::SAMPLER_PIXEL) |
| 516 | { |
| 517 | if (index < 0 || index >= gl::MAX_TEXTURE_IMAGE_UNITS) |
| 518 | { |
| 519 | ERR("Pixel shader sampler index %i is not valid.", index); |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | if (mForceSetPixelSamplerStates[index] || memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0) |
| 524 | { |
| 525 | ID3D11SamplerState *dxSamplerState = mStateCache.getSamplerState(samplerState); |
| 526 | |
| 527 | if (!dxSamplerState) |
| 528 | { |
| 529 | ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" |
| 530 | "sampler state for pixel shaders at slot %i.", index); |
| 531 | } |
| 532 | |
| 533 | mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState); |
| 534 | |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 535 | mCurPixelSamplerStates[index] = samplerState; |
| 536 | } |
| 537 | |
| 538 | mForceSetPixelSamplerStates[index] = false; |
| 539 | } |
| 540 | else if (type == gl::SAMPLER_VERTEX) |
| 541 | { |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 542 | if (index < 0 || index >= (int)getMaxVertexTextureImageUnits()) |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 543 | { |
| 544 | ERR("Vertex shader sampler index %i is not valid.", index); |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | if (mForceSetVertexSamplerStates[index] || memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0) |
| 549 | { |
| 550 | ID3D11SamplerState *dxSamplerState = mStateCache.getSamplerState(samplerState); |
| 551 | |
| 552 | if (!dxSamplerState) |
| 553 | { |
| 554 | ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" |
| 555 | "sampler state for vertex shaders at slot %i.", index); |
| 556 | } |
| 557 | |
| 558 | mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState); |
| 559 | |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 560 | mCurVertexSamplerStates[index] = samplerState; |
| 561 | } |
| 562 | |
| 563 | mForceSetVertexSamplerStates[index] = false; |
| 564 | } |
| 565 | else UNREACHABLE(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) |
| 569 | { |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 570 | ID3D11ShaderResourceView *textureSRV = NULL; |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 571 | unsigned int serial = 0; |
| 572 | bool forceSetTexture = false; |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 573 | |
| 574 | if (texture) |
| 575 | { |
| 576 | TextureStorageInterface *texStorage = texture->getNativeTexture(); |
| 577 | if (texStorage) |
| 578 | { |
| 579 | TextureStorage11 *storage11 = TextureStorage11::makeTextureStorage11(texStorage->getStorageInstance()); |
| 580 | textureSRV = storage11->getSRV(); |
| 581 | } |
| 582 | |
| 583 | // If we get NULL back from getSRV here, something went wrong in the texture class and we're unexpectedly |
| 584 | // missing the shader resource view |
| 585 | ASSERT(textureSRV != NULL); |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 586 | |
| 587 | serial = texture->getTextureSerial(); |
| 588 | forceSetTexture = texture->hasDirtyImages(); |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | if (type == gl::SAMPLER_PIXEL) |
| 592 | { |
| 593 | if (index < 0 || index >= gl::MAX_TEXTURE_IMAGE_UNITS) |
| 594 | { |
| 595 | ERR("Pixel shader sampler index %i is not valid.", index); |
| 596 | return; |
| 597 | } |
| 598 | |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 599 | if (forceSetTexture || mCurPixelTextureSerials[index] != serial) |
| 600 | { |
| 601 | mDeviceContext->PSSetShaderResources(index, 1, &textureSRV); |
| 602 | } |
| 603 | |
| 604 | mCurPixelTextureSerials[index] = serial; |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 605 | } |
| 606 | else if (type == gl::SAMPLER_VERTEX) |
| 607 | { |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 608 | if (index < 0 || index >= (int)getMaxVertexTextureImageUnits()) |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 609 | { |
| 610 | ERR("Vertex shader sampler index %i is not valid.", index); |
| 611 | return; |
| 612 | } |
| 613 | |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 614 | if (forceSetTexture || mCurVertexTextureSerials[index] != serial) |
| 615 | { |
| 616 | mDeviceContext->VSSetShaderResources(index, 1, &textureSRV); |
| 617 | } |
| 618 | |
| 619 | mCurVertexTextureSerials[index] = serial; |
daniel@transgaming.com | 0785fad | 2013-01-11 04:08:10 +0000 | [diff] [blame] | 620 | } |
| 621 | else UNREACHABLE(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 622 | } |
| 623 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 624 | void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 625 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 626 | if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 627 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 628 | ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mScissorEnabled, |
| 629 | mCurDepthSize); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 630 | if (!dxRasterState) |
| 631 | { |
daniel@transgaming.com | 0f9b320 | 2013-01-11 04:08:05 +0000 | [diff] [blame] | 632 | ERR("NULL rasterizer state returned by RenderStateCache::getRasterizerState, setting the default" |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 633 | "rasterizer state."); |
| 634 | } |
| 635 | |
| 636 | mDeviceContext->RSSetState(dxRasterState); |
| 637 | |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 638 | mCurRasterState = rasterState; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | mForceSetRasterState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, |
| 645 | unsigned int sampleMask) |
| 646 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 647 | if (mForceSetBlendState || |
| 648 | memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 || |
| 649 | memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0 || |
| 650 | sampleMask != mCurSampleMask) |
| 651 | { |
| 652 | ID3D11BlendState *dxBlendState = mStateCache.getBlendState(blendState); |
| 653 | if (!dxBlendState) |
| 654 | { |
| 655 | ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " |
| 656 | "blend state."); |
| 657 | } |
| 658 | |
| 659 | const float blendColors[] = { blendColor.red, blendColor.green, blendColor.blue, blendColor.alpha }; |
| 660 | mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask); |
| 661 | |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 662 | mCurBlendState = blendState; |
| 663 | mCurBlendColor = blendColor; |
| 664 | mCurSampleMask = sampleMask; |
| 665 | } |
| 666 | |
| 667 | mForceSetBlendState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 668 | } |
| 669 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 670 | void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 671 | int stencilBackRef, bool frontFaceCCW) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 672 | { |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 673 | if (mForceSetDepthStencilState || |
| 674 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || |
| 675 | stencilRef != mCurStencilRef || stencilBackRef != mCurStencilBackRef) |
| 676 | { |
| 677 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 678 | stencilRef != stencilBackRef || |
| 679 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 680 | { |
| 681 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are " |
| 682 | "invalid under WebGL."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 683 | return gl::error(GL_INVALID_OPERATION); |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); |
| 687 | if (!dxDepthStencilState) |
| 688 | { |
| 689 | ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " |
| 690 | "setting the default depth stencil state."); |
| 691 | } |
| 692 | |
| 693 | mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, static_cast<UINT>(stencilRef)); |
| 694 | |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 695 | mCurDepthStencilState = depthStencilState; |
| 696 | mCurStencilRef = stencilRef; |
| 697 | mCurStencilBackRef = stencilBackRef; |
| 698 | } |
| 699 | |
| 700 | mForceSetDepthStencilState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 701 | } |
| 702 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 703 | void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 704 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 705 | if (mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0 || |
| 706 | enabled != mScissorEnabled) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 707 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 708 | if (enabled) |
| 709 | { |
| 710 | D3D11_RECT rect; |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 711 | rect.left = std::max(0, scissor.x); |
| 712 | rect.top = std::max(0, scissor.y); |
| 713 | rect.right = scissor.x + std::max(0, scissor.width); |
| 714 | rect.bottom = scissor.y + std::max(0, scissor.height); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 715 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 716 | mDeviceContext->RSSetScissorRects(1, &rect); |
| 717 | } |
| 718 | |
| 719 | if (enabled != mScissorEnabled) |
| 720 | { |
| 721 | mForceSetRasterState = true; |
| 722 | } |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 723 | |
| 724 | mCurScissor = scissor; |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 725 | mScissorEnabled = enabled; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | mForceSetScissor = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 729 | } |
| 730 | |
daniel@transgaming.com | 1298518 | 2012-12-20 20:56:31 +0000 | [diff] [blame] | 731 | bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, |
shannon.woods@transgaming.com | 0b236e2 | 2013-01-25 21:57:07 +0000 | [diff] [blame] | 732 | bool ignoreViewport) |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 733 | { |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 734 | gl::Rectangle actualViewport = viewport; |
| 735 | float actualZNear = gl::clamp01(zNear); |
| 736 | float actualZFar = gl::clamp01(zFar); |
| 737 | if (ignoreViewport) |
| 738 | { |
| 739 | actualViewport.x = 0; |
| 740 | actualViewport.y = 0; |
| 741 | actualViewport.width = mRenderTargetDesc.width; |
| 742 | actualViewport.height = mRenderTargetDesc.height; |
| 743 | actualZNear = 0.0f; |
| 744 | actualZFar = 1.0f; |
| 745 | } |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 746 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 747 | // Get D3D viewport bounds, which depends on the feature level |
| 748 | const Range& viewportBounds = getViewportBounds(); |
| 749 | |
| 750 | // Clamp width and height first to the gl maximum, then clamp further if we extend past the D3D maximum bounds |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 751 | D3D11_VIEWPORT dxViewport; |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 752 | dxViewport.TopLeftX = gl::clamp(actualViewport.x, viewportBounds.start, viewportBounds.end); |
| 753 | dxViewport.TopLeftY = gl::clamp(actualViewport.y, viewportBounds.start, viewportBounds.end); |
| 754 | dxViewport.Width = gl::clamp(actualViewport.width, 0, getMaxViewportDimension()); |
| 755 | dxViewport.Height = gl::clamp(actualViewport.height, 0, getMaxViewportDimension()); |
| 756 | dxViewport.Width = std::min((int)dxViewport.Width, viewportBounds.end - static_cast<int>(dxViewport.TopLeftX)); |
| 757 | dxViewport.Height = std::min((int)dxViewport.Height, viewportBounds.end - static_cast<int>(dxViewport.TopLeftY)); |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 758 | dxViewport.MinDepth = actualZNear; |
| 759 | dxViewport.MaxDepth = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 760 | |
| 761 | if (dxViewport.Width <= 0 || dxViewport.Height <= 0) |
| 762 | { |
| 763 | return false; // Nothing to render |
| 764 | } |
| 765 | |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 766 | bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || |
| 767 | actualZNear != mCurNear || actualZFar != mCurFar; |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 768 | |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 769 | if (viewportChanged) |
| 770 | { |
| 771 | mDeviceContext->RSSetViewports(1, &dxViewport); |
| 772 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 773 | mCurViewport = actualViewport; |
| 774 | mCurNear = actualZNear; |
| 775 | mCurFar = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 776 | |
shannon.woods@transgaming.com | a14ecf3 | 2013-02-28 23:09:42 +0000 | [diff] [blame] | 777 | mPixelConstants.viewCoords[0] = actualViewport.width * 0.5f; |
| 778 | mPixelConstants.viewCoords[1] = actualViewport.height * 0.5f; |
| 779 | mPixelConstants.viewCoords[2] = actualViewport.x + (actualViewport.width * 0.5f); |
| 780 | mPixelConstants.viewCoords[3] = actualViewport.y + (actualViewport.height * 0.5f); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 781 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 782 | mPixelConstants.depthFront[0] = (actualZFar - actualZNear) * 0.5f; |
| 783 | mPixelConstants.depthFront[1] = (actualZNear + actualZFar) * 0.5f; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 784 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 785 | mVertexConstants.depthRange[0] = actualZNear; |
| 786 | mVertexConstants.depthRange[1] = actualZFar; |
| 787 | mVertexConstants.depthRange[2] = actualZFar - actualZNear; |
daniel@transgaming.com | ed36abd | 2013-01-11 21:15:58 +0000 | [diff] [blame] | 788 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 789 | mPixelConstants.depthRange[0] = actualZNear; |
| 790 | mPixelConstants.depthRange[1] = actualZFar; |
| 791 | mPixelConstants.depthRange[2] = actualZFar - actualZNear; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | mForceSetViewport = false; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 795 | return true; |
| 796 | } |
| 797 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 798 | bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count) |
| 799 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 800 | D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 801 | |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 802 | switch (mode) |
| 803 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 804 | case GL_POINTS: primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; break; |
| 805 | case GL_LINES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINELIST; break; |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 806 | case GL_LINE_LOOP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; break; |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 807 | case GL_LINE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; break; |
| 808 | case GL_TRIANGLES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; break; |
| 809 | case GL_TRIANGLE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; break; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 810 | // emulate fans via rewriting index buffer |
| 811 | case GL_TRIANGLE_FAN: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; break; |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 812 | default: |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 813 | return gl::error(GL_INVALID_ENUM, false); |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 814 | } |
| 815 | |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 816 | mDeviceContext->IASetPrimitiveTopology(primitiveTopology); |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 817 | |
| 818 | return count > 0; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 822 | { |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 823 | // Get the color render buffer and serial |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 824 | // Also extract the render target dimensions and view |
| 825 | unsigned int renderTargetWidth = 0; |
| 826 | unsigned int renderTargetHeight = 0; |
| 827 | GLenum renderTargetFormat = 0; |
| 828 | unsigned int renderTargetSerials[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS] = {0}; |
| 829 | ID3D11RenderTargetView* framebufferRTVs[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS] = {NULL}; |
| 830 | bool missingColorRenderTarget = true; |
| 831 | |
| 832 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 833 | { |
shannon.woods%transgaming.com@gtempaccount.com | 4059a38 | 2013-04-13 03:31:16 +0000 | [diff] [blame] | 834 | const GLenum drawBufferState = framebuffer->getDrawBufferState(colorAttachment); |
| 835 | |
| 836 | if (framebuffer->getColorbufferType(colorAttachment) != GL_NONE && drawBufferState != GL_NONE) |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 837 | { |
shannon.woods%transgaming.com@gtempaccount.com | 4059a38 | 2013-04-13 03:31:16 +0000 | [diff] [blame] | 838 | // the draw buffer must be either "none", "back" for the default buffer or the same index as this color (in order) |
| 839 | ASSERT(drawBufferState == GL_BACK || drawBufferState == (GL_COLOR_ATTACHMENT0_EXT + colorAttachment)); |
| 840 | |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 841 | gl::Renderbuffer *colorbuffer = framebuffer->getColorbuffer(colorAttachment); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 842 | |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 843 | if (!colorbuffer) |
| 844 | { |
| 845 | ERR("render target pointer unexpectedly null."); |
| 846 | return false; |
| 847 | } |
shannon.woods@transgaming.com | 3e3da58 | 2013-02-28 23:09:03 +0000 | [diff] [blame] | 848 | |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 849 | // check for zero-sized default framebuffer, which is a special case. |
| 850 | // in this case we do not wish to modify any state and just silently return false. |
| 851 | // this will not report any gl error but will cause the calling method to return. |
| 852 | if (colorbuffer->getWidth() == 0 || colorbuffer->getHeight() == 0) |
| 853 | { |
| 854 | return false; |
| 855 | } |
| 856 | |
| 857 | renderTargetSerials[colorAttachment] = colorbuffer->getSerial(); |
| 858 | |
| 859 | // Extract the render target dimensions and view |
| 860 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 861 | if (!renderTarget) |
| 862 | { |
| 863 | ERR("render target pointer unexpectedly null."); |
| 864 | return false; |
| 865 | } |
| 866 | |
| 867 | framebufferRTVs[colorAttachment] = renderTarget->getRenderTargetView(); |
| 868 | if (!framebufferRTVs[colorAttachment]) |
| 869 | { |
| 870 | ERR("render target view pointer unexpectedly null."); |
| 871 | return false; |
| 872 | } |
| 873 | |
| 874 | if (missingColorRenderTarget) |
| 875 | { |
| 876 | renderTargetWidth = colorbuffer->getWidth(); |
| 877 | renderTargetHeight = colorbuffer->getHeight(); |
| 878 | renderTargetFormat = colorbuffer->getActualFormat(); |
| 879 | missingColorRenderTarget = false; |
| 880 | } |
| 881 | } |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | // Get the depth stencil render buffer and serials |
| 885 | gl::Renderbuffer *depthStencil = NULL; |
| 886 | unsigned int depthbufferSerial = 0; |
| 887 | unsigned int stencilbufferSerial = 0; |
| 888 | if (framebuffer->getDepthbufferType() != GL_NONE) |
| 889 | { |
| 890 | depthStencil = framebuffer->getDepthbuffer(); |
| 891 | if (!depthStencil) |
| 892 | { |
| 893 | ERR("Depth stencil pointer unexpectedly null."); |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 894 | SafeRelease(framebufferRTVs); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 895 | return false; |
| 896 | } |
| 897 | |
| 898 | depthbufferSerial = depthStencil->getSerial(); |
| 899 | } |
| 900 | else if (framebuffer->getStencilbufferType() != GL_NONE) |
| 901 | { |
| 902 | depthStencil = framebuffer->getStencilbuffer(); |
| 903 | if (!depthStencil) |
| 904 | { |
| 905 | ERR("Depth stencil pointer unexpectedly null."); |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 906 | SafeRelease(framebufferRTVs); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 907 | return false; |
| 908 | } |
| 909 | |
| 910 | stencilbufferSerial = depthStencil->getSerial(); |
| 911 | } |
| 912 | |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 913 | // Extract the depth stencil sizes and view |
| 914 | unsigned int depthSize = 0; |
| 915 | unsigned int stencilSize = 0; |
| 916 | ID3D11DepthStencilView* framebufferDSV = NULL; |
| 917 | if (depthStencil) |
| 918 | { |
| 919 | RenderTarget11 *depthStencilRenderTarget = RenderTarget11::makeRenderTarget11(depthStencil->getDepthStencil()); |
| 920 | if (!depthStencilRenderTarget) |
| 921 | { |
| 922 | ERR("render target pointer unexpectedly null."); |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 923 | SafeRelease(framebufferRTVs); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 924 | return false; |
| 925 | } |
| 926 | |
| 927 | framebufferDSV = depthStencilRenderTarget->getDepthStencilView(); |
| 928 | if (!framebufferDSV) |
| 929 | { |
| 930 | ERR("depth stencil view pointer unexpectedly null."); |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 931 | SafeRelease(framebufferRTVs); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 932 | return false; |
| 933 | } |
| 934 | |
| 935 | // If there is no render buffer, the width, height and format values come from |
| 936 | // the depth stencil |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 937 | if (missingColorRenderTarget) |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 938 | { |
| 939 | renderTargetWidth = depthStencil->getWidth(); |
| 940 | renderTargetHeight = depthStencil->getHeight(); |
| 941 | renderTargetFormat = depthStencil->getActualFormat(); |
| 942 | } |
| 943 | |
| 944 | depthSize = depthStencil->getDepthSize(); |
| 945 | stencilSize = depthStencil->getStencilSize(); |
| 946 | } |
| 947 | |
| 948 | // Apply the render target and depth stencil |
| 949 | if (!mRenderTargetDescInitialized || !mDepthStencilInitialized || |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 950 | memcmp(renderTargetSerials, mAppliedRenderTargetSerials, sizeof(renderTargetSerials)) != 0 || |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 951 | depthbufferSerial != mAppliedDepthbufferSerial || |
| 952 | stencilbufferSerial != mAppliedStencilbufferSerial) |
| 953 | { |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 954 | mDeviceContext->OMSetRenderTargets(getMaxRenderTargets(), framebufferRTVs, framebufferDSV); |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 955 | |
| 956 | mRenderTargetDesc.width = renderTargetWidth; |
| 957 | mRenderTargetDesc.height = renderTargetHeight; |
| 958 | mRenderTargetDesc.format = renderTargetFormat; |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 959 | mForceSetViewport = true; |
| 960 | mForceSetScissor = true; |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 961 | |
| 962 | if (!mDepthStencilInitialized || depthSize != mCurDepthSize) |
| 963 | { |
| 964 | mCurDepthSize = depthSize; |
| 965 | mForceSetRasterState = true; |
| 966 | } |
| 967 | |
| 968 | mCurStencilSize = stencilSize; |
| 969 | |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 970 | for (unsigned int rtIndex = 0; rtIndex < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; rtIndex++) |
| 971 | { |
| 972 | mAppliedRenderTargetSerials[rtIndex] = renderTargetSerials[rtIndex]; |
| 973 | } |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 974 | mAppliedDepthbufferSerial = depthbufferSerial; |
| 975 | mAppliedStencilbufferSerial = stencilbufferSerial; |
| 976 | mRenderTargetDescInitialized = true; |
| 977 | mDepthStencilInitialized = true; |
| 978 | } |
| 979 | |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 980 | SafeRelease(framebufferRTVs); |
| 981 | SafeRelease(framebufferDSV); |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 982 | |
| 983 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 984 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 985 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 986 | GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 987 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 988 | TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; |
| 989 | GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, programBinary, first, count, attributes, instances); |
| 990 | if (err != GL_NO_ERROR) |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 991 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 992 | return err; |
| 993 | } |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 994 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 995 | return mInputLayoutCache.applyVertexBuffers(attributes, programBinary); |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 996 | } |
| 997 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 998 | GLenum Renderer11::applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 999 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1000 | GLenum err = mIndexDataManager->prepareIndexData(type, count, elementArrayBuffer, indices, indexInfo); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1001 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1002 | if (err == GL_NO_ERROR) |
| 1003 | { |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1004 | if (indexInfo->storage) |
| 1005 | { |
| 1006 | if (indexInfo->serial != mAppliedStorageIBSerial || indexInfo->startOffset != mAppliedIBOffset) |
| 1007 | { |
| 1008 | BufferStorage11 *storage = BufferStorage11::makeBufferStorage11(indexInfo->storage); |
| 1009 | IndexBuffer11* indexBuffer = IndexBuffer11::makeIndexBuffer11(indexInfo->indexBuffer); |
| 1010 | |
| 1011 | mDeviceContext->IASetIndexBuffer(storage->getBuffer(), indexBuffer->getIndexFormat(), indexInfo->startOffset); |
| 1012 | |
| 1013 | mAppliedIBSerial = 0; |
| 1014 | mAppliedStorageIBSerial = storage->getSerial(); |
| 1015 | mAppliedIBOffset = indexInfo->startOffset; |
| 1016 | } |
| 1017 | } |
| 1018 | else if (indexInfo->serial != mAppliedIBSerial || indexInfo->startOffset != mAppliedIBOffset) |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1019 | { |
| 1020 | IndexBuffer11* indexBuffer = IndexBuffer11::makeIndexBuffer11(indexInfo->indexBuffer); |
| 1021 | |
daniel@transgaming.com | 22ada2c | 2013-01-11 04:07:12 +0000 | [diff] [blame] | 1022 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexInfo->startOffset); |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1023 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1024 | mAppliedIBSerial = indexInfo->serial; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1025 | mAppliedStorageIBSerial = 0; |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1026 | mAppliedIBOffset = indexInfo->startOffset; |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | return err; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances) |
| 1034 | { |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 1035 | if (mode == GL_LINE_LOOP) |
| 1036 | { |
| 1037 | drawLineLoop(count, GL_NONE, NULL, 0, NULL); |
| 1038 | } |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1039 | else if (mode == GL_TRIANGLE_FAN) |
| 1040 | { |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1041 | drawTriangleFan(count, GL_NONE, NULL, 0, NULL, instances); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1042 | } |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 1043 | else if (instances > 0) |
| 1044 | { |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1045 | mDeviceContext->DrawInstanced(count, instances, 0, 0); |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 1046 | } |
| 1047 | else |
| 1048 | { |
| 1049 | mDeviceContext->Draw(count, 0); |
| 1050 | } |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1053 | void Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1054 | { |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1055 | if (mode == GL_LINE_LOOP) |
| 1056 | { |
| 1057 | drawLineLoop(count, type, indices, indexInfo.minIndex, elementArrayBuffer); |
| 1058 | } |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1059 | else if (mode == GL_TRIANGLE_FAN) |
| 1060 | { |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1061 | drawTriangleFan(count, type, indices, indexInfo.minIndex, elementArrayBuffer, instances); |
| 1062 | } |
| 1063 | else if (instances > 0) |
| 1064 | { |
| 1065 | mDeviceContext->DrawIndexedInstanced(count, instances, 0, -static_cast<int>(indexInfo.minIndex), 0); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1066 | } |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1067 | else |
| 1068 | { |
daniel@transgaming.com | 9f7ede6 | 2013-01-11 04:07:06 +0000 | [diff] [blame] | 1069 | mDeviceContext->DrawIndexed(count, 0, -static_cast<int>(indexInfo.minIndex)); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) |
| 1074 | { |
| 1075 | // Get the raw indices for an indexed draw |
| 1076 | if (type != GL_NONE && elementArrayBuffer) |
| 1077 | { |
| 1078 | gl::Buffer *indexBuffer = elementArrayBuffer; |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1079 | BufferStorage *storage = indexBuffer->getStorage(); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1080 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1081 | indices = static_cast<const GLubyte*>(storage->getData()) + offset; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | if (!mLineLoopIB) |
| 1085 | { |
| 1086 | mLineLoopIB = new StreamingIndexBufferInterface(this); |
| 1087 | if (!mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT)) |
| 1088 | { |
| 1089 | delete mLineLoopIB; |
| 1090 | mLineLoopIB = NULL; |
| 1091 | |
| 1092 | ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1093 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | const int spaceNeeded = (count + 1) * sizeof(unsigned int); |
| 1098 | if (!mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)) |
| 1099 | { |
| 1100 | ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1101 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | void* mappedMemory = NULL; |
| 1105 | int offset = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory); |
| 1106 | if (offset == -1 || mappedMemory == NULL) |
| 1107 | { |
| 1108 | ERR("Could not map index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1109 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1112 | unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1113 | unsigned int indexBufferOffset = static_cast<unsigned int>(offset); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1114 | |
| 1115 | switch (type) |
| 1116 | { |
| 1117 | case GL_NONE: // Non-indexed draw |
| 1118 | for (int i = 0; i < count; i++) |
| 1119 | { |
| 1120 | data[i] = i; |
| 1121 | } |
| 1122 | data[count] = 0; |
| 1123 | break; |
| 1124 | case GL_UNSIGNED_BYTE: |
| 1125 | for (int i = 0; i < count; i++) |
| 1126 | { |
| 1127 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 1128 | } |
| 1129 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 1130 | break; |
| 1131 | case GL_UNSIGNED_SHORT: |
| 1132 | for (int i = 0; i < count; i++) |
| 1133 | { |
| 1134 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 1135 | } |
| 1136 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 1137 | break; |
| 1138 | case GL_UNSIGNED_INT: |
| 1139 | for (int i = 0; i < count; i++) |
| 1140 | { |
| 1141 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 1142 | } |
| 1143 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 1144 | break; |
| 1145 | default: UNREACHABLE(); |
| 1146 | } |
| 1147 | |
| 1148 | if (!mLineLoopIB->unmapBuffer()) |
| 1149 | { |
| 1150 | ERR("Could not unmap index buffer for GL_LINE_LOOP."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1151 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1154 | if (mAppliedIBSerial != mLineLoopIB->getSerial() || mAppliedIBOffset != indexBufferOffset) |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1155 | { |
| 1156 | IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mLineLoopIB->getIndexBuffer()); |
| 1157 | |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1158 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexBufferOffset); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1159 | mAppliedIBSerial = mLineLoopIB->getSerial(); |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1160 | mAppliedStorageIBSerial = 0; |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1161 | mAppliedIBOffset = indexBufferOffset; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
daniel@transgaming.com | 1ef0967 | 2013-01-11 04:10:37 +0000 | [diff] [blame] | 1164 | mDeviceContext->DrawIndexed(count + 1, 0, -minIndex); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1167 | void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances) |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1168 | { |
| 1169 | // Get the raw indices for an indexed draw |
| 1170 | if (type != GL_NONE && elementArrayBuffer) |
| 1171 | { |
| 1172 | gl::Buffer *indexBuffer = elementArrayBuffer; |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1173 | BufferStorage *storage = indexBuffer->getStorage(); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1174 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 1175 | indices = static_cast<const GLubyte*>(storage->getData()) + offset; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | if (!mTriangleFanIB) |
| 1179 | { |
| 1180 | mTriangleFanIB = new StreamingIndexBufferInterface(this); |
| 1181 | if (!mTriangleFanIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT)) |
| 1182 | { |
| 1183 | delete mTriangleFanIB; |
| 1184 | mTriangleFanIB = NULL; |
| 1185 | |
| 1186 | ERR("Could not create a scratch index buffer for GL_TRIANGLE_FAN."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1187 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | const int numTris = count - 2; |
| 1192 | const int spaceNeeded = (numTris * 3) * sizeof(unsigned int); |
| 1193 | if (!mTriangleFanIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)) |
| 1194 | { |
| 1195 | ERR("Could not reserve enough space in scratch index buffer for GL_TRIANGLE_FAN."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1196 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | void* mappedMemory = NULL; |
| 1200 | int offset = mTriangleFanIB->mapBuffer(spaceNeeded, &mappedMemory); |
| 1201 | if (offset == -1 || mappedMemory == NULL) |
| 1202 | { |
| 1203 | ERR("Could not map scratch index buffer for GL_TRIANGLE_FAN."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1204 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); |
| 1208 | unsigned int indexBufferOffset = static_cast<unsigned int>(offset); |
| 1209 | |
| 1210 | switch (type) |
| 1211 | { |
| 1212 | case GL_NONE: // Non-indexed draw |
| 1213 | for (int i = 0; i < numTris; i++) |
| 1214 | { |
| 1215 | data[i*3 + 0] = 0; |
| 1216 | data[i*3 + 1] = i + 1; |
| 1217 | data[i*3 + 2] = i + 2; |
| 1218 | } |
| 1219 | break; |
| 1220 | case GL_UNSIGNED_BYTE: |
| 1221 | for (int i = 0; i < numTris; i++) |
| 1222 | { |
| 1223 | data[i*3 + 0] = static_cast<const GLubyte*>(indices)[0]; |
| 1224 | data[i*3 + 1] = static_cast<const GLubyte*>(indices)[i + 1]; |
| 1225 | data[i*3 + 2] = static_cast<const GLubyte*>(indices)[i + 2]; |
| 1226 | } |
| 1227 | break; |
| 1228 | case GL_UNSIGNED_SHORT: |
| 1229 | for (int i = 0; i < numTris; i++) |
| 1230 | { |
| 1231 | data[i*3 + 0] = static_cast<const GLushort*>(indices)[0]; |
| 1232 | data[i*3 + 1] = static_cast<const GLushort*>(indices)[i + 1]; |
| 1233 | data[i*3 + 2] = static_cast<const GLushort*>(indices)[i + 2]; |
| 1234 | } |
| 1235 | break; |
| 1236 | case GL_UNSIGNED_INT: |
| 1237 | for (int i = 0; i < numTris; i++) |
| 1238 | { |
| 1239 | data[i*3 + 0] = static_cast<const GLuint*>(indices)[0]; |
| 1240 | data[i*3 + 1] = static_cast<const GLuint*>(indices)[i + 1]; |
| 1241 | data[i*3 + 2] = static_cast<const GLuint*>(indices)[i + 2]; |
| 1242 | } |
| 1243 | break; |
| 1244 | default: UNREACHABLE(); |
| 1245 | } |
| 1246 | |
| 1247 | if (!mTriangleFanIB->unmapBuffer()) |
| 1248 | { |
| 1249 | ERR("Could not unmap scratch index buffer for GL_TRIANGLE_FAN."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1250 | return gl::error(GL_OUT_OF_MEMORY); |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | if (mAppliedIBSerial != mTriangleFanIB->getSerial() || mAppliedIBOffset != indexBufferOffset) |
| 1254 | { |
| 1255 | IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mTriangleFanIB->getIndexBuffer()); |
| 1256 | |
| 1257 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexBufferOffset); |
| 1258 | mAppliedIBSerial = mTriangleFanIB->getSerial(); |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1259 | mAppliedStorageIBSerial = 0; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1260 | mAppliedIBOffset = indexBufferOffset; |
| 1261 | } |
| 1262 | |
shannon.woods@transgaming.com | 00032cb | 2013-01-25 21:56:30 +0000 | [diff] [blame] | 1263 | if (instances > 0) |
| 1264 | { |
| 1265 | mDeviceContext->DrawIndexedInstanced(numTris * 3, instances, 0, -minIndex, 0); |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | mDeviceContext->DrawIndexed(numTris * 3, 0, -minIndex); |
| 1270 | } |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1273 | void Renderer11::applyShaders(gl::ProgramBinary *programBinary) |
| 1274 | { |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1275 | unsigned int programBinarySerial = programBinary->getSerial(); |
shannon.woods@transgaming.com | 43ccf3f | 2013-02-28 23:07:19 +0000 | [diff] [blame] | 1276 | const bool updateProgramState = (programBinarySerial != mAppliedProgramBinarySerial); |
| 1277 | |
| 1278 | if (updateProgramState) |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1279 | { |
| 1280 | ShaderExecutable *vertexExe = programBinary->getVertexExecutable(); |
| 1281 | ShaderExecutable *pixelExe = programBinary->getPixelExecutable(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 1282 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1283 | ID3D11VertexShader *vertexShader = NULL; |
| 1284 | if (vertexExe) vertexShader = ShaderExecutable11::makeShaderExecutable11(vertexExe)->getVertexShader(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 1285 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1286 | ID3D11PixelShader *pixelShader = NULL; |
| 1287 | if (pixelExe) pixelShader = ShaderExecutable11::makeShaderExecutable11(pixelExe)->getPixelShader(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 1288 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1289 | mDeviceContext->PSSetShader(pixelShader, NULL, 0); |
| 1290 | mDeviceContext->VSSetShader(vertexShader, NULL, 0); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 1291 | |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 1292 | programBinary->dirtyAllUniforms(); |
| 1293 | |
| 1294 | mAppliedProgramBinarySerial = programBinarySerial; |
| 1295 | } |
| 1296 | |
| 1297 | // Only use the geometry shader currently for point sprite drawing |
shannon.woods@transgaming.com | 43ccf3f | 2013-02-28 23:07:19 +0000 | [diff] [blame] | 1298 | const bool usesGeometryShader = (programBinary->usesGeometryShader() && mCurRasterState.pointDrawMode); |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 1299 | |
shannon.woods@transgaming.com | 43ccf3f | 2013-02-28 23:07:19 +0000 | [diff] [blame] | 1300 | if (updateProgramState || usesGeometryShader != mIsGeometryShaderActive) |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 1301 | { |
| 1302 | if (usesGeometryShader) |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 1303 | { |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 1304 | ShaderExecutable *geometryExe = programBinary->getGeometryExecutable(); |
| 1305 | ID3D11GeometryShader *geometryShader = ShaderExecutable11::makeShaderExecutable11(geometryExe)->getGeometryShader(); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 1306 | mDeviceContext->GSSetShader(geometryShader, NULL, 0); |
| 1307 | } |
| 1308 | else |
| 1309 | { |
| 1310 | mDeviceContext->GSSetShader(NULL, NULL, 0); |
| 1311 | } |
| 1312 | |
shannon.woods@transgaming.com | dd2524c | 2013-02-28 23:04:33 +0000 | [diff] [blame] | 1313 | mIsGeometryShaderActive = usesGeometryShader; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1314 | } |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1317 | void Renderer11::applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 1318 | { |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1319 | ShaderExecutable11 *vertexExecutable = ShaderExecutable11::makeShaderExecutable11(programBinary->getVertexExecutable()); |
| 1320 | ShaderExecutable11 *pixelExecutable = ShaderExecutable11::makeShaderExecutable11(programBinary->getPixelExecutable()); |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1321 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1322 | unsigned int totalRegisterCountVS = 0; |
| 1323 | unsigned int totalRegisterCountPS = 0; |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1324 | |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1325 | bool vertexUniformsDirty = false; |
| 1326 | bool pixelUniformsDirty = false; |
| 1327 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1328 | for (gl::UniformArray::const_iterator uniform_iterator = uniformArray->begin(); uniform_iterator != uniformArray->end(); uniform_iterator++) |
| 1329 | { |
| 1330 | const gl::Uniform *uniform = *uniform_iterator; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1331 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1332 | if (uniform->vsRegisterIndex >= 0) |
| 1333 | { |
| 1334 | totalRegisterCountVS += uniform->registerCount; |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1335 | vertexUniformsDirty = vertexUniformsDirty || uniform->dirty; |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1336 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1337 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1338 | if (uniform->psRegisterIndex >= 0) |
| 1339 | { |
| 1340 | totalRegisterCountPS += uniform->registerCount; |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1341 | pixelUniformsDirty = pixelUniformsDirty || uniform->dirty; |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1342 | } |
| 1343 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1344 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1345 | ID3D11Buffer *vertexConstantBuffer = vertexExecutable->getConstantBuffer(mDevice, totalRegisterCountVS); |
| 1346 | ID3D11Buffer *pixelConstantBuffer = pixelExecutable->getConstantBuffer(mDevice, totalRegisterCountPS); |
| 1347 | |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1348 | float (*mapVS)[4] = NULL; |
| 1349 | float (*mapPS)[4] = NULL; |
| 1350 | |
| 1351 | if (totalRegisterCountVS > 0 && vertexUniformsDirty) |
| 1352 | { |
| 1353 | D3D11_MAPPED_SUBRESOURCE map = {0}; |
| 1354 | HRESULT result = mDeviceContext->Map(vertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); |
| 1355 | ASSERT(SUCCEEDED(result)); |
| 1356 | mapVS = (float(*)[4])map.pData; |
| 1357 | } |
| 1358 | |
| 1359 | if (totalRegisterCountPS > 0 && pixelUniformsDirty) |
| 1360 | { |
| 1361 | D3D11_MAPPED_SUBRESOURCE map = {0}; |
| 1362 | HRESULT result = mDeviceContext->Map(pixelConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); |
| 1363 | ASSERT(SUCCEEDED(result)); |
| 1364 | mapPS = (float(*)[4])map.pData; |
| 1365 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1366 | |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1367 | for (gl::UniformArray::iterator uniform_iterator = uniformArray->begin(); uniform_iterator != uniformArray->end(); uniform_iterator++) |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 1368 | { |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1369 | gl::Uniform *uniform = *uniform_iterator; |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1370 | |
shannon.woods@transgaming.com | 13979a6 | 2013-02-28 23:10:18 +0000 | [diff] [blame] | 1371 | if (uniform->type != GL_SAMPLER_2D && uniform->type != GL_SAMPLER_CUBE) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1372 | { |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1373 | if (uniform->vsRegisterIndex >= 0 && mapVS) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1374 | { |
shannon.woods@transgaming.com | 13979a6 | 2013-02-28 23:10:18 +0000 | [diff] [blame] | 1375 | memcpy(mapVS + uniform->vsRegisterIndex, uniform->data, uniform->registerCount * sizeof(float[4])); |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1376 | } |
shannon.woods@transgaming.com | 13979a6 | 2013-02-28 23:10:18 +0000 | [diff] [blame] | 1377 | |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1378 | if (uniform->psRegisterIndex >= 0 && mapPS) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1379 | { |
shannon.woods@transgaming.com | 13979a6 | 2013-02-28 23:10:18 +0000 | [diff] [blame] | 1380 | memcpy(mapPS + uniform->psRegisterIndex, uniform->data, uniform->registerCount * sizeof(float[4])); |
daniel@transgaming.com | e76b64b | 2013-01-11 04:10:08 +0000 | [diff] [blame] | 1381 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1382 | } |
shannon.woods@transgaming.com | 21ba647 | 2013-01-25 21:53:32 +0000 | [diff] [blame] | 1383 | |
| 1384 | uniform->dirty = false; |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 1385 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1386 | |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1387 | if (mapVS) |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1388 | { |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1389 | mDeviceContext->Unmap(vertexConstantBuffer, 0); |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1392 | if (mapPS) |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1393 | { |
shannon.woods@transgaming.com | 09bf2a7 | 2013-02-28 23:12:54 +0000 | [diff] [blame] | 1394 | mDeviceContext->Unmap(pixelConstantBuffer, 0); |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1395 | } |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1396 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1397 | mDeviceContext->VSSetConstantBuffers(0, 1, &vertexConstantBuffer); |
| 1398 | mDeviceContext->PSSetConstantBuffers(0, 1, &pixelConstantBuffer); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 1399 | |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 1400 | // Driver uniforms |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1401 | if (!mDriverConstantBufferVS) |
| 1402 | { |
| 1403 | D3D11_BUFFER_DESC constantBufferDescription = {0}; |
| 1404 | constantBufferDescription.ByteWidth = sizeof(dx_VertexConstants); |
| 1405 | constantBufferDescription.Usage = D3D11_USAGE_DEFAULT; |
| 1406 | constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
| 1407 | constantBufferDescription.CPUAccessFlags = 0; |
| 1408 | constantBufferDescription.MiscFlags = 0; |
| 1409 | constantBufferDescription.StructureByteStride = 0; |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 1410 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1411 | HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferVS); |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1412 | ASSERT(SUCCEEDED(result)); |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 1413 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1414 | mDeviceContext->VSSetConstantBuffers(1, 1, &mDriverConstantBufferVS); |
| 1415 | } |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1416 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1417 | if (!mDriverConstantBufferPS) |
| 1418 | { |
| 1419 | D3D11_BUFFER_DESC constantBufferDescription = {0}; |
| 1420 | constantBufferDescription.ByteWidth = sizeof(dx_PixelConstants); |
| 1421 | constantBufferDescription.Usage = D3D11_USAGE_DEFAULT; |
| 1422 | constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
| 1423 | constantBufferDescription.CPUAccessFlags = 0; |
| 1424 | constantBufferDescription.MiscFlags = 0; |
| 1425 | constantBufferDescription.StructureByteStride = 0; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1426 | |
shannon.woods@transgaming.com | 5929ef2 | 2013-01-25 21:53:24 +0000 | [diff] [blame] | 1427 | HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferPS); |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1428 | ASSERT(SUCCEEDED(result)); |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1429 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1430 | mDeviceContext->PSSetConstantBuffers(1, 1, &mDriverConstantBufferPS); |
| 1431 | } |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1432 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1433 | if (memcmp(&mVertexConstants, &mAppliedVertexConstants, sizeof(dx_VertexConstants)) != 0) |
| 1434 | { |
| 1435 | mDeviceContext->UpdateSubresource(mDriverConstantBufferVS, 0, NULL, &mVertexConstants, 16, 0); |
| 1436 | memcpy(&mAppliedVertexConstants, &mVertexConstants, sizeof(dx_VertexConstants)); |
| 1437 | } |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 1438 | |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1439 | if (memcmp(&mPixelConstants, &mAppliedPixelConstants, sizeof(dx_PixelConstants)) != 0) |
| 1440 | { |
| 1441 | mDeviceContext->UpdateSubresource(mDriverConstantBufferPS, 0, NULL, &mPixelConstants, 16, 0); |
| 1442 | memcpy(&mAppliedPixelConstants, &mPixelConstants, sizeof(dx_PixelConstants)); |
| 1443 | } |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 1444 | |
| 1445 | // needed for the point sprite geometry shader |
| 1446 | mDeviceContext->GSSetConstantBuffers(0, 1, &mDriverConstantBufferPS); |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 1449 | void Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1450 | { |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1451 | bool alphaUnmasked = (gl::GetAlphaSize(mRenderTargetDesc.format) == 0) || clearParams.colorMaskAlpha; |
| 1452 | bool needMaskedColorClear = (clearParams.mask & GL_COLOR_BUFFER_BIT) && |
| 1453 | !(clearParams.colorMaskRed && clearParams.colorMaskGreen && |
| 1454 | clearParams.colorMaskBlue && alphaUnmasked); |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1455 | |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1456 | unsigned int stencilUnmasked = 0x0; |
| 1457 | if (frameBuffer->hasStencil()) |
| 1458 | { |
| 1459 | unsigned int stencilSize = gl::GetStencilSize(frameBuffer->getStencilbuffer()->getActualFormat()); |
| 1460 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 1461 | } |
| 1462 | bool needMaskedStencilClear = (clearParams.mask & GL_STENCIL_BUFFER_BIT) && |
| 1463 | (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1464 | |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1465 | bool needScissoredClear = mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 1466 | mCurScissor.x + mCurScissor.width < mRenderTargetDesc.width || |
| 1467 | mCurScissor.y + mCurScissor.height < mRenderTargetDesc.height); |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1468 | |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1469 | if (needMaskedColorClear || needMaskedStencilClear || needScissoredClear) |
| 1470 | { |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 1471 | maskedClear(clearParams); |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1472 | } |
| 1473 | else |
| 1474 | { |
| 1475 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 1476 | { |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 1477 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1478 | { |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 1479 | if (frameBuffer->isEnabledColorAttachment(colorAttachment)) |
| 1480 | { |
| 1481 | gl::Renderbuffer *renderbufferObject = frameBuffer->getColorbuffer(colorAttachment); |
| 1482 | if (renderbufferObject) |
| 1483 | { |
| 1484 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 1485 | if (!renderTarget) |
| 1486 | { |
| 1487 | ERR("render target pointer unexpectedly null."); |
| 1488 | return; |
| 1489 | } |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1490 | |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 1491 | ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView(); |
| 1492 | if (!framebufferRTV) |
| 1493 | { |
| 1494 | ERR("render target view pointer unexpectedly null."); |
| 1495 | return; |
| 1496 | } |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1497 | |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 1498 | const float clearValues[4] = { clearParams.colorClearValue.red, |
| 1499 | clearParams.colorClearValue.green, |
| 1500 | clearParams.colorClearValue.blue, |
| 1501 | clearParams.colorClearValue.alpha }; |
| 1502 | mDeviceContext->ClearRenderTargetView(framebufferRTV, clearValues); |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1503 | |
shannon.woods%transgaming.com@gtempaccount.com | dae2409 | 2013-04-13 03:31:31 +0000 | [diff] [blame] | 1504 | framebufferRTV->Release(); |
| 1505 | } |
| 1506 | } |
| 1507 | } |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1508 | } |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1509 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT || clearParams.mask & GL_STENCIL_BUFFER_BIT) |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1510 | { |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1511 | gl::Renderbuffer *renderbufferObject = frameBuffer->getDepthOrStencilbuffer(); |
| 1512 | if (renderbufferObject) |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1513 | { |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1514 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getDepthStencil()); |
| 1515 | if (!renderTarget) |
| 1516 | { |
| 1517 | ERR("render target pointer unexpectedly null."); |
| 1518 | return; |
| 1519 | } |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1520 | |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1521 | ID3D11DepthStencilView *framebufferDSV = renderTarget->getDepthStencilView(); |
| 1522 | if (!framebufferDSV) |
| 1523 | { |
| 1524 | ERR("depth stencil view pointer unexpectedly null."); |
| 1525 | return; |
| 1526 | } |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1527 | |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1528 | UINT clearFlags = 0; |
| 1529 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 1530 | { |
| 1531 | clearFlags |= D3D11_CLEAR_DEPTH; |
| 1532 | } |
| 1533 | if (clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 1534 | { |
| 1535 | clearFlags |= D3D11_CLEAR_STENCIL; |
| 1536 | } |
| 1537 | |
shannon.woods@transgaming.com | be211b3 | 2013-02-28 23:17:16 +0000 | [diff] [blame] | 1538 | float depthClear = gl::clamp01(clearParams.depthClearValue); |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1539 | UINT8 stencilClear = clearParams.stencilClearValue & 0x000000FF; |
| 1540 | |
| 1541 | mDeviceContext->ClearDepthStencilView(framebufferDSV, clearFlags, depthClear, stencilClear); |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1542 | |
shannon.woods@transgaming.com | 81c5ef9 | 2013-01-25 21:52:08 +0000 | [diff] [blame] | 1543 | framebufferDSV->Release(); |
| 1544 | } |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 1545 | } |
| 1546 | } |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 1549 | void Renderer11::maskedClear(const gl::ClearParameters &clearParams) |
| 1550 | { |
| 1551 | HRESULT result; |
| 1552 | |
| 1553 | if (!mClearResourcesInitialized) |
| 1554 | { |
| 1555 | ASSERT(!mClearVB && !mClearVS && !mClearPS && !mClearScissorRS && !mClearNoScissorRS); |
| 1556 | |
| 1557 | D3D11_BUFFER_DESC vbDesc; |
| 1558 | vbDesc.ByteWidth = sizeof(d3d11::PositionDepthColorVertex) * 4; |
| 1559 | vbDesc.Usage = D3D11_USAGE_DYNAMIC; |
| 1560 | vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; |
| 1561 | vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| 1562 | vbDesc.MiscFlags = 0; |
| 1563 | vbDesc.StructureByteStride = 0; |
| 1564 | |
| 1565 | result = mDevice->CreateBuffer(&vbDesc, NULL, &mClearVB); |
| 1566 | ASSERT(SUCCEEDED(result)); |
| 1567 | d3d11::SetDebugName(mClearVB, "Renderer11 masked clear vertex buffer"); |
| 1568 | |
| 1569 | D3D11_INPUT_ELEMENT_DESC quadLayout[] = |
| 1570 | { |
| 1571 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| 1572 | { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| 1573 | }; |
| 1574 | |
| 1575 | result = mDevice->CreateInputLayout(quadLayout, 2, g_VS_Clear, sizeof(g_VS_Clear), &mClearIL); |
| 1576 | ASSERT(SUCCEEDED(result)); |
| 1577 | d3d11::SetDebugName(mClearIL, "Renderer11 masked clear input layout"); |
| 1578 | |
| 1579 | result = mDevice->CreateVertexShader(g_VS_Clear, sizeof(g_VS_Clear), NULL, &mClearVS); |
| 1580 | ASSERT(SUCCEEDED(result)); |
| 1581 | d3d11::SetDebugName(mClearVS, "Renderer11 masked clear vertex shader"); |
| 1582 | |
| 1583 | result = mDevice->CreatePixelShader(g_PS_Clear, sizeof(g_PS_Clear), NULL, &mClearPS); |
| 1584 | ASSERT(SUCCEEDED(result)); |
| 1585 | d3d11::SetDebugName(mClearPS, "Renderer11 masked clear pixel shader"); |
| 1586 | |
| 1587 | D3D11_RASTERIZER_DESC rsScissorDesc; |
| 1588 | rsScissorDesc.FillMode = D3D11_FILL_SOLID; |
| 1589 | rsScissorDesc.CullMode = D3D11_CULL_NONE; |
| 1590 | rsScissorDesc.FrontCounterClockwise = FALSE; |
| 1591 | rsScissorDesc.DepthBias = 0; |
| 1592 | rsScissorDesc.DepthBiasClamp = 0.0f; |
| 1593 | rsScissorDesc.SlopeScaledDepthBias = 0.0f; |
| 1594 | rsScissorDesc.DepthClipEnable = FALSE; |
| 1595 | rsScissorDesc.ScissorEnable = TRUE; |
| 1596 | rsScissorDesc.MultisampleEnable = FALSE; |
| 1597 | rsScissorDesc.AntialiasedLineEnable = FALSE; |
| 1598 | |
| 1599 | result = mDevice->CreateRasterizerState(&rsScissorDesc, &mClearScissorRS); |
| 1600 | ASSERT(SUCCEEDED(result)); |
| 1601 | d3d11::SetDebugName(mClearScissorRS, "Renderer11 masked clear scissor rasterizer state"); |
| 1602 | |
| 1603 | D3D11_RASTERIZER_DESC rsNoScissorDesc; |
| 1604 | rsNoScissorDesc.FillMode = D3D11_FILL_SOLID; |
| 1605 | rsNoScissorDesc.CullMode = D3D11_CULL_NONE; |
| 1606 | rsNoScissorDesc.FrontCounterClockwise = FALSE; |
| 1607 | rsNoScissorDesc.DepthBias = 0; |
| 1608 | rsNoScissorDesc.DepthBiasClamp = 0.0f; |
| 1609 | rsNoScissorDesc.SlopeScaledDepthBias = 0.0f; |
| 1610 | rsNoScissorDesc.DepthClipEnable = FALSE; |
| 1611 | rsNoScissorDesc.ScissorEnable = FALSE; |
| 1612 | rsNoScissorDesc.MultisampleEnable = FALSE; |
| 1613 | rsNoScissorDesc.AntialiasedLineEnable = FALSE; |
| 1614 | |
| 1615 | result = mDevice->CreateRasterizerState(&rsNoScissorDesc, &mClearNoScissorRS); |
| 1616 | ASSERT(SUCCEEDED(result)); |
| 1617 | d3d11::SetDebugName(mClearNoScissorRS, "Renderer11 masked clear no scissor rasterizer state"); |
| 1618 | |
| 1619 | mClearResourcesInitialized = true; |
| 1620 | } |
| 1621 | |
| 1622 | // Prepare the depth stencil state to write depth values if the depth should be cleared |
| 1623 | // and stencil values if the stencil should be cleared |
| 1624 | gl::DepthStencilState glDSState; |
| 1625 | glDSState.depthTest = (clearParams.mask & GL_DEPTH_BUFFER_BIT) != 0; |
| 1626 | glDSState.depthFunc = GL_ALWAYS; |
| 1627 | glDSState.depthMask = (clearParams.mask & GL_DEPTH_BUFFER_BIT) != 0; |
| 1628 | glDSState.stencilTest = (clearParams.mask & GL_STENCIL_BUFFER_BIT) != 0; |
| 1629 | glDSState.stencilFunc = GL_ALWAYS; |
| 1630 | glDSState.stencilMask = 0; |
| 1631 | glDSState.stencilFail = GL_REPLACE; |
| 1632 | glDSState.stencilPassDepthFail = GL_REPLACE; |
| 1633 | glDSState.stencilPassDepthPass = GL_REPLACE; |
| 1634 | glDSState.stencilWritemask = clearParams.stencilWriteMask; |
| 1635 | glDSState.stencilBackFunc = GL_ALWAYS; |
| 1636 | glDSState.stencilBackMask = 0; |
| 1637 | glDSState.stencilBackFail = GL_REPLACE; |
| 1638 | glDSState.stencilBackPassDepthFail = GL_REPLACE; |
| 1639 | glDSState.stencilBackPassDepthPass = GL_REPLACE; |
| 1640 | glDSState.stencilBackWritemask = clearParams.stencilWriteMask; |
| 1641 | |
| 1642 | int stencilClear = clearParams.stencilClearValue & 0x000000FF; |
| 1643 | |
| 1644 | ID3D11DepthStencilState *dsState = mStateCache.getDepthStencilState(glDSState); |
| 1645 | |
| 1646 | // Prepare the blend state to use a write mask if the color buffer should be cleared |
| 1647 | gl::BlendState glBlendState; |
| 1648 | glBlendState.blend = false; |
| 1649 | glBlendState.sourceBlendRGB = GL_ONE; |
| 1650 | glBlendState.destBlendRGB = GL_ZERO; |
| 1651 | glBlendState.sourceBlendAlpha = GL_ONE; |
| 1652 | glBlendState.destBlendAlpha = GL_ZERO; |
| 1653 | glBlendState.blendEquationRGB = GL_FUNC_ADD; |
| 1654 | glBlendState.blendEquationAlpha = GL_FUNC_ADD; |
| 1655 | glBlendState.colorMaskRed = (clearParams.mask & GL_COLOR_BUFFER_BIT) ? clearParams.colorMaskRed : false; |
| 1656 | glBlendState.colorMaskGreen = (clearParams.mask & GL_COLOR_BUFFER_BIT) ? clearParams.colorMaskGreen : false; |
| 1657 | glBlendState.colorMaskBlue = (clearParams.mask & GL_COLOR_BUFFER_BIT) ? clearParams.colorMaskBlue : false; |
shannon.woods@transgaming.com | 50ea993 | 2013-02-28 23:13:40 +0000 | [diff] [blame] | 1658 | glBlendState.colorMaskAlpha = (clearParams.mask & GL_COLOR_BUFFER_BIT) ? clearParams.colorMaskAlpha : false; |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 1659 | glBlendState.sampleAlphaToCoverage = false; |
| 1660 | glBlendState.dither = false; |
| 1661 | |
| 1662 | static const float blendFactors[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; |
| 1663 | static const UINT sampleMask = 0xFFFFFFFF; |
| 1664 | |
| 1665 | ID3D11BlendState *blendState = mStateCache.getBlendState(glBlendState); |
| 1666 | |
| 1667 | // Set the vertices |
| 1668 | D3D11_MAPPED_SUBRESOURCE mappedResource; |
| 1669 | result = mDeviceContext->Map(mClearVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); |
| 1670 | if (FAILED(result)) |
| 1671 | { |
| 1672 | ERR("Failed to map masked clear vertex buffer, HRESULT: 0x%X.", result); |
| 1673 | return; |
| 1674 | } |
| 1675 | |
| 1676 | d3d11::PositionDepthColorVertex *vertices = reinterpret_cast<d3d11::PositionDepthColorVertex*>(mappedResource.pData); |
| 1677 | |
| 1678 | float depthClear = gl::clamp01(clearParams.depthClearValue); |
| 1679 | d3d11::SetPositionDepthColorVertex(&vertices[0], -1.0f, 1.0f, depthClear, clearParams.colorClearValue); |
| 1680 | d3d11::SetPositionDepthColorVertex(&vertices[1], -1.0f, -1.0f, depthClear, clearParams.colorClearValue); |
| 1681 | d3d11::SetPositionDepthColorVertex(&vertices[2], 1.0f, 1.0f, depthClear, clearParams.colorClearValue); |
| 1682 | d3d11::SetPositionDepthColorVertex(&vertices[3], 1.0f, -1.0f, depthClear, clearParams.colorClearValue); |
| 1683 | |
| 1684 | mDeviceContext->Unmap(mClearVB, 0); |
| 1685 | |
| 1686 | // Apply state |
| 1687 | mDeviceContext->OMSetBlendState(blendState, blendFactors, sampleMask); |
| 1688 | mDeviceContext->OMSetDepthStencilState(dsState, stencilClear); |
| 1689 | mDeviceContext->RSSetState(mScissorEnabled ? mClearScissorRS : mClearNoScissorRS); |
| 1690 | |
| 1691 | // Apply shaders |
| 1692 | mDeviceContext->IASetInputLayout(mClearIL); |
| 1693 | mDeviceContext->VSSetShader(mClearVS, NULL, 0); |
| 1694 | mDeviceContext->PSSetShader(mClearPS, NULL, 0); |
shannon.woods@transgaming.com | 2c53e47 | 2013-02-28 23:13:56 +0000 | [diff] [blame] | 1695 | mDeviceContext->GSSetShader(NULL, NULL, 0); |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 1696 | |
| 1697 | // Apply vertex buffer |
| 1698 | static UINT stride = sizeof(d3d11::PositionDepthColorVertex); |
| 1699 | static UINT startIdx = 0; |
| 1700 | mDeviceContext->IASetVertexBuffers(0, 1, &mClearVB, &stride, &startIdx); |
| 1701 | mDeviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); |
| 1702 | |
| 1703 | // Draw the clear quad |
| 1704 | mDeviceContext->Draw(4, 0); |
| 1705 | |
| 1706 | // Clean up |
| 1707 | markAllStateDirty(); |
| 1708 | } |
| 1709 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1710 | void Renderer11::markAllStateDirty() |
| 1711 | { |
shannon.woods%transgaming.com@gtempaccount.com | f4fe710 | 2013-04-13 03:30:26 +0000 | [diff] [blame] | 1712 | for (unsigned int rtIndex = 0; rtIndex < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; rtIndex++) |
| 1713 | { |
| 1714 | mAppliedRenderTargetSerials[rtIndex] = 0; |
| 1715 | } |
daniel@transgaming.com | 9a06737 | 2012-12-20 20:55:24 +0000 | [diff] [blame] | 1716 | mAppliedDepthbufferSerial = 0; |
| 1717 | mAppliedStencilbufferSerial = 0; |
daniel@transgaming.com | 7b6b83e | 2012-11-28 21:00:30 +0000 | [diff] [blame] | 1718 | mDepthStencilInitialized = false; |
| 1719 | mRenderTargetDescInitialized = false; |
| 1720 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 1721 | for (int i = 0; i < gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS; i++) |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 1722 | { |
| 1723 | mForceSetVertexSamplerStates[i] = true; |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 1724 | mCurVertexTextureSerials[i] = 0; |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 1725 | } |
| 1726 | for (int i = 0; i < gl::MAX_TEXTURE_IMAGE_UNITS; i++) |
| 1727 | { |
| 1728 | mForceSetPixelSamplerStates[i] = true; |
daniel@transgaming.com | e33c8bf | 2013-01-11 04:11:33 +0000 | [diff] [blame] | 1729 | mCurPixelTextureSerials[i] = 0; |
daniel@transgaming.com | 54de24f | 2013-01-11 04:07:59 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1732 | mForceSetBlendState = true; |
| 1733 | mForceSetRasterState = true; |
| 1734 | mForceSetDepthStencilState = true; |
| 1735 | mForceSetScissor = true; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 1736 | mForceSetViewport = true; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1737 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1738 | mAppliedIBSerial = 0; |
shannon.woods@transgaming.com | a1229a3 | 2013-02-28 23:08:40 +0000 | [diff] [blame] | 1739 | mAppliedStorageIBSerial = 0; |
daniel@transgaming.com | 7fbf486 | 2013-01-11 04:09:22 +0000 | [diff] [blame] | 1740 | mAppliedIBOffset = 0; |
| 1741 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1742 | mAppliedProgramBinarySerial = 0; |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1743 | memset(&mAppliedVertexConstants, 0, sizeof(dx_VertexConstants)); |
| 1744 | memset(&mAppliedPixelConstants, 0, sizeof(dx_PixelConstants)); |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1747 | void Renderer11::releaseDeviceResources() |
| 1748 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 1749 | mStateCache.clear(); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1750 | mInputLayoutCache.clear(); |
| 1751 | |
| 1752 | delete mVertexDataManager; |
| 1753 | mVertexDataManager = NULL; |
| 1754 | |
| 1755 | delete mIndexDataManager; |
| 1756 | mIndexDataManager = NULL; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1757 | |
| 1758 | delete mLineLoopIB; |
| 1759 | mLineLoopIB = NULL; |
daniel@transgaming.com | 4fd1f98 | 2013-01-11 04:12:58 +0000 | [diff] [blame] | 1760 | |
| 1761 | delete mTriangleFanIB; |
| 1762 | mTriangleFanIB = NULL; |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 1763 | |
| 1764 | if (mCopyVB) |
| 1765 | { |
| 1766 | mCopyVB->Release(); |
| 1767 | mCopyVB = NULL; |
| 1768 | } |
| 1769 | |
| 1770 | if (mCopySampler) |
| 1771 | { |
| 1772 | mCopySampler->Release(); |
| 1773 | mCopySampler = NULL; |
| 1774 | } |
| 1775 | |
| 1776 | if (mCopyIL) |
| 1777 | { |
| 1778 | mCopyIL->Release(); |
| 1779 | mCopyIL = NULL; |
| 1780 | } |
| 1781 | |
| 1782 | if (mCopyVS) |
| 1783 | { |
| 1784 | mCopyVS->Release(); |
| 1785 | mCopyVS = NULL; |
| 1786 | } |
| 1787 | |
| 1788 | if (mCopyRGBAPS) |
| 1789 | { |
| 1790 | mCopyRGBAPS->Release(); |
| 1791 | mCopyRGBAPS = NULL; |
| 1792 | } |
| 1793 | |
| 1794 | if (mCopyRGBPS) |
| 1795 | { |
| 1796 | mCopyRGBPS->Release(); |
| 1797 | mCopyRGBPS = NULL; |
| 1798 | } |
| 1799 | |
| 1800 | if (mCopyLumPS) |
| 1801 | { |
| 1802 | mCopyLumPS->Release(); |
| 1803 | mCopyLumPS = NULL; |
| 1804 | } |
| 1805 | |
| 1806 | if (mCopyLumAlphaPS) |
| 1807 | { |
| 1808 | mCopyLumAlphaPS->Release(); |
| 1809 | mCopyLumAlphaPS = NULL; |
| 1810 | } |
| 1811 | |
| 1812 | mCopyResourcesInitialized = false; |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 1813 | |
| 1814 | if (mClearVB) |
| 1815 | { |
| 1816 | mClearVB->Release(); |
| 1817 | mClearVB = NULL; |
| 1818 | } |
| 1819 | |
| 1820 | if (mClearIL) |
| 1821 | { |
| 1822 | mClearIL->Release(); |
| 1823 | mClearIL = NULL; |
| 1824 | } |
| 1825 | |
| 1826 | if (mClearVS) |
| 1827 | { |
| 1828 | mClearVS->Release(); |
| 1829 | mClearVS = NULL; |
| 1830 | } |
| 1831 | |
| 1832 | if (mClearPS) |
| 1833 | { |
| 1834 | mClearPS->Release(); |
| 1835 | mClearPS = NULL; |
| 1836 | } |
| 1837 | |
| 1838 | if (mClearScissorRS) |
| 1839 | { |
| 1840 | mClearScissorRS->Release(); |
| 1841 | mClearScissorRS = NULL; |
| 1842 | } |
| 1843 | |
| 1844 | if (mClearNoScissorRS) |
| 1845 | { |
| 1846 | mClearNoScissorRS->Release(); |
| 1847 | mClearNoScissorRS = NULL; |
| 1848 | } |
| 1849 | |
| 1850 | mClearResourcesInitialized = false; |
shannon.woods@transgaming.com | 5fb979d | 2013-01-25 21:53:04 +0000 | [diff] [blame] | 1851 | |
| 1852 | if (mDriverConstantBufferVS) |
| 1853 | { |
| 1854 | mDriverConstantBufferVS->Release(); |
| 1855 | mDriverConstantBufferVS = NULL; |
| 1856 | } |
| 1857 | |
| 1858 | if (mDriverConstantBufferPS) |
| 1859 | { |
| 1860 | mDriverConstantBufferPS->Release(); |
| 1861 | mDriverConstantBufferPS = NULL; |
| 1862 | } |
daniel@transgaming.com | bdf787f | 2013-02-01 03:20:36 +0000 | [diff] [blame] | 1863 | |
| 1864 | if (mSyncQuery) |
| 1865 | { |
| 1866 | mSyncQuery->Release(); |
| 1867 | mSyncQuery = NULL; |
| 1868 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 1871 | void Renderer11::notifyDeviceLost() |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1872 | { |
| 1873 | mDeviceLost = true; |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 1874 | mDisplay->notifyDeviceLost(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | bool Renderer11::isDeviceLost() |
| 1878 | { |
| 1879 | return mDeviceLost; |
| 1880 | } |
| 1881 | |
| 1882 | // set notify to true to broadcast a message to all contexts of the device loss |
| 1883 | bool Renderer11::testDeviceLost(bool notify) |
| 1884 | { |
| 1885 | bool isLost = false; |
| 1886 | |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1887 | // GetRemovedReason is used to test if the device is removed |
| 1888 | HRESULT result = mDevice->GetDeviceRemovedReason(); |
| 1889 | isLost = d3d11::isDeviceLostError(result); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1890 | |
| 1891 | if (isLost) |
| 1892 | { |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1893 | // Log error if this is a new device lost event |
| 1894 | if (mDeviceLost == false) |
| 1895 | { |
| 1896 | ERR("The D3D11 device was removed: 0x%08X", result); |
| 1897 | } |
| 1898 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1899 | // ensure we note the device loss -- |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 1900 | // we'll probably get this done again by notifyDeviceLost |
| 1901 | // but best to remember it! |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1902 | // Note that we don't want to clear the device loss status here |
| 1903 | // -- this needs to be done by resetDevice |
| 1904 | mDeviceLost = true; |
| 1905 | if (notify) |
| 1906 | { |
shannon.woods@transgaming.com | eb049e2 | 2013-02-28 23:04:49 +0000 | [diff] [blame] | 1907 | notifyDeviceLost(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | return isLost; |
| 1912 | } |
| 1913 | |
| 1914 | bool Renderer11::testDeviceResettable() |
| 1915 | { |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1916 | // determine if the device is resettable by creating a dummy device |
| 1917 | PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1918 | |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1919 | if (D3D11CreateDevice == NULL) |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1920 | { |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1921 | return false; |
| 1922 | } |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1923 | |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 1924 | D3D_FEATURE_LEVEL featureLevels[] = |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1925 | { |
| 1926 | D3D_FEATURE_LEVEL_11_0, |
| 1927 | D3D_FEATURE_LEVEL_10_1, |
| 1928 | D3D_FEATURE_LEVEL_10_0, |
| 1929 | }; |
| 1930 | |
| 1931 | ID3D11Device* dummyDevice; |
| 1932 | D3D_FEATURE_LEVEL dummyFeatureLevel; |
| 1933 | ID3D11DeviceContext* dummyContext; |
| 1934 | |
| 1935 | HRESULT result = D3D11CreateDevice(NULL, |
| 1936 | D3D_DRIVER_TYPE_HARDWARE, |
| 1937 | NULL, |
| 1938 | #if defined(_DEBUG) |
| 1939 | D3D11_CREATE_DEVICE_DEBUG, |
| 1940 | #else |
| 1941 | 0, |
| 1942 | #endif |
shannon.woods@transgaming.com | d438fd4 | 2013-02-28 23:17:45 +0000 | [diff] [blame] | 1943 | featureLevels, |
| 1944 | ArraySize(featureLevels), |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 1945 | D3D11_SDK_VERSION, |
| 1946 | &dummyDevice, |
| 1947 | &dummyFeatureLevel, |
| 1948 | &dummyContext); |
| 1949 | |
| 1950 | if (!mDevice || FAILED(result)) |
| 1951 | { |
| 1952 | return false; |
| 1953 | } |
| 1954 | |
| 1955 | dummyContext->Release(); |
| 1956 | dummyDevice->Release(); |
| 1957 | |
| 1958 | return true; |
| 1959 | } |
| 1960 | |
| 1961 | void Renderer11::release() |
| 1962 | { |
| 1963 | releaseDeviceResources(); |
| 1964 | |
| 1965 | if (mDxgiFactory) |
| 1966 | { |
| 1967 | mDxgiFactory->Release(); |
| 1968 | mDxgiFactory = NULL; |
| 1969 | } |
| 1970 | |
| 1971 | if (mDxgiAdapter) |
| 1972 | { |
| 1973 | mDxgiAdapter->Release(); |
| 1974 | mDxgiAdapter = NULL; |
| 1975 | } |
| 1976 | |
| 1977 | if (mDeviceContext) |
| 1978 | { |
| 1979 | mDeviceContext->ClearState(); |
| 1980 | mDeviceContext->Flush(); |
| 1981 | mDeviceContext->Release(); |
| 1982 | mDeviceContext = NULL; |
| 1983 | } |
| 1984 | |
| 1985 | if (mDevice) |
| 1986 | { |
| 1987 | mDevice->Release(); |
| 1988 | mDevice = NULL; |
| 1989 | } |
| 1990 | |
| 1991 | if (mD3d11Module) |
| 1992 | { |
| 1993 | FreeLibrary(mD3d11Module); |
| 1994 | mD3d11Module = NULL; |
| 1995 | } |
| 1996 | |
| 1997 | if (mDxgiModule) |
| 1998 | { |
| 1999 | FreeLibrary(mDxgiModule); |
| 2000 | mDxgiModule = NULL; |
| 2001 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | bool Renderer11::resetDevice() |
| 2005 | { |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 2006 | // recreate everything |
| 2007 | release(); |
| 2008 | EGLint result = initialize(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2009 | |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 2010 | if (result != EGL_SUCCESS) |
| 2011 | { |
| 2012 | ERR("Could not reinitialize D3D11 device: %08X", result); |
| 2013 | return false; |
| 2014 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2015 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2016 | mDeviceLost = false; |
| 2017 | |
| 2018 | return true; |
| 2019 | } |
| 2020 | |
| 2021 | DWORD Renderer11::getAdapterVendor() const |
| 2022 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 2023 | return mAdapterDescription.VendorId; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2026 | std::string Renderer11::getRendererDescription() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2027 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2028 | std::ostringstream rendererString; |
| 2029 | |
| 2030 | rendererString << mDescription; |
| 2031 | rendererString << " Direct3D11"; |
| 2032 | |
| 2033 | rendererString << " vs_" << getMajorShaderModel() << "_" << getMinorShaderModel(); |
| 2034 | rendererString << " ps_" << getMajorShaderModel() << "_" << getMinorShaderModel(); |
| 2035 | |
| 2036 | return rendererString.str(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | GUID Renderer11::getAdapterIdentifier() const |
| 2040 | { |
shannon.woods@transgaming.com | 43db795 | 2013-02-28 23:04:28 +0000 | [diff] [blame] | 2041 | // Use the adapter LUID as our adapter ID |
| 2042 | // This number is local to a machine is only guaranteed to be unique between restarts |
| 2043 | META_ASSERT(sizeof(LUID) <= sizeof(GUID)); |
| 2044 | GUID adapterId = {0}; |
| 2045 | memcpy(&adapterId, &mAdapterDescription.AdapterLuid, sizeof(LUID)); |
| 2046 | return adapterId; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
shannon.woods@transgaming.com | bec04bf | 2013-01-25 21:53:52 +0000 | [diff] [blame] | 2049 | bool Renderer11::getBGRATextureSupport() const |
| 2050 | { |
| 2051 | return mBGRATextureSupport; |
| 2052 | } |
| 2053 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2054 | bool Renderer11::getDXT1TextureSupport() |
| 2055 | { |
shannon.woods@transgaming.com | 09f326b | 2013-02-28 23:13:34 +0000 | [diff] [blame] | 2056 | return mDXT1TextureSupport; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | bool Renderer11::getDXT3TextureSupport() |
| 2060 | { |
shannon.woods@transgaming.com | 09f326b | 2013-02-28 23:13:34 +0000 | [diff] [blame] | 2061 | return mDXT3TextureSupport; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | bool Renderer11::getDXT5TextureSupport() |
| 2065 | { |
shannon.woods@transgaming.com | 09f326b | 2013-02-28 23:13:34 +0000 | [diff] [blame] | 2066 | return mDXT5TextureSupport; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | bool Renderer11::getDepthTextureSupport() const |
| 2070 | { |
shannon.woods@transgaming.com | cf103f3 | 2013-02-28 23:18:45 +0000 | [diff] [blame] | 2071 | return mDepthTextureSupport; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | bool Renderer11::getFloat32TextureSupport(bool *filtering, bool *renderable) |
| 2075 | { |
shannon.woods@transgaming.com | 9cdced6 | 2013-02-28 23:07:31 +0000 | [diff] [blame] | 2076 | *renderable = mFloat32RenderSupport; |
| 2077 | *filtering = mFloat32FilterSupport; |
| 2078 | return mFloat32TextureSupport; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | bool Renderer11::getFloat16TextureSupport(bool *filtering, bool *renderable) |
| 2082 | { |
shannon.woods@transgaming.com | 9cdced6 | 2013-02-28 23:07:31 +0000 | [diff] [blame] | 2083 | *renderable = mFloat16RenderSupport; |
| 2084 | *filtering = mFloat16FilterSupport; |
| 2085 | return mFloat16TextureSupport; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | bool Renderer11::getLuminanceTextureSupport() |
| 2089 | { |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2090 | return false; |
| 2091 | } |
| 2092 | |
| 2093 | bool Renderer11::getLuminanceAlphaTextureSupport() |
| 2094 | { |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2095 | return false; |
| 2096 | } |
| 2097 | |
| 2098 | bool Renderer11::getTextureFilterAnisotropySupport() const |
| 2099 | { |
shannon.woods@transgaming.com | 1abd797 | 2013-02-28 23:06:58 +0000 | [diff] [blame] | 2100 | return true; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | float Renderer11::getTextureMaxAnisotropy() const |
| 2104 | { |
shannon.woods@transgaming.com | 1abd797 | 2013-02-28 23:06:58 +0000 | [diff] [blame] | 2105 | switch (mFeatureLevel) |
| 2106 | { |
| 2107 | case D3D_FEATURE_LEVEL_11_0: |
| 2108 | return D3D11_MAX_MAXANISOTROPY; |
| 2109 | case D3D_FEATURE_LEVEL_10_1: |
| 2110 | case D3D_FEATURE_LEVEL_10_0: |
| 2111 | return D3D10_MAX_MAXANISOTROPY; |
| 2112 | default: UNREACHABLE(); |
| 2113 | return 0; |
| 2114 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | bool Renderer11::getEventQuerySupport() |
| 2118 | { |
shannon.woods@transgaming.com | be58aa0 | 2013-02-28 23:03:55 +0000 | [diff] [blame] | 2119 | return true; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2122 | Range Renderer11::getViewportBounds() const |
| 2123 | { |
| 2124 | switch (mFeatureLevel) |
| 2125 | { |
| 2126 | case D3D_FEATURE_LEVEL_11_0: |
| 2127 | return Range(D3D11_VIEWPORT_BOUNDS_MIN, D3D11_VIEWPORT_BOUNDS_MAX); |
| 2128 | case D3D_FEATURE_LEVEL_10_1: |
| 2129 | case D3D_FEATURE_LEVEL_10_0: |
| 2130 | return Range(D3D10_VIEWPORT_BOUNDS_MIN, D3D10_VIEWPORT_BOUNDS_MAX); |
| 2131 | default: UNREACHABLE(); |
| 2132 | return Range(0, 0); |
| 2133 | } |
| 2134 | } |
| 2135 | |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 2136 | unsigned int Renderer11::getMaxVertexTextureImageUnits() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2137 | { |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 2138 | META_ASSERT(MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 <= gl::IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS); |
| 2139 | switch (mFeatureLevel) |
| 2140 | { |
| 2141 | case D3D_FEATURE_LEVEL_11_0: |
| 2142 | case D3D_FEATURE_LEVEL_10_1: |
| 2143 | case D3D_FEATURE_LEVEL_10_0: |
| 2144 | return MAX_TEXTURE_IMAGE_UNITS_VTF_SM4; |
| 2145 | default: UNREACHABLE(); |
| 2146 | return 0; |
| 2147 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
shannon.woods@transgaming.com | 76cd88c | 2013-01-25 21:54:36 +0000 | [diff] [blame] | 2150 | unsigned int Renderer11::getMaxCombinedTextureImageUnits() const |
| 2151 | { |
| 2152 | return gl::MAX_TEXTURE_IMAGE_UNITS + getMaxVertexTextureImageUnits(); |
| 2153 | } |
| 2154 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2155 | unsigned int Renderer11::getReservedVertexUniformVectors() const |
| 2156 | { |
| 2157 | return 0; // Driver uniforms are stored in a separate constant buffer |
| 2158 | } |
| 2159 | |
| 2160 | unsigned int Renderer11::getReservedFragmentUniformVectors() const |
| 2161 | { |
| 2162 | return 0; // Driver uniforms are stored in a separate constant buffer |
| 2163 | } |
| 2164 | |
| 2165 | unsigned int Renderer11::getMaxVertexUniformVectors() const |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2166 | { |
shannon.woods@transgaming.com | 4e48204 | 2013-01-25 21:54:18 +0000 | [diff] [blame] | 2167 | META_ASSERT(MAX_VERTEX_UNIFORM_VECTORS_D3D11 <= D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT); |
| 2168 | ASSERT(mFeatureLevel >= D3D_FEATURE_LEVEL_10_0); |
| 2169 | return MAX_VERTEX_UNIFORM_VECTORS_D3D11; |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2172 | unsigned int Renderer11::getMaxFragmentUniformVectors() const |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2173 | { |
shannon.woods@transgaming.com | 4e48204 | 2013-01-25 21:54:18 +0000 | [diff] [blame] | 2174 | META_ASSERT(MAX_FRAGMENT_UNIFORM_VECTORS_D3D11 <= D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT); |
| 2175 | ASSERT(mFeatureLevel >= D3D_FEATURE_LEVEL_10_0); |
| 2176 | return MAX_FRAGMENT_UNIFORM_VECTORS_D3D11; |
shannon.woods@transgaming.com | 254317d | 2013-01-25 21:54:09 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
shannon.woods@transgaming.com | d8136cb | 2013-02-28 23:14:44 +0000 | [diff] [blame] | 2179 | unsigned int Renderer11::getMaxVaryingVectors() const |
shannon.woods@transgaming.com | 28d268e | 2013-01-25 21:54:26 +0000 | [diff] [blame] | 2180 | { |
| 2181 | META_ASSERT(gl::IMPLEMENTATION_MAX_VARYING_VECTORS == D3D11_VS_OUTPUT_REGISTER_COUNT); |
| 2182 | switch (mFeatureLevel) |
| 2183 | { |
| 2184 | case D3D_FEATURE_LEVEL_11_0: |
| 2185 | return D3D11_VS_OUTPUT_REGISTER_COUNT; |
| 2186 | case D3D_FEATURE_LEVEL_10_1: |
| 2187 | case D3D_FEATURE_LEVEL_10_0: |
| 2188 | return D3D10_VS_OUTPUT_REGISTER_COUNT; |
| 2189 | default: UNREACHABLE(); |
| 2190 | return 0; |
| 2191 | } |
| 2192 | } |
| 2193 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 2194 | unsigned int Renderer11::getMaxVertexShaderUniformBuffers() const |
| 2195 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 2196 | META_ASSERT(gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS >= D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT && |
| 2197 | gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS >= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); |
| 2198 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 2199 | switch (mFeatureLevel) |
| 2200 | { |
| 2201 | case D3D_FEATURE_LEVEL_11_0: |
| 2202 | return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; |
| 2203 | case D3D_FEATURE_LEVEL_10_1: |
| 2204 | case D3D_FEATURE_LEVEL_10_0: |
| 2205 | return D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; |
| 2206 | default: UNREACHABLE(); |
| 2207 | return 0; |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | unsigned int Renderer11::getMaxFragmentShaderUniformBuffers() const |
| 2212 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 2213 | META_ASSERT(gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS >= D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT && |
| 2214 | gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS >= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); |
| 2215 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 2216 | switch (mFeatureLevel) |
| 2217 | { |
| 2218 | case D3D_FEATURE_LEVEL_11_0: |
| 2219 | return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; |
| 2220 | case D3D_FEATURE_LEVEL_10_1: |
| 2221 | case D3D_FEATURE_LEVEL_10_0: |
| 2222 | return D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; |
| 2223 | default: UNREACHABLE(); |
| 2224 | return 0; |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | unsigned int Renderer11::getMaxTransformFeedbackBuffers() const |
| 2229 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 2230 | META_ASSERT(gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS >= D3D11_SO_BUFFER_SLOT_COUNT && |
| 2231 | gl::IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS >= D3D10_SO_BUFFER_SLOT_COUNT); |
| 2232 | |
shannon.woods%transgaming.com@gtempaccount.com | 3f72ce3 | 2013-04-13 03:36:43 +0000 | [diff] [blame] | 2233 | switch (mFeatureLevel) |
| 2234 | { |
| 2235 | case D3D_FEATURE_LEVEL_11_0: |
| 2236 | return D3D11_SO_BUFFER_SLOT_COUNT; |
| 2237 | case D3D_FEATURE_LEVEL_10_1: |
| 2238 | case D3D_FEATURE_LEVEL_10_0: |
| 2239 | return D3D10_SO_BUFFER_SLOT_COUNT; |
| 2240 | default: UNREACHABLE(); |
| 2241 | return 0; |
| 2242 | } |
| 2243 | } |
| 2244 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2245 | bool Renderer11::getNonPower2TextureSupport() const |
| 2246 | { |
shannon.woods@transgaming.com | 03951cf | 2013-01-25 21:57:01 +0000 | [diff] [blame] | 2247 | switch (mFeatureLevel) |
| 2248 | { |
| 2249 | case D3D_FEATURE_LEVEL_11_0: |
| 2250 | case D3D_FEATURE_LEVEL_10_1: |
| 2251 | case D3D_FEATURE_LEVEL_10_0: |
| 2252 | return true; |
| 2253 | default: UNREACHABLE(); |
| 2254 | return false; |
| 2255 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | bool Renderer11::getOcclusionQuerySupport() const |
| 2259 | { |
shannon.woods@transgaming.com | 8b7606a | 2013-02-28 23:03:47 +0000 | [diff] [blame] | 2260 | switch (mFeatureLevel) |
| 2261 | { |
| 2262 | case D3D_FEATURE_LEVEL_11_0: |
| 2263 | case D3D_FEATURE_LEVEL_10_1: |
| 2264 | case D3D_FEATURE_LEVEL_10_0: |
| 2265 | return true; |
| 2266 | default: UNREACHABLE(); |
| 2267 | return false; |
| 2268 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | bool Renderer11::getInstancingSupport() const |
| 2272 | { |
daniel@transgaming.com | fe32464 | 2013-02-01 03:20:11 +0000 | [diff] [blame] | 2273 | switch (mFeatureLevel) |
| 2274 | { |
| 2275 | case D3D_FEATURE_LEVEL_11_0: |
| 2276 | case D3D_FEATURE_LEVEL_10_1: |
| 2277 | case D3D_FEATURE_LEVEL_10_0: |
| 2278 | return true; |
| 2279 | default: UNREACHABLE(); |
| 2280 | return false; |
| 2281 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | bool Renderer11::getShareHandleSupport() const |
| 2285 | { |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 2286 | // We only currently support share handles with BGRA surfaces, because |
| 2287 | // chrome needs BGRA. Once chrome fixes this, we should always support them. |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2288 | // PIX doesn't seem to support using share handles, so disable them. |
shannon.woods@transgaming.com | c60c521 | 2013-01-25 21:54:01 +0000 | [diff] [blame] | 2289 | return getBGRATextureSupport() && !gl::perfActive(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
daniel@transgaming.com | 7629bb6 | 2013-01-11 04:12:28 +0000 | [diff] [blame] | 2292 | bool Renderer11::getDerivativeInstructionSupport() const |
| 2293 | { |
shannon.woods@transgaming.com | 09fd945 | 2013-02-28 23:02:28 +0000 | [diff] [blame] | 2294 | switch (mFeatureLevel) |
| 2295 | { |
| 2296 | case D3D_FEATURE_LEVEL_11_0: |
| 2297 | case D3D_FEATURE_LEVEL_10_1: |
| 2298 | case D3D_FEATURE_LEVEL_10_0: |
| 2299 | return true; |
| 2300 | default: UNREACHABLE(); |
| 2301 | return false; |
| 2302 | } |
daniel@transgaming.com | 7629bb6 | 2013-01-11 04:12:28 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
shannon.woods@transgaming.com | 8d2f086 | 2013-02-28 23:09:19 +0000 | [diff] [blame] | 2305 | bool Renderer11::getPostSubBufferSupport() const |
| 2306 | { |
| 2307 | // D3D11 does not support present with dirty rectangles until D3D11.1 and DXGI 1.2. |
| 2308 | return false; |
| 2309 | } |
| 2310 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2311 | int Renderer11::getMajorShaderModel() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2312 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2313 | switch (mFeatureLevel) |
| 2314 | { |
| 2315 | case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MAJOR_VERSION; // 5 |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2316 | case D3D_FEATURE_LEVEL_10_1: return D3D10_1_SHADER_MAJOR_VERSION; // 4 |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 2317 | case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MAJOR_VERSION; // 4 |
| 2318 | default: UNREACHABLE(); return 0; |
| 2319 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2322 | int Renderer11::getMinorShaderModel() const |
| 2323 | { |
| 2324 | switch (mFeatureLevel) |
| 2325 | { |
| 2326 | case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MINOR_VERSION; // 0 |
| 2327 | case D3D_FEATURE_LEVEL_10_1: return D3D10_1_SHADER_MINOR_VERSION; // 1 |
| 2328 | case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MINOR_VERSION; // 0 |
| 2329 | default: UNREACHABLE(); return 0; |
| 2330 | } |
| 2331 | } |
| 2332 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2333 | float Renderer11::getMaxPointSize() const |
| 2334 | { |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2335 | // choose a reasonable maximum. we enforce this in the shader. |
| 2336 | // (nb: on a Radeon 2600xt, DX9 reports a 256 max point size) |
| 2337 | return 1024.0f; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2340 | int Renderer11::getMaxViewportDimension() const |
| 2341 | { |
shannon.woods@transgaming.com | fd86c2c | 2013-02-28 23:13:07 +0000 | [diff] [blame] | 2342 | // Maximum viewport size must be at least as large as the largest render buffer (or larger). |
| 2343 | // In our case return the maximum texture size, which is the maximum render buffer size. |
| 2344 | META_ASSERT(D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION * 2 - 1 <= D3D11_VIEWPORT_BOUNDS_MAX); |
| 2345 | META_ASSERT(D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION * 2 - 1 <= D3D10_VIEWPORT_BOUNDS_MAX); |
| 2346 | |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2347 | switch (mFeatureLevel) |
| 2348 | { |
| 2349 | case D3D_FEATURE_LEVEL_11_0: |
shannon.woods@transgaming.com | fd86c2c | 2013-02-28 23:13:07 +0000 | [diff] [blame] | 2350 | return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2351 | case D3D_FEATURE_LEVEL_10_1: |
| 2352 | case D3D_FEATURE_LEVEL_10_0: |
shannon.woods@transgaming.com | fd86c2c | 2013-02-28 23:13:07 +0000 | [diff] [blame] | 2353 | return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
shannon.woods@transgaming.com | 8ce2f8f | 2013-02-28 23:07:10 +0000 | [diff] [blame] | 2354 | default: UNREACHABLE(); |
| 2355 | return 0; |
| 2356 | } |
| 2357 | } |
| 2358 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2359 | int Renderer11::getMaxTextureWidth() const |
| 2360 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 2361 | switch (mFeatureLevel) |
| 2362 | { |
| 2363 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 2364 | case D3D_FEATURE_LEVEL_10_1: |
| 2365 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 2366 | default: UNREACHABLE(); return 0; |
| 2367 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | int Renderer11::getMaxTextureHeight() const |
| 2371 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 2372 | switch (mFeatureLevel) |
| 2373 | { |
| 2374 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 2375 | case D3D_FEATURE_LEVEL_10_1: |
| 2376 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 2377 | default: UNREACHABLE(); return 0; |
| 2378 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
shannon.woods%transgaming.com@gtempaccount.com | c1fdf6b | 2013-04-13 03:44:41 +0000 | [diff] [blame^] | 2381 | int Renderer11::getMaxTextureDepth() const |
| 2382 | { |
| 2383 | switch (mFeatureLevel) |
| 2384 | { |
| 2385 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION; // 2048 |
| 2386 | case D3D_FEATURE_LEVEL_10_1: |
| 2387 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION; // 2048 |
| 2388 | default: UNREACHABLE(); return 0; |
| 2389 | } |
| 2390 | } |
| 2391 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2392 | bool Renderer11::get32BitIndexSupport() const |
| 2393 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 2394 | switch (mFeatureLevel) |
| 2395 | { |
| 2396 | case D3D_FEATURE_LEVEL_11_0: |
| 2397 | case D3D_FEATURE_LEVEL_10_1: |
| 2398 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP >= 32; // true |
| 2399 | default: UNREACHABLE(); return false; |
| 2400 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | int Renderer11::getMinSwapInterval() const |
| 2404 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 2405 | return 0; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | int Renderer11::getMaxSwapInterval() const |
| 2409 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 2410 | return 4; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | int Renderer11::getMaxSupportedSamples() const |
| 2414 | { |
shannon.woods@transgaming.com | df2fd57 | 2013-02-28 23:05:40 +0000 | [diff] [blame] | 2415 | return mMaxSupportedSamples; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
shannon.woods@transgaming.com | 88fbd0f | 2013-02-28 23:05:46 +0000 | [diff] [blame] | 2418 | int Renderer11::getNearestSupportedSamples(DXGI_FORMAT format, unsigned int requested) const |
| 2419 | { |
| 2420 | if (requested == 0) |
| 2421 | { |
| 2422 | return 0; |
| 2423 | } |
| 2424 | |
| 2425 | MultisampleSupportMap::const_iterator iter = mMultisampleSupportMap.find(format); |
| 2426 | if (iter != mMultisampleSupportMap.end()) |
| 2427 | { |
| 2428 | const MultisampleSupportInfo& info = iter->second; |
| 2429 | for (unsigned int i = requested - 1; i < D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; i++) |
| 2430 | { |
| 2431 | if (info.qualityLevels[i] > 0) |
| 2432 | { |
| 2433 | return i + 1; |
| 2434 | } |
| 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | return -1; |
| 2439 | } |
| 2440 | |
shannon.woods%transgaming.com@gtempaccount.com | b290ac1 | 2013-04-13 03:28:15 +0000 | [diff] [blame] | 2441 | unsigned int Renderer11::getMaxRenderTargets() const |
| 2442 | { |
shannon.woods%transgaming.com@gtempaccount.com | f30ccc2 | 2013-04-13 03:28:36 +0000 | [diff] [blame] | 2443 | META_ASSERT(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT <= gl::IMPLEMENTATION_MAX_DRAW_BUFFERS); |
| 2444 | META_ASSERT(D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT <= gl::IMPLEMENTATION_MAX_DRAW_BUFFERS); |
| 2445 | |
shannon.woods%transgaming.com@gtempaccount.com | b290ac1 | 2013-04-13 03:28:15 +0000 | [diff] [blame] | 2446 | switch (mFeatureLevel) |
| 2447 | { |
| 2448 | case D3D_FEATURE_LEVEL_11_0: |
| 2449 | return D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; // 8 |
| 2450 | case D3D_FEATURE_LEVEL_10_1: |
| 2451 | case D3D_FEATURE_LEVEL_10_0: |
| 2452 | return D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; // 8 |
| 2453 | default: |
| 2454 | UNREACHABLE(); |
| 2455 | return 1; |
| 2456 | } |
| 2457 | } |
| 2458 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2459 | bool Renderer11::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 2460 | { |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2461 | if (source && dest) |
| 2462 | { |
| 2463 | TextureStorage11_2D *source11 = TextureStorage11_2D::makeTextureStorage11_2D(source->getStorageInstance()); |
| 2464 | TextureStorage11_2D *dest11 = TextureStorage11_2D::makeTextureStorage11_2D(dest->getStorageInstance()); |
| 2465 | |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 2466 | mDeviceContext->CopyResource(dest11->getBaseTexture(), source11->getBaseTexture()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2467 | return true; |
| 2468 | } |
| 2469 | |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 2470 | return false; |
| 2471 | } |
| 2472 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2473 | bool Renderer11::copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 2474 | { |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2475 | if (source && dest) |
| 2476 | { |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 2477 | TextureStorage11_Cube *source11 = TextureStorage11_Cube::makeTextureStorage11_Cube(source->getStorageInstance()); |
| 2478 | TextureStorage11_Cube *dest11 = TextureStorage11_Cube::makeTextureStorage11_Cube(dest->getStorageInstance()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2479 | |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 2480 | mDeviceContext->CopyResource(dest11->getBaseTexture(), source11->getBaseTexture()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 2481 | return true; |
| 2482 | } |
| 2483 | |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 2484 | return false; |
| 2485 | } |
| 2486 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2487 | bool Renderer11::copyToRenderTarget(TextureStorageInterface3D *dest, TextureStorageInterface3D *source) |
| 2488 | { |
| 2489 | if (source && dest) |
| 2490 | { |
| 2491 | TextureStorage11_3D *source11 = TextureStorage11_3D::makeTextureStorage11_3D(source->getStorageInstance()); |
| 2492 | TextureStorage11_3D *dest11 = TextureStorage11_3D::makeTextureStorage11_3D(dest->getStorageInstance()); |
| 2493 | |
| 2494 | mDeviceContext->CopyResource(dest11->getBaseTexture(), source11->getBaseTexture()); |
| 2495 | return true; |
| 2496 | } |
| 2497 | |
| 2498 | return false; |
| 2499 | } |
| 2500 | |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2501 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2502 | GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 2503 | { |
shannon.woods%transgaming.com@gtempaccount.com | 89ae113 | 2013-04-13 03:28:43 +0000 | [diff] [blame] | 2504 | gl::Renderbuffer *colorbuffer = framebuffer->getReadColorbuffer(); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2505 | if (!colorbuffer) |
| 2506 | { |
| 2507 | ERR("Failed to retrieve the color buffer from the frame buffer."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2508 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | RenderTarget11 *sourceRenderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 2512 | if (!sourceRenderTarget) |
| 2513 | { |
| 2514 | ERR("Failed to retrieve the render target from the frame buffer."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2515 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView(); |
| 2519 | if (!source) |
| 2520 | { |
| 2521 | ERR("Failed to retrieve the render target view from the render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2522 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | TextureStorage11_2D *storage11 = TextureStorage11_2D::makeTextureStorage11_2D(storage->getStorageInstance()); |
| 2526 | if (!storage11) |
| 2527 | { |
| 2528 | source->Release(); |
| 2529 | ERR("Failed to retrieve the texture storage from the destination."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2530 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTarget(level)); |
| 2534 | if (!destRenderTarget) |
| 2535 | { |
| 2536 | source->Release(); |
| 2537 | ERR("Failed to retrieve the render target from the destination storage."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2538 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView(); |
| 2542 | if (!dest) |
| 2543 | { |
| 2544 | source->Release(); |
| 2545 | ERR("Failed to retrieve the render target view from the destination render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2546 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | gl::Rectangle destRect; |
| 2550 | destRect.x = xoffset; |
| 2551 | destRect.y = yoffset; |
| 2552 | destRect.width = sourceRect.width; |
| 2553 | destRect.height = sourceRect.height; |
| 2554 | |
| 2555 | bool ret = copyTexture(source, sourceRect, sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), |
| 2556 | dest, destRect, destRenderTarget->getWidth(), destRenderTarget->getHeight(), destFormat); |
| 2557 | |
| 2558 | source->Release(); |
| 2559 | dest->Release(); |
| 2560 | |
| 2561 | return ret; |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 2562 | } |
| 2563 | |
shannon.woods@transgaming.com | 664916b | 2013-01-25 21:50:32 +0000 | [diff] [blame] | 2564 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 2565 | GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 2566 | { |
shannon.woods%transgaming.com@gtempaccount.com | 89ae113 | 2013-04-13 03:28:43 +0000 | [diff] [blame] | 2567 | gl::Renderbuffer *colorbuffer = framebuffer->getReadColorbuffer(); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2568 | if (!colorbuffer) |
| 2569 | { |
| 2570 | ERR("Failed to retrieve the color buffer from the frame buffer."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2571 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | RenderTarget11 *sourceRenderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 2575 | if (!sourceRenderTarget) |
| 2576 | { |
| 2577 | ERR("Failed to retrieve the render target from the frame buffer."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2578 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView(); |
| 2582 | if (!source) |
| 2583 | { |
| 2584 | ERR("Failed to retrieve the render target view from the render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2585 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | TextureStorage11_Cube *storage11 = TextureStorage11_Cube::makeTextureStorage11_Cube(storage->getStorageInstance()); |
| 2589 | if (!storage11) |
| 2590 | { |
| 2591 | source->Release(); |
| 2592 | ERR("Failed to retrieve the texture storage from the destination."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2593 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTarget(target, level)); |
| 2597 | if (!destRenderTarget) |
| 2598 | { |
| 2599 | source->Release(); |
| 2600 | ERR("Failed to retrieve the render target from the destination storage."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2601 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView(); |
| 2605 | if (!dest) |
| 2606 | { |
| 2607 | source->Release(); |
| 2608 | ERR("Failed to retrieve the render target view from the destination render target."); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2609 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | gl::Rectangle destRect; |
| 2613 | destRect.x = xoffset; |
| 2614 | destRect.y = yoffset; |
| 2615 | destRect.width = sourceRect.width; |
| 2616 | destRect.height = sourceRect.height; |
| 2617 | |
| 2618 | bool ret = copyTexture(source, sourceRect, sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), |
| 2619 | dest, destRect, destRenderTarget->getWidth(), destRenderTarget->getHeight(), destFormat); |
| 2620 | |
| 2621 | source->Release(); |
| 2622 | dest->Release(); |
| 2623 | |
| 2624 | return ret; |
| 2625 | } |
| 2626 | |
shannon.woods%transgaming.com@gtempaccount.com | 414e82a | 2013-04-13 03:44:05 +0000 | [diff] [blame] | 2627 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, |
| 2628 | GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface3D *storage, GLint level) |
| 2629 | { |
| 2630 | gl::Renderbuffer *colorbuffer = framebuffer->getReadColorbuffer(); |
| 2631 | if (!colorbuffer) |
| 2632 | { |
| 2633 | ERR("Failed to retrieve the color buffer from the frame buffer."); |
| 2634 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2635 | } |
| 2636 | |
| 2637 | RenderTarget11 *sourceRenderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 2638 | if (!sourceRenderTarget) |
| 2639 | { |
| 2640 | ERR("Failed to retrieve the render target from the frame buffer."); |
| 2641 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2642 | } |
| 2643 | |
| 2644 | ID3D11ShaderResourceView *source = sourceRenderTarget->getShaderResourceView(); |
| 2645 | if (!source) |
| 2646 | { |
| 2647 | ERR("Failed to retrieve the render target view from the render target."); |
| 2648 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2649 | } |
| 2650 | |
| 2651 | TextureStorage11_3D *storage11 = TextureStorage11_3D::makeTextureStorage11_3D(storage->getStorageInstance()); |
| 2652 | if (!storage11) |
| 2653 | { |
| 2654 | source->Release(); |
| 2655 | ERR("Failed to retrieve the texture storage from the destination."); |
| 2656 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2657 | } |
| 2658 | |
| 2659 | RenderTarget11 *destRenderTarget = RenderTarget11::makeRenderTarget11(storage11->getRenderTargetLayer(level, zOffset)); |
| 2660 | if (!destRenderTarget) |
| 2661 | { |
| 2662 | source->Release(); |
| 2663 | ERR("Failed to retrieve the render target from the destination storage."); |
| 2664 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2665 | } |
| 2666 | |
| 2667 | ID3D11RenderTargetView *dest = destRenderTarget->getRenderTargetView(); |
| 2668 | if (!dest) |
| 2669 | { |
| 2670 | source->Release(); |
| 2671 | ERR("Failed to retrieve the render target view from the destination render target."); |
| 2672 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 2673 | } |
| 2674 | |
| 2675 | gl::Rectangle destRect; |
| 2676 | destRect.x = xoffset; |
| 2677 | destRect.y = yoffset; |
| 2678 | destRect.width = sourceRect.width; |
| 2679 | destRect.height = sourceRect.height; |
| 2680 | |
| 2681 | bool ret = copyTexture(source, sourceRect, sourceRenderTarget->getWidth(), sourceRenderTarget->getHeight(), |
| 2682 | dest, destRect, destRenderTarget->getWidth(), destRenderTarget->getHeight(), destFormat); |
| 2683 | |
| 2684 | source->Release(); |
| 2685 | dest->Release(); |
| 2686 | |
| 2687 | return ret; |
| 2688 | } |
| 2689 | |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2690 | bool Renderer11::copyTexture(ID3D11ShaderResourceView *source, const gl::Rectangle &sourceArea, unsigned int sourceWidth, unsigned int sourceHeight, |
| 2691 | ID3D11RenderTargetView *dest, const gl::Rectangle &destArea, unsigned int destWidth, unsigned int destHeight, GLenum destFormat) |
| 2692 | { |
| 2693 | HRESULT result; |
| 2694 | |
| 2695 | if (!mCopyResourcesInitialized) |
| 2696 | { |
| 2697 | ASSERT(!mCopyVB && !mCopySampler && !mCopyIL && !mCopyVS && !mCopyRGBAPS && !mCopyRGBPS && !mCopyLumPS && !mCopyLumAlphaPS); |
| 2698 | |
| 2699 | D3D11_BUFFER_DESC vbDesc; |
| 2700 | vbDesc.ByteWidth = sizeof(d3d11::PositionTexCoordVertex) * 4; |
| 2701 | vbDesc.Usage = D3D11_USAGE_DYNAMIC; |
| 2702 | vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; |
| 2703 | vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| 2704 | vbDesc.MiscFlags = 0; |
| 2705 | vbDesc.StructureByteStride = 0; |
| 2706 | |
| 2707 | result = mDevice->CreateBuffer(&vbDesc, NULL, &mCopyVB); |
| 2708 | ASSERT(SUCCEEDED(result)); |
| 2709 | d3d11::SetDebugName(mCopyVB, "Renderer11 copy texture vertex buffer"); |
| 2710 | |
| 2711 | D3D11_SAMPLER_DESC samplerDesc; |
| 2712 | samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; |
| 2713 | samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 2714 | samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 2715 | samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; |
| 2716 | samplerDesc.MipLODBias = 0.0f; |
| 2717 | samplerDesc.MaxAnisotropy = 0; |
| 2718 | samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER; |
| 2719 | samplerDesc.BorderColor[0] = 0.0f; |
| 2720 | samplerDesc.BorderColor[1] = 0.0f; |
| 2721 | samplerDesc.BorderColor[2] = 0.0f; |
| 2722 | samplerDesc.BorderColor[3] = 0.0f; |
| 2723 | samplerDesc.MinLOD = 0.0f; |
| 2724 | samplerDesc.MaxLOD = 0.0f; |
| 2725 | |
| 2726 | result = mDevice->CreateSamplerState(&samplerDesc, &mCopySampler); |
| 2727 | ASSERT(SUCCEEDED(result)); |
| 2728 | d3d11::SetDebugName(mCopySampler, "Renderer11 copy sampler"); |
| 2729 | |
| 2730 | D3D11_INPUT_ELEMENT_DESC quadLayout[] = |
| 2731 | { |
| 2732 | { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| 2733 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 }, |
| 2734 | }; |
| 2735 | |
| 2736 | result = mDevice->CreateInputLayout(quadLayout, 2, g_VS_Passthrough, sizeof(g_VS_Passthrough), &mCopyIL); |
| 2737 | ASSERT(SUCCEEDED(result)); |
| 2738 | d3d11::SetDebugName(mCopyIL, "Renderer11 copy texture input layout"); |
| 2739 | |
| 2740 | result = mDevice->CreateVertexShader(g_VS_Passthrough, sizeof(g_VS_Passthrough), NULL, &mCopyVS); |
| 2741 | ASSERT(SUCCEEDED(result)); |
| 2742 | d3d11::SetDebugName(mCopyVS, "Renderer11 copy texture vertex shader"); |
| 2743 | |
| 2744 | result = mDevice->CreatePixelShader(g_PS_PassthroughRGBA, sizeof(g_PS_PassthroughRGBA), NULL, &mCopyRGBAPS); |
| 2745 | ASSERT(SUCCEEDED(result)); |
| 2746 | d3d11::SetDebugName(mCopyRGBAPS, "Renderer11 copy texture RGBA pixel shader"); |
| 2747 | |
| 2748 | result = mDevice->CreatePixelShader(g_PS_PassthroughRGB, sizeof(g_PS_PassthroughRGB), NULL, &mCopyRGBPS); |
| 2749 | ASSERT(SUCCEEDED(result)); |
| 2750 | d3d11::SetDebugName(mCopyRGBPS, "Renderer11 copy texture RGB pixel shader"); |
| 2751 | |
| 2752 | result = mDevice->CreatePixelShader(g_PS_PassthroughLum, sizeof(g_PS_PassthroughLum), NULL, &mCopyLumPS); |
| 2753 | ASSERT(SUCCEEDED(result)); |
| 2754 | d3d11::SetDebugName(mCopyLumPS, "Renderer11 copy texture luminance pixel shader"); |
| 2755 | |
| 2756 | result = mDevice->CreatePixelShader(g_PS_PassthroughLumAlpha, sizeof(g_PS_PassthroughLumAlpha), NULL, &mCopyLumAlphaPS); |
| 2757 | ASSERT(SUCCEEDED(result)); |
| 2758 | d3d11::SetDebugName(mCopyLumAlphaPS, "Renderer11 copy texture luminance alpha pixel shader"); |
| 2759 | |
| 2760 | mCopyResourcesInitialized = true; |
| 2761 | } |
| 2762 | |
| 2763 | // Verify the source and destination area sizes |
| 2764 | if (sourceArea.x < 0 || sourceArea.x + sourceArea.width > static_cast<int>(sourceWidth) || |
| 2765 | sourceArea.y < 0 || sourceArea.y + sourceArea.height > static_cast<int>(sourceHeight) || |
| 2766 | destArea.x < 0 || destArea.x + destArea.width > static_cast<int>(destWidth) || |
| 2767 | destArea.y < 0 || destArea.y + destArea.height > static_cast<int>(destHeight)) |
| 2768 | { |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2769 | return gl::error(GL_INVALID_VALUE, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | // Set vertices |
| 2773 | D3D11_MAPPED_SUBRESOURCE mappedResource; |
| 2774 | result = mDeviceContext->Map(mCopyVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); |
| 2775 | if (FAILED(result)) |
| 2776 | { |
| 2777 | ERR("Failed to map vertex buffer for texture copy, HRESULT: 0x%X.", result); |
shannon.woods@transgaming.com | 779aa26 | 2013-02-28 23:04:58 +0000 | [diff] [blame] | 2778 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | d3d11::PositionTexCoordVertex *vertices = static_cast<d3d11::PositionTexCoordVertex*>(mappedResource.pData); |
| 2782 | |
| 2783 | // Create a quad in homogeneous coordinates |
shannon.woods@transgaming.com | c25537e | 2013-02-28 23:06:03 +0000 | [diff] [blame] | 2784 | float x1 = (destArea.x / float(destWidth)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | cfdfd46 | 2013-02-28 23:13:01 +0000 | [diff] [blame] | 2785 | float y1 = ((destHeight - destArea.y - destArea.height) / float(destHeight)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | c25537e | 2013-02-28 23:06:03 +0000 | [diff] [blame] | 2786 | float x2 = ((destArea.x + destArea.width) / float(destWidth)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | cfdfd46 | 2013-02-28 23:13:01 +0000 | [diff] [blame] | 2787 | float y2 = ((destHeight - destArea.y) / float(destHeight)) * 2.0f - 1.0f; |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2788 | |
| 2789 | float u1 = sourceArea.x / float(sourceWidth); |
| 2790 | float v1 = sourceArea.y / float(sourceHeight); |
| 2791 | float u2 = (sourceArea.x + sourceArea.width) / float(sourceWidth); |
| 2792 | float v2 = (sourceArea.y + sourceArea.height) / float(sourceHeight); |
| 2793 | |
| 2794 | d3d11::SetPositionTexCoordVertex(&vertices[0], x1, y1, u1, v2); |
| 2795 | d3d11::SetPositionTexCoordVertex(&vertices[1], x1, y2, u1, v1); |
| 2796 | d3d11::SetPositionTexCoordVertex(&vertices[2], x2, y1, u2, v2); |
| 2797 | d3d11::SetPositionTexCoordVertex(&vertices[3], x2, y2, u2, v1); |
| 2798 | |
| 2799 | mDeviceContext->Unmap(mCopyVB, 0); |
| 2800 | |
| 2801 | static UINT stride = sizeof(d3d11::PositionTexCoordVertex); |
| 2802 | static UINT startIdx = 0; |
| 2803 | mDeviceContext->IASetVertexBuffers(0, 1, &mCopyVB, &stride, &startIdx); |
| 2804 | |
| 2805 | // Apply state |
shannon.woods@transgaming.com | c25537e | 2013-02-28 23:06:03 +0000 | [diff] [blame] | 2806 | mDeviceContext->OMSetBlendState(NULL, NULL, 0xFFFFFFF); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2807 | mDeviceContext->OMSetDepthStencilState(NULL, 0xFFFFFFFF); |
| 2808 | mDeviceContext->RSSetState(NULL); |
| 2809 | |
| 2810 | // Apply shaders |
| 2811 | mDeviceContext->IASetInputLayout(mCopyIL); |
| 2812 | mDeviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); |
| 2813 | mDeviceContext->VSSetShader(mCopyVS, NULL, 0); |
| 2814 | |
| 2815 | ID3D11PixelShader *ps = NULL; |
| 2816 | switch(destFormat) |
| 2817 | { |
| 2818 | case GL_RGBA: ps = mCopyRGBAPS; break; |
| 2819 | case GL_RGB: ps = mCopyRGBPS; break; |
| 2820 | case GL_ALPHA: ps = mCopyRGBAPS; break; |
| 2821 | case GL_BGRA_EXT: ps = mCopyRGBAPS; break; |
| 2822 | case GL_LUMINANCE: ps = mCopyLumPS; break; |
| 2823 | case GL_LUMINANCE_ALPHA: ps = mCopyLumAlphaPS; break; |
| 2824 | default: UNREACHABLE(); ps = NULL; break; |
| 2825 | } |
| 2826 | |
| 2827 | mDeviceContext->PSSetShader(ps, NULL, 0); |
shannon.woods@transgaming.com | 28e7ba0 | 2013-02-28 23:09:28 +0000 | [diff] [blame] | 2828 | mDeviceContext->GSSetShader(NULL, NULL, 0); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2829 | |
| 2830 | // Unset the currently bound shader resource to avoid conflicts |
| 2831 | static ID3D11ShaderResourceView *const nullSRV = NULL; |
| 2832 | mDeviceContext->PSSetShaderResources(0, 1, &nullSRV); |
| 2833 | |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 2834 | // Apply render target |
| 2835 | setOneTimeRenderTarget(dest); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2836 | |
| 2837 | // Set the viewport |
| 2838 | D3D11_VIEWPORT viewport; |
| 2839 | viewport.TopLeftX = 0; |
| 2840 | viewport.TopLeftY = 0; |
| 2841 | viewport.Width = destWidth; |
| 2842 | viewport.Height = destHeight; |
| 2843 | viewport.MinDepth = 0.0f; |
| 2844 | viewport.MaxDepth = 1.0f; |
| 2845 | mDeviceContext->RSSetViewports(1, &viewport); |
| 2846 | |
| 2847 | // Apply textures |
| 2848 | mDeviceContext->PSSetShaderResources(0, 1, &source); |
| 2849 | mDeviceContext->PSSetSamplers(0, 1, &mCopySampler); |
| 2850 | |
| 2851 | // Draw the quad |
| 2852 | mDeviceContext->Draw(4, 0); |
| 2853 | |
| 2854 | // Unbind textures and render targets and vertex buffer |
| 2855 | mDeviceContext->PSSetShaderResources(0, 1, &nullSRV); |
| 2856 | |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 2857 | unapplyRenderTargets(); |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2858 | |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 2859 | UINT zero = 0; |
| 2860 | ID3D11Buffer *const nullBuffer = NULL; |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 2861 | mDeviceContext->IASetVertexBuffers(0, 1, &nullBuffer, &zero, &zero); |
| 2862 | |
| 2863 | markAllStateDirty(); |
| 2864 | |
| 2865 | return true; |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 2866 | } |
| 2867 | |
shannon.woods%transgaming.com@gtempaccount.com | ba2744f | 2013-04-13 03:33:38 +0000 | [diff] [blame] | 2868 | void Renderer11::unapplyRenderTargets() |
| 2869 | { |
| 2870 | setOneTimeRenderTarget(NULL); |
| 2871 | } |
| 2872 | |
| 2873 | void Renderer11::setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView) |
| 2874 | { |
| 2875 | ID3D11RenderTargetView *rtvArray[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS] = {NULL}; |
| 2876 | |
| 2877 | rtvArray[0] = renderTargetView; |
| 2878 | |
| 2879 | mDeviceContext->OMSetRenderTargets(getMaxRenderTargets(), rtvArray, NULL); |
| 2880 | |
| 2881 | // Do not preserve the serial for this one-time-use render target |
| 2882 | for (unsigned int rtIndex = 0; rtIndex < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; rtIndex++) |
| 2883 | { |
| 2884 | mAppliedRenderTargetSerials[rtIndex] = 0; |
| 2885 | } |
| 2886 | } |
| 2887 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2888 | RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth) |
| 2889 | { |
shannon.woods@transgaming.com | 183408d | 2013-01-25 21:50:07 +0000 | [diff] [blame] | 2890 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 2891 | RenderTarget11 *renderTarget = NULL; |
shannon.woods@transgaming.com | 8c6d9df | 2013-02-28 23:08:57 +0000 | [diff] [blame] | 2892 | |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 2893 | if (depth) |
| 2894 | { |
shannon.woods@transgaming.com | 8c6d9df | 2013-02-28 23:08:57 +0000 | [diff] [blame] | 2895 | // Note: depth stencil may be NULL for 0 sized surfaces |
shannon.woods@transgaming.com | 7e23285 | 2013-02-28 23:06:15 +0000 | [diff] [blame] | 2896 | renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(), |
| 2897 | swapChain11->getDepthStencilTexture(), NULL, |
shannon.woods@transgaming.com | 183408d | 2013-01-25 21:50:07 +0000 | [diff] [blame] | 2898 | swapChain11->getWidth(), swapChain11->getHeight()); |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 2899 | } |
| 2900 | else |
| 2901 | { |
shannon.woods@transgaming.com | 8c6d9df | 2013-02-28 23:08:57 +0000 | [diff] [blame] | 2902 | // Note: render target may be NULL for 0 sized surfaces |
shannon.woods@transgaming.com | 183408d | 2013-01-25 21:50:07 +0000 | [diff] [blame] | 2903 | renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(), |
shannon.woods@transgaming.com | 7e23285 | 2013-02-28 23:06:15 +0000 | [diff] [blame] | 2904 | swapChain11->getOffscreenTexture(), |
shannon.woods@transgaming.com | 183408d | 2013-01-25 21:50:07 +0000 | [diff] [blame] | 2905 | swapChain11->getRenderTargetShaderResource(), |
| 2906 | swapChain11->getWidth(), swapChain11->getHeight()); |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 2907 | } |
| 2908 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) |
| 2912 | { |
daniel@transgaming.com | c9a501d | 2013-01-11 04:08:46 +0000 | [diff] [blame] | 2913 | RenderTarget11 *renderTarget = new RenderTarget11(this, width, height, format, samples, depth); |
| 2914 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2917 | ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, rx::ShaderType type) |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 2918 | { |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2919 | ShaderExecutable11 *executable = NULL; |
| 2920 | |
| 2921 | switch (type) |
| 2922 | { |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2923 | case rx::SHADER_VERTEX: |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2924 | { |
| 2925 | ID3D11VertexShader *vshader = NULL; |
| 2926 | HRESULT result = mDevice->CreateVertexShader(function, length, NULL, &vshader); |
| 2927 | ASSERT(SUCCEEDED(result)); |
| 2928 | |
| 2929 | if (vshader) |
| 2930 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 2931 | executable = new ShaderExecutable11(function, length, vshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2932 | } |
| 2933 | } |
| 2934 | break; |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2935 | case rx::SHADER_PIXEL: |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2936 | { |
| 2937 | ID3D11PixelShader *pshader = NULL; |
| 2938 | HRESULT result = mDevice->CreatePixelShader(function, length, NULL, &pshader); |
| 2939 | ASSERT(SUCCEEDED(result)); |
| 2940 | |
| 2941 | if (pshader) |
| 2942 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 2943 | executable = new ShaderExecutable11(function, length, pshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2944 | } |
| 2945 | } |
| 2946 | break; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2947 | case rx::SHADER_GEOMETRY: |
| 2948 | { |
| 2949 | ID3D11GeometryShader *gshader = NULL; |
| 2950 | HRESULT result = mDevice->CreateGeometryShader(function, length, NULL, &gshader); |
| 2951 | ASSERT(SUCCEEDED(result)); |
| 2952 | |
| 2953 | if (gshader) |
| 2954 | { |
| 2955 | executable = new ShaderExecutable11(function, length, gshader); |
| 2956 | } |
| 2957 | } |
| 2958 | break; |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 2959 | default: |
| 2960 | UNREACHABLE(); |
| 2961 | break; |
| 2962 | } |
| 2963 | |
| 2964 | return executable; |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2967 | ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type) |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 2968 | { |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2969 | const char *profile = NULL; |
| 2970 | |
| 2971 | switch (type) |
| 2972 | { |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2973 | case rx::SHADER_VERTEX: |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2974 | profile = "vs_4_0"; |
| 2975 | break; |
shannon.woods@transgaming.com | 69ff776 | 2013-01-25 21:55:24 +0000 | [diff] [blame] | 2976 | case rx::SHADER_PIXEL: |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2977 | profile = "ps_4_0"; |
| 2978 | break; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 2979 | case rx::SHADER_GEOMETRY: |
| 2980 | profile = "gs_4_0"; |
| 2981 | break; |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2982 | default: |
| 2983 | UNREACHABLE(); |
| 2984 | return NULL; |
| 2985 | } |
| 2986 | |
shannon.woods@transgaming.com | d3d4208 | 2013-02-28 23:14:31 +0000 | [diff] [blame] | 2987 | ID3DBlob *binary = (ID3DBlob*)compileToBinary(infoLog, shaderHLSL, profile, D3DCOMPILE_OPTIMIZATION_LEVEL0, false); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2988 | if (!binary) |
| 2989 | return NULL; |
| 2990 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 2991 | ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 2992 | binary->Release(); |
| 2993 | |
| 2994 | return executable; |
| 2995 | } |
| 2996 | |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 2997 | VertexBuffer *Renderer11::createVertexBuffer() |
| 2998 | { |
daniel@transgaming.com | 2c4d070 | 2012-12-20 21:08:51 +0000 | [diff] [blame] | 2999 | return new VertexBuffer11(this); |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 3002 | IndexBuffer *Renderer11::createIndexBuffer() |
| 3003 | { |
daniel@transgaming.com | 11c2af5 | 2012-12-20 21:10:01 +0000 | [diff] [blame] | 3004 | return new IndexBuffer11(this); |
shannon.woods@transgaming.com | cfe787e | 2013-02-28 23:03:35 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
shannon.woods@transgaming.com | 4e52b63 | 2013-02-28 23:08:01 +0000 | [diff] [blame] | 3007 | BufferStorage *Renderer11::createBufferStorage() |
| 3008 | { |
| 3009 | return new BufferStorage11(this); |
| 3010 | } |
| 3011 | |
shannon.woods@transgaming.com | cfe787e | 2013-02-28 23:03:35 +0000 | [diff] [blame] | 3012 | QueryImpl *Renderer11::createQuery(GLenum type) |
| 3013 | { |
shannon.woods@transgaming.com | 8b7606a | 2013-02-28 23:03:47 +0000 | [diff] [blame] | 3014 | return new Query11(this, type); |
shannon.woods@transgaming.com | cfe787e | 2013-02-28 23:03:35 +0000 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | FenceImpl *Renderer11::createFence() |
| 3018 | { |
shannon.woods@transgaming.com | be58aa0 | 2013-02-28 23:03:55 +0000 | [diff] [blame] | 3019 | return new Fence11(this); |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3022 | bool Renderer11::getRenderTargetResource(gl::Renderbuffer *colorbuffer, unsigned int *subresourceIndex, ID3D11Texture2D **resource) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 3023 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3024 | ASSERT(colorbuffer != NULL); |
| 3025 | |
| 3026 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(colorbuffer->getRenderTarget()); |
| 3027 | if (renderTarget) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 3028 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3029 | *subresourceIndex = renderTarget->getSubresourceIndex(); |
| 3030 | |
| 3031 | ID3D11RenderTargetView *colorBufferRTV = renderTarget->getRenderTargetView(); |
| 3032 | if (colorBufferRTV) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 3033 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3034 | ID3D11Resource *textureResource = NULL; |
| 3035 | colorBufferRTV->GetResource(&textureResource); |
| 3036 | colorBufferRTV->Release(); |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 3037 | |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3038 | if (textureResource) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 3039 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3040 | HRESULT result = textureResource->QueryInterface(IID_ID3D11Texture2D, (void**)resource); |
| 3041 | textureResource->Release(); |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 3042 | |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3043 | if (SUCCEEDED(result)) |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 3044 | { |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3045 | return true; |
| 3046 | } |
| 3047 | else |
| 3048 | { |
| 3049 | ERR("Failed to extract the ID3D11Texture2D from the render target resource, " |
| 3050 | "HRESULT: 0x%X.", result); |
shannon.woods@transgaming.com | fdeacb8 | 2013-01-25 21:52:34 +0000 | [diff] [blame] | 3051 | } |
| 3052 | } |
| 3053 | } |
| 3054 | } |
| 3055 | |
| 3056 | return false; |
| 3057 | } |
| 3058 | |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 3059 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect, |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 3060 | bool blitRenderTarget, bool blitDepthStencil) |
| 3061 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3062 | if (blitRenderTarget) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3063 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3064 | gl::Renderbuffer *readBuffer = readTarget->getReadColorbuffer(); |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3065 | |
| 3066 | if (!readBuffer) |
| 3067 | { |
| 3068 | ERR("Failed to retrieve the read buffer from the read framebuffer."); |
| 3069 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 3070 | } |
| 3071 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3072 | RenderTarget *readRenderTarget = readBuffer->getRenderTarget(); |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3073 | |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 3074 | for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++) |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3075 | { |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 3076 | if (drawTarget->isEnabledColorAttachment(colorAttachment)) |
| 3077 | { |
| 3078 | gl::Renderbuffer *drawBuffer = drawTarget->getColorbuffer(colorAttachment); |
| 3079 | |
| 3080 | if (!drawBuffer) |
| 3081 | { |
| 3082 | ERR("Failed to retrieve the draw buffer from the draw framebuffer."); |
| 3083 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 3084 | } |
| 3085 | |
| 3086 | RenderTarget *drawRenderTarget = drawBuffer->getRenderTarget(); |
| 3087 | |
shannon.woods%transgaming.com@gtempaccount.com | 86df5a4 | 2013-04-13 03:34:07 +0000 | [diff] [blame] | 3088 | if (!blitRenderbufferRect(readRect, drawRect, readRenderTarget, drawRenderTarget, false)) |
shannon.woods%transgaming.com@gtempaccount.com | f6863e0 | 2013-04-13 03:34:00 +0000 | [diff] [blame] | 3089 | { |
| 3090 | return false; |
| 3091 | } |
| 3092 | } |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3093 | } |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3096 | if (blitDepthStencil) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3097 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3098 | gl::Renderbuffer *readBuffer = readTarget->getDepthOrStencilbuffer(); |
| 3099 | gl::Renderbuffer *drawBuffer = drawTarget->getDepthOrStencilbuffer(); |
| 3100 | |
| 3101 | if (!readBuffer) |
| 3102 | { |
| 3103 | ERR("Failed to retrieve the read depth-stencil buffer from the read framebuffer."); |
| 3104 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 3105 | } |
| 3106 | |
| 3107 | if (!drawBuffer) |
| 3108 | { |
| 3109 | ERR("Failed to retrieve the draw depth-stencil buffer from the draw framebuffer."); |
| 3110 | return gl::error(GL_OUT_OF_MEMORY, false); |
| 3111 | } |
| 3112 | |
| 3113 | RenderTarget *readRenderTarget = readBuffer->getDepthStencil(); |
| 3114 | RenderTarget *drawRenderTarget = drawBuffer->getDepthStencil(); |
| 3115 | |
shannon.woods%transgaming.com@gtempaccount.com | 86df5a4 | 2013-04-13 03:34:07 +0000 | [diff] [blame] | 3116 | if (!blitRenderbufferRect(readRect, drawRect, readRenderTarget, drawRenderTarget, true)) |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3117 | { |
| 3118 | return false; |
| 3119 | } |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | return true; |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 3126 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 3127 | { |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3128 | ID3D11Texture2D *colorBufferTexture = NULL; |
daniel@transgaming.com | 2eb7ab7 | 2013-01-11 04:10:21 +0000 | [diff] [blame] | 3129 | unsigned int subresourceIndex = 0; |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3130 | |
shannon.woods%transgaming.com@gtempaccount.com | 00e3f0c | 2013-04-13 03:31:02 +0000 | [diff] [blame] | 3131 | gl::Renderbuffer *colorbuffer = framebuffer->getReadColorbuffer(); |
| 3132 | |
| 3133 | if (colorbuffer && getRenderTargetResource(colorbuffer, &subresourceIndex, &colorBufferTexture)) |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3134 | { |
| 3135 | gl::Rectangle area; |
| 3136 | area.x = x; |
| 3137 | area.y = y; |
| 3138 | area.width = width; |
| 3139 | area.height = height; |
| 3140 | |
daniel@transgaming.com | 2eb7ab7 | 2013-01-11 04:10:21 +0000 | [diff] [blame] | 3141 | readTextureData(colorBufferTexture, subresourceIndex, area, format, type, outputPitch, |
| 3142 | packReverseRowOrder, packAlignment, pixels); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3143 | |
| 3144 | colorBufferTexture->Release(); |
| 3145 | colorBufferTexture = NULL; |
| 3146 | } |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 3147 | } |
| 3148 | |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 3149 | Image *Renderer11::createImage() |
| 3150 | { |
daniel@transgaming.com | a8aac67 | 2012-12-20 21:08:00 +0000 | [diff] [blame] | 3151 | return new Image11(); |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 3154 | void Renderer11::generateMipmap(Image *dest, Image *src) |
| 3155 | { |
shannon.woods@transgaming.com | 2b132f4 | 2013-01-25 21:52:47 +0000 | [diff] [blame] | 3156 | Image11 *dest11 = Image11::makeImage11(dest); |
| 3157 | Image11 *src11 = Image11::makeImage11(src); |
| 3158 | Image11::generateMipmap(dest11, src11); |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 3159 | } |
| 3160 | |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3161 | TextureStorage *Renderer11::createTextureStorage2D(SwapChain *swapChain) |
| 3162 | { |
daniel@transgaming.com | 36670db | 2013-01-11 04:08:22 +0000 | [diff] [blame] | 3163 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
| 3164 | return new TextureStorage11_2D(this, swapChain11); |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | TextureStorage *Renderer11::createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) |
| 3168 | { |
daniel@transgaming.com | 36670db | 2013-01-11 04:08:22 +0000 | [diff] [blame] | 3169 | return new TextureStorage11_2D(this, levels, internalformat, usage, forceRenderable, width, height); |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | TextureStorage *Renderer11::createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) |
| 3173 | { |
daniel@transgaming.com | 36670db | 2013-01-11 04:08:22 +0000 | [diff] [blame] | 3174 | return new TextureStorage11_Cube(this, levels, internalformat, usage, forceRenderable, size); |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 3175 | } |
| 3176 | |
shannon.woods%transgaming.com@gtempaccount.com | 2058d64 | 2013-04-13 03:42:50 +0000 | [diff] [blame] | 3177 | TextureStorage *Renderer11::createTextureStorage3D(int levels, GLenum internalformat, GLenum usage, GLsizei width, GLsizei height, GLsizei depth) |
| 3178 | { |
| 3179 | return new TextureStorage11_3D(this, levels, internalformat, usage, width, height, depth); |
| 3180 | } |
| 3181 | |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3182 | static inline unsigned int getFastPixelCopySize(DXGI_FORMAT sourceFormat, GLenum destFormat, GLenum destType) |
| 3183 | { |
| 3184 | if (sourceFormat == DXGI_FORMAT_A8_UNORM && |
| 3185 | destFormat == GL_ALPHA && |
| 3186 | destType == GL_UNSIGNED_BYTE) |
| 3187 | { |
| 3188 | return 1; |
| 3189 | } |
| 3190 | else if (sourceFormat == DXGI_FORMAT_R8G8B8A8_UNORM && |
| 3191 | destFormat == GL_RGBA && |
| 3192 | destType == GL_UNSIGNED_BYTE) |
| 3193 | { |
| 3194 | return 4; |
| 3195 | } |
| 3196 | else if (sourceFormat == DXGI_FORMAT_B8G8R8A8_UNORM && |
| 3197 | destFormat == GL_BGRA_EXT && |
| 3198 | destType == GL_UNSIGNED_BYTE) |
| 3199 | { |
| 3200 | return 4; |
| 3201 | } |
| 3202 | else if (sourceFormat == DXGI_FORMAT_R16G16B16A16_FLOAT && |
| 3203 | destFormat == GL_RGBA && |
| 3204 | destType == GL_HALF_FLOAT_OES) |
| 3205 | { |
| 3206 | return 8; |
| 3207 | } |
| 3208 | else if (sourceFormat == DXGI_FORMAT_R32G32B32_FLOAT && |
| 3209 | destFormat == GL_RGB && |
| 3210 | destType == GL_FLOAT) |
| 3211 | { |
| 3212 | return 12; |
| 3213 | } |
| 3214 | else if (sourceFormat == DXGI_FORMAT_R32G32B32A32_FLOAT && |
| 3215 | destFormat == GL_RGBA && |
| 3216 | destType == GL_FLOAT) |
| 3217 | { |
| 3218 | return 16; |
| 3219 | } |
| 3220 | else |
| 3221 | { |
| 3222 | return 0; |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | static inline void readPixelColor(const unsigned char *data, DXGI_FORMAT format, unsigned int x, |
| 3227 | unsigned int y, int inputPitch, gl::Color *outColor) |
| 3228 | { |
| 3229 | switch (format) |
| 3230 | { |
| 3231 | case DXGI_FORMAT_R8G8B8A8_UNORM: |
shannon.woods%transgaming.com@gtempaccount.com | 8dce651 | 2013-04-13 03:42:19 +0000 | [diff] [blame] | 3232 | case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3233 | { |
| 3234 | unsigned int rgba = *reinterpret_cast<const unsigned int*>(data + 4 * x + y * inputPitch); |
shannon.woods@transgaming.com | 25950ea | 2013-02-28 23:04:15 +0000 | [diff] [blame] | 3235 | outColor->red = (rgba & 0x000000FF) * (1.0f / 0x000000FF); |
| 3236 | outColor->green = (rgba & 0x0000FF00) * (1.0f / 0x0000FF00); |
| 3237 | outColor->blue = (rgba & 0x00FF0000) * (1.0f / 0x00FF0000); |
| 3238 | outColor->alpha = (rgba & 0xFF000000) * (1.0f / 0xFF000000); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3239 | } |
| 3240 | break; |
| 3241 | |
| 3242 | case DXGI_FORMAT_A8_UNORM: |
| 3243 | { |
| 3244 | outColor->red = 0.0f; |
| 3245 | outColor->green = 0.0f; |
| 3246 | outColor->blue = 0.0f; |
| 3247 | outColor->alpha = *(data + x + y * inputPitch) / 255.0f; |
| 3248 | } |
| 3249 | break; |
| 3250 | |
| 3251 | case DXGI_FORMAT_R32G32B32A32_FLOAT: |
| 3252 | { |
| 3253 | outColor->red = *(reinterpret_cast<const float*>(data + 16 * x + y * inputPitch) + 0); |
| 3254 | outColor->green = *(reinterpret_cast<const float*>(data + 16 * x + y * inputPitch) + 1); |
| 3255 | outColor->blue = *(reinterpret_cast<const float*>(data + 16 * x + y * inputPitch) + 2); |
| 3256 | outColor->alpha = *(reinterpret_cast<const float*>(data + 16 * x + y * inputPitch) + 3); |
| 3257 | } |
| 3258 | break; |
| 3259 | |
| 3260 | case DXGI_FORMAT_R32G32B32_FLOAT: |
| 3261 | { |
| 3262 | outColor->red = *(reinterpret_cast<const float*>(data + 12 * x + y * inputPitch) + 0); |
| 3263 | outColor->green = *(reinterpret_cast<const float*>(data + 12 * x + y * inputPitch) + 1); |
| 3264 | outColor->blue = *(reinterpret_cast<const float*>(data + 12 * x + y * inputPitch) + 2); |
| 3265 | outColor->alpha = 1.0f; |
| 3266 | } |
| 3267 | break; |
| 3268 | |
| 3269 | case DXGI_FORMAT_R16G16B16A16_FLOAT: |
| 3270 | { |
| 3271 | outColor->red = gl::float16ToFloat32(*(reinterpret_cast<const unsigned short*>(data + 8 * x + y * inputPitch) + 0)); |
| 3272 | outColor->green = gl::float16ToFloat32(*(reinterpret_cast<const unsigned short*>(data + 8 * x + y * inputPitch) + 1)); |
| 3273 | outColor->blue = gl::float16ToFloat32(*(reinterpret_cast<const unsigned short*>(data + 8 * x + y * inputPitch) + 2)); |
| 3274 | outColor->alpha = gl::float16ToFloat32(*(reinterpret_cast<const unsigned short*>(data + 8 * x + y * inputPitch) + 3)); |
| 3275 | } |
| 3276 | break; |
| 3277 | |
| 3278 | case DXGI_FORMAT_B8G8R8A8_UNORM: |
| 3279 | { |
| 3280 | unsigned int bgra = *reinterpret_cast<const unsigned int*>(data + 4 * x + y * inputPitch); |
shannon.woods@transgaming.com | 25950ea | 2013-02-28 23:04:15 +0000 | [diff] [blame] | 3281 | outColor->red = (bgra & 0x00FF0000) * (1.0f / 0x00FF0000); |
| 3282 | outColor->blue = (bgra & 0x000000FF) * (1.0f / 0x000000FF); |
| 3283 | outColor->green = (bgra & 0x0000FF00) * (1.0f / 0x0000FF00); |
| 3284 | outColor->alpha = (bgra & 0xFF000000) * (1.0f / 0xFF000000); |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3285 | } |
| 3286 | break; |
| 3287 | |
| 3288 | case DXGI_FORMAT_R8_UNORM: |
| 3289 | { |
| 3290 | outColor->red = *(data + x + y * inputPitch) / 255.0f; |
| 3291 | outColor->green = 0.0f; |
| 3292 | outColor->blue = 0.0f; |
| 3293 | outColor->alpha = 1.0f; |
| 3294 | } |
| 3295 | break; |
| 3296 | |
| 3297 | case DXGI_FORMAT_R8G8_UNORM: |
| 3298 | { |
| 3299 | unsigned short rg = *reinterpret_cast<const unsigned short*>(data + 2 * x + y * inputPitch); |
| 3300 | |
| 3301 | outColor->red = (rg & 0xFF00) * (1.0f / 0xFF00); |
| 3302 | outColor->green = (rg & 0x00FF) * (1.0f / 0x00FF); |
| 3303 | outColor->blue = 0.0f; |
| 3304 | outColor->alpha = 1.0f; |
| 3305 | } |
| 3306 | break; |
| 3307 | |
| 3308 | case DXGI_FORMAT_R16_FLOAT: |
| 3309 | { |
| 3310 | outColor->red = gl::float16ToFloat32(*reinterpret_cast<const unsigned short*>(data + 2 * x + y * inputPitch)); |
| 3311 | outColor->green = 0.0f; |
| 3312 | outColor->blue = 0.0f; |
| 3313 | outColor->alpha = 1.0f; |
| 3314 | } |
| 3315 | break; |
| 3316 | |
| 3317 | case DXGI_FORMAT_R16G16_FLOAT: |
| 3318 | { |
| 3319 | outColor->red = gl::float16ToFloat32(*(reinterpret_cast<const unsigned short*>(data + 4 * x + y * inputPitch) + 0)); |
| 3320 | outColor->green = gl::float16ToFloat32(*(reinterpret_cast<const unsigned short*>(data + 4 * x + y * inputPitch) + 1)); |
| 3321 | outColor->blue = 0.0f; |
| 3322 | outColor->alpha = 1.0f; |
| 3323 | } |
| 3324 | break; |
| 3325 | |
shannon.woods%transgaming.com@gtempaccount.com | 8dce651 | 2013-04-13 03:42:19 +0000 | [diff] [blame] | 3326 | case DXGI_FORMAT_R10G10B10A2_UNORM: |
| 3327 | { |
| 3328 | unsigned int rgba = *reinterpret_cast<const unsigned int*>(data + 4 * x + y * inputPitch); |
| 3329 | outColor->red = (rgba & 0x000003FF) * (1.0f / 0x000003FF); |
| 3330 | outColor->green = (rgba & 0x000FFC00) * (1.0f / 0x000FFC00); |
| 3331 | outColor->blue = (rgba & 0x3FF00000) * (1.0f / 0x3FF00000); |
| 3332 | outColor->alpha = (rgba & 0xC0000000) * (1.0f / 0xC0000000); |
| 3333 | } |
| 3334 | break; |
| 3335 | |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3336 | default: |
| 3337 | ERR("ReadPixelColor not implemented for DXGI format %u.", format); |
| 3338 | UNIMPLEMENTED(); |
| 3339 | break; |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | static inline void writePixelColor(const gl::Color &color, GLenum format, GLenum type, unsigned int x, |
| 3344 | unsigned int y, int outputPitch, void *outData) |
| 3345 | { |
| 3346 | unsigned char* byteData = reinterpret_cast<unsigned char*>(outData); |
| 3347 | unsigned short* shortData = reinterpret_cast<unsigned short*>(outData); |
| 3348 | |
| 3349 | switch (format) |
| 3350 | { |
| 3351 | case GL_RGBA: |
| 3352 | switch (type) |
| 3353 | { |
| 3354 | case GL_UNSIGNED_BYTE: |
| 3355 | byteData[4 * x + y * outputPitch + 0] = static_cast<unsigned char>(255 * color.red + 0.5f); |
| 3356 | byteData[4 * x + y * outputPitch + 1] = static_cast<unsigned char>(255 * color.green + 0.5f); |
| 3357 | byteData[4 * x + y * outputPitch + 2] = static_cast<unsigned char>(255 * color.blue + 0.5f); |
| 3358 | byteData[4 * x + y * outputPitch + 3] = static_cast<unsigned char>(255 * color.alpha + 0.5f); |
| 3359 | break; |
| 3360 | |
| 3361 | default: |
| 3362 | ERR("WritePixelColor not implemented for format GL_RGBA and type 0x%X.", type); |
| 3363 | UNIMPLEMENTED(); |
| 3364 | break; |
| 3365 | } |
| 3366 | break; |
| 3367 | |
| 3368 | case GL_BGRA_EXT: |
| 3369 | switch (type) |
| 3370 | { |
| 3371 | case GL_UNSIGNED_BYTE: |
| 3372 | byteData[4 * x + y * outputPitch + 0] = static_cast<unsigned char>(255 * color.blue + 0.5f); |
| 3373 | byteData[4 * x + y * outputPitch + 1] = static_cast<unsigned char>(255 * color.green + 0.5f); |
| 3374 | byteData[4 * x + y * outputPitch + 2] = static_cast<unsigned char>(255 * color.red + 0.5f); |
| 3375 | byteData[4 * x + y * outputPitch + 3] = static_cast<unsigned char>(255 * color.alpha + 0.5f); |
| 3376 | break; |
| 3377 | |
| 3378 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 3379 | // According to the desktop GL spec in the "Transfer of Pixel Rectangles" section |
| 3380 | // this type is packed as follows: |
| 3381 | // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
| 3382 | // -------------------------------------------------------------------------------- |
| 3383 | // | 4th | 3rd | 2nd | 1st component | |
| 3384 | // -------------------------------------------------------------------------------- |
| 3385 | // in the case of BGRA_EXT, B is the first component, G the second, and so forth. |
| 3386 | shortData[x + y * outputPitch / sizeof(unsigned short)] = |
| 3387 | (static_cast<unsigned short>(15 * color.alpha + 0.5f) << 12) | |
| 3388 | (static_cast<unsigned short>(15 * color.red + 0.5f) << 8) | |
| 3389 | (static_cast<unsigned short>(15 * color.green + 0.5f) << 4) | |
| 3390 | (static_cast<unsigned short>(15 * color.blue + 0.5f) << 0); |
| 3391 | break; |
| 3392 | |
| 3393 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 3394 | // According to the desktop GL spec in the "Transfer of Pixel Rectangles" section |
| 3395 | // this type is packed as follows: |
| 3396 | // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
| 3397 | // -------------------------------------------------------------------------------- |
| 3398 | // | 4th | 3rd | 2nd | 1st component | |
| 3399 | // -------------------------------------------------------------------------------- |
| 3400 | // in the case of BGRA_EXT, B is the first component, G the second, and so forth. |
| 3401 | shortData[x + y * outputPitch / sizeof(unsigned short)] = |
| 3402 | (static_cast<unsigned short>( color.alpha + 0.5f) << 15) | |
| 3403 | (static_cast<unsigned short>(31 * color.red + 0.5f) << 10) | |
| 3404 | (static_cast<unsigned short>(31 * color.green + 0.5f) << 5) | |
| 3405 | (static_cast<unsigned short>(31 * color.blue + 0.5f) << 0); |
| 3406 | break; |
| 3407 | |
| 3408 | default: |
| 3409 | ERR("WritePixelColor not implemented for format GL_BGRA_EXT and type 0x%X.", type); |
| 3410 | UNIMPLEMENTED(); |
| 3411 | break; |
| 3412 | } |
| 3413 | break; |
| 3414 | |
| 3415 | case GL_RGB: |
| 3416 | switch (type) |
| 3417 | { |
| 3418 | case GL_UNSIGNED_SHORT_5_6_5: |
| 3419 | shortData[x + y * outputPitch / sizeof(unsigned short)] = |
| 3420 | (static_cast<unsigned short>(31 * color.blue + 0.5f) << 0) | |
| 3421 | (static_cast<unsigned short>(63 * color.green + 0.5f) << 5) | |
| 3422 | (static_cast<unsigned short>(31 * color.red + 0.5f) << 11); |
| 3423 | break; |
| 3424 | |
| 3425 | case GL_UNSIGNED_BYTE: |
| 3426 | byteData[3 * x + y * outputPitch + 0] = static_cast<unsigned char>(255 * color.red + 0.5f); |
| 3427 | byteData[3 * x + y * outputPitch + 1] = static_cast<unsigned char>(255 * color.green + 0.5f); |
| 3428 | byteData[3 * x + y * outputPitch + 2] = static_cast<unsigned char>(255 * color.blue + 0.5f); |
| 3429 | break; |
| 3430 | |
| 3431 | default: |
| 3432 | ERR("WritePixelColor not implemented for format GL_RGB and type 0x%X.", type); |
| 3433 | UNIMPLEMENTED(); |
| 3434 | break; |
| 3435 | } |
| 3436 | break; |
| 3437 | |
| 3438 | default: |
| 3439 | ERR("WritePixelColor not implemented for format 0x%X.", format); |
| 3440 | UNIMPLEMENTED(); |
| 3441 | break; |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | void Renderer11::readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, |
| 3446 | GLenum format, GLenum type, GLsizei outputPitch, bool packReverseRowOrder, |
| 3447 | GLint packAlignment, void *pixels) |
| 3448 | { |
| 3449 | D3D11_TEXTURE2D_DESC textureDesc; |
| 3450 | texture->GetDesc(&textureDesc); |
| 3451 | |
| 3452 | D3D11_TEXTURE2D_DESC stagingDesc; |
| 3453 | stagingDesc.Width = area.width; |
| 3454 | stagingDesc.Height = area.height; |
| 3455 | stagingDesc.MipLevels = 1; |
| 3456 | stagingDesc.ArraySize = 1; |
| 3457 | stagingDesc.Format = textureDesc.Format; |
| 3458 | stagingDesc.SampleDesc.Count = 1; |
| 3459 | stagingDesc.SampleDesc.Quality = 0; |
| 3460 | stagingDesc.Usage = D3D11_USAGE_STAGING; |
| 3461 | stagingDesc.BindFlags = 0; |
| 3462 | stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; |
| 3463 | stagingDesc.MiscFlags = 0; |
| 3464 | |
| 3465 | ID3D11Texture2D* stagingTex = NULL; |
| 3466 | HRESULT result = mDevice->CreateTexture2D(&stagingDesc, NULL, &stagingTex); |
| 3467 | if (FAILED(result)) |
| 3468 | { |
| 3469 | ERR("Failed to create staging texture for readPixels, HRESULT: 0x%X.", result); |
| 3470 | return; |
| 3471 | } |
| 3472 | |
| 3473 | ID3D11Texture2D* srcTex = NULL; |
| 3474 | if (textureDesc.SampleDesc.Count > 1) |
| 3475 | { |
| 3476 | D3D11_TEXTURE2D_DESC resolveDesc; |
| 3477 | resolveDesc.Width = textureDesc.Width; |
| 3478 | resolveDesc.Height = textureDesc.Height; |
| 3479 | resolveDesc.MipLevels = 1; |
| 3480 | resolveDesc.ArraySize = 1; |
| 3481 | resolveDesc.Format = textureDesc.Format; |
| 3482 | resolveDesc.SampleDesc.Count = 1; |
| 3483 | resolveDesc.SampleDesc.Quality = 0; |
| 3484 | resolveDesc.Usage = D3D11_USAGE_DEFAULT; |
| 3485 | resolveDesc.BindFlags = 0; |
| 3486 | resolveDesc.CPUAccessFlags = 0; |
| 3487 | resolveDesc.MiscFlags = 0; |
| 3488 | |
| 3489 | result = mDevice->CreateTexture2D(&resolveDesc, NULL, &srcTex); |
| 3490 | if (FAILED(result)) |
| 3491 | { |
| 3492 | ERR("Failed to create resolve texture for readPixels, HRESULT: 0x%X.", result); |
| 3493 | stagingTex->Release(); |
| 3494 | return; |
| 3495 | } |
| 3496 | |
| 3497 | mDeviceContext->ResolveSubresource(srcTex, 0, texture, subResource, textureDesc.Format); |
| 3498 | subResource = 0; |
| 3499 | } |
| 3500 | else |
| 3501 | { |
| 3502 | srcTex = texture; |
| 3503 | srcTex->AddRef(); |
| 3504 | } |
| 3505 | |
| 3506 | D3D11_BOX srcBox; |
| 3507 | srcBox.left = area.x; |
| 3508 | srcBox.right = area.x + area.width; |
| 3509 | srcBox.top = area.y; |
| 3510 | srcBox.bottom = area.y + area.height; |
| 3511 | srcBox.front = 0; |
| 3512 | srcBox.back = 1; |
| 3513 | |
| 3514 | mDeviceContext->CopySubresourceRegion(stagingTex, 0, 0, 0, 0, srcTex, subResource, &srcBox); |
| 3515 | |
| 3516 | srcTex->Release(); |
| 3517 | srcTex = NULL; |
| 3518 | |
| 3519 | D3D11_MAPPED_SUBRESOURCE mapping; |
| 3520 | mDeviceContext->Map(stagingTex, 0, D3D11_MAP_READ, 0, &mapping); |
| 3521 | |
| 3522 | unsigned char *source; |
| 3523 | int inputPitch; |
| 3524 | if (packReverseRowOrder) |
| 3525 | { |
| 3526 | source = static_cast<unsigned char*>(mapping.pData) + mapping.RowPitch * (area.height - 1); |
| 3527 | inputPitch = -static_cast<int>(mapping.RowPitch); |
| 3528 | } |
| 3529 | else |
| 3530 | { |
| 3531 | source = static_cast<unsigned char*>(mapping.pData); |
| 3532 | inputPitch = static_cast<int>(mapping.RowPitch); |
| 3533 | } |
| 3534 | |
| 3535 | unsigned int fastPixelSize = getFastPixelCopySize(textureDesc.Format, format, type); |
| 3536 | if (fastPixelSize != 0) |
| 3537 | { |
| 3538 | unsigned char *dest = static_cast<unsigned char*>(pixels); |
| 3539 | for (int j = 0; j < area.height; j++) |
| 3540 | { |
| 3541 | memcpy(dest + j * outputPitch, source + j * inputPitch, area.width * fastPixelSize); |
| 3542 | } |
| 3543 | } |
shannon.woods%transgaming.com@gtempaccount.com | 676dc8f | 2013-04-13 03:35:13 +0000 | [diff] [blame] | 3544 | else if (textureDesc.Format == DXGI_FORMAT_B8G8R8A8_UNORM && |
| 3545 | format == GL_RGBA && |
| 3546 | type == GL_UNSIGNED_BYTE) |
| 3547 | { |
| 3548 | // Fast path for swapping red with blue |
| 3549 | unsigned char *dest = static_cast<unsigned char*>(pixels); |
| 3550 | |
| 3551 | for (int j = 0; j < area.height; j++) |
| 3552 | { |
| 3553 | for (int i = 0; i < area.width; i++) |
| 3554 | { |
| 3555 | unsigned int argb = *(unsigned int*)(source + 4 * i + j * inputPitch); |
| 3556 | *(unsigned int*)(dest + 4 * i + j * outputPitch) = |
| 3557 | (argb & 0xFF00FF00) | // Keep alpha and green |
| 3558 | (argb & 0x00FF0000) >> 16 | // Move red to blue |
| 3559 | (argb & 0x000000FF) << 16; // Move blue to red |
| 3560 | } |
| 3561 | } |
| 3562 | } |
daniel@transgaming.com | ee42a0a | 2013-01-11 04:09:15 +0000 | [diff] [blame] | 3563 | else |
| 3564 | { |
| 3565 | gl::Color pixelColor; |
| 3566 | for (int j = 0; j < area.height; j++) |
| 3567 | { |
| 3568 | for (int i = 0; i < area.width; i++) |
| 3569 | { |
| 3570 | readPixelColor(source, textureDesc.Format, i, j, inputPitch, &pixelColor); |
| 3571 | writePixelColor(pixelColor, format, type, i, j, outputPitch, pixels); |
| 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | mDeviceContext->Unmap(stagingTex, 0); |
| 3577 | |
| 3578 | stagingTex->Release(); |
| 3579 | stagingTex = NULL; |
| 3580 | } |
| 3581 | |
shannon.woods%transgaming.com@gtempaccount.com | 86df5a4 | 2013-04-13 03:34:07 +0000 | [diff] [blame] | 3582 | bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget, |
| 3583 | RenderTarget *drawRenderTarget, bool wholeBufferCopy) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3584 | { |
| 3585 | ASSERT(readRect.width == drawRect.width && readRect.height == drawRect.height); |
| 3586 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3587 | RenderTarget11 *readRenderTarget11 = RenderTarget11::makeRenderTarget11(readRenderTarget); |
| 3588 | if (!readRenderTarget) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3589 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3590 | ERR("Failed to retrieve the read render target from the read framebuffer."); |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 3591 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3592 | } |
| 3593 | |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3594 | ID3D11Resource *readTexture = NULL; |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3595 | unsigned int readSubresource = 0; |
| 3596 | if (readRenderTarget->getSamples() > 0) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3597 | { |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3598 | ID3D11Resource *unresolvedResource = readRenderTarget11->getTexture(); |
| 3599 | ID3D11Texture2D *unresolvedTexture = d3d11::DynamicCastComObject<ID3D11Texture2D>(unresolvedResource); |
| 3600 | unresolvedResource->Release(); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3601 | |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3602 | if (unresolvedTexture) |
| 3603 | { |
| 3604 | readTexture = resolveMultisampledTexture(unresolvedTexture, readRenderTarget11->getSubresourceIndex()); |
| 3605 | readSubresource = 0; |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3606 | |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3607 | unresolvedTexture->Release(); |
| 3608 | } |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3609 | } |
| 3610 | else |
| 3611 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3612 | readTexture = readRenderTarget11->getTexture(); |
| 3613 | readSubresource = readRenderTarget11->getSubresourceIndex(); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3614 | } |
| 3615 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3616 | if (!readTexture) |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3617 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3618 | ERR("Failed to retrieve the read render target view from the read render target."); |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 3619 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3620 | } |
| 3621 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3622 | RenderTarget11 *drawRenderTarget11 = RenderTarget11::makeRenderTarget11(drawRenderTarget); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3623 | if (!drawRenderTarget) |
| 3624 | { |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3625 | readTexture->Release(); |
| 3626 | ERR("Failed to retrieve the draw render target from the draw framebuffer."); |
shannon.woods@transgaming.com | ea4a0c6 | 2013-02-28 23:06:29 +0000 | [diff] [blame] | 3627 | return gl::error(GL_OUT_OF_MEMORY, false); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3628 | } |
| 3629 | |
shannon.woods%transgaming.com@gtempaccount.com | 27ac40e | 2013-04-13 03:43:17 +0000 | [diff] [blame] | 3630 | ID3D11Resource *drawTexture = drawRenderTarget11->getTexture(); |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3631 | unsigned int drawSubresource = drawRenderTarget11->getSubresourceIndex(); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3632 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3633 | D3D11_BOX readBox; |
| 3634 | readBox.left = readRect.x; |
| 3635 | readBox.right = readRect.x + readRect.width; |
| 3636 | readBox.top = readRect.y; |
| 3637 | readBox.bottom = readRect.y + readRect.height; |
| 3638 | readBox.front = 0; |
| 3639 | readBox.back = 1; |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3640 | |
shannon.woods%transgaming.com@gtempaccount.com | 86df5a4 | 2013-04-13 03:34:07 +0000 | [diff] [blame] | 3641 | // D3D11 needs depth-stencil CopySubresourceRegions to have a NULL pSrcBox |
| 3642 | // We also require complete framebuffer copies for depth-stencil blit. |
| 3643 | D3D11_BOX *pSrcBox = wholeBufferCopy ? NULL : &readBox; |
| 3644 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3645 | mDeviceContext->CopySubresourceRegion(drawTexture, drawSubresource, drawRect.x, drawRect.y, 0, |
shannon.woods%transgaming.com@gtempaccount.com | 86df5a4 | 2013-04-13 03:34:07 +0000 | [diff] [blame] | 3646 | readTexture, readSubresource, pSrcBox); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3647 | |
shannon.woods%transgaming.com@gtempaccount.com | 1d64b62 | 2013-04-13 03:33:53 +0000 | [diff] [blame] | 3648 | readTexture->Release(); |
| 3649 | drawTexture->Release(); |
shannon.woods@transgaming.com | 1e1deda | 2013-02-28 23:06:23 +0000 | [diff] [blame] | 3650 | |
| 3651 | return true; |
| 3652 | } |
| 3653 | |
shannon.woods@transgaming.com | d67f9ce | 2013-02-28 23:06:09 +0000 | [diff] [blame] | 3654 | ID3D11Texture2D *Renderer11::resolveMultisampledTexture(ID3D11Texture2D *source, unsigned int subresource) |
| 3655 | { |
| 3656 | D3D11_TEXTURE2D_DESC textureDesc; |
| 3657 | source->GetDesc(&textureDesc); |
| 3658 | |
| 3659 | if (textureDesc.SampleDesc.Count > 1) |
| 3660 | { |
| 3661 | D3D11_TEXTURE2D_DESC resolveDesc; |
| 3662 | resolveDesc.Width = textureDesc.Width; |
| 3663 | resolveDesc.Height = textureDesc.Height; |
| 3664 | resolveDesc.MipLevels = 1; |
| 3665 | resolveDesc.ArraySize = 1; |
| 3666 | resolveDesc.Format = textureDesc.Format; |
| 3667 | resolveDesc.SampleDesc.Count = 1; |
| 3668 | resolveDesc.SampleDesc.Quality = 0; |
| 3669 | resolveDesc.Usage = textureDesc.Usage; |
| 3670 | resolveDesc.BindFlags = textureDesc.BindFlags; |
| 3671 | resolveDesc.CPUAccessFlags = 0; |
| 3672 | resolveDesc.MiscFlags = 0; |
| 3673 | |
| 3674 | ID3D11Texture2D *resolveTexture = NULL; |
| 3675 | HRESULT result = mDevice->CreateTexture2D(&resolveDesc, NULL, &resolveTexture); |
| 3676 | if (FAILED(result)) |
| 3677 | { |
| 3678 | ERR("Failed to create a multisample resolve texture, HRESULT: 0x%X.", result); |
| 3679 | return NULL; |
| 3680 | } |
| 3681 | |
| 3682 | mDeviceContext->ResolveSubresource(resolveTexture, 0, source, subresource, textureDesc.Format); |
| 3683 | return resolveTexture; |
| 3684 | } |
| 3685 | else |
| 3686 | { |
| 3687 | source->AddRef(); |
| 3688 | return source; |
| 3689 | } |
| 3690 | } |
| 3691 | |
shannon.woods@transgaming.com | 9d971ff | 2013-01-25 21:50:53 +0000 | [diff] [blame] | 3692 | } |