MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / WriteToFile

Method WriteToFile

SampleFramework11/v1.02/Graphics/GraphicsTypes.cpp:460–512  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458}
459
460void StructuredBuffer::WriteToFile(const wchar* path, ID3D11Device* device, ID3D11DeviceContext* context)
461{
462 Assert_(Buffer != nullptr);
463
464 // Get the buffer info
465 D3D11_BUFFER_DESC desc;
466 Buffer->GetDesc(&desc);
467
468 uint32 useAsUAV = (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS) ? 1 : 0;
469
470 uint32 appendConsume = 0;
471 uint32 hiddenCounter = 0;
472 if(useAsUAV)
473 {
474 D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
475 UAView->GetDesc(&uavDesc);
476 appendConsume = (uavDesc.Format & D3D11_BUFFER_UAV_FLAG_APPEND) ? 1 : 0;
477 hiddenCounter =(uavDesc.Format & D3D11_BUFFER_UAV_FLAG_COUNTER) ? 1 : 0;
478 }
479
480 // If the exists, delete it
481 if(FileExists(path))
482 Win32Call(DeleteFile(path));
483
484 // Create the file
485 HANDLE fileHandle = CreateFile(path, GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
486 if(fileHandle == INVALID_HANDLE_VALUE)
487 Win32Call(false);
488
489 // Write the buffer info
490 DWORD bytesWritten = 0;
491 Win32Call(WriteFile(fileHandle, &Size, 4, &bytesWritten, nullptr));
492 Win32Call(WriteFile(fileHandle, &Stride, 4, &bytesWritten, nullptr));
493 Win32Call(WriteFile(fileHandle, &NumElements, 4, &bytesWritten, nullptr));
494 Win32Call(WriteFile(fileHandle, &useAsUAV, 4, &bytesWritten, nullptr));
495 Win32Call(WriteFile(fileHandle, &hiddenCounter, 4, &bytesWritten, nullptr));
496 Win32Call(WriteFile(fileHandle, &appendConsume, 4, &bytesWritten, nullptr));
497
498 // Get the buffer data
499 StagingBuffer stagingBuffer;
500 stagingBuffer.Initialize(device, Size);
501 context->CopyResource(stagingBuffer.Buffer, Buffer);
502 const void* bufferData= stagingBuffer.Map(context);
503
504 // Write the data to the file
505 Win32Call(WriteFile(fileHandle, bufferData, Size, &bytesWritten, nullptr));
506
507 // Un-map the staging buffer
508 stagingBuffer.Unmap(context);
509
510 // Close the file
511 Win32Call(CloseHandle(fileHandle));
512}
513
514void StructuredBuffer::ReadFromFile(const wchar* path, ID3D11Device* device)
515{

Callers

nothing calls this directly

Calls 5

FileExistsFunction · 0.85
Win32CallFunction · 0.85
UnmapMethod · 0.80
InitializeMethod · 0.45
MapMethod · 0.45

Tested by

no test coverage detected