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
...@@ -99,15 +99,15 @@ ID3D11Resource *CreateStagingTexture(ID3D11Device *device, ID3D11DeviceContext * ...@@ -99,15 +99,15 @@ ID3D11Resource *CreateStagingTexture(ID3D11Device *device, ID3D11DeviceContext *
stagingDesc.MiscFlags = 0; stagingDesc.MiscFlags = 0;
stagingDesc.BindFlags = 0; stagingDesc.BindFlags = 0;
ID3D11Texture2D *stagingTexture = NULL; ID3D11Texture2D *stagingTexture = nullptr;
HRESULT result = device->CreateTexture2D(&stagingDesc, NULL, &stagingTexture); HRESULT result = device->CreateTexture2D(&stagingDesc, nullptr, &stagingTexture);
if (FAILED(result)) if (FAILED(result))
{ {
ERR("Failed to create staging texture for depth stencil blit. HRESULT: 0x%X.", result); ERR("Failed to create staging texture for depth stencil blit. HRESULT: 0x%X.", result);
return NULL; return nullptr;
} }
context->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, source, subresource, NULL); context->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, source, subresource, nullptr);
return stagingTexture; return stagingTexture;
} }
...@@ -200,19 +200,19 @@ inline unsigned int GetSwizzleIndex(GLenum swizzle) ...@@ -200,19 +200,19 @@ inline unsigned int GetSwizzleIndex(GLenum swizzle)
Blit11::Blit11(Renderer11 *renderer) Blit11::Blit11(Renderer11 *renderer)
: mRenderer(renderer), : mRenderer(renderer),
mVertexBuffer(NULL), mVertexBuffer(nullptr),
mPointSampler(NULL), mPointSampler(nullptr),
mLinearSampler(NULL), mLinearSampler(nullptr),
mScissorEnabledRasterizerState(NULL), mScissorEnabledRasterizerState(nullptr),
mScissorDisabledRasterizerState(NULL), mScissorDisabledRasterizerState(nullptr),
mDepthStencilState(NULL), mDepthStencilState(nullptr),
mQuad2DIL(NULL), mQuad2DIL(nullptr),
mQuad2DVS(NULL), mQuad2DVS(g_VS_Passthrough2D, ArraySize(g_VS_Passthrough2D), "Blit11 2D vertex shader"),
mDepthPS(NULL), mDepthPS(g_PS_PassthroughDepth2D, ArraySize(g_PS_PassthroughDepth2D), "Blit11 2D depth pixel shader"),
mQuad3DIL(NULL), mQuad3DIL(nullptr),
mQuad3DVS(NULL), mQuad3DVS(g_VS_Passthrough3D, ArraySize(g_VS_Passthrough3D), "Blit11 3D vertex shader"),
mQuad3DGS(NULL), mQuad3DGS(g_GS_Passthrough3D, ArraySize(g_GS_Passthrough3D), "Blit11 3D geometry shader"),
mSwizzleCB(NULL) mSwizzleCB(nullptr)
{ {
TRACE_EVENT0("gpu.angle", "Blit11::Blit11"); TRACE_EVENT0("gpu.angle", "Blit11::Blit11");
...@@ -228,7 +228,7 @@ Blit11::Blit11(Renderer11 *renderer) ...@@ -228,7 +228,7 @@ Blit11::Blit11(Renderer11 *renderer)
vbDesc.MiscFlags = 0; vbDesc.MiscFlags = 0;
vbDesc.StructureByteStride = 0; vbDesc.StructureByteStride = 0;
result = device->CreateBuffer(&vbDesc, NULL, &mVertexBuffer); result = device->CreateBuffer(&vbDesc, nullptr, &mVertexBuffer);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mVertexBuffer, "Blit11 vertex buffer"); d3d11::SetDebugName(mVertexBuffer, "Blit11 vertex buffer");
...@@ -322,16 +322,8 @@ Blit11::Blit11(Renderer11 *renderer) ...@@ -322,16 +322,8 @@ Blit11::Blit11(Renderer11 *renderer)
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mQuad2DIL, "Blit11 2D input layout"); d3d11::SetDebugName(mQuad2DIL, "Blit11 2D input layout");
result = device->CreateVertexShader(g_VS_Passthrough2D, ArraySize(g_VS_Passthrough2D), NULL, &mQuad2DVS);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mQuad2DVS, "Blit11 2D vertex shader");
if (renderer->isES3Capable()) if (renderer->isES3Capable())
{ {
result = device->CreatePixelShader(g_PS_PassthroughDepth2D, ArraySize(g_PS_PassthroughDepth2D), NULL, &mDepthPS);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mDepthPS, "Blit11 2D depth pixel shader");
D3D11_INPUT_ELEMENT_DESC quad3DLayout[] = D3D11_INPUT_ELEMENT_DESC quad3DLayout[] =
{ {
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
...@@ -342,14 +334,6 @@ Blit11::Blit11(Renderer11 *renderer) ...@@ -342,14 +334,6 @@ Blit11::Blit11(Renderer11 *renderer)
result = device->CreateInputLayout(quad3DLayout, ArraySize(quad3DLayout), g_VS_Passthrough3D, ArraySize(g_VS_Passthrough3D), &mQuad3DIL); result = device->CreateInputLayout(quad3DLayout, ArraySize(quad3DLayout), g_VS_Passthrough3D, ArraySize(g_VS_Passthrough3D), &mQuad3DIL);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mQuad3DIL, "Blit11 3D input layout"); d3d11::SetDebugName(mQuad3DIL, "Blit11 3D input layout");
result = device->CreateVertexShader(g_VS_Passthrough3D, ArraySize(g_VS_Passthrough3D), NULL, &mQuad3DVS);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mQuad3DVS, "Blit11 3D vertex shader");
result = device->CreateGeometryShader(g_GS_Passthrough3D, ArraySize(g_GS_Passthrough3D), NULL, &mQuad3DGS);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mQuad3DGS, "Renderer11 copy 3D texture geometry shader");
} }
D3D11_BUFFER_DESC swizzleBufferDesc; D3D11_BUFFER_DESC swizzleBufferDesc;
...@@ -360,7 +344,7 @@ Blit11::Blit11(Renderer11 *renderer) ...@@ -360,7 +344,7 @@ Blit11::Blit11(Renderer11 *renderer)
swizzleBufferDesc.MiscFlags = 0; swizzleBufferDesc.MiscFlags = 0;
swizzleBufferDesc.StructureByteStride = 0; swizzleBufferDesc.StructureByteStride = 0;
result = device->CreateBuffer(&swizzleBufferDesc, NULL, &mSwizzleCB); result = device->CreateBuffer(&swizzleBufferDesc, nullptr, &mSwizzleCB);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mSwizzleCB, "Blit11 swizzle constant buffer"); d3d11::SetDebugName(mSwizzleCB, "Blit11 swizzle constant buffer");
} }
...@@ -375,12 +359,12 @@ Blit11::~Blit11() ...@@ -375,12 +359,12 @@ Blit11::~Blit11()
SafeRelease(mDepthStencilState); SafeRelease(mDepthStencilState);
SafeRelease(mQuad2DIL); SafeRelease(mQuad2DIL);
SafeRelease(mQuad2DVS); mQuad2DVS.releaseShader();
SafeRelease(mDepthPS); mDepthPS.releaseShader();
SafeRelease(mQuad3DIL); SafeRelease(mQuad3DIL);
SafeRelease(mQuad3DVS); mQuad3DVS.releaseShader();
SafeRelease(mQuad3DGS); mQuad3DGS.releaseShader();
SafeRelease(mSwizzleCB); SafeRelease(mSwizzleCB);
...@@ -592,20 +576,20 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderT ...@@ -592,20 +576,20 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderT
deviceContext->PSSetConstantBuffers(0, 1, &mSwizzleCB); deviceContext->PSSetConstantBuffers(0, 1, &mSwizzleCB);
// Apply state // Apply state
deviceContext->OMSetBlendState(NULL, NULL, 0xFFFFFFF); deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
deviceContext->OMSetDepthStencilState(NULL, 0xFFFFFFFF); deviceContext->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
deviceContext->RSSetState(mScissorDisabledRasterizerState); deviceContext->RSSetState(mScissorDisabledRasterizerState);
// Apply shaders // Apply shaders
deviceContext->IASetInputLayout(shader->mInputLayout); deviceContext->IASetInputLayout(shader->mInputLayout);
deviceContext->IASetPrimitiveTopology(topology); deviceContext->IASetPrimitiveTopology(topology);
deviceContext->VSSetShader(shader->mVertexShader, NULL, 0); deviceContext->VSSetShader(shader->mVertexShader, nullptr, 0);
deviceContext->PSSetShader(shader->mPixelShader, NULL, 0); deviceContext->PSSetShader(shader->mPixelShader, nullptr, 0);
deviceContext->GSSetShader(shader->mGeometryShader, NULL, 0); deviceContext->GSSetShader(shader->mGeometryShader, nullptr, 0);
// Unset the currently bound shader resource to avoid conflicts // Unset the currently bound shader resource to avoid conflicts
mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL); mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, nullptr);
// Apply render target // Apply render target
mRenderer->setOneTimeRenderTarget(dest); mRenderer->setOneTimeRenderTarget(dest);
...@@ -630,12 +614,12 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderT ...@@ -630,12 +614,12 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderT
deviceContext->Draw(drawCount, 0); deviceContext->Draw(drawCount, 0);
// Unbind textures and render targets and vertex buffer // Unbind textures and render targets and vertex buffer
mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL); mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, nullptr);
mRenderer->unapplyRenderTargets(); mRenderer->unapplyRenderTargets();
UINT zero = 0; UINT zero = 0;
ID3D11Buffer *const nullBuffer = NULL; ID3D11Buffer *const nullBuffer = nullptr;
deviceContext->IASetVertexBuffers(0, 1, &nullBuffer, &zero, &zero); deviceContext->IASetVertexBuffers(0, 1, &nullBuffer, &zero, &zero);
mRenderer->markAllStateDirty(); mRenderer->markAllStateDirty();
...@@ -690,8 +674,8 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &s ...@@ -690,8 +674,8 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &s
deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &startIdx); deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &startIdx);
// Apply state // Apply state
deviceContext->OMSetBlendState(NULL, NULL, 0xFFFFFFF); deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
deviceContext->OMSetDepthStencilState(NULL, 0xFFFFFFFF); deviceContext->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
if (scissor) if (scissor)
{ {
...@@ -712,13 +696,13 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &s ...@@ -712,13 +696,13 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &s
// Apply shaders // Apply shaders
deviceContext->IASetInputLayout(shader->mInputLayout); deviceContext->IASetInputLayout(shader->mInputLayout);
deviceContext->IASetPrimitiveTopology(topology); deviceContext->IASetPrimitiveTopology(topology);
deviceContext->VSSetShader(shader->mVertexShader, NULL, 0); deviceContext->VSSetShader(shader->mVertexShader, nullptr, 0);
deviceContext->PSSetShader(shader->mPixelShader, NULL, 0); deviceContext->PSSetShader(shader->mPixelShader, nullptr, 0);
deviceContext->GSSetShader(shader->mGeometryShader, NULL, 0); deviceContext->GSSetShader(shader->mGeometryShader, nullptr, 0);
// Unset the currently bound shader resource to avoid conflicts // Unset the currently bound shader resource to avoid conflicts
mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL); mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, nullptr);
// Apply render target // Apply render target
mRenderer->setOneTimeRenderTarget(dest); mRenderer->setOneTimeRenderTarget(dest);
...@@ -737,7 +721,7 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &s ...@@ -737,7 +721,7 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &s
mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, source); mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, source);
// Apply samplers // Apply samplers
ID3D11SamplerState *sampler = NULL; ID3D11SamplerState *sampler = nullptr;
switch (filter) switch (filter)
{ {
case GL_NEAREST: sampler = mPointSampler; break; case GL_NEAREST: sampler = mPointSampler; break;
...@@ -753,12 +737,12 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &s ...@@ -753,12 +737,12 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source, const gl::Box &s
deviceContext->Draw(drawCount, 0); deviceContext->Draw(drawCount, 0);
// Unbind textures and render targets and vertex buffer // Unbind textures and render targets and vertex buffer
mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL); mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, nullptr);
mRenderer->unapplyRenderTargets(); mRenderer->unapplyRenderTargets();
UINT zero = 0; UINT zero = 0;
ID3D11Buffer *const nullBuffer = NULL; ID3D11Buffer *const nullBuffer = nullptr;
deviceContext->IASetVertexBuffers(0, 1, &nullBuffer, &zero, &zero); deviceContext->IASetVertexBuffers(0, 1, &nullBuffer, &zero, &zero);
mRenderer->markAllStateDirty(); mRenderer->markAllStateDirty();
...@@ -804,7 +788,7 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sou ...@@ -804,7 +788,7 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sou
deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &startIdx); deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &startIdx);
// Apply state // Apply state
deviceContext->OMSetBlendState(NULL, NULL, 0xFFFFFFF); deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
deviceContext->OMSetDepthStencilState(mDepthStencilState, 0xFFFFFFFF); deviceContext->OMSetDepthStencilState(mDepthStencilState, 0xFFFFFFFF);
if (scissor) if (scissor)
...@@ -823,19 +807,26 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sou ...@@ -823,19 +807,26 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sou
deviceContext->RSSetState(mScissorDisabledRasterizerState); deviceContext->RSSetState(mScissorDisabledRasterizerState);
} }
ID3D11Device *device = mRenderer->getDevice();
ID3D11VertexShader *quad2DVS = mQuad2DVS.getShader(device);
if (quad2DVS == nullptr)
{
return gl::Error(GL_INVALID_OPERATION, "Error compiling internal 2D blit vertex shader");
}
// Apply shaders // Apply shaders
deviceContext->IASetInputLayout(mQuad2DIL); deviceContext->IASetInputLayout(mQuad2DIL);
deviceContext->IASetPrimitiveTopology(topology); deviceContext->IASetPrimitiveTopology(topology);
deviceContext->VSSetShader(mQuad2DVS, NULL, 0); deviceContext->VSSetShader(quad2DVS, nullptr, 0);
deviceContext->PSSetShader(mDepthPS, NULL, 0); deviceContext->PSSetShader(mDepthPS.getShader(device), nullptr, 0);
deviceContext->GSSetShader(NULL, NULL, 0); deviceContext->GSSetShader(nullptr, nullptr, 0);
// Unset the currently bound shader resource to avoid conflicts // Unset the currently bound shader resource to avoid conflicts
mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL); mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, nullptr);
// Apply render target // Apply render target
deviceContext->OMSetRenderTargets(0, NULL, dest); deviceContext->OMSetRenderTargets(0, nullptr, dest);
// Set the viewport // Set the viewport
D3D11_VIEWPORT viewport; D3D11_VIEWPORT viewport;
...@@ -857,12 +848,12 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sou ...@@ -857,12 +848,12 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sou
deviceContext->Draw(drawCount, 0); deviceContext->Draw(drawCount, 0);
// Unbind textures and render targets and vertex buffer // Unbind textures and render targets and vertex buffer
mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, NULL); mRenderer->setShaderResource(gl::SAMPLER_PIXEL, 0, nullptr);
mRenderer->unapplyRenderTargets(); mRenderer->unapplyRenderTargets();
UINT zero = 0; UINT zero = 0;
ID3D11Buffer *const nullBuffer = NULL; ID3D11Buffer *const nullBuffer = nullptr;
deviceContext->IASetVertexBuffers(0, 1, &nullBuffer, &zero, &zero); deviceContext->IASetVertexBuffers(0, 1, &nullBuffer, &zero, &zero);
mRenderer->markAllStateDirty(); mRenderer->markAllStateDirty();
...@@ -999,14 +990,14 @@ gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSu ...@@ -999,14 +990,14 @@ gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSu
// HACK: Use ID3D11DevicContext::UpdateSubresource which causes an extra copy compared to ID3D11DevicContext::CopySubresourceRegion // HACK: Use ID3D11DevicContext::UpdateSubresource which causes an extra copy compared to ID3D11DevicContext::CopySubresourceRegion
// according to MSDN. // according to MSDN.
deviceContext->UpdateSubresource(dest, destSubresource, NULL, destMapping.pData, destMapping.RowPitch, destMapping.DepthPitch); deviceContext->UpdateSubresource(dest, destSubresource, nullptr, destMapping.pData, destMapping.RowPitch, destMapping.DepthPitch);
deviceContext->Unmap(sourceStaging, 0); deviceContext->Unmap(sourceStaging, 0);
deviceContext->Unmap(destStaging, 0); deviceContext->Unmap(destStaging, 0);
// TODO: Determine why this call to ID3D11DevicContext::CopySubresourceRegion causes a TDR timeout on some // TODO: Determine why this call to ID3D11DevicContext::CopySubresourceRegion causes a TDR timeout on some
// systems when called repeatedly. // systems when called repeatedly.
// deviceContext->CopySubresourceRegion(dest, destSubresource, 0, 0, 0, destStaging, 0, NULL); // deviceContext->CopySubresourceRegion(dest, destSubresource, 0, 0, 0, destStaging, 0, nullptr);
SafeRelease(sourceStaging); SafeRelease(sourceStaging);
SafeRelease(destStaging); SafeRelease(destStaging);
...@@ -1014,7 +1005,7 @@ gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSu ...@@ -1014,7 +1005,7 @@ gl::Error Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSu
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
void Blit11::add2DBlitShaderToMap(BlitShaderType blitShaderType, ID3D11PixelShader *ps) void Blit11::add2DBlitShaderToMap(BlitShaderType blitShaderType, const CommonShaders &commonShaders, ID3D11PixelShader *ps)
{ {
ASSERT(mBlitShaderMap.find(blitShaderType) == mBlitShaderMap.end()); ASSERT(mBlitShaderMap.find(blitShaderType) == mBlitShaderMap.end());
ASSERT(ps); ASSERT(ps);
...@@ -1022,14 +1013,14 @@ void Blit11::add2DBlitShaderToMap(BlitShaderType blitShaderType, ID3D11PixelShad ...@@ -1022,14 +1013,14 @@ void Blit11::add2DBlitShaderToMap(BlitShaderType blitShaderType, ID3D11PixelShad
Shader shader; Shader shader;
shader.mVertexWriteFunction = Write2DVertices; shader.mVertexWriteFunction = Write2DVertices;
shader.mInputLayout = mQuad2DIL; shader.mInputLayout = mQuad2DIL;
shader.mVertexShader = mQuad2DVS; shader.mVertexShader = commonShaders.vertexShader2D;
shader.mGeometryShader = NULL; shader.mGeometryShader = nullptr;
shader.mPixelShader = ps; shader.mPixelShader = ps;
mBlitShaderMap[blitShaderType] = shader; mBlitShaderMap[blitShaderType] = shader;
} }
void Blit11::add3DBlitShaderToMap(BlitShaderType blitShaderType, ID3D11PixelShader *ps) void Blit11::add3DBlitShaderToMap(BlitShaderType blitShaderType, const CommonShaders &commonShaders, ID3D11PixelShader *ps)
{ {
ASSERT(mBlitShaderMap.find(blitShaderType) == mBlitShaderMap.end()); ASSERT(mBlitShaderMap.find(blitShaderType) == mBlitShaderMap.end());
ASSERT(ps); ASSERT(ps);
...@@ -1037,14 +1028,14 @@ void Blit11::add3DBlitShaderToMap(BlitShaderType blitShaderType, ID3D11PixelShad ...@@ -1037,14 +1028,14 @@ void Blit11::add3DBlitShaderToMap(BlitShaderType blitShaderType, ID3D11PixelShad
Shader shader; Shader shader;
shader.mVertexWriteFunction = Write3DVertices; shader.mVertexWriteFunction = Write3DVertices;
shader.mInputLayout = mQuad3DIL; shader.mInputLayout = mQuad3DIL;
shader.mVertexShader = mQuad3DVS; shader.mVertexShader = commonShaders.vertexShader3D;
shader.mGeometryShader = mQuad3DGS; shader.mGeometryShader = commonShaders.geometryShader3D;
shader.mPixelShader = ps; shader.mPixelShader = ps;
mBlitShaderMap[blitShaderType] = shader; mBlitShaderMap[blitShaderType] = shader;
} }
void Blit11::addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, bool is2D, ID3D11PixelShader *ps) void Blit11::addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, bool is2D, const CommonShaders &commonShaders, ID3D11PixelShader *ps)
{ {
ASSERT(mSwizzleShaderMap.find(swizzleShaderType) == mSwizzleShaderMap.end()); ASSERT(mSwizzleShaderMap.find(swizzleShaderType) == mSwizzleShaderMap.end());
ASSERT(ps); ASSERT(ps);
...@@ -1054,15 +1045,15 @@ void Blit11::addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, bool is2 ...@@ -1054,15 +1045,15 @@ void Blit11::addSwizzleShaderToMap(SwizzleShaderType swizzleShaderType, bool is2
{ {
shader.mVertexWriteFunction = Write2DVertices; shader.mVertexWriteFunction = Write2DVertices;
shader.mInputLayout = mQuad2DIL; shader.mInputLayout = mQuad2DIL;
shader.mVertexShader = mQuad2DVS; shader.mVertexShader = commonShaders.vertexShader2D;
shader.mGeometryShader = NULL; shader.mGeometryShader = nullptr;
} }
else else
{ {
shader.mVertexWriteFunction = Write3DVertices; shader.mVertexWriteFunction = Write3DVertices;
shader.mInputLayout = mQuad3DIL; shader.mInputLayout = mQuad3DIL;
shader.mVertexShader = mQuad3DVS; shader.mVertexShader = commonShaders.vertexShader3D;
shader.mGeometryShader = mQuad3DGS; shader.mGeometryShader = commonShaders.geometryShader3D;
} }
shader.mPixelShader = ps; shader.mPixelShader = ps;
...@@ -1102,105 +1093,108 @@ gl::Error Blit11::getBlitShader(GLenum destFormat, bool isSigned, bool is3D, con ...@@ -1102,105 +1093,108 @@ gl::Error Blit11::getBlitShader(GLenum destFormat, bool isSigned, bool is3D, con
ASSERT(!is3D || mRenderer->isES3Capable()); ASSERT(!is3D || mRenderer->isES3Capable());
CommonShaders commonShaders;
gl::Error error = getCommonShaders(&commonShaders, is3D);
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
switch (blitShaderType) switch (blitShaderType)
{ {
case BLITSHADER_2D_RGBAF: case BLITSHADER_2D_RGBAF:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA2D, "Blit11 2D RGBA pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA2D, "Blit11 2D RGBA pixel shader"));
break; break;
case BLITSHADER_2D_BGRAF: case BLITSHADER_2D_BGRAF:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA2D, "Blit11 2D BGRA pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA2D, "Blit11 2D BGRA pixel shader"));
break; break;
case BLITSHADER_2D_RGBF: case BLITSHADER_2D_RGBF:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGB2D, "Blit11 2D RGB pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGB2D, "Blit11 2D RGB pixel shader"));
break; break;
case BLITSHADER_2D_RGF: case BLITSHADER_2D_RGF:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRG2D, "Blit11 2D RG pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRG2D, "Blit11 2D RG pixel shader"));
break; break;
case BLITSHADER_2D_RF: case BLITSHADER_2D_RF:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughR2D, "Blit11 2D R pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughR2D, "Blit11 2D R pixel shader"));
break; break;
case BLITSHADER_2D_ALPHA: case BLITSHADER_2D_ALPHA:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA2D, "Blit11 2D alpha pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA2D, "Blit11 2D alpha pixel shader"));
break; break;
case BLITSHADER_2D_LUMA: case BLITSHADER_2D_LUMA:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughLum2D, "Blit11 2D lum pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughLum2D, "Blit11 2D lum pixel shader"));
break; break;
case BLITSHADER_2D_LUMAALPHA: case BLITSHADER_2D_LUMAALPHA:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughLumAlpha2D, "Blit11 2D luminance alpha pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughLumAlpha2D, "Blit11 2D luminance alpha pixel shader"));
break; break;
case BLITSHADER_2D_RGBAUI: case BLITSHADER_2D_RGBAUI:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA2DUI, "Blit11 2D RGBA UI pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA2DUI, "Blit11 2D RGBA UI pixel shader"));
break; break;
case BLITSHADER_2D_RGBAI: case BLITSHADER_2D_RGBAI:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA2DI, "Blit11 2D RGBA I pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA2DI, "Blit11 2D RGBA I pixel shader"));
break; break;
case BLITSHADER_2D_RGBUI: case BLITSHADER_2D_RGBUI:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGB2DUI, "Blit11 2D RGB UI pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGB2DUI, "Blit11 2D RGB UI pixel shader"));
break; break;
case BLITSHADER_2D_RGBI: case BLITSHADER_2D_RGBI:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGB2DI, "Blit11 2D RGB I pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGB2DI, "Blit11 2D RGB I pixel shader"));
break; break;
case BLITSHADER_2D_RGUI: case BLITSHADER_2D_RGUI:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRG2DUI, "Blit11 2D RG UI pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRG2DUI, "Blit11 2D RG UI pixel shader"));
break; break;
case BLITSHADER_2D_RGI: case BLITSHADER_2D_RGI:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRG2DI, "Blit11 2D RG I pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRG2DI, "Blit11 2D RG I pixel shader"));
break; break;
case BLITSHADER_2D_RUI: case BLITSHADER_2D_RUI:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughR2DUI, "Blit11 2D R UI pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughR2DUI, "Blit11 2D R UI pixel shader"));
break; break;
case BLITSHADER_2D_RI: case BLITSHADER_2D_RI:
add2DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughR2DI, "Blit11 2D R I pixel shader")); add2DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughR2DI, "Blit11 2D R I pixel shader"));
break; break;
case BLITSHADER_3D_RGBAF: case BLITSHADER_3D_RGBAF:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA3D, "Blit11 3D RGBA pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA3D, "Blit11 3D RGBA pixel shader"));
break; break;
case BLITSHADER_3D_RGBAUI: case BLITSHADER_3D_RGBAUI:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA3DUI, "Blit11 3D UI RGBA pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA3DUI, "Blit11 3D UI RGBA pixel shader"));
break; break;
case BLITSHADER_3D_RGBAI: case BLITSHADER_3D_RGBAI:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA3DI, "Blit11 3D I RGBA pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA3DI, "Blit11 3D I RGBA pixel shader"));
break; break;
case BLITSHADER_3D_BGRAF: case BLITSHADER_3D_BGRAF:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA3D, "Blit11 3D BGRA pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA3D, "Blit11 3D BGRA pixel shader"));
break; break;
case BLITSHADER_3D_RGBF: case BLITSHADER_3D_RGBF:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGB3D, "Blit11 3D RGB pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGB3D, "Blit11 3D RGB pixel shader"));
break; break;
case BLITSHADER_3D_RGBUI: case BLITSHADER_3D_RGBUI:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGB3DUI, "Blit11 3D RGB UI pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGB3DUI, "Blit11 3D RGB UI pixel shader"));
break; break;
case BLITSHADER_3D_RGBI: case BLITSHADER_3D_RGBI:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGB3DI, "Blit11 3D RGB I pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGB3DI, "Blit11 3D RGB I pixel shader"));
break; break;
case BLITSHADER_3D_RGF: case BLITSHADER_3D_RGF:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRG3D, "Blit11 3D RG pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRG3D, "Blit11 3D RG pixel shader"));
break; break;
case BLITSHADER_3D_RGUI: case BLITSHADER_3D_RGUI:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRG3DUI, "Blit11 3D RG UI pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRG3DUI, "Blit11 3D RG UI pixel shader"));
break; break;
case BLITSHADER_3D_RGI: case BLITSHADER_3D_RGI:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRG3DI, "Blit11 3D RG I pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRG3DI, "Blit11 3D RG I pixel shader"));
break; break;
case BLITSHADER_3D_RF: case BLITSHADER_3D_RF:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughR3D, "Blit11 3D R pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughR3D, "Blit11 3D R pixel shader"));
break; break;
case BLITSHADER_3D_RUI: case BLITSHADER_3D_RUI:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughR3DUI, "Blit11 3D R UI pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughR3DUI, "Blit11 3D R UI pixel shader"));
break; break;
case BLITSHADER_3D_RI: case BLITSHADER_3D_RI:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughR3DI, "Blit11 3D R I pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughR3DI, "Blit11 3D R I pixel shader"));
break; break;
case BLITSHADER_3D_ALPHA: case BLITSHADER_3D_ALPHA:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughRGBA3D, "Blit11 3D alpha pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughRGBA3D, "Blit11 3D alpha pixel shader"));
break; break;
case BLITSHADER_3D_LUMA: case BLITSHADER_3D_LUMA:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughLum3D, "Blit11 3D luminance pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughLum3D, "Blit11 3D luminance pixel shader"));
break; break;
case BLITSHADER_3D_LUMAALPHA: case BLITSHADER_3D_LUMAALPHA:
add3DBlitShaderToMap(blitShaderType, d3d11::CompilePS(device, g_PS_PassthroughLumAlpha3D, "Blit11 3D luminance alpha pixel shader")); add3DBlitShaderToMap(blitShaderType, commonShaders, d3d11::CompilePS(device, g_PS_PassthroughLumAlpha3D, "Blit11 3D luminance alpha pixel shader"));
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -1232,45 +1226,48 @@ gl::Error Blit11::getSwizzleShader(GLenum type, D3D11_SRV_DIMENSION viewDimensio ...@@ -1232,45 +1226,48 @@ gl::Error Blit11::getSwizzleShader(GLenum type, D3D11_SRV_DIMENSION viewDimensio
// Swizzling shaders (OpenGL ES 3+) // Swizzling shaders (OpenGL ES 3+)
ASSERT(mRenderer->isES3Capable()); ASSERT(mRenderer->isES3Capable());
CommonShaders commonShaders;
gl::Error error = getCommonShaders(&commonShaders, true);
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
switch (swizzleShaderType) switch (swizzleShaderType)
{ {
case SWIZZLESHADER_2D_FLOAT: case SWIZZLESHADER_2D_FLOAT:
addSwizzleShaderToMap(swizzleShaderType, true, d3d11::CompilePS(device, g_PS_SwizzleF2D, "Blit11 2D F swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, true, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleF2D, "Blit11 2D F swizzle pixel shader"));
break; break;
case SWIZZLESHADER_2D_UINT: case SWIZZLESHADER_2D_UINT:
addSwizzleShaderToMap(swizzleShaderType, true, d3d11::CompilePS(device, g_PS_SwizzleUI2D, "Blit11 2D UI swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, true, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleUI2D, "Blit11 2D UI swizzle pixel shader"));
break; break;
case SWIZZLESHADER_2D_INT: case SWIZZLESHADER_2D_INT:
addSwizzleShaderToMap(swizzleShaderType, true, d3d11::CompilePS(device, g_PS_SwizzleI2D, "Blit11 2D I swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, true, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleI2D, "Blit11 2D I swizzle pixel shader"));
break; break;
case SWIZZLESHADER_CUBE_FLOAT: case SWIZZLESHADER_CUBE_FLOAT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleF2DArray, "Blit11 2D Cube F swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleF2DArray, "Blit11 2D Cube F swizzle pixel shader"));
break; break;
case SWIZZLESHADER_CUBE_UINT: case SWIZZLESHADER_CUBE_UINT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleUI2DArray, "Blit11 2D Cube UI swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleUI2DArray, "Blit11 2D Cube UI swizzle pixel shader"));
break; break;
case SWIZZLESHADER_CUBE_INT: case SWIZZLESHADER_CUBE_INT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleI2DArray, "Blit11 2D Cube I swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleI2DArray, "Blit11 2D Cube I swizzle pixel shader"));
break; break;
case SWIZZLESHADER_3D_FLOAT: case SWIZZLESHADER_3D_FLOAT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleF3D, "Blit11 3D F swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleF3D, "Blit11 3D F swizzle pixel shader"));
break; break;
case SWIZZLESHADER_3D_UINT: case SWIZZLESHADER_3D_UINT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleUI3D, "Blit11 3D UI swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleUI3D, "Blit11 3D UI swizzle pixel shader"));
break; break;
case SWIZZLESHADER_3D_INT: case SWIZZLESHADER_3D_INT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleI3D, "Blit11 3D I swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleI3D, "Blit11 3D I swizzle pixel shader"));
break; break;
case SWIZZLESHADER_ARRAY_FLOAT: case SWIZZLESHADER_ARRAY_FLOAT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleF2DArray, "Blit11 2D Array F swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleF2DArray, "Blit11 2D Array F swizzle pixel shader"));
break; break;
case SWIZZLESHADER_ARRAY_UINT: case SWIZZLESHADER_ARRAY_UINT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleUI2DArray, "Blit11 2D Array UI swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleUI2DArray, "Blit11 2D Array UI swizzle pixel shader"));
break; break;
case SWIZZLESHADER_ARRAY_INT: case SWIZZLESHADER_ARRAY_INT:
addSwizzleShaderToMap(swizzleShaderType, false, d3d11::CompilePS(device, g_PS_SwizzleI2DArray, "Blit11 2D Array I swizzle pixel shader")); addSwizzleShaderToMap(swizzleShaderType, false, commonShaders, d3d11::CompilePS(device, g_PS_SwizzleI2DArray, "Blit11 2D Array I swizzle pixel shader"));
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -1283,4 +1280,28 @@ gl::Error Blit11::getSwizzleShader(GLenum type, D3D11_SRV_DIMENSION viewDimensio ...@@ -1283,4 +1280,28 @@ gl::Error Blit11::getSwizzleShader(GLenum type, D3D11_SRV_DIMENSION viewDimensio
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
gl::Error Blit11::getCommonShaders(CommonShaders *commonShadersOut, bool get3D)
{
ID3D11Device *device = mRenderer->getDevice();
commonShadersOut->vertexShader2D = mQuad2DVS.getShader(device);
if (commonShadersOut->vertexShader2D == nullptr)
{
return gl::Error(GL_INVALID_OPERATION, "Error compiling internal blit 2d vertex shader");
}
if (get3D)
{
commonShadersOut->vertexShader3D = mQuad3DVS.getShader(device);
commonShadersOut->geometryShader3D = mQuad3DGS.getShader(device);
if (commonShadersOut->vertexShader3D == nullptr || commonShadersOut->geometryShader3D == nullptr)
{
return gl::Error(GL_INVALID_OPERATION, "Error compiling internal blit 3d shaders");
}
}
return gl::Error(GL_NO_ERROR);
}
} }
...@@ -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