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