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