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