public void EndToEndTest() { // Arrange. var device = new Device(); var logger = new TracefileBuilder(device); var expectedData = RenderScene(device); var stringWriter = new StringWriter(); logger.WriteTo(stringWriter); var loggedJson = stringWriter.ToString(); var logReader = new StringReader(loggedJson); var tracefile = Tracefile.FromTextReader(logReader); // Act. var swapChainPresenter = new RawSwapChainPresenter(); var replayer = new Replayer( tracefile.Frames[0], tracefile.Frames[0].Events.Last(), swapChainPresenter); replayer.Replay(); var actualData = swapChainPresenter.Data; // Assert. Assert.That(actualData, Is.EqualTo(expectedData)); }
public IDocument Create(string path) { using (var reader = new StreamReader(File.OpenRead(path))) { var tracefile = Tracefile.FromTextReader(reader); return(new TracefileViewerViewModel(_selectionService, path, tracefile)); } }
public TracefileBuilder( Device device, int?renderTargetViewID = null, int?renderTargetArrayIndex = null, int?pixelX = null, int?pixelY = null) { _tracefile = new Tracefile(); Func <OperationType, DiagnosticEventHandler> makeHandler = type => (sender, e) => LogOperation(type, e.Arguments); device.CreatingBlendState += makeHandler(OperationType.DeviceCreateBlendState); device.CreatingBuffer += makeHandler(OperationType.DeviceCreateBuffer); device.CreatingDepthStencilState += makeHandler(OperationType.DeviceCreateDepthStencilState); device.CreatingDepthStencilView += makeHandler(OperationType.DeviceCreateDepthStencilView); device.CreatingGeometryShader += makeHandler(OperationType.DeviceCreateGeometryShader); device.CreatingInputLayout += makeHandler(OperationType.DeviceCreateInputLayout); device.CreatingPixelShader += makeHandler(OperationType.DeviceCreatePixelShader); device.CreatingRasterizerState += makeHandler(OperationType.DeviceCreateRasterizerState); device.CreatingRenderTargetView += makeHandler(OperationType.DeviceCreateRenderTargetView); device.CreatingSamplerState += makeHandler(OperationType.DeviceCreateSamplerState); device.CreatingShaderResourceView += makeHandler(OperationType.DeviceCreateShaderResourceView); device.CreatingSwapChain += makeHandler(OperationType.DeviceCreateSwapChain); device.CreatingTexture1D += makeHandler(OperationType.DeviceCreateTexture1D); device.CreatingTexture2D += makeHandler(OperationType.DeviceCreateTexture2D); device.CreatingTexture3D += makeHandler(OperationType.DeviceCreateTexture3D); device.CreatingVertexShader += makeHandler(OperationType.DeviceCreateVertexShader); var deviceContext = device.ImmediateContext; deviceContext.ClearingDepthStencilView += makeHandler(OperationType.DeviceContextClearDepthStencilView); deviceContext.ClearingRenderTargetView += makeHandler(OperationType.DeviceContextClearRenderTargetView); deviceContext.Drawing += makeHandler(OperationType.DeviceContextDraw); deviceContext.DrawingIndexed += makeHandler(OperationType.DeviceContextDrawIndexed); deviceContext.DrawingInstanced += makeHandler(OperationType.DeviceContextDrawInstanced); deviceContext.GeneratingMips += makeHandler(OperationType.DeviceContextGenerateMips); deviceContext.Presenting += makeHandler(OperationType.DeviceContextPresent); deviceContext.SettingBufferData += makeHandler(OperationType.DeviceContextSetBufferData); deviceContext.SettingTextureData += makeHandler(OperationType.DeviceContextSetTextureData); var inputAssemblerStage = deviceContext.InputAssembler; inputAssemblerStage.SettingInputLayout += makeHandler(OperationType.InputAssemblerStageSetInputLayout); inputAssemblerStage.SettingPrimitiveTopology += makeHandler(OperationType.InputAssemblerStageSetPrimitiveTopology); inputAssemblerStage.SettingVertexBuffers += makeHandler(OperationType.InputAssemblerStageSetVertexBuffers); inputAssemblerStage.SettingIndexBuffer += makeHandler(OperationType.InputAssemblerStageSetIndexBuffer); inputAssemblerStage.ProcessedVertex += (sender, e) => { var lastEvent = _currentFrame.Events.Last(); lastEvent.InputAssemblerOutputs.Add(e.Vertex); }; var vertexShaderStage = deviceContext.VertexShader; vertexShaderStage.SettingShader += makeHandler(OperationType.VertexShaderStageSetShader); vertexShaderStage.SettingConstantBuffers += makeHandler(OperationType.VertexShaderStageSetConstantBuffers); vertexShaderStage.SettingSamplers += makeHandler(OperationType.VertexShaderStageSetSamplers); vertexShaderStage.SettingShaderResources += makeHandler(OperationType.VertexShaderStageSetShaderResources); var geometryShaderStage = deviceContext.GeometryShader; geometryShaderStage.SettingShader += makeHandler(OperationType.GeometryShaderStageSetShader); geometryShaderStage.SettingConstantBuffers += makeHandler(OperationType.GeometryShaderStageSetConstantBuffers); geometryShaderStage.SettingSamplers += makeHandler(OperationType.GeometryShaderStageSetSamplers); geometryShaderStage.SettingShaderResources += makeHandler(OperationType.GeometryShaderStageSetShaderResources); var rasterizerStage = deviceContext.Rasterizer; rasterizerStage.SettingState += makeHandler(OperationType.RasterizerStageSetState); rasterizerStage.SettingViewports += makeHandler(OperationType.RasterizerStageSetViewports); var pixelShaderStage = deviceContext.PixelShader; pixelShaderStage.SettingShader += makeHandler(OperationType.PixelShaderStageSetShader); pixelShaderStage.SettingConstantBuffers += makeHandler(OperationType.PixelShaderStageSetConstantBuffers); pixelShaderStage.SettingSamplers += makeHandler(OperationType.PixelShaderStageSetSamplers); pixelShaderStage.SettingShaderResources += makeHandler(OperationType.PixelShaderStageSetShaderResources); var outputMergerStage = deviceContext.OutputMerger; outputMergerStage.SettingDepthStencilState += makeHandler(OperationType.OutputMergerStageSetDepthStencilState); outputMergerStage.SettingDepthStencilReference += makeHandler(OperationType.OutputMergerStageSetDepthStencilReference); outputMergerStage.SettingBlendState += makeHandler(OperationType.OutputMergerStageSetBlendState); outputMergerStage.SettingBlendFactor += makeHandler(OperationType.OutputMergerStageSetBlendFactor); outputMergerStage.SettingBlendSampleMask += makeHandler(OperationType.OutputMergerStageSetBlendSampleMask); outputMergerStage.SettingTargets += makeHandler(OperationType.OutputMergerStageSetTargets); if (pixelX != null && pixelY != null) { deviceContext.ClearingRenderTargetView += (sender, e) => { if ((int)e.Arguments[0] != renderTargetViewID) { return; } var color = (Color4)e.Arguments[1]; AddPixelEvent(new SimpleEvent(color.ToNumber4())); }; // TODO: Can't use this because it only works for the back buffer. //rasterizerStage.FragmentFilter = (x, y) => x == pixelX.Value && y == pixelY.Value; outputMergerStage.ProcessedPixel += (sender, e) => { if (e.X != pixelX || e.Y != pixelY || e.RenderTargetArrayIndex != renderTargetArrayIndex) { return; } // TODO: Support multiple render targets. DepthStencilView depthStencilView; RenderTargetView[] renderTargetViews; outputMergerStage.GetTargets(out depthStencilView, out renderTargetViews); if (renderTargetViews[0].ID != renderTargetViewID) { return; } var activeShader = (geometryShaderStage.Shader != null) ? (ShaderBase)geometryShaderStage.Shader : vertexShaderStage.Shader; AddPixelEvent(new DrawEvent { Vertices = e.Vertices.Select(x => new DrawEventVertex { VertexID = x.VertexID, PreVertexShaderData = MapVertexShaderData(x.InputData, activeShader.Bytecode.InputSignature), PostVertexShaderData = MapVertexShaderData(x.OutputData, activeShader.Bytecode.OutputSignature) }).ToArray(), PrimitiveID = e.PrimitiveID, X = e.X, Y = e.Y, PixelShader = e.PixelShader, Previous = e.Previous, Result = e.Result, ExclusionReason = e.ExclusionReason }); }; } }
public TracefileViewModel(ISelectionService selectionService, Tracefile tracefile) { _tracefile = tracefile; _frames = _tracefile.Frames.Select(x => new TracefileFrameViewModel(selectionService, x)).ToList(); }
public TracefileViewerViewModel(ISelectionService selectionService, string fileName, Tracefile tracefile) { _selectionService = selectionService; _selectionService.SelectedEventChanged += OnSelectedEventChanged; _tracefile = new TracefileViewModel(selectionService, tracefile); _hasSelectedPixel = false; DisplayName = Path.GetFileName(fileName); SelectedFrame = _tracefile.Frames[0]; }