mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Refactor shader initialization in CompositorD3D11. (bug 1203829 part 3, r=mattwoodrow)
This commit is contained in:
parent
7b232067b8
commit
3d562fc5d6
@ -46,6 +46,13 @@ const FLOAT sBlendFactor[] = { 0, 0, 0, 0 };
|
||||
|
||||
struct DeviceAttachmentsD3D11
|
||||
{
|
||||
DeviceAttachmentsD3D11(ID3D11Device* device)
|
||||
: mDevice(device),
|
||||
mInitOkay(true)
|
||||
{}
|
||||
|
||||
bool CreateShaders();
|
||||
|
||||
typedef EnumeratedArray<MaskType, MaskType::NumMaskTypes, RefPtr<ID3D11VertexShader>>
|
||||
VertexShaderArray;
|
||||
typedef EnumeratedArray<MaskType, MaskType::NumMaskTypes, RefPtr<ID3D11PixelShader>>
|
||||
@ -93,6 +100,34 @@ struct DeviceAttachmentsD3D11
|
||||
RefPtr<ID3D11Buffer> mVRDistortionVertices[2]; // one for each eye
|
||||
RefPtr<ID3D11Buffer> mVRDistortionIndices[2];
|
||||
uint32_t mVRDistortionIndexCount[2];
|
||||
|
||||
private:
|
||||
void InitVertexShader(const ShaderBytes& aShader, VertexShaderArray& aArray, MaskType aMaskType) {
|
||||
InitVertexShader(aShader, byRef(aArray[aMaskType]));
|
||||
}
|
||||
void InitPixelShader(const ShaderBytes& aShader, PixelShaderArray& aArray, MaskType aMaskType) {
|
||||
InitPixelShader(aShader, byRef(aArray[aMaskType]));
|
||||
}
|
||||
void InitVertexShader(const ShaderBytes& aShader, ID3D11VertexShader** aOut) {
|
||||
if (!mInitOkay) {
|
||||
return;
|
||||
}
|
||||
if (FAILED(mDevice->CreateVertexShader(aShader.mData, aShader.mLength, nullptr, aOut))) {
|
||||
mInitOkay = false;
|
||||
}
|
||||
}
|
||||
void InitPixelShader(const ShaderBytes& aShader, ID3D11PixelShader** aOut) {
|
||||
if (!mInitOkay) {
|
||||
return;
|
||||
}
|
||||
if (FAILED(mDevice->CreatePixelShader(aShader.mData, aShader.mLength, nullptr, aOut))) {
|
||||
mInitOkay = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Only used during initialization.
|
||||
RefPtr<ID3D11Device> mDevice;
|
||||
bool mInitOkay;
|
||||
};
|
||||
|
||||
CompositorD3D11::CompositorD3D11(nsIWidget* aWidget)
|
||||
@ -171,7 +206,7 @@ CompositorD3D11::Initialize()
|
||||
if (FAILED(mDevice->GetPrivateData(sDeviceAttachmentsD3D11,
|
||||
&size,
|
||||
&mAttachments))) {
|
||||
mAttachments = new DeviceAttachmentsD3D11;
|
||||
mAttachments = new DeviceAttachmentsD3D11(mDevice);
|
||||
mDevice->SetPrivateData(sDeviceAttachmentsD3D11,
|
||||
sizeof(mAttachments),
|
||||
&mAttachments);
|
||||
@ -202,7 +237,7 @@ CompositorD3D11::Initialize()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CreateShaders()) {
|
||||
if (!mAttachments->CreateShaders()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1236,86 +1271,34 @@ CompositorD3D11::UpdateRenderTarget()
|
||||
}
|
||||
|
||||
bool
|
||||
CompositorD3D11::CreateShaders()
|
||||
DeviceAttachmentsD3D11::CreateShaders()
|
||||
{
|
||||
HRESULT hr;
|
||||
InitVertexShader(sLayerQuadVS, mVSQuadShader, MaskType::MaskNone);
|
||||
InitVertexShader(sLayerQuadMaskVS, mVSQuadShader, MaskType::Mask2d);
|
||||
InitVertexShader(sLayerQuadMask3DVS, mVSQuadShader, MaskType::Mask3d);
|
||||
|
||||
hr = mDevice->CreateVertexShader(LayerQuadVS,
|
||||
sizeof(LayerQuadVS),
|
||||
nullptr,
|
||||
byRef(mAttachments->mVSQuadShader[MaskType::MaskNone]));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = mDevice->CreateVertexShader(LayerQuadMaskVS,
|
||||
sizeof(LayerQuadMaskVS),
|
||||
nullptr,
|
||||
byRef(mAttachments->mVSQuadShader[MaskType::Mask2d]));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = mDevice->CreateVertexShader(LayerQuadMask3DVS,
|
||||
sizeof(LayerQuadMask3DVS),
|
||||
nullptr,
|
||||
byRef(mAttachments->mVSQuadShader[MaskType::Mask3d]));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#define LOAD_PIXEL_SHADER(x) hr = mDevice->CreatePixelShader(x, sizeof(x), nullptr, byRef(mAttachments->m##x[MaskType::MaskNone])); \
|
||||
if (FAILED(hr)) { \
|
||||
return false; \
|
||||
} \
|
||||
hr = mDevice->CreatePixelShader(x##Mask, sizeof(x##Mask), nullptr, byRef(mAttachments->m##x[MaskType::Mask2d])); \
|
||||
if (FAILED(hr)) { \
|
||||
return false; \
|
||||
}
|
||||
|
||||
LOAD_PIXEL_SHADER(SolidColorShader);
|
||||
LOAD_PIXEL_SHADER(RGBShader);
|
||||
LOAD_PIXEL_SHADER(RGBAShader);
|
||||
LOAD_PIXEL_SHADER(YCbCrShader);
|
||||
InitPixelShader(sSolidColorShader, mSolidColorShader, MaskType::MaskNone);
|
||||
InitPixelShader(sSolidColorShaderMask, mSolidColorShader, MaskType::Mask2d);
|
||||
InitPixelShader(sRGBShader, mRGBShader, MaskType::MaskNone);
|
||||
InitPixelShader(sRGBShaderMask, mRGBShader, MaskType::Mask2d);
|
||||
InitPixelShader(sRGBAShader, mRGBAShader, MaskType::MaskNone);
|
||||
InitPixelShader(sRGBAShaderMask, mRGBAShader, MaskType::Mask2d);
|
||||
InitPixelShader(sRGBAShaderMask3D, mRGBAShader, MaskType::Mask3d);
|
||||
InitPixelShader(sYCbCrShader, mYCbCrShader, MaskType::MaskNone);
|
||||
InitPixelShader(sYCbCrShaderMask, mYCbCrShader, MaskType::Mask2d);
|
||||
if (gfxPrefs::ComponentAlphaEnabled()) {
|
||||
LOAD_PIXEL_SHADER(ComponentAlphaShader);
|
||||
InitPixelShader(sComponentAlphaShader, mComponentAlphaShader, MaskType::MaskNone);
|
||||
InitPixelShader(sComponentAlphaShaderMask, mComponentAlphaShader, MaskType::Mask2d);
|
||||
}
|
||||
|
||||
#undef LOAD_PIXEL_SHADER
|
||||
|
||||
hr = mDevice->CreatePixelShader(RGBAShaderMask3D,
|
||||
sizeof(RGBAShaderMask3D),
|
||||
nullptr,
|
||||
byRef(mAttachments->mRGBAShader[MaskType::Mask3d]));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* VR stuff */
|
||||
|
||||
hr = mDevice->CreateVertexShader(Oculus050VRDistortionVS,
|
||||
sizeof(Oculus050VRDistortionVS),
|
||||
nullptr,
|
||||
byRef(mAttachments->mVRDistortionVS[VRHMDType::Oculus050]));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = mDevice->CreatePixelShader(Oculus050VRDistortionPS,
|
||||
sizeof(Oculus050VRDistortionPS),
|
||||
nullptr,
|
||||
byRef(mAttachments->mVRDistortionPS[VRHMDType::Oculus050]));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
InitVertexShader(sOculus050VRDistortionVS, byRef(mVRDistortionVS[VRHMDType::Oculus050]));
|
||||
InitPixelShader(sOculus050VRDistortionPS, byRef(mVRDistortionPS[VRHMDType::Oculus050]));
|
||||
|
||||
// These are shared
|
||||
// XXX rename Oculus050 shaders to something more generic
|
||||
mAttachments->mVRDistortionVS[VRHMDType::Cardboard] = mAttachments->mVRDistortionVS[VRHMDType::Oculus050];
|
||||
mAttachments->mVRDistortionPS[VRHMDType::Cardboard] = mAttachments->mVRDistortionPS[VRHMDType::Oculus050];
|
||||
|
||||
return true;
|
||||
mVRDistortionVS[VRHMDType::Cardboard] = mVRDistortionVS[VRHMDType::Oculus050];
|
||||
mVRDistortionPS[VRHMDType::Cardboard] = mVRDistortionPS[VRHMDType::Oculus050];
|
||||
return mInitOkay;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -164,7 +164,6 @@ private:
|
||||
void EnsureSize();
|
||||
bool VerifyBufferSize();
|
||||
void UpdateRenderTarget();
|
||||
bool CreateShaders();
|
||||
bool UpdateConstantBuffers();
|
||||
void SetSamplerForFilter(gfx::Filter aFilter);
|
||||
void SetPSForEffect(Effect *aEffect, MaskType aMaskType, gfx::SurfaceFormat aFormat);
|
||||
|
@ -1,3 +1,4 @@
|
||||
struct ShaderBytes { const void* mData; size_t mLength; };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -390,6 +391,7 @@ const BYTE LayerQuadVS[] =
|
||||
84, 69, 88, 67, 79, 79,
|
||||
82, 68, 0, 171, 171, 171
|
||||
};
|
||||
ShaderBytes sLayerQuadVS = { LayerQuadVS, sizeof(LayerQuadVS) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -625,6 +627,7 @@ const BYTE SolidColorShader[] =
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171
|
||||
};
|
||||
ShaderBytes sSolidColorShader = { SolidColorShader, sizeof(SolidColorShader) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -924,6 +927,7 @@ const BYTE RGBShader[] =
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171
|
||||
};
|
||||
ShaderBytes sRGBShader = { RGBShader, sizeof(RGBShader) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -1215,6 +1219,7 @@ const BYTE RGBAShader[] =
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171
|
||||
};
|
||||
ShaderBytes sRGBAShader = { RGBAShader, sizeof(RGBAShader) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -1588,6 +1593,7 @@ const BYTE ComponentAlphaShader[] =
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171
|
||||
};
|
||||
ShaderBytes sComponentAlphaShader = { ComponentAlphaShader, sizeof(ComponentAlphaShader) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -2043,6 +2049,7 @@ const BYTE YCbCrShader[] =
|
||||
83, 86, 95, 84, 97, 114,
|
||||
103, 101, 116, 0, 171, 171
|
||||
};
|
||||
ShaderBytes sYCbCrShader = { YCbCrShader, sizeof(YCbCrShader) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -2478,6 +2485,7 @@ const BYTE LayerQuadMaskVS[] =
|
||||
88, 67, 79, 79, 82, 68,
|
||||
0, 171, 171, 171
|
||||
};
|
||||
ShaderBytes sLayerQuadMaskVS = { LayerQuadMaskVS, sizeof(LayerQuadMaskVS) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -2931,6 +2939,7 @@ const BYTE LayerQuadMask3DVS[] =
|
||||
88, 67, 79, 79, 82, 68,
|
||||
0, 171, 171, 171
|
||||
};
|
||||
ShaderBytes sLayerQuadMask3DVS = { LayerQuadMask3DVS, sizeof(LayerQuadMask3DVS) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -3230,6 +3239,7 @@ const BYTE SolidColorShaderMask[] =
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171
|
||||
};
|
||||
ShaderBytes sSolidColorShaderMask = { SolidColorShaderMask, sizeof(SolidColorShaderMask) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -3576,6 +3586,7 @@ const BYTE RGBShaderMask[] =
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171
|
||||
};
|
||||
ShaderBytes sRGBShaderMask = { RGBShaderMask, sizeof(RGBShaderMask) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -3914,6 +3925,7 @@ const BYTE RGBAShaderMask[] =
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171
|
||||
};
|
||||
ShaderBytes sRGBAShaderMask = { RGBAShaderMask, sizeof(RGBAShaderMask) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -4277,6 +4289,7 @@ const BYTE RGBAShaderMask3D[] =
|
||||
83, 86, 95, 84, 97, 114,
|
||||
103, 101, 116, 0, 171, 171
|
||||
};
|
||||
ShaderBytes sRGBAShaderMask3D = { RGBAShaderMask3D, sizeof(RGBAShaderMask3D) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -4779,6 +4792,7 @@ const BYTE YCbCrShaderMask[] =
|
||||
97, 114, 103, 101, 116, 0,
|
||||
171, 171
|
||||
};
|
||||
ShaderBytes sYCbCrShaderMask = { YCbCrShaderMask, sizeof(YCbCrShaderMask) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -5197,3 +5211,4 @@ const BYTE ComponentAlphaShaderMask[] =
|
||||
83, 86, 95, 84, 97, 114,
|
||||
103, 101, 116, 0, 171, 171
|
||||
};
|
||||
ShaderBytes sComponentAlphaShaderMask = { ComponentAlphaShaderMask, sizeof(ComponentAlphaShaderMask) };
|
||||
|
@ -361,6 +361,7 @@ const BYTE Oculus050VRDistortionVS[] =
|
||||
79, 79, 82, 68, 0, 67,
|
||||
79, 76, 79, 82, 0, 171
|
||||
};
|
||||
ShaderBytes sOculus050VRDistortionVS = { Oculus050VRDistortionVS, sizeof(Oculus050VRDistortionVS) };
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
|
||||
@ -634,3 +635,4 @@ const BYTE Oculus050VRDistortionPS[] =
|
||||
83, 86, 95, 84, 97, 114,
|
||||
103, 101, 116, 0, 171, 171
|
||||
};
|
||||
ShaderBytes sOculus050VRDistortionPS = { Oculus050VRDistortionPS, sizeof(Oculus050VRDistortionPS) };
|
||||
|
@ -14,11 +14,13 @@ fi
|
||||
|
||||
makeShaderVS() {
|
||||
fxc -nologo $FXC_FLAGS -Tvs_4_0_level_9_3 $SRC -E$1 -Vn$1 -Fh$tempfile
|
||||
echo "ShaderBytes s$1 = { $1, sizeof($1) };" >> $tempfile;
|
||||
cat $tempfile >> $DEST
|
||||
}
|
||||
|
||||
makeShaderPS() {
|
||||
fxc -nologo $FXC_FLAGS -Tps_4_0_level_9_3 $SRC -E$1 -Vn$1 -Fh$tempfile
|
||||
echo "ShaderBytes s$1 = { $1, sizeof($1) };" >> $tempfile;
|
||||
cat $tempfile >> $DEST
|
||||
}
|
||||
|
||||
@ -26,6 +28,7 @@ SRC=CompositorD3D11.hlsl
|
||||
DEST=CompositorD3D11Shaders.h
|
||||
|
||||
rm -f $DEST
|
||||
echo "struct ShaderBytes { const void* mData; size_t mLength; };" >> $DEST;
|
||||
makeShaderVS LayerQuadVS
|
||||
makeShaderPS SolidColorShader
|
||||
makeShaderPS RGBShader
|
||||
|
Loading…
Reference in New Issue
Block a user