コード例 #1
0
ファイル: GraphicsTypes.cpp プロジェクト: bxs3514/Realtime_GI
void StructuredBuffer::WriteToFile(const wchar* path, ID3D11Device* device, ID3D11DeviceContext* context)
{
    Assert_(Buffer != nullptr);

    // Get the buffer info
    D3D11_BUFFER_DESC desc;
    Buffer->GetDesc(&desc);

    uint32 useAsUAV = (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS) ? 1 : 0;
	uint32 dynamic = (desc.BindFlags & D3D11_USAGE_DYNAMIC) ? 1 : 0;

    uint32 appendConsume = 0;
    uint32 hiddenCounter = 0;
    if(useAsUAV)
    {
        D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
        UAView->GetDesc(&uavDesc);
        appendConsume = (uavDesc.Format & D3D11_BUFFER_UAV_FLAG_APPEND) ? 1 : 0;
        hiddenCounter =(uavDesc.Format & D3D11_BUFFER_UAV_FLAG_COUNTER) ? 1 : 0;
    }

    // If the exists, delete it
    if(FileExists(path))
        Win32Call(DeleteFile(path));

    // Create the file
    HANDLE fileHandle = CreateFile(path, GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
    if(fileHandle == INVALID_HANDLE_VALUE)
        Win32Call(false);

    // Write the buffer info
    DWORD bytesWritten = 0;
    Win32Call(WriteFile(fileHandle, &Size, 4, &bytesWritten, nullptr));
    Win32Call(WriteFile(fileHandle, &Stride, 4, &bytesWritten, nullptr));
    Win32Call(WriteFile(fileHandle, &NumElements, 4, &bytesWritten, nullptr));
    Win32Call(WriteFile(fileHandle, &dynamic, 4, &bytesWritten, nullptr));
    Win32Call(WriteFile(fileHandle, &useAsUAV, 4, &bytesWritten, nullptr));
    Win32Call(WriteFile(fileHandle, &hiddenCounter, 4, &bytesWritten, nullptr));
    Win32Call(WriteFile(fileHandle, &appendConsume, 4, &bytesWritten, nullptr));

    // Get the buffer data
    StagingBuffer stagingBuffer;
    stagingBuffer.Initialize(device, Size);
    context->CopyResource(stagingBuffer.Buffer, Buffer);
    const void* bufferData= stagingBuffer.Map(context);

    // Write the data to the file
    Win32Call(WriteFile(fileHandle, bufferData, Size, &bytesWritten, nullptr));

    // Un-map the staging buffer
    stagingBuffer.Unmap(context);

    // Close the file
    Win32Call(CloseHandle(fileHandle));
}
コード例 #2
0
void StructuredBuffer::WriteToFile(const WCHAR* path, ID3D11Device* device, ID3D11DeviceContext* context)
{
    _ASSERT(Buffer != NULL);

    // Get the buffer info
    D3D11_BUFFER_DESC desc;
    Buffer->GetDesc(&desc);

    UINT32 useAsUAV = (desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS) ? 1 : 0;
    UINT32 useAsDrawIndirect = (desc.MiscFlags & D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS) ? 1 : 0;

    UINT32 appendConsume = 0;
    if(useAsUAV)
    {
        D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
        UAView->GetDesc(&uavDesc);
        appendConsume = (uavDesc.Format & D3D11_BUFFER_UAV_FLAG_APPEND) ? 1 : 0;
    }

    // If the exists, delete it
    if(FileExists(path))
        Win32Call(DeleteFileW(path));

    // Create the file
    HANDLE fileHandle = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    if(fileHandle == INVALID_HANDLE_VALUE)
        Win32Call(false);

    // Write the buffer info
    DWORD bytesWritten = 0;
    Win32Call(WriteFile(fileHandle, &Size, 4, &bytesWritten, NULL));
    Win32Call(WriteFile(fileHandle, &Stride, 4, &bytesWritten, NULL));
    Win32Call(WriteFile(fileHandle, &NumElements, 4, &bytesWritten, NULL));
    Win32Call(WriteFile(fileHandle, &useAsUAV, 4, &bytesWritten, NULL));
    Win32Call(WriteFile(fileHandle, &useAsDrawIndirect, 4, &bytesWritten, NULL));
    Win32Call(WriteFile(fileHandle, &appendConsume, 4, &bytesWritten, NULL));

    // Get the buffer data
    StagingBuffer stagingBuffer;
    stagingBuffer.Initialize(device, Size);
    context->CopyResource(stagingBuffer.Buffer, Buffer);
    const void* bufferData= stagingBuffer.Map(context);

    // Write the data to the file
    Win32Call(WriteFile(fileHandle, bufferData, Size, &bytesWritten, NULL));

    // Un-map the staging buffer
    stagingBuffer.Unmap(context);

    // Close the file
    Win32Call(CloseHandle(fileHandle));
}