Graphics Reference
In-Depth Information
public int ThreadsY = 1; // default thread group height
// Compile compute shader from file
public void CompileComputeShader(string csFunction,
string csFile = @"Shaders\ParticleCS.hlsl")
{
SharpDX.Direct3D.ShaderMacro[] defines = new[] {
new SharpDX.Direct3D.ShaderMacro("THREADSX",
ThreadsX),
new SharpDX.Direct3D.ShaderMacro("THREADSY",
ThreadsY),
};
using (var bytecode = HLSLCompiler.CompileFromFile(
csFile, csFunction, "cs_5_0", defines))
{
computeShaders[csFunction] = ToDispose(new
ComputeShader(this.DeviceManager
.Direct3DDevice, bytecode));
}
}
22. To complete our ParticleRenderer class, we will add the DoRender
implementation. The following snippet shows the code to back up and
restore the state of the pipeline:
protected override void DoRender()
{
// Retrieve existing pipeline states for backup
Color4 oldBlendFactor;
int oldSampleMask;
int oldStencil;
var oldPSBufs
=context.PixelShader.GetConstantBuffers(0,1);
using (var oldVS = context.VertexShader.Get())
using (var oldPS = context.PixelShader.Get())
using (var oldGS = context.GeometryShader.Get())
using (var oldSamp = context.PixelShader
.GetSamplers(0, 1).FirstOrDefault())
using (var oldBlendState = context.OutputMerger
.GetBlendState(out oldBlendFactor, out oldSampleMask))
using (var oldIA = context.InputAssembler.InputLayout)
using (var oldDepth = context.OutputMerger
 
Search WWH ::




Custom Search