summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/d3d11/GpuProgramsD3D11.h
blob: 305144b6d4b0786f84ab58b5889fa549d7ec071a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once

#include "Runtime/GfxDevice/GpuProgram.h"
#include "Runtime/Utilities/dynamic_array.h"
#include "D3D11Includes.h"

class GfxDevice;

class ConstantBuffersD3D11;
struct FixedFunctionStateD3D11;
struct InputSignatureD3D11;

class D3D11CommonShader : public GpuProgram {
public:
	virtual ~D3D11CommonShader();
	IUnknown* GetShader(FogMode fog, bool haveDomainShader, bool& outResetToNoFog);

protected:
	D3D11CommonShader ()
		: m_FogFailed(0)
	{
		for (int i = 0; i < kFogModeCount; ++i)
			m_Shaders[i] = NULL;
	}

	const UInt8* ApplyTextures (GfxDevice& device, ShaderType shaderType, const GpuProgramParameters& params, const UInt8* buffer);

	// default implementation just uses non-fog shader
	virtual bool PatchShaderForFog (FogMode fog);

protected:
	IUnknown*	m_Shaders[kFogModeCount];
	dynamic_array<UInt8> m_ByteCode; // stored for fog patching
	UInt32		m_FogFailed;
};

class D3D11VertexShader : public D3D11CommonShader {
public:
	D3D11VertexShader (const std::string& compiledSource);
	virtual ~D3D11VertexShader();
	virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer);

protected:
	virtual bool PatchShaderForFog (FogMode fog);
private:
	bool Create (const std::string& compiledSource);
	const InputSignatureD3D11* m_InputSignature;
};

class D3D11PixelShader : public D3D11CommonShader {
public:
	D3D11PixelShader (const std::string& compiledSource);
	virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer);
protected:
	virtual bool PatchShaderForFog (FogMode fog);
private:
	bool Create (const std::string& compiledSource);
};

class D3D11GeometryShader : public D3D11CommonShader {
public:
	D3D11GeometryShader (const std::string& compiledSource);
	virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer);
private:
	bool Create (const std::string& compiledSource);
};

class D3D11HullShader : public D3D11CommonShader {
public:
	D3D11HullShader (const std::string& compiledSource);
	virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer);
private:
	bool Create (const std::string& compiledSource);
};

class D3D11DomainShader : public D3D11CommonShader {
public:
	D3D11DomainShader (const std::string& compiledSource);
	virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer);
protected:
	virtual bool PatchShaderForFog (FogMode fog);
private:
	bool Create (const std::string& compiledSource);
};


class FixedFunctionProgramD3D11
{
public:
	struct ValueParameter {
		int	m_Name;
		int m_Index;
		int m_Bytes;
		ValueParameter (int n, int idx, int bytes) : m_Name(n), m_Index(idx), m_Bytes(bytes) {}
	};
	typedef dynamic_array<ValueParameter> ValueParameterArray;
	struct ValueParameters {
		ValueParameters() : m_CBID(0), m_CBSize(0) { }
		void AddVectorParam (int index, int dim, BuiltinShaderVectorParam name) { m_Params.push_back (ValueParameter (name, index, dim*4)); }
		bool HasVectorParams() const { return !m_Params.empty(); }
		void ApplyValues (const BuiltinShaderParamValues& values, ConstantBuffersD3D11& cbs, ShaderType shaderType) const;
		ValueParameterArray	m_Params;
		int	m_CBID;
		int	m_CBSize;
	};

public:
	FixedFunctionProgramD3D11 (const FixedFunctionStateD3D11& state);
	~FixedFunctionProgramD3D11 ();

	void ApplyFFGpuProgram (const BuiltinShaderParamValues& values, ConstantBuffersD3D11& cbs) const;

	const BuiltinShaderParamIndices& GetVPMatrices() const { return m_VPMatrices; }

	ID3D11VertexShader* GetVertexShader() { return m_VS; }
	ID3D11PixelShader* GetPixelShader() { return m_PS; }

private:
	ValueParameters		m_VPParams;
	ValueParameters		m_FPParams;
	BuiltinShaderParamIndices	m_VPMatrices;
	ID3D11VertexShader*		m_VS;
	ID3D11PixelShader*		m_PS;
	const InputSignatureD3D11* m_InputSig;
};