Commit e636e140 by Jamie Madill

Blit11: Defer built-in shader loads.

Introduce a 'DeferredShader' utility class. Other classes can use DeferredShader to delay loading shader resources until we render with them, which saves on loading time as well as memory, if we aren't using particular shaders. BUG=angleproject:1014 Change-Id: Ic6767c3c422a7fedbf23cce5d0c9d822aaf2e652 Reviewed-on: https://chromium-review.googlesource.com/275778Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org>
parent 8eeb2bd1
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include <map> #include <map>
...@@ -121,16 +122,25 @@ class Blit11 : angle::NonCopyable ...@@ -121,16 +122,25 @@ class Blit11 : angle::NonCopyable
ID3D11PixelShader *mPixelShader; ID3D11PixelShader *mPixelShader;
}; };
void add2DBlitShaderToMap(BlitShaderType blitShaderType, ID3D11PixelShader *ps); struct CommonShaders
void add3DBlitShaderToMap(BlitShaderType blitShaderType, ID3D11PixelShader *ps); {
ID3D11VertexShader *vertexShader2D;
ID3D11VertexShader *vertexShader3D;
ID3D11GeometryShader *geometryShader3D;
};
void add2DBlitShaderToMap(BlitShaderType blitShaderType, const CommonShaders &commonShaders, ID3D11PixelShader *ps);
void add3DBlitShaderToMap(BlitShaderType blitShaderType, const CommonShaders &commonShaders, ID3D11PixelShader *ps);
gl::Error getBlitShader(GLenum destFormat, bool isSigned, bool is3D, const Shader **shaderOut); gl::Error getBlitShader(GLenum destFormat, bool isSigned, bool is3D, const Shader **shaderOut);
gl::Error getSwizzleShader(GLenum type, D3D11_SRV_DIMENSION viewDimension, const Shader **shaderOut); gl::Error getSwizzleShader(GLenum type, D3D11_SRV_DIMENSION viewDimension, const Shader **shaderOut);
void addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, bool is2D, ID3D11PixelShader *ps); void addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, bool is2D, const CommonShaders &commonShaders, ID3D11PixelShader *ps);
void clearShaderMap(); void clearShaderMap();
gl::Error getCommonShaders(CommonShaders *commonShadersOut, bool get3D);
Renderer11 *mRenderer; Renderer11 *mRenderer;
std::map<BlitShaderType, Shader> mBlitShaderMap; std::map<BlitShaderType, Shader> mBlitShaderMap;
...@@ -144,12 +154,12 @@ class Blit11 : angle::NonCopyable ...@@ -144,12 +154,12 @@ class Blit11 : angle::NonCopyable
ID3D11DepthStencilState *mDepthStencilState; ID3D11DepthStencilState *mDepthStencilState;
ID3D11InputLayout *mQuad2DIL; ID3D11InputLayout *mQuad2DIL;
ID3D11VertexShader *mQuad2DVS; d3d11::DeferredShader<ID3D11VertexShader> mQuad2DVS;
ID3D11PixelShader *mDepthPS; d3d11::DeferredShader<ID3D11PixelShader> mDepthPS;
ID3D11InputLayout *mQuad3DIL; ID3D11InputLayout *mQuad3DIL;
ID3D11VertexShader *mQuad3DVS; d3d11::DeferredShader<ID3D11VertexShader> mQuad3DVS;
ID3D11GeometryShader *mQuad3DGS; d3d11::DeferredShader<ID3D11GeometryShader> mQuad3DGS;
ID3D11Buffer *mSwizzleCB; ID3D11Buffer *mSwizzleCB;
}; };
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/Caps.h" #include "libANGLE/Caps.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
#include <vector> #include <vector>
...@@ -134,8 +135,7 @@ inline bool isDeviceLostError(HRESULT errorCode) ...@@ -134,8 +135,7 @@ inline bool isDeviceLostError(HRESULT errorCode)
} }
} }
template <unsigned int N> inline ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
inline ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE (&byteCode)[N], const char *name)
{ {
ID3D11VertexShader *vs = NULL; ID3D11VertexShader *vs = NULL;
HRESULT result = device->CreateVertexShader(byteCode, N, NULL, &vs); HRESULT result = device->CreateVertexShader(byteCode, N, NULL, &vs);
...@@ -146,7 +146,12 @@ inline ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE (&byteCode ...@@ -146,7 +146,12 @@ inline ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE (&byteCode
} }
template <unsigned int N> template <unsigned int N>
inline ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE (&byteCode)[N], const char *name) ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE (&byteCode)[N], const char *name)
{
return CompileVS(device, byteCode, N, name);
}
inline ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
{ {
ID3D11GeometryShader *gs = NULL; ID3D11GeometryShader *gs = NULL;
HRESULT result = device->CreateGeometryShader(byteCode, N, NULL, &gs); HRESULT result = device->CreateGeometryShader(byteCode, N, NULL, &gs);
...@@ -157,7 +162,12 @@ inline ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE (&byteCo ...@@ -157,7 +162,12 @@ inline ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE (&byteCo
} }
template <unsigned int N> template <unsigned int N>
inline ID3D11PixelShader *CompilePS(ID3D11Device *device, const BYTE (&byteCode)[N], const char *name) ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE (&byteCode)[N], const char *name)
{
return CompileGS(device, byteCode, N, name);
}
inline ID3D11PixelShader *CompilePS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
{ {
ID3D11PixelShader *ps = NULL; ID3D11PixelShader *ps = NULL;
HRESULT result = device->CreatePixelShader(byteCode, N, NULL, &ps); HRESULT result = device->CreatePixelShader(byteCode, N, NULL, &ps);
...@@ -167,10 +177,87 @@ inline ID3D11PixelShader *CompilePS(ID3D11Device *device, const BYTE (&byteCode) ...@@ -167,10 +177,87 @@ inline ID3D11PixelShader *CompilePS(ID3D11Device *device, const BYTE (&byteCode)
return ps; return ps;
} }
template <unsigned int N>
ID3D11PixelShader *CompilePS(ID3D11Device *device, const BYTE (&byteCode)[N], const char *name)
{
return CompilePS(device, byteCode, N, name);
}
template <typename D3D11ShaderType>
class DeferredShader final : public angle::NonCopyable
{
public:
// All parameters must be constexpr. Not supported in VS2013.
DeferredShader(const BYTE *byteCode,
size_t byteCodeSize,
const char *name)
: mByteCode(byteCode),
mByteCodeSize(byteCodeSize),
mName(name),
mShader(nullptr),
mAssociatedDevice(nullptr)
{
}
~DeferredShader() { releaseShader(); }
void releaseShader() { SafeRelease(mShader); }
D3D11ShaderType *getShader(ID3D11Device *device);
private:
void checkAssociatedDevice(ID3D11Device *device);
const BYTE *mByteCode;
size_t mByteCodeSize;
const char *mName;
D3D11ShaderType *mShader;
ID3D11Device *mAssociatedDevice;
};
template <typename D3D11ShaderType>
void DeferredShader<D3D11ShaderType>::checkAssociatedDevice(ID3D11Device *device)
{
ASSERT(mAssociatedDevice == nullptr || device == mAssociatedDevice);
mAssociatedDevice = device;
}
template <>
inline ID3D11VertexShader *DeferredShader<ID3D11VertexShader>::getShader(ID3D11Device *device)
{
checkAssociatedDevice(device);
if (mShader == nullptr)
{
mShader = CompileVS(device, mByteCode, mByteCodeSize, mName);
}
return mShader;
}
template <>
inline ID3D11GeometryShader *DeferredShader<ID3D11GeometryShader>::getShader(ID3D11Device *device)
{
checkAssociatedDevice(device);
if (mShader == nullptr)
{
mShader = CompileGS(device, mByteCode, mByteCodeSize, mName);
}
return mShader;
}
template <>
inline ID3D11PixelShader *DeferredShader<ID3D11PixelShader>::getShader(ID3D11Device *device)
{
checkAssociatedDevice(device);
if (mShader == nullptr)
{
mShader = CompilePS(device, mByteCode, mByteCodeSize, mName);
}
return mShader;
}
// Copy data to small D3D11 buffers, such as for small constant buffers, which use one struct to // Copy data to small D3D11 buffers, such as for small constant buffers, which use one struct to
// represent an entire buffer. // represent an entire buffer.
template <class T> template <class T>
inline void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBuffer, const T &value) void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBuffer, const T &value)
{ {
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
......
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