I'm trying out different ways to implement pipeline stages in my framework. In a moment I'll show you what I have so far, and if possible I'd like to get some feedback on whether this is acceptable or just bad practice.
I have a Model, which is just any mesh object in my world that could be passed through the pipeline. The model has all the pipeline stages available coupled to it.
class Model
{
public:
/*****/
private:
//Input Assembler
ID3D11Buffer* mVertexBuffer;
ID3D11Buffer* mIndexBuffer;
D3D11_PRIMITIVE_TOPOLOGY mTopology;
ID3D11InputLayout* mInputLayout;
UINT mNumIndices;
//Vertex Shader Stage
ID3D11VertexShader* mVertexShader;
std::vector<ID3D11Buffer*> mVSConstantBuffers;
//Hull Shader Stage
ID3D11HullShader* mHullShader;
std::vector<ID3D11Buffer*> mHSConstantBuffers;
//Domain Shader Stage
ID3D11DomainShader* mDomainShader;
std::vector<ID3D11Buffer*> mDSConstantBuffers;
//Geometry Shader Stage
ID3D11GeometryShader* mGeometryShader;
std::vector<ID3D11Buffer*> mGSConstantBuffers;
//Stream Output Stage
//implemented elsewhere
//Rasterizer Stage
ID3D11RasterizerState* mRasterizerState;
//Pixel Shader Stage
ID3D11PixelShader* mPixelShader;
ID3D11ShaderResourceView* mPSResourceView;
ID3D11SamplerState* mPSSampler;
std::vector<ID3D11Buffer*> mPSConstantBuffers;
//Output Merger Stage
//implemented elsewhere
};Whenever the Model call it's Draw() function, I set the stages to the pipeline. The immediate issue I see is that this results in redundant state change calls. DirectX debug even tells me that. So if multiple models are using the same pixel shader for example I still set the pixel shader. Would this be considered an acceptable design? Is there any better way to do this?
Model::Draw()
{
//set input assembler stage
context->IASet...
//set vertex assembler stage
context->VSSet..
//and so on until all pipeline stages are set
context->DrawIndexed(mNumIndices, 0, 0);
}Thanks.