Commit e62cedd0 by Jamie Madill

Load Clear11 resources lazily.

Again this saves on startup time and memory use. BUG=angleproject:1014 Change-Id: I3890dc2ea50ff4e4f1ff9d7cb223e1ab57c330ce Reviewed-on: https://chromium-review.googlesource.com/282552Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 86a07aec
......@@ -45,7 +45,7 @@ static void ApplyVertices(const gl::Extents &framebufferSize, const gl::Rectangl
float bottom = 1.0f;
// Clip the quad coordinates to the scissor if needed
if (scissor != NULL)
if (scissor != nullptr)
{
left = std::max(left, (scissor->x / float(framebufferSize.width)) * 2.0f - 1.0f);
right = std::min(right, ((scissor->x + scissor->width) / float(framebufferSize.width)) * 2.0f - 1.0f);
......@@ -59,34 +59,43 @@ static void ApplyVertices(const gl::Extents &framebufferSize, const gl::Rectangl
d3d11::SetPositionDepthColorVertex<T>(vertices + 3, right, top, depthClear, color);
}
template <unsigned int vsSize, unsigned int psSize>
Clear11::ClearShader Clear11::CreateClearShader(ID3D11Device *device, DXGI_FORMAT colorType, const BYTE (&vsByteCode)[vsSize], const BYTE (&psByteCode)[psSize])
Clear11::ClearShader::ClearShader(DXGI_FORMAT colorType,
const char *inputLayoutName,
const BYTE *vsByteCode,
size_t vsSize,
const char *vsDebugName,
const BYTE *psByteCode,
size_t psSize,
const char *psDebugName)
: inputLayout(nullptr),
vertexShader(vsByteCode, vsSize, vsDebugName),
pixelShader(psByteCode, psSize, psDebugName)
{
HRESULT result;
ClearShader shader = { 0 };
D3D11_INPUT_ELEMENT_DESC quadLayout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, colorType, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
result = device->CreateInputLayout(quadLayout, ArraySize(quadLayout), vsByteCode, vsSize, &shader.inputLayout);
ASSERT(SUCCEEDED(result));
result = device->CreateVertexShader(vsByteCode, vsSize, NULL, &shader.vertexShader);
ASSERT(SUCCEEDED(result));
result = device->CreatePixelShader(psByteCode, psSize, NULL, &shader.pixelShader);
ASSERT(SUCCEEDED(result));
inputLayout = new d3d11::LazyInputLayout(quadLayout, 2, vsByteCode, vsSize, inputLayoutName);
}
return shader;
Clear11::ClearShader::~ClearShader()
{
SafeDelete(inputLayout);
vertexShader.release();
pixelShader.release();
}
Clear11::Clear11(Renderer11 *renderer)
: mRenderer(renderer), mClearBlendStates(StructLessThan<ClearBlendInfo>), mClearDepthStencilStates(StructLessThan<ClearDepthStencilInfo>),
mVertexBuffer(NULL), mRasterizerState(NULL)
: mRenderer(renderer),
mClearBlendStates(StructLessThan<ClearBlendInfo>),
mFloatClearShader(nullptr),
mUintClearShader(nullptr),
mIntClearShader(nullptr),
mClearDepthStencilStates(StructLessThan<ClearDepthStencilInfo>),
mVertexBuffer(nullptr),
mRasterizerState(nullptr)
{
TRACE_EVENT0("gpu.angle", "Clear11::Clear11");
......@@ -101,7 +110,7 @@ Clear11::Clear11(Renderer11 *renderer)
vbDesc.MiscFlags = 0;
vbDesc.StructureByteStride = 0;
result = device->CreateBuffer(&vbDesc, NULL, &mVertexBuffer);
result = device->CreateBuffer(&vbDesc, nullptr, &mVertexBuffer);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mVertexBuffer, "Clear11 masked clear vertex buffer");
......@@ -123,17 +132,45 @@ Clear11::Clear11(Renderer11 *renderer)
if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3)
{
mFloatClearShader = CreateClearShader(device, DXGI_FORMAT_R32G32B32A32_FLOAT, g_VS_ClearFloat, g_PS_ClearFloat_FL9);
mFloatClearShader = new ClearShader(DXGI_FORMAT_R32G32B32A32_FLOAT,
"Clear11 Float IL",
g_VS_ClearFloat,
ArraySize(g_VS_ClearFloat),
"Clear11 Float VS",
g_PS_ClearFloat_FL9,
ArraySize(g_PS_ClearFloat_FL9),
"Clear11 Float PS");
}
else
{
mFloatClearShader = CreateClearShader(device, DXGI_FORMAT_R32G32B32A32_FLOAT, g_VS_ClearFloat, g_PS_ClearFloat);
mFloatClearShader = new ClearShader(DXGI_FORMAT_R32G32B32A32_FLOAT,
"Clear11 Float IL",
g_VS_ClearFloat,
ArraySize(g_VS_ClearFloat),
"Clear11 Float VS",
g_PS_ClearFloat,
ArraySize(g_PS_ClearFloat),
"Clear11 Float PS");
}
if (renderer->isES3Capable())
{
mUintClearShader = CreateClearShader(device, DXGI_FORMAT_R32G32B32A32_UINT, g_VS_ClearUint, g_PS_ClearUint );
mIntClearShader = CreateClearShader(device, DXGI_FORMAT_R32G32B32A32_SINT, g_VS_ClearSint, g_PS_ClearSint );
mUintClearShader = new ClearShader(DXGI_FORMAT_R32G32B32A32_UINT,
"Clear11 UINT IL",
g_VS_ClearUint,
ArraySize(g_VS_ClearUint),
"Clear11 UINT VS",
g_PS_ClearUint,
ArraySize(g_PS_ClearUint),
"Clear11 UINT PS");
mIntClearShader = new ClearShader(DXGI_FORMAT_R32G32B32A32_UINT,
"Clear11 SINT IL",
g_VS_ClearSint,
ArraySize(g_VS_ClearSint),
"Clear11 SINT VS",
g_PS_ClearSint,
ArraySize(g_PS_ClearSint),
"Clear11 SINT PS");
}
}
......@@ -145,20 +182,9 @@ Clear11::~Clear11()
}
mClearBlendStates.clear();
SafeRelease(mFloatClearShader.inputLayout);
SafeRelease(mFloatClearShader.vertexShader);
SafeRelease(mFloatClearShader.pixelShader);
if (mRenderer->isES3Capable())
{
SafeRelease(mUintClearShader.inputLayout);
SafeRelease(mUintClearShader.vertexShader);
SafeRelease(mUintClearShader.pixelShader);
SafeRelease(mIntClearShader.inputLayout);
SafeRelease(mIntClearShader.vertexShader);
SafeRelease(mIntClearShader.pixelShader);
}
SafeDelete(mFloatClearShader);
SafeDelete(mUintClearShader);
SafeDelete(mIntClearShader);
for (ClearDepthStencilStateMap::iterator i = mClearDepthStencilStates.begin(); i != mClearDepthStencilStates.end(); i++)
{
......@@ -239,10 +265,11 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
clearParams.scissor.y + clearParams.scissor.height < framebufferSize.height);
std::vector<MaskedRenderTarget> maskedClearRenderTargets;
RenderTarget11* maskedClearDepthStencil = NULL;
RenderTarget11* maskedClearDepthStencil = nullptr;
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported();
ID3D11Device *device = mRenderer->getDevice();
for (size_t colorAttachment = 0; colorAttachment < colorAttachments.size(); colorAttachment++)
{
......@@ -252,7 +279,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
attachment.isAttached() &&
drawBufferStates[colorAttachment] != GL_NONE)
{
RenderTarget11 *renderTarget = NULL;
RenderTarget11 *renderTarget = nullptr;
gl::Error error = attachment.getRenderTarget(&renderTarget);
if (error.isError())
{
......@@ -349,7 +376,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
const gl::FramebufferAttachment *attachment = (depthAttachment != nullptr) ? depthAttachment : stencilAttachment;
ASSERT(attachment != nullptr);
RenderTarget11 *renderTarget = NULL;
RenderTarget11 *renderTarget = nullptr;
gl::Error error = attachment->getRenderTarget(&renderTarget);
if (error.isError())
{
......@@ -421,7 +448,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
rtvs[i] = rtv;
}
ID3D11DepthStencilView *dsv = maskedClearDepthStencil ? maskedClearDepthStencil->getDepthStencilView() : NULL;
ID3D11DepthStencilView *dsv = maskedClearDepthStencil ? maskedClearDepthStencil->getDepthStencilView() : nullptr;
ID3D11BlendState *blendState = getBlendState(maskedClearRenderTargets);
const FLOAT blendFactors[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
......@@ -433,7 +460,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
// Set the vertices
UINT vertexStride = 0;
const UINT startIdx = 0;
const ClearShader* shader = NULL;
ClearShader *shader = nullptr;
D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT result = deviceContext->Map(mVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
......@@ -441,25 +468,25 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal masked clear vertex buffer, HRESULT: 0x%X.", result);
}
const gl::Rectangle *scissorPtr = clearParams.scissorEnabled ? &clearParams.scissor : NULL;
const gl::Rectangle *scissorPtr = clearParams.scissorEnabled ? &clearParams.scissor : nullptr;
switch (clearParams.colorClearType)
{
case GL_FLOAT:
ApplyVertices(framebufferSize, scissorPtr, clearParams.colorFClearValue, clearParams.depthClearValue, mappedResource.pData);
vertexStride = sizeof(d3d11::PositionDepthColorVertex<float>);
shader = &mFloatClearShader;
shader = mFloatClearShader;
break;
case GL_UNSIGNED_INT:
ApplyVertices(framebufferSize, scissorPtr, clearParams.colorUIClearValue, clearParams.depthClearValue, mappedResource.pData);
vertexStride = sizeof(d3d11::PositionDepthColorVertex<unsigned int>);
shader = &mUintClearShader;
shader = mUintClearShader;
break;
case GL_INT:
ApplyVertices(framebufferSize, scissorPtr, clearParams.colorIClearValue, clearParams.depthClearValue, mappedResource.pData);
vertexStride = sizeof(d3d11::PositionDepthColorVertex<int>);
shader = &mIntClearShader;
shader = mIntClearShader;
break;
default:
......@@ -485,17 +512,17 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
deviceContext->RSSetState(mRasterizerState);
// Apply shaders
deviceContext->IASetInputLayout(shader->inputLayout);
deviceContext->VSSetShader(shader->vertexShader, NULL, 0);
deviceContext->PSSetShader(shader->pixelShader, NULL, 0);
deviceContext->GSSetShader(NULL, NULL, 0);
deviceContext->IASetInputLayout(shader->inputLayout->resolve(device));
deviceContext->VSSetShader(shader->vertexShader.resolve(device), nullptr, 0);
deviceContext->PSSetShader(shader->pixelShader.resolve(device), nullptr, 0);
deviceContext->GSSetShader(nullptr, nullptr, 0);
// Apply vertex buffer
deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &vertexStride, &startIdx);
deviceContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
// Apply render targets
deviceContext->OMSetRenderTargets(rtvs.size(), (rtvs.empty() ? NULL : &rtvs[0]), dsv);
deviceContext->OMSetRenderTargets(rtvs.size(), (rtvs.empty() ? nullptr : &rtvs[0]), dsv);
// Draw the clear quad
deviceContext->Draw(4, 0);
......@@ -552,12 +579,12 @@ ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>&
}
ID3D11Device *device = mRenderer->getDevice();
ID3D11BlendState* blendState = NULL;
ID3D11BlendState* blendState = nullptr;
HRESULT result = device->CreateBlendState(&blendDesc, &blendState);
if (FAILED(result) || !blendState)
{
ERR("Unable to create a ID3D11BlendState, HRESULT: 0x%X.", result);
return NULL;
return nullptr;
}
mClearBlendStates[blendKey] = blendState;
......@@ -597,12 +624,12 @@ ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &cl
dsDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
ID3D11Device *device = mRenderer->getDevice();
ID3D11DepthStencilState* dsState = NULL;
ID3D11DepthStencilState* dsState = nullptr;
HRESULT result = device->CreateDepthStencilState(&dsDesc, &dsState);
if (FAILED(result) || !dsState)
{
ERR("Unable to create a ID3D11DepthStencilState, HRESULT: 0x%X.", result);
return NULL;
return nullptr;
}
mClearDepthStencilStates[dsKey] = dsState;
......
......@@ -15,6 +15,7 @@
#include "libANGLE/angletypes.h"
#include "libANGLE/Error.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
namespace rx
{
......@@ -41,29 +42,32 @@ class Clear11 : angle::NonCopyable
ID3D11BlendState *getBlendState(const std::vector<MaskedRenderTarget> &rts);
ID3D11DepthStencilState *getDepthStencilState(const ClearParameters &clearParams);
struct ClearShader
struct ClearShader final : public angle::NonCopyable
{
ID3D11InputLayout *inputLayout;
ID3D11VertexShader *vertexShader;
ID3D11PixelShader *pixelShader;
ClearShader(DXGI_FORMAT colorType,
const char *inputLayoutName,
const BYTE *vsByteCode,
size_t vsSize,
const char *vsDebugName,
const BYTE *psByteCode,
size_t psSize,
const char *psDebugName);
~ClearShader();
d3d11::LazyInputLayout *inputLayout;
d3d11::LazyShader<ID3D11VertexShader> vertexShader;
d3d11::LazyShader<ID3D11PixelShader> pixelShader;
};
template <unsigned int vsSize, unsigned int psSize>
static ClearShader CreateClearShader(ID3D11Device *device, DXGI_FORMAT colorType, const BYTE(&vsByteCode)[vsSize], const BYTE(&psByteCode)[psSize]);
Renderer11 *mRenderer;
struct ClearBlendInfo
{
bool maskChannels[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT][4];
};
typedef bool(*ClearBlendInfoComparisonFunction)(const ClearBlendInfo&, const ClearBlendInfo &);
typedef std::map<ClearBlendInfo, ID3D11BlendState*, ClearBlendInfoComparisonFunction> ClearBlendStateMap;
ClearBlendStateMap mClearBlendStates;
ClearShader mFloatClearShader;
ClearShader mUintClearShader;
ClearShader mIntClearShader;
struct ClearDepthStencilInfo
{
......@@ -71,8 +75,17 @@ class Clear11 : angle::NonCopyable
bool clearStencil;
UINT8 stencilWriteMask;
};
typedef bool (*ClearDepthStencilInfoComparisonFunction)(const ClearDepthStencilInfo&, const ClearDepthStencilInfo &);
typedef bool(*ClearDepthStencilInfoComparisonFunction)(const ClearDepthStencilInfo&, const ClearDepthStencilInfo &);
typedef std::map<ClearDepthStencilInfo, ID3D11DepthStencilState*, ClearDepthStencilInfoComparisonFunction> ClearDepthStencilStateMap;
Renderer11 *mRenderer;
ClearBlendStateMap mClearBlendStates;
ClearShader *mFloatClearShader;
ClearShader *mUintClearShader;
ClearShader *mIntClearShader;
ClearDepthStencilStateMap mClearDepthStencilStates;
ID3D11Buffer *mVertexBuffer;
......
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