private void Update(EvaluationContext context) { var resourceManager = ResourceManager.Instance(); var device = resourceManager.Device; var deviceContext = device.ImmediateContext; var csStage = deviceContext.ComputeShader; _cs = ComputeShader.GetValue(context); Int3 dispatchCount = Dispatch.GetValue(context); int count = DispatchCallCount.GetValue(context).Clamp(1, 10); ConstantBuffers.GetValues(ref _constantBuffers, context); ShaderResources.GetValues(ref _shaderResourceViews, context); SamplerStates.GetValues(ref _samplerStates, context); Uavs.GetValues(ref _uavs, context); int counter = UavBufferCount.GetValue(context); if (_uavs.Length == 0 || _uavs[0] == null || _cs == null) { return; } csStage.Set(_cs); csStage.SetConstantBuffers(0, _constantBuffers.Length, _constantBuffers); csStage.SetShaderResources(0, _shaderResourceViews.Length, _shaderResourceViews); csStage.SetSamplers(0, _samplerStates); if (_uavs.Length == 4) { csStage.SetUnorderedAccessViews(0, _uavs, new[] { -1, 0, -1, -1 }); } else if (_uavs.Length == 1) { if (counter == -1) { csStage.SetUnorderedAccessView(0, _uavs[0]); } else { csStage.SetUnorderedAccessViews(0, _uavs, new[] { counter }); } } else if (_uavs.Length == 3) { csStage.SetUnorderedAccessViews(0, _uavs, new[] { counter, -1, -1 }); } else { csStage.SetUnorderedAccessViews(0, _uavs); } for (int i = 0; i < count; i++) { deviceContext.Dispatch(dispatchCount.X, dispatchCount.Y, dispatchCount.Z); } // unbind resources for (int i = 0; i < _uavs.Length; i++) { csStage.SetUnorderedAccessView(i, null); } for (int i = 0; i < _samplerStates.Length; i++) { csStage.SetSampler(i, null); } for (int i = 0; i < _shaderResourceViews.Length; i++) { csStage.SetShaderResource(i, null); } for (int i = 0; i < _constantBuffers.Length; i++) { csStage.SetConstantBuffer(i, null); } }