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