RHI: 增强RHIResourceView抽象接口,添加GetViewType/GetDimension/GetFormat虚函数
- 在RHIResourceView基类添加3个纯虚函数:GetViewType()、GetDimension()、GetFormat() - D3D12ResourceView和OpenGLResourceView子类实现这些虚函数 - 在各InitializeAs*方法中正确存储format和dimension信息 - 消除调用者必须向下转型才能获取视图类型的需求
This commit is contained in:
@@ -6,6 +6,8 @@ namespace RHI {
|
||||
|
||||
D3D12ResourceView::D3D12ResourceView()
|
||||
: m_viewType(ResourceViewType::ShaderResource)
|
||||
, m_format(Format::Unknown)
|
||||
, m_dimension(ResourceViewDimension::Unknown)
|
||||
, m_handle({0})
|
||||
, m_resource(nullptr)
|
||||
, m_heap(nullptr)
|
||||
@@ -35,6 +37,8 @@ void D3D12ResourceView::InitializeAsRenderTarget(ID3D12Device* device, ID3D12Res
|
||||
const D3D12_RENDER_TARGET_VIEW_DESC* desc,
|
||||
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
||||
m_viewType = ResourceViewType::RenderTarget;
|
||||
m_format = desc ? static_cast<Format>(desc->Format) : Format::Unknown;
|
||||
m_dimension = ResourceViewDimension::Texture2D;
|
||||
m_resource = resource;
|
||||
m_heap = heap;
|
||||
m_slotIndex = slotIndex;
|
||||
@@ -48,6 +52,8 @@ void D3D12ResourceView::InitializeAsDepthStencil(ID3D12Device* device, ID3D12Res
|
||||
const D3D12_DEPTH_STENCIL_VIEW_DESC* desc,
|
||||
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
||||
m_viewType = ResourceViewType::DepthStencil;
|
||||
m_format = desc ? static_cast<Format>(desc->Format) : Format::Unknown;
|
||||
m_dimension = ResourceViewDimension::Texture2D;
|
||||
m_resource = resource;
|
||||
m_heap = heap;
|
||||
m_slotIndex = slotIndex;
|
||||
@@ -61,6 +67,8 @@ void D3D12ResourceView::InitializeAsShaderResource(ID3D12Device* device, ID3D12R
|
||||
const D3D12_SHADER_RESOURCE_VIEW_DESC* desc,
|
||||
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
||||
m_viewType = ResourceViewType::ShaderResource;
|
||||
m_format = desc ? static_cast<Format>(desc->Format) : Format::Unknown;
|
||||
m_dimension = desc ? static_cast<ResourceViewDimension>(desc->ViewDimension) : ResourceViewDimension::Unknown;
|
||||
m_resource = resource;
|
||||
m_heap = heap;
|
||||
m_slotIndex = slotIndex;
|
||||
@@ -74,6 +82,8 @@ void D3D12ResourceView::InitializeAsUnorderedAccess(ID3D12Device* device, ID3D12
|
||||
const D3D12_UNORDERED_ACCESS_VIEW_DESC* desc,
|
||||
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
||||
m_viewType = ResourceViewType::UnorderedAccess;
|
||||
m_format = desc ? static_cast<Format>(desc->Format) : Format::Unknown;
|
||||
m_dimension = desc ? static_cast<ResourceViewDimension>(desc->ViewDimension) : ResourceViewDimension::Unknown;
|
||||
m_resource = resource;
|
||||
m_heap = heap;
|
||||
m_slotIndex = slotIndex;
|
||||
@@ -87,6 +97,8 @@ void D3D12ResourceView::InitializeAsConstantBuffer(ID3D12Device* device, ID3D12R
|
||||
const D3D12_CONSTANT_BUFFER_VIEW_DESC* desc,
|
||||
D3D12DescriptorHeap* heap, uint32_t slotIndex) {
|
||||
m_viewType = ResourceViewType::ConstantBuffer;
|
||||
m_format = Format::Unknown;
|
||||
m_dimension = ResourceViewDimension::Buffer;
|
||||
m_resource = resource;
|
||||
m_heap = heap;
|
||||
m_slotIndex = slotIndex;
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace RHI {
|
||||
|
||||
OpenGLResourceView::OpenGLResourceView()
|
||||
: m_viewType(ResourceViewType::RenderTarget)
|
||||
, m_format(Format::Unknown)
|
||||
, m_dimension(ResourceViewDimension::Unknown)
|
||||
, m_framebufferID(0)
|
||||
, m_textureUnit(-1)
|
||||
, m_bindingPoint(-1)
|
||||
@@ -81,12 +83,13 @@ bool OpenGLResourceView::InitializeAsRenderTarget(
|
||||
OpenGLTexture* texture,
|
||||
const ResourceViewDesc& desc,
|
||||
OpenGLFramebuffer* framebuffer) {
|
||||
(void)desc;
|
||||
if (!texture || !framebuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::RenderTarget;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_framebuffer = framebuffer;
|
||||
m_framebufferID = framebuffer->GetFramebuffer();
|
||||
@@ -97,12 +100,13 @@ bool OpenGLResourceView::InitializeAsDepthStencil(
|
||||
OpenGLTexture* texture,
|
||||
const ResourceViewDesc& desc,
|
||||
OpenGLFramebuffer* framebuffer) {
|
||||
(void)desc;
|
||||
if (!texture || !framebuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::DepthStencil;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_framebuffer = framebuffer;
|
||||
m_framebufferID = framebuffer->GetFramebuffer();
|
||||
@@ -123,6 +127,8 @@ bool OpenGLResourceView::InitializeAsShaderResource(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::ShaderResource;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_textureUnit = unit;
|
||||
m_textureUnitAllocator = allocator;
|
||||
@@ -144,6 +150,8 @@ bool OpenGLResourceView::InitializeAsUnorderedAccess(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::UnorderedAccess;
|
||||
m_format = static_cast<Format>(desc.format);
|
||||
m_dimension = desc.dimension;
|
||||
m_texture = texture;
|
||||
m_textureUnit = unit;
|
||||
m_textureUnitAllocator = allocator;
|
||||
@@ -169,6 +177,8 @@ bool OpenGLResourceView::InitializeAsConstantBuffer(
|
||||
}
|
||||
|
||||
m_viewType = ResourceViewType::ConstantBuffer;
|
||||
m_format = Format::Unknown;
|
||||
m_dimension = ResourceViewDimension::Buffer;
|
||||
m_buffer = buffer;
|
||||
m_bindingPoint = bindingPoint;
|
||||
m_uniformBufferManager = manager;
|
||||
|
||||
Reference in New Issue
Block a user