如何部分更新DirectX 11.1中的常量缓冲区

2022-03-24 00:00:00 game-engine c++ directx

我正在尝试部分更新常量缓冲区(就像在OpenGL中一样),但总是收到奇怪的错误,因为我刚刚移植到DX11.1以实现常量缓冲区部分更新功能(我也支持它和CBOffting),这里是否遗漏了什么?

void DX11UniformBuffer::Update(void * data, unsigned int offset, unsigned int size)
{
    const D3D11_BOX sDstBox = { offset, 0U, 0U, size, 1U, 1U };
    DX11Context::GetContext()->UpdateSubresource1(buffer, 0, &sDstBox, data, 0, 0,D3D11_COPY_DISCARD);
    DX11Context::GetContext()->PSSetConstantBuffers1(0, 1, &buffer, &offset, &size);
}

等效于(在OpenGL中)

void GLUniformBuffer::Update(void * data, unsigned int offset, unsigned int size)
{
    glBindBuffer(GL_UNIFORM_BUFFER, buffer);
    glBufferSubData(GL_UNIFORM_BUFFER, offset, size, data);
    glBindBuffer(GL_UNIFORM_BUFFER, 0);
}

但是,我收到这些错误,并且没有绘制任何内容.

D3D11 ERROR: ID3D11DeviceContext::UpdateSubresource1: pDstBox is not a valid box, as the End coordinates must be greater than or equal to the Start. *pDstBox = { left:144, top:0, front:0, right:48, bottom:1, back:1 }. [ RESOURCE_MANIPULATION ERROR #288: UPDATESUBRESOURCE_INVALIDDESTINATIONBOX]

解决方案

D3D11_BOXright的值是位置,而不是宽度。您需要将offsetsize相加才能得到right的值。sDstBox应初始化为:

const D3D11_BOX sDstBox = { offset, 0U, 0U, offset + size, 1U, 1U };

相关文章