Exemplo n.º 1
0
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));
}
Exemplo n.º 2
0
    //-----------------------------------------------------------------------------------
    void NULLVaoManager::_update(void)
    {
        VaoManager::_update();

        unsigned long currentTimeMs = mTimer->getMilliseconds();

        if( currentTimeMs >= mNextStagingBufferTimestampCheckpoint )
        {
            mNextStagingBufferTimestampCheckpoint = (unsigned long)(~0);

            for( size_t i=0; i<2; ++i )
            {
                StagingBufferVec::iterator itor = mZeroRefStagingBuffers[i].begin();
                StagingBufferVec::iterator end  = mZeroRefStagingBuffers[i].end();

                while( itor != end )
                {
                    StagingBuffer *stagingBuffer = *itor;

                    mNextStagingBufferTimestampCheckpoint = std::min(
                        mNextStagingBufferTimestampCheckpoint, 
                        stagingBuffer->getLastUsedTimestamp() + stagingBuffer->getLifetimeThreshold() );

                    /*if( stagingBuffer->getLastUsedTimestamp() + stagingBuffer->getUnfencedTimeThreshold() < currentTimeMs )
                    {
                        static_cast<NULLStagingBuffer*>( stagingBuffer )->cleanUnfencedHazards();
                    }*/

                    if( stagingBuffer->getLastUsedTimestamp() + stagingBuffer->getLifetimeThreshold() < currentTimeMs )
                    {
                        //Time to delete this buffer.
                        delete *itor;

                        itor = efficientVectorRemove( mZeroRefStagingBuffers[i], itor );
                        end  = mZeroRefStagingBuffers[i].end();
                    }
                    else
                    {
                        ++itor;
                    }
                }
            }
        }

        if( !mDelayedDestroyBuffers.empty() &&
            mDelayedDestroyBuffers.front().frameNumDynamic == mDynamicBufferCurrentFrame )
        {
            waitForTailFrameToFinish();
            destroyDelayedBuffers( mDynamicBufferCurrentFrame );
        }

        mDynamicBufferCurrentFrame = (mDynamicBufferCurrentFrame + 1) % mDynamicBufferMultiplier;
    }
Exemplo n.º 3
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));
}