Ejemplo n.º 1
0
gl::Error Image11::recoverFromAssociatedStorage()
{
    if (mRecoverFromStorage)
    {
        gl::Error error = createStagingTexture();
        if (error.isError())
        {
            return error;
        }

        bool textureStorageCorrect = mAssociatedStorage->isAssociatedImageValid(mAssociatedImageIndex, this);

        // This means that the cached TextureStorage has been modified after this Image11 released its copy of its data. 
        // This should not have happened. The TextureStorage should have told this Image11 to recover its data before it was overwritten.
        ASSERT(textureStorageCorrect);

        if (textureStorageCorrect)
        {
            // CopySubResource from the Storage to the Staging texture
            gl::Box region(0, 0, 0, mWidth, mHeight, mDepth);
            error = mAssociatedStorage->copySubresourceLevel(mStagingTexture, mStagingSubresource, mAssociatedImageIndex, region);
            if (error.isError())
            {
                return error;
            }

            mRecoveredFromStorageCount += 1;
        }

        // Reset all the recovery parameters, even if the texture storage association is broken.
        disassociateStorage();
    }

    return gl::Error(GL_NO_ERROR);
}
Ejemplo n.º 2
0
gl::Error Image11::getStagingTexture(const TextureHelper11 **outStagingTexture,
                                     unsigned int *outSubresourceIndex)
{
    ANGLE_TRY(createStagingTexture());

    *outStagingTexture   = &mStagingTexture;
    *outSubresourceIndex = mStagingSubresource;
    return gl::NoError();
}
Ejemplo n.º 3
0
gl::Error Image11::getStagingTexture(ID3D11Resource **outStagingTexture, unsigned int *outSubresourceIndex)
{
    gl::Error error = createStagingTexture();
    if (error.isError())
    {
        return error;
    }

    *outStagingTexture = mStagingTexture;
    *outSubresourceIndex = mStagingSubresource;
    return gl::Error(GL_NO_ERROR);
}
Ejemplo n.º 4
0
gl::Error Image11::recoverFromAssociatedStorage(const gl::Context *context)
{
    if (mRecoverFromStorage)
    {
        ANGLE_TRY(createStagingTexture());

        mAssociatedStorage->verifyAssociatedImageValid(mAssociatedImageIndex, this);

        // CopySubResource from the Storage to the Staging texture
        gl::Box region(0, 0, 0, mWidth, mHeight, mDepth);
        ANGLE_TRY(mAssociatedStorage->copySubresourceLevel(
            context, mStagingTexture, mStagingSubresource, mAssociatedImageIndex, region));
        mRecoveredFromStorageCount += 1;

        // Reset all the recovery parameters, even if the texture storage association is broken.
        disassociateStorage();
    }

    return gl::NoError();
}
Result GraphicsInterfaceD3D11::writeTexture2D(void *dst_tex_, int width, int height, TextureFormat format, const void *src, size_t write_size)
{
    if (write_size == 0) { return Result::OK; }
    if (!dst_tex_ || !src) { return Result::InvalidParameter; }

    auto *dst_tex = (ID3D11Texture2D*)dst_tex_;

    auto proc_write = [this](ID3D11Texture2D *tex, int width, int height, TextureFormat format, const void *src, size_t write_size) -> HRESULT {
        D3D11_MAPPED_SUBRESOURCE mapped = { 0 };
        auto hr = m_context->Map(tex, 0, D3D11_MAP_WRITE, 0, &mapped);
        if (FAILED(hr)) { return hr; }

        auto *dst_pixels = (char*)mapped.pData;
        auto *src_pixels = (const char*)src;
        int dst_pitch = mapped.RowPitch;
        int src_pitch = width * GetTexelSize(format);
        int num_rows = std::min<int>(height, (int)ceildiv<size_t>(write_size, src_pitch));
        CopyRegion(dst_pixels, dst_pitch, src_pixels, src_pitch, num_rows);

        m_context->Unmap(tex, 0);
        return S_OK;
    };


    // try direct access
    auto hr = proc_write(dst_tex, width, height, format, src, write_size);
    if (SUCCEEDED(hr)) { return Result::OK; }


    // try copy-via-staging
    auto staging = createStagingTexture(width, height, format, StagingFlag::Upload);
    hr = proc_write(staging.Get(), width, height, format, src, write_size);
    m_context->CopyResource(dst_tex, staging.Get());

    return TranslateReturnCode(hr);
}
Result GraphicsInterfaceD3D11::readTexture2D(void *dst, size_t read_size, void *src_tex_, int width, int height, TextureFormat format)
{
    if (read_size == 0) { return Result::OK; }
    if (!dst || !src_tex_) { return Result::InvalidParameter; }

    auto *src_tex = (ID3D11Texture2D*)src_tex_;

    auto proc_read = [this](void *dst, size_t dst_size, ID3D11Texture2D *tex, int width, int height, TextureFormat format) -> HRESULT {
        D3D11_MAPPED_SUBRESOURCE mapped = { 0 };
        auto hr = m_context->Map(tex, 0, D3D11_MAP_READ, 0, &mapped);
        if (FAILED(hr)) { return hr; }

        auto *dst_pixels = (char*)dst;
        auto *src_pixels = (const char*)mapped.pData;
        int dst_pitch = width * GetTexelSize(format);
        int src_pitch = mapped.RowPitch;
        int num_rows = std::min<int>(height, (int)ceildiv<size_t>(dst_size, dst_pitch));
        CopyRegion(dst_pixels, dst_pitch, src_pixels, src_pitch, num_rows);

        m_context->Unmap(tex, 0);
        return S_OK;
    };

    // try direct access
    auto hr = proc_read(dst, read_size, src_tex, width, height, format);
    if (SUCCEEDED(hr)) { return Result::OK; }


    // try copy-via-staging
    auto staging = createStagingTexture(width, height, format, StagingFlag::Readback);
    m_context->CopyResource(staging.Get(), src_tex);
    sync(); // Map() doesn't wait completion of above CopyResource(). manual synchronization is required.
    hr = proc_read(dst, read_size, staging.Get(), width, height, format);

    return TranslateReturnCode(hr);
}
Ejemplo n.º 7
0
HRESULT Image11::map(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map)
{
    createStagingTexture();

    HRESULT result = E_FAIL;

    if (mStagingTexture)
    {
        ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
        result = deviceContext->Map(mStagingTexture, mStagingSubresource, mapType, 0, map);

        // this can fail if the device is removed (from TDR)
        if (d3d11::isDeviceLostError(result))
        {
            mRenderer->notifyDeviceLost();
        }
        else if (SUCCEEDED(result))
        {
            mDirty = true;
        }
    }

    return result;
}
Ejemplo n.º 8
0
unsigned int Image11::getStagingSubresource()
{
    createStagingTexture();

    return mStagingSubresource;
}
Ejemplo n.º 9
0
ID3D11Resource *Image11::getStagingTexture()
{
    createStagingTexture();

    return mStagingTexture;
}
Ejemplo n.º 10
0
ID3D11Texture2D *Image11::getStagingTexture()
{
    createStagingTexture();

    return mStagingTexture;
}