Skip to content
Permalink
Browse files

overlay: replace use of Effects11 with direct use of our split HLSL s…

…haders.

Effects11 is quite heavy, in that it pulls D3DCompiler_43.dll (x86)
and D3DCompiler_47.dll (x64) into our Mumble installations on Windows.

Together, these two DLLs are ~6MB in size.

Also, the removal of the Effects11 library itself cuts the sizes of
the overlay DLLs by more than half:

  mumble_ol.dll with Effects11:         407 KB
  mumble_ol.dll without Effects11:      162 KB

  mumble_ol_x64.dll with Effects11:     497 KB
  mumble_ol_x64.dll without Effects11:  211 KB

Directly using the split shaders is just as easy, and uses less code than
using the Effects11 library. At least for our simple shaders.

And we gain a lot from it.

Done.
  • Loading branch information...
mkrautz committed Nov 26, 2015
1 parent 53a529c commit 3763d596c689515aac4618719d59227cc4485c06
Showing with 19 additions and 55 deletions.
  1. +19 −42 overlay/d3d11.cpp
  2. +0 −13 overlay/overlay-shared.pro
@@ -32,8 +32,8 @@

#include "lib.h"
#include "D11StateBlock.h"
#include "overlay11.hex"
#include "d3dx11effect.h"
#include "overlay11.vs.h"
#include "overlay11.ps.h"
#include <d3d11.h>
#include <d3dx11.h>
#include <time.h>
@@ -75,9 +75,8 @@ class D11State: protected Pipe {
D11StateBlock *pOrigStateBlock;
D11StateBlock *pMyStateBlock;
ID3D11RenderTargetView *pRTV;
ID3DX11Effect *pEffect;
ID3DX11EffectTechnique *pTechnique;
ID3DX11EffectShaderResourceVariable * pDiffuseTexture;
ID3D11VertexShader *pVertexShader;
ID3D11PixelShader *pPixelShader;
ID3D11InputLayout *pVertexLayout;
ID3D11Buffer *pVertexBuffer;
ID3D11Buffer *pIndexBuffer;
@@ -116,9 +115,6 @@ D11State::D11State(IDXGISwapChain *pSwapChain, ID3D11Device *pDevice)
pOrigStateBlock = NULL;
pMyStateBlock = NULL;
pRTV = NULL;
pEffect = NULL;
pTechnique = NULL;
pDiffuseTexture = NULL;
pVertexLayout = NULL;
pVertexBuffer = NULL;
pIndexBuffer = NULL;
@@ -322,22 +318,15 @@ bool D11State::init() {

pDeviceContext->OMSetBlendState(pBlendState, NULL, 0xffffffff);

hr = D3DX11CreateEffectFromMemory((LPCVOID) g_main, sizeof(g_main), 0, pDevice, &pEffect);
hr = pDevice->CreateVertexShader(g_vertex_shader, sizeof(g_vertex_shader), NULL, &pVertexShader);
if (FAILED(hr)) {
ods("D3D11: D3DX11CreateEffectFromMemory failed!");
ods("D3D11: Failed to create vertex shader.");
return false;
}

pTechnique = pEffect->GetTechniqueByName("Render");
if (pTechnique == NULL) {
ods("D3D11: Could not get technique for name 'Render'");
return false;
}


pDiffuseTexture = pEffect->GetVariableByName("txDiffuse")->AsShaderResource();
if (pDiffuseTexture == NULL) {
ods("D3D11: Could not get variable by name 'txDiffuse'");
hr = pDevice->CreatePixelShader(g_pixel_shader, sizeof(g_pixel_shader), NULL, &pPixelShader);
if (FAILED(hr)) {
ods("D3D11: Failed to create pixel shader.");
return false;
}

@@ -350,15 +339,7 @@ bool D11State::init() {
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

// Create the input layout
D3DX11_PASS_DESC PassDesc;
hr = pTechnique->GetPassByIndex(0)->GetDesc(&PassDesc);
if (FAILED(hr)) {
ods("D3D11: Couldn't get pass description for technique");
return false;
}

hr = pDevice->CreateInputLayout(layout, ARRAY_NUM_ELEMENTS(layout), PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &pVertexLayout);
hr = pDevice->CreateInputLayout(layout, ARRAY_NUM_ELEMENTS(layout), g_vertex_shader, sizeof(g_vertex_shader), &pVertexLayout);
if (FAILED(hr)) {
ods("D3D11: pDevice->CreateInputLayout failure!");
return false;
@@ -425,8 +406,10 @@ D11State::~D11State() {
pIndexBuffer->Release();
if (pVertexLayout)
pVertexLayout->Release();
if (pEffect)
pEffect->Release();
if (pVertexShader)
pVertexShader->Release();
if (pPixelShader)
pPixelShader->Release();
if (pRTV)
pRTV->Release();

@@ -469,22 +452,16 @@ void D11State::draw() {
pMyStateBlock->Apply();
}

D3DX11_TECHNIQUE_DESC techDesc;
pTechnique->GetDesc(&techDesc);

// Set vertex buffer
UINT stride = sizeof(SimpleVertex);
UINT offset = 0;
pDeviceContext->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset);

HRESULT hr = pDiffuseTexture->SetResource(pSRView);
if (FAILED(hr))
ods("D3D11: Failed to set resource");

for (UINT p = 0; p < techDesc.Passes; ++p) {
pTechnique->GetPassByIndex(p)->Apply(0, pDeviceContext);
pDeviceContext->DrawIndexed(6, 0, 0);
}
pDeviceContext->VSSetShader(pVertexShader, NULL, 0);
pDeviceContext->GSSetShader(NULL, NULL, 0);
pDeviceContext->PSSetShaderResources(0, 1, &pSRView);
pDeviceContext->PSSetShader(pPixelShader, NULL, 0);
pDeviceContext->DrawIndexed(6, 0, 0);

if (bDeferredContext) {
ID3D11CommandList *pCommandList;
@@ -23,22 +23,15 @@ QMAKE_CXXFLAGS_DEBUG -= -MDd
QMAKE_CXXFLAGS_RELEASE *= -MT
QMAKE_CXXFLAGS_DEBUG *= -MTd

INCLUDEPATH *= "$$FX11DIR/inc"

LIBS *= -ldxguid -luuid -lole32 -luser32 -ladvapi32
LIBS *= -ld3d9 -ld3d10 -ld3d11 -ld3dcompiler -ld3dx9 -ld3dx10 -ld3dx11 -ldxgi

CONFIG(force-x86_64-toolchain) {
LIBS *= -leffects11_x64
DEFINES += USE_MINHOOK
INCLUDEPATH *= ../3rdparty/minhook-src/include
LIBS *= -lminhook
}

CONFIG(force-x86-toolchain) {
LIBS *= -leffects11_x86
}

CONFIG(release, debug|release) {
DESTDIR = ../release
QMAKE_LIBDIR += ../release
@@ -63,12 +56,6 @@ fxc.input = EFFECTS
fxc.CONFIG *= no_link target_predeps
QMAKE_EXTRA_COMPILERS *= fxc

fxc11.output = ${QMAKE_FILE_BASE}11.hex
fxc11.commands = $${FXC} /Tfx_5_0 /O3 /Fh${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
fxc11.input = EFFECTS
fxc11.CONFIG *= no_link target_predeps
QMAKE_EXTRA_COMPILERS *= fxc11

vs11.output = ${QMAKE_FILE_BASE}.ps.h
vs11.commands = $${FXC} /Tvs_5_0 /O3 /Vng_vertex_shader /Fh${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
vs11.input = DX11_VERTEX_SHADERS

0 comments on commit 3763d59

Please sign in to comment.
You can’t perform that action at this time.