Add CreateDesc for D3D12ShaderResourceView

This commit is contained in:
2026-03-17 01:26:40 +08:00
parent 07450e76a4
commit f615a86aab
2 changed files with 16 additions and 0 deletions

View File

@@ -3,6 +3,9 @@
#include <d3d12.h> #include <d3d12.h>
#include <wrl/client.h> #include <wrl/client.h>
#include "../Enums.h"
#include "D3D12Enum.h"
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;
namespace XCEngine { namespace XCEngine {
@@ -19,6 +22,8 @@ public:
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle() const { return m_handle; } D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle() const { return m_handle; }
static D3D12_SHADER_RESOURCE_VIEW_DESC CreateDesc(Format format, D3D12_SRV_DIMENSION dimension = D3D12_SRV_DIMENSION_TEXTURE2D, uint32_t mipLevels = 1);
private: private:
D3D12_CPU_DESCRIPTOR_HANDLE m_handle; D3D12_CPU_DESCRIPTOR_HANDLE m_handle;
ID3D12Resource* m_resource; ID3D12Resource* m_resource;

View File

@@ -29,5 +29,16 @@ void D3D12ShaderResourceView::Shutdown() {
m_resource = nullptr; m_resource = nullptr;
} }
D3D12_SHADER_RESOURCE_VIEW_DESC D3D12ShaderResourceView::CreateDesc(Format format, D3D12_SRV_DIMENSION dimension, uint32_t mipLevels) {
D3D12_SHADER_RESOURCE_VIEW_DESC desc = {};
desc.Format = ToD3D12(format);
desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
desc.ViewDimension = dimension;
if (dimension == D3D12_SRV_DIMENSION_TEXTURE2D) {
desc.Texture2D.MipLevels = mipLevels;
}
return desc;
}
} // namespace RHI } // namespace RHI
} // namespace XCEngine } // namespace XCEngine