Commit 8b3c1afb by jbauman@chromium.org

Improve performance of applyRenderTarget and applyTextures

Get rid of unnecessary GetSurfaceLevel/Release calls, move invariants out of the applyTextures loop, and fix the if in getSemanticIndex so we can avoid calling getMaximumCombinedTextureImageUnits. Gets donuts NaCl demo from 14->16 fps. BUG= TEST=webgl conformance tests Review URL: http://codereview.appspot.com/5248057 git-svn-id: https://angleproject.googlecode.com/svn/trunk@787 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c6209856
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 786 #define BUILD_REVISION 787
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -1621,19 +1621,19 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1621,19 +1621,19 @@ bool Context::applyRenderTarget(bool ignoreViewport)
return error(GL_INVALID_FRAMEBUFFER_OPERATION, false); return error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
} }
IDirect3DSurface9 *renderTarget = framebufferObject->getRenderTarget(); IDirect3DSurface9 *renderTarget = NULL;
if (!renderTarget)
{
return false; // Context must be lost
}
IDirect3DSurface9 *depthStencil = NULL; IDirect3DSurface9 *depthStencil = NULL;
bool renderTargetChanged = false; bool renderTargetChanged = false;
unsigned int renderTargetSerial = framebufferObject->getRenderTargetSerial(); unsigned int renderTargetSerial = framebufferObject->getRenderTargetSerial();
if (renderTargetSerial != mAppliedRenderTargetSerial) if (renderTargetSerial != mAppliedRenderTargetSerial)
{ {
renderTarget = framebufferObject->getRenderTarget();
if (!renderTarget)
{
return false; // Context must be lost
}
device->SetRenderTarget(0, renderTarget); device->SetRenderTarget(0, renderTarget);
mAppliedRenderTargetSerial = renderTargetSerial; mAppliedRenderTargetSerial = renderTargetSerial;
mScissorStateDirty = true; // Scissor area must be clamped to render target's size-- this is different for different render targets. mScissorStateDirty = true; // Scissor area must be clamped to render target's size-- this is different for different render targets.
...@@ -1677,6 +1677,15 @@ bool Context::applyRenderTarget(bool ignoreViewport) ...@@ -1677,6 +1677,15 @@ bool Context::applyRenderTarget(bool ignoreViewport)
if (!mRenderTargetDescInitialized || renderTargetChanged) if (!mRenderTargetDescInitialized || renderTargetChanged)
{ {
if (!renderTarget)
{
renderTarget = framebufferObject->getRenderTarget();
if (!renderTarget)
{
return false; // Context must be lost
}
}
renderTarget->GetDesc(&mRenderTargetDesc); renderTarget->GetDesc(&mRenderTargetDesc);
mRenderTargetDescInitialized = true; mRenderTargetDescInitialized = true;
} }
...@@ -2096,12 +2105,13 @@ void Context::applyTextures(SamplerType type) ...@@ -2096,12 +2105,13 @@ void Context::applyTextures(SamplerType type)
Program *programObject = getCurrentProgram(); Program *programObject = getCurrentProgram();
int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type int samplerCount = (type == SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF; // Range of Direct3D 9 samplers of given sampler type
unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS;
int d3dSamplerOffset = (type == SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
for (int samplerIndex = 0; samplerIndex < samplerCount; samplerIndex++) for (int samplerIndex = 0; samplerIndex < samplerCount; samplerIndex++)
{ {
int textureUnit = programObject->getSamplerMapping(type, samplerIndex); // OpenGL texture image unit index int textureUnit = programObject->getSamplerMapping(type, samplerIndex); // OpenGL texture image unit index
int d3dSampler = (type == SAMPLER_PIXEL) ? samplerIndex : D3DVERTEXTEXTURESAMPLER0 + samplerIndex; int d3dSampler = samplerIndex + d3dSamplerOffset;
unsigned int *appliedTextureSerial = (type == SAMPLER_PIXEL) ? mAppliedTextureSerialPS : mAppliedTextureSerialVS;
if (textureUnit != -1) if (textureUnit != -1)
{ {
......
...@@ -202,7 +202,7 @@ int Program::getSemanticIndex(int attributeIndex) ...@@ -202,7 +202,7 @@ int Program::getSemanticIndex(int attributeIndex)
// index (0-15 for the pixel shader and 0-3 for the vertex shader). // index (0-15 for the pixel shader and 0-3 for the vertex shader).
GLint Program::getSamplerMapping(SamplerType type, unsigned int samplerIndex) GLint Program::getSamplerMapping(SamplerType type, unsigned int samplerIndex)
{ {
GLuint logicalTextureUnit = -1; GLint logicalTextureUnit = -1;
switch (type) switch (type)
{ {
...@@ -225,7 +225,7 @@ GLint Program::getSamplerMapping(SamplerType type, unsigned int samplerIndex) ...@@ -225,7 +225,7 @@ GLint Program::getSamplerMapping(SamplerType type, unsigned int samplerIndex)
default: UNREACHABLE(); default: UNREACHABLE();
} }
if (logicalTextureUnit >= 0 && logicalTextureUnit < getContext()->getMaximumCombinedTextureImageUnits()) if (logicalTextureUnit >= 0 && logicalTextureUnit < (GLint)getContext()->getMaximumCombinedTextureImageUnits())
{ {
return logicalTextureUnit; return logicalTextureUnit;
} }
......
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