Minimize BeginScene / EndScene calls

TRAC #12139 Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@231 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c28e76be
...@@ -26,6 +26,8 @@ Display::Display(HDC deviceContext) : mDc(deviceContext) ...@@ -26,6 +26,8 @@ Display::Display(HDC deviceContext) : mDc(deviceContext)
mAdapter = D3DADAPTER_DEFAULT; mAdapter = D3DADAPTER_DEFAULT;
mDeviceType = D3DDEVTYPE_HAL; mDeviceType = D3DDEVTYPE_HAL;
mSceneStarted = false;
} }
Display::~Display() Display::~Display()
...@@ -166,6 +168,26 @@ void Display::terminate() ...@@ -166,6 +168,26 @@ void Display::terminate()
} }
} }
void Display::startScene()
{
if (!mSceneStarted)
{
long result = mDevice->BeginScene();
ASSERT(SUCCEEDED(result));
mSceneStarted = true;
}
}
void Display::endScene()
{
if (mSceneStarted)
{
long result = mDevice->EndScene();
ASSERT(SUCCEEDED(result));
mSceneStarted = false;
}
}
bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig) bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig)
{ {
return mConfigSet.getConfigs(configs, attribList, configSize, numConfig); return mConfigSet.getConfigs(configs, attribList, configSize, numConfig);
...@@ -323,7 +345,7 @@ egl::Surface *Display::createWindowSurface(HWND window, EGLConfig config) ...@@ -323,7 +345,7 @@ egl::Surface *Display::createWindowSurface(HWND window, EGLConfig config)
if (swapChain) if (swapChain)
{ {
surface = new Surface(mDevice, swapChain, depthStencilSurface, configuration->mConfigID); surface = new Surface(this, swapChain, depthStencilSurface, configuration->mConfigID);
mSurfaceSet.insert(surface); mSurfaceSet.insert(surface);
swapChain->Release(); swapChain->Release();
......
...@@ -36,6 +36,9 @@ class Display ...@@ -36,6 +36,9 @@ class Display
bool initialize(); bool initialize();
void terminate(); void terminate();
virtual void startScene();
virtual void endScene();
bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig); bool getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig);
bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value); bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
...@@ -62,6 +65,8 @@ class Display ...@@ -62,6 +65,8 @@ class Display
IDirect3D9 *mD3d9; IDirect3D9 *mD3d9;
IDirect3DDevice9 *mDevice; IDirect3DDevice9 *mDevice;
bool mSceneStarted;
typedef std::set<Surface*> SurfaceSet; typedef std::set<Surface*> SurfaceSet;
SurfaceSet mSurfaceSet; SurfaceSet mSurfaceSet;
......
...@@ -13,11 +13,12 @@ ...@@ -13,11 +13,12 @@
#include "common/debug.h" #include "common/debug.h"
#include "libEGL/main.h" #include "libEGL/main.h"
#include "libEGL/Display.h"
namespace egl namespace egl
{ {
Surface::Surface(IDirect3DDevice9 *device, IDirect3DSwapChain9 *swapChain, IDirect3DSurface9 *depthStencil, EGLint configID) Surface::Surface(Display *display, IDirect3DSwapChain9 *swapChain, IDirect3DSurface9 *depthStencil, EGLint configID)
: mSwapChain(swapChain), mConfigID(configID), mDepthStencil(depthStencil) : mDisplay(display), mSwapChain(swapChain), mConfigID(configID), mDepthStencil(depthStencil)
{ {
mBackBuffer = NULL; mBackBuffer = NULL;
mRenderTarget = NULL; mRenderTarget = NULL;
...@@ -37,6 +38,7 @@ Surface::Surface(IDirect3DDevice9 *device, IDirect3DSwapChain9 *swapChain, IDire ...@@ -37,6 +38,7 @@ Surface::Surface(IDirect3DDevice9 *device, IDirect3DSwapChain9 *swapChain, IDire
mWidth = description.Width; mWidth = description.Width;
mHeight = description.Height; mHeight = description.Height;
IDirect3DDevice9 *device = display->getDevice();
HRESULT result = device->CreateRenderTarget(mWidth, mHeight, description.Format, description.MultiSampleType, description.MultiSampleQuality, FALSE, &mRenderTarget, NULL); HRESULT result = device->CreateRenderTarget(mWidth, mHeight, description.Format, description.MultiSampleType, description.MultiSampleQuality, FALSE, &mRenderTarget, NULL);
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY) if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY)
...@@ -90,9 +92,7 @@ void Surface::swap() ...@@ -90,9 +92,7 @@ void Surface::swap()
{ {
if (mSwapChain) if (mSwapChain)
{ {
IDirect3DDevice9 *device; IDirect3DDevice9 *device = mDisplay->getDevice();
mSwapChain->GetDevice(&device);
D3DSURFACE_DESC description; D3DSURFACE_DESC description;
mBackBuffer->GetDesc(&description); mBackBuffer->GetDesc(&description);
...@@ -110,6 +110,7 @@ void Surface::swap() ...@@ -110,6 +110,7 @@ void Surface::swap()
IDirect3DSurface9 *textureSurface; IDirect3DSurface9 *textureSurface;
texture->GetSurfaceLevel(0, &textureSurface); texture->GetSurfaceLevel(0, &textureSurface);
mDisplay->endScene();
device->StretchRect(mRenderTarget, NULL, textureSurface, NULL, D3DTEXF_NONE); device->StretchRect(mRenderTarget, NULL, textureSurface, NULL, D3DTEXF_NONE);
// Disable all pipeline operations // Disable all pipeline operations
...@@ -142,11 +143,11 @@ void Surface::swap() ...@@ -142,11 +143,11 @@ void Surface::swap()
{mWidth - 0.5f, mHeight - 0.5f, 0.0f, 1.0f, 1.0f, 0.0f}, {mWidth - 0.5f, mHeight - 0.5f, 0.0f, 1.0f, 1.0f, 0.0f},
{ 0 - 0.5f, mHeight - 0.5f, 0.0f, 1.0f, 0.0f, 0.0f}}; // x, y, z, rhw, u, v { 0 - 0.5f, mHeight - 0.5f, 0.0f, 1.0f, 0.0f, 0.0f}}; // x, y, z, rhw, u, v
device->BeginScene(); mDisplay->startScene();
device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, quad, 6 * sizeof(float)); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, quad, 6 * sizeof(float));
device->EndScene();
result = mSwapChain->Present(NULL, NULL, NULL, NULL, D3DPRESENT_INTERVAL_DEFAULT); // FIXME: Get the swap interval from the associated Display mDisplay->endScene();
result = mSwapChain->Present(NULL, NULL, NULL, NULL, D3DPRESENT_INTERVAL_IMMEDIATE | D3DPRESENT_DONOTWAIT); // FIXME: Get the swap interval from the associated Display
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DRIVERINTERNALERROR) if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DRIVERINTERNALERROR)
{ {
...@@ -155,7 +156,6 @@ void Surface::swap() ...@@ -155,7 +156,6 @@ void Surface::swap()
textureSurface->Release(); textureSurface->Release();
texture->Release(); texture->Release();
device->Release();
} }
} }
......
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
namespace egl namespace egl
{ {
class Display;
class Surface class Surface
{ {
public: public:
Surface(IDirect3DDevice9 *device, IDirect3DSwapChain9 *swapChain, IDirect3DSurface9* depthStencil, EGLint configID); Surface(Display *display, IDirect3DSwapChain9 *swapChain, IDirect3DSurface9* depthStencil, EGLint configID);
~Surface(); ~Surface();
...@@ -37,27 +39,28 @@ class Surface ...@@ -37,27 +39,28 @@ class Surface
private: private:
DISALLOW_COPY_AND_ASSIGN(Surface); DISALLOW_COPY_AND_ASSIGN(Surface);
Display *const mDisplay;
IDirect3DSwapChain9 *const mSwapChain; IDirect3DSwapChain9 *const mSwapChain;
IDirect3DSurface9 *mBackBuffer; IDirect3DSurface9 *mBackBuffer;
IDirect3DSurface9 *mRenderTarget; IDirect3DSurface9 *mRenderTarget;
IDirect3DSurface9 *mDepthStencil; IDirect3DSurface9 *mDepthStencil;
const EGLint mConfigID; // ID of EGLConfig surface was created with const EGLint mConfigID; // ID of EGLConfig surface was created with
EGLint mHeight; // Height of surface EGLint mHeight; // Height of surface
EGLint mWidth; // Width of surface EGLint mWidth; // Width of surface
// EGLint horizontalResolution; // Horizontal dot pitch // EGLint horizontalResolution; // Horizontal dot pitch
// EGLint verticalResolution; // Vertical dot pitch // EGLint verticalResolution; // Vertical dot pitch
// EGLBoolean largestPBuffer; // If true, create largest pbuffer possible // EGLBoolean largestPBuffer; // If true, create largest pbuffer possible
// EGLBoolean mipmapTexture; // True if texture has mipmaps // EGLBoolean mipmapTexture; // True if texture has mipmaps
// EGLint mipmapLevel; // Mipmap level to render to // EGLint mipmapLevel; // Mipmap level to render to
// EGLenum multisampleResolve; // Multisample resolve behavior // EGLenum multisampleResolve; // Multisample resolve behavior
EGLint mPixelAspectRatio; // Display aspect ratio EGLint mPixelAspectRatio; // Display aspect ratio
EGLenum mRenderBuffer; // Render buffer EGLenum mRenderBuffer; // Render buffer
EGLenum mSwapBehavior; // Buffer swap behavior EGLenum mSwapBehavior; // Buffer swap behavior
// EGLenum textureFormat; // Format of texture: RGB, RGBA, or no texture // EGLenum textureFormat; // Format of texture: RGB, RGBA, or no texture
// EGLenum textureTarget; // Type of texture: 2D or no texture // EGLenum textureTarget; // Type of texture: 2D or no texture
// EGLenum vgAlphaFormat; // Alpha format for OpenVG // EGLenum vgAlphaFormat; // Alpha format for OpenVG
// EGLenum vgColorSpace; // Color space for OpenVG // EGLenum vgColorSpace; // Color space for OpenVG
}; };
} }
......
...@@ -370,6 +370,7 @@ bool Blit::setFormatConvertShaders(GLenum destFormat) ...@@ -370,6 +370,7 @@ bool Blit::setFormatConvertShaders(GLenum destFormat)
IDirect3DTexture9 *Blit::copySurfaceToTexture(IDirect3DSurface9 *surface, const RECT &sourceRect) IDirect3DTexture9 *Blit::copySurfaceToTexture(IDirect3DSurface9 *surface, const RECT &sourceRect)
{ {
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DSURFACE_DESC sourceDesc; D3DSURFACE_DESC sourceDesc;
...@@ -401,6 +402,7 @@ IDirect3DTexture9 *Blit::copySurfaceToTexture(IDirect3DSurface9 *surface, const ...@@ -401,6 +402,7 @@ IDirect3DTexture9 *Blit::copySurfaceToTexture(IDirect3DSurface9 *surface, const
d3dSourceRect.top = sourceRect.top; d3dSourceRect.top = sourceRect.top;
d3dSourceRect.bottom = sourceRect.bottom; d3dSourceRect.bottom = sourceRect.bottom;
display->endScene();
result = device->StretchRect(surface, &d3dSourceRect, textureSurface, NULL, D3DTEXF_NONE); result = device->StretchRect(surface, &d3dSourceRect, textureSurface, NULL, D3DTEXF_NONE);
textureSurface->Release(); textureSurface->Release();
...@@ -456,14 +458,14 @@ void Blit::setCommonBlitState() ...@@ -456,14 +458,14 @@ void Blit::setCommonBlitState()
void Blit::render() void Blit::render()
{ {
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
HRESULT hr = device->SetStreamSource(0, mQuadVertexBuffer, 0, 2 * sizeof(float)); HRESULT hr = device->SetStreamSource(0, mQuadVertexBuffer, 0, 2 * sizeof(float));
hr = device->SetVertexDeclaration(mQuadVertexDeclaration); hr = device->SetVertexDeclaration(mQuadVertexDeclaration);
device->BeginScene(); display->startScene();
hr = device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); hr = device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
device->EndScene();
} }
} }
...@@ -2014,6 +2014,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum ...@@ -2014,6 +2014,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
void Context::clear(GLbitfield mask) void Context::clear(GLbitfield mask)
{ {
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
DWORD flags = 0; DWORD flags = 0;
...@@ -2153,9 +2154,8 @@ void Context::clear(GLbitfield mask) ...@@ -2153,9 +2154,8 @@ void Context::clear(GLbitfield mask)
quad[3].w = 1.0f; quad[3].w = 1.0f;
quad[3].diffuse = color; quad[3].diffuse = color;
device->BeginScene(); display->startScene();
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(Vertex)); device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, sizeof(Vertex));
device->EndScene();
if (flags & D3DCLEAR_ZBUFFER) if (flags & D3DCLEAR_ZBUFFER)
{ {
...@@ -2177,6 +2177,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count) ...@@ -2177,6 +2177,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DPRIMITIVETYPE primitiveType; D3DPRIMITIVETYPE primitiveType;
int primitiveCount; int primitiveCount;
...@@ -2206,9 +2207,8 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count) ...@@ -2206,9 +2207,8 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
if (!cullSkipsDraw(mode)) if (!cullSkipsDraw(mode))
{ {
device->BeginScene(); display->startScene();
device->DrawPrimitive(primitiveType, 0, primitiveCount); device->DrawPrimitive(primitiveType, 0, primitiveCount);
device->EndScene();
} }
} }
...@@ -2224,6 +2224,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void* ...@@ -2224,6 +2224,7 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void*
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DPRIMITIVETYPE primitiveType; D3DPRIMITIVETYPE primitiveType;
int primitiveCount; int primitiveCount;
...@@ -2254,14 +2255,14 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void* ...@@ -2254,14 +2255,14 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void*
if (!cullSkipsDraw(mode)) if (!cullSkipsDraw(mode))
{ {
device->BeginScene(); display->startScene();
device->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, indexInfo.maxIndex-indexInfo.minIndex+1, indexInfo.offset/sizeof(Index), primitiveCount); device->DrawIndexedPrimitive(primitiveType, -(INT)indexInfo.minIndex, indexInfo.minIndex, indexInfo.maxIndex-indexInfo.minIndex+1, indexInfo.offset/sizeof(Index), primitiveCount);
device->EndScene();
} }
} }
void Context::finish() void Context::finish()
{ {
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
IDirect3DQuery9 *occlusionQuery = NULL; IDirect3DQuery9 *occlusionQuery = NULL;
...@@ -2283,9 +2284,8 @@ void Context::finish() ...@@ -2283,9 +2284,8 @@ void Context::finish()
device->SetVertexShader(NULL); device->SetVertexShader(NULL);
device->SetFVF(D3DFVF_XYZRHW); device->SetFVF(D3DFVF_XYZRHW);
float data[4] = {-1.0f, -1.0f, -1.0f, 1.0f}; float data[4] = {-1.0f, -1.0f, -1.0f, 1.0f};
device->BeginScene(); display->startScene();
device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data)); device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, data, sizeof(data));
device->EndScene();
occlusionQuery->Issue(D3DISSUE_END); occlusionQuery->Issue(D3DISSUE_END);
......
...@@ -681,6 +681,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() ...@@ -681,6 +681,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
if (mWidth != 0 && mHeight != 0) if (mWidth != 0 && mHeight != 0)
{ {
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0].format); D3DFORMAT format = selectFormat(mImageArray[0].format);
...@@ -722,6 +723,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() ...@@ -722,6 +723,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
} }
display->endScene();
result = device->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE); result = device->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE);
if (FAILED(result)) if (FAILED(result))
...@@ -1056,6 +1058,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() ...@@ -1056,6 +1058,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
if (mWidth != 0) if (mWidth != 0)
{ {
egl::Display *display = getDisplay();
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0][0].format); D3DFORMAT format = selectFormat(mImageArray[0][0].format);
...@@ -1099,6 +1102,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() ...@@ -1099,6 +1102,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
} }
display->endScene();
result = device->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE); result = device->StretchRect(source, NULL, dest, NULL, D3DTEXF_NONE);
if (FAILED(result)) if (FAILED(result))
......
...@@ -93,10 +93,16 @@ Context *getContext() ...@@ -93,10 +93,16 @@ Context *getContext()
return current->context; return current->context;
} }
IDirect3DDevice9 *getDevice() egl::Display *getDisplay()
{ {
Current *current = (Current*)TlsGetValue(currentTLS); Current *current = (Current*)TlsGetValue(currentTLS);
egl::Display *display = current->display;
return current->display;
}
IDirect3DDevice9 *getDevice()
{
egl::Display *display = getDisplay();
return display->getDevice(); return display->getDevice();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment