Add RHI texture upload and descriptor set fixes
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12DescriptorSet.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12DescriptorHeap.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12Sampler.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
@@ -50,13 +52,61 @@ void D3D12DescriptorSet::Unbind() {
|
||||
}
|
||||
|
||||
void D3D12DescriptorSet::Update(uint32_t offset, RHIResourceView* view) {
|
||||
(void)offset;
|
||||
(void)view;
|
||||
if (m_heap == nullptr || view == nullptr || m_heap->GetType() != DescriptorHeapType::CBV_SRV_UAV) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t descriptorOffset = 0;
|
||||
bool foundBinding = false;
|
||||
for (uint32_t i = 0; i < m_bindingCount; ++i) {
|
||||
if (m_bindings[i].binding == offset) {
|
||||
foundBinding = true;
|
||||
break;
|
||||
}
|
||||
descriptorOffset += m_bindings[i].count;
|
||||
}
|
||||
|
||||
if (!foundBinding) {
|
||||
return;
|
||||
}
|
||||
|
||||
D3D12ResourceView* d3d12View = static_cast<D3D12ResourceView*>(view);
|
||||
if (!d3d12View->IsValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CPUDescriptorHandle dstHandle = m_heap->GetCPUDescriptorHandle(m_offset + descriptorOffset);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dst = { dstHandle.ptr };
|
||||
m_heap->GetDevice()->CopyDescriptorsSimple(
|
||||
1,
|
||||
dst,
|
||||
d3d12View->GetCPUHandle(),
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
}
|
||||
|
||||
void D3D12DescriptorSet::UpdateSampler(uint32_t offset, RHISampler* sampler) {
|
||||
(void)offset;
|
||||
(void)sampler;
|
||||
if (m_heap == nullptr || sampler == nullptr || m_heap->GetType() != DescriptorHeapType::Sampler) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t descriptorOffset = 0;
|
||||
bool foundBinding = false;
|
||||
for (uint32_t i = 0; i < m_bindingCount; ++i) {
|
||||
if (m_bindings[i].binding == offset) {
|
||||
foundBinding = true;
|
||||
break;
|
||||
}
|
||||
descriptorOffset += m_bindings[i].count;
|
||||
}
|
||||
|
||||
if (!foundBinding) {
|
||||
return;
|
||||
}
|
||||
|
||||
D3D12Sampler* d3d12Sampler = static_cast<D3D12Sampler*>(sampler);
|
||||
CPUDescriptorHandle dstHandle = m_heap->GetCPUDescriptorHandle(m_offset + descriptorOffset);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dst = { dstHandle.ptr };
|
||||
m_heap->GetDevice()->CreateSampler(&d3d12Sampler->GetDesc(), dst);
|
||||
}
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE D3D12DescriptorSet::GetGPUHandle(uint32_t index) const {
|
||||
@@ -77,4 +127,4 @@ void D3D12DescriptorSet::WriteConstant(uint32_t binding, const void* data, size_
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
} // namespace XCEngine
|
||||
|
||||
Reference in New Issue
Block a user