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