| 235 | } |
| 236 | |
| 237 | void BeginRender(ID3D12GraphicsCommandList7* cmdList, uint32 cursorX, uint32 cursorY) |
| 238 | { |
| 239 | PIXMarker marker(cmdList, "ShaderDebug - BeginRender"); |
| 240 | |
| 241 | DebugInfo debugInfo = |
| 242 | { |
| 243 | .PrintBuffer = PrintBuffer.SRV, |
| 244 | .PrintBufferSize = uint32(PrintBuffer.InternalBuffer.Size), |
| 245 | .CursorXY = { cursorX, cursorY }, |
| 246 | }; |
| 247 | DebugInfoBuffer.MapAndSetData(&debugInfo, sizeof(debugInfo) / 4); |
| 248 | |
| 249 | List<std::string> argStrings; |
| 250 | |
| 251 | if(DX12::CurrentCPUFrame >= DX12::RenderLatency) |
| 252 | { |
| 253 | const ReadbackBuffer& readbackBuffer = PrintReadbackBuffers[(DX12::CurrentCPUFrame + 1) % DX12::RenderLatency]; |
| 254 | DebugPrintReader printReader(readbackBuffer.Map<uint8>(), uint32(readbackBuffer.Size)); |
| 255 | while(printReader.HasMoreData(sizeof(DebugPrintHeader))) |
| 256 | { |
| 257 | const DebugPrintHeader header = printReader.Consume<DebugPrintHeader>(DebugPrintHeader{}); |
| 258 | if(header.NumBytes == 0 || printReader.HasMoreData(header.NumBytes) == false) |
| 259 | break; |
| 260 | |
| 261 | std::string formatStr = printReader.ConsumeString(header.StringSize); |
| 262 | if(formatStr.length() == 0) |
| 263 | break; |
| 264 | |
| 265 | if(header.NumArgs > MaxDebugPrintArgs) |
| 266 | break; |
| 267 | |
| 268 | argStrings.Reserve(header.NumArgs); |
| 269 | for(uint32 argIdx = 0; argIdx < header.NumArgs; ++argIdx) |
| 270 | { |
| 271 | |
| 272 | const ArgCode argCode = (ArgCode)printReader.Consume<uint8>(0xFF); |
| 273 | if(argCode >= NumDebugPrintArgCodes) |
| 274 | break; |
| 275 | |
| 276 | const uint32 argSize = ArgCodeSizes[argCode]; |
| 277 | if(printReader.HasMoreData(argSize) == false) |
| 278 | break; |
| 279 | |
| 280 | const std::string argStr = MakeArgString(printReader, argCode); |
| 281 | ReplaceStringInPlace(formatStr, ArgPlaceHolders[argIdx], argStr); |
| 282 | } |
| 283 | |
| 284 | GlobalApp->AddToGPULog(formatStr.c_str()); |
| 285 | |
| 286 | printReader.CurrOffset = AlignTo(printReader.CurrOffset, 4); |
| 287 | } |
| 288 | |
| 289 | readbackBuffer.Unmap(); |
| 290 | } |
| 291 | |
| 292 | DX12::ClearRawBuffer(cmdList, PrintBuffer, Uint4(0, 0, 0, 0)); |
| 293 | |
| 294 | DX12::Barrier(cmdList, PrintBuffer.InternalBuffer.WriteToWriteBarrier()); |
no test coverage detected