chore: sync workspace state

This commit is contained in:
2026-03-29 01:36:53 +08:00
parent eb5de3e3d4
commit e5cb79f3ce
4935 changed files with 35593 additions and 360696 deletions

View File

@@ -17,6 +17,7 @@
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
#include "XCEngine/RHI/D3D12/D3D12RenderPass.h"
#include "XCEngine/RHI/D3D12/D3D12Framebuffer.h"
#include <algorithm>
#include <stdio.h>
#include <memory>
#include <string>
@@ -83,6 +84,75 @@ uint32_t GetFormatBytesPerPixel(Format format) {
}
}
TextureType ResolveTextureType(uint32_t rawType) {
return static_cast<TextureType>(rawType);
}
uint16_t ResolveDepthOrArraySize(const TextureDesc& desc, TextureType textureType) {
switch (textureType) {
case TextureType::Texture3D:
return static_cast<uint16_t>(std::max<uint32_t>(desc.depth, 1));
case TextureType::Texture2DArray:
return static_cast<uint16_t>(std::max<uint32_t>(desc.arraySize, 1));
case TextureType::TextureCube:
case TextureType::TextureCubeArray:
return static_cast<uint16_t>(std::max<uint32_t>(desc.arraySize, 6));
default:
return 1;
}
}
std::string ShaderModelToString(D3D_SHADER_MODEL shaderModel) {
switch (shaderModel) {
case D3D_SHADER_MODEL_6_7: return "6.7";
case D3D_SHADER_MODEL_6_6: return "6.6";
case D3D_SHADER_MODEL_6_5: return "6.5";
case D3D_SHADER_MODEL_6_4: return "6.4";
case D3D_SHADER_MODEL_6_3: return "6.3";
case D3D_SHADER_MODEL_6_2: return "6.2";
case D3D_SHADER_MODEL_6_1: return "6.1";
case D3D_SHADER_MODEL_6_0: return "6.0";
case D3D_SHADER_MODEL_5_1: return "5.1";
default: return {};
}
}
D3D12_RTV_DIMENSION ResolveRTVDimension(const ResourceViewDesc& desc, TextureType textureType) {
switch (desc.dimension) {
case ResourceViewDimension::Texture1D:
return D3D12_RTV_DIMENSION_TEXTURE1D;
case ResourceViewDimension::Texture1DArray:
return D3D12_RTV_DIMENSION_TEXTURE1DARRAY;
case ResourceViewDimension::Texture2DArray:
case ResourceViewDimension::TextureCube:
case ResourceViewDimension::TextureCubeArray:
return D3D12_RTV_DIMENSION_TEXTURE2DARRAY;
case ResourceViewDimension::Texture3D:
return D3D12_RTV_DIMENSION_TEXTURE3D;
case ResourceViewDimension::Texture2DMS:
return D3D12_RTV_DIMENSION_TEXTURE2DMS;
case ResourceViewDimension::Texture2DMSArray:
return D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY;
case ResourceViewDimension::Unknown:
break;
default:
return D3D12_RTV_DIMENSION_TEXTURE2D;
}
switch (textureType) {
case TextureType::Texture1D:
return D3D12_RTV_DIMENSION_TEXTURE1D;
case TextureType::Texture2DArray:
case TextureType::TextureCube:
case TextureType::TextureCubeArray:
return D3D12_RTV_DIMENSION_TEXTURE2DARRAY;
case TextureType::Texture3D:
return D3D12_RTV_DIMENSION_TEXTURE3D;
default:
return D3D12_RTV_DIMENSION_TEXTURE2D;
}
}
} // namespace
D3D12Device::D3D12Device()
@@ -226,6 +296,28 @@ void D3D12Device::QueryAdapterInfo() {
m_capabilities.bSupportsConservativeRasterization = options.ConservativeRasterizationTier != D3D12_CONSERVATIVE_RASTERIZATION_TIER_NOT_SUPPORTED;
}
m_capabilities.bSupportsComputeShaders = true;
D3D12_FEATURE_DATA_SHADER_MODEL shaderModel = {};
const D3D_SHADER_MODEL shaderModelCandidates[] = {
D3D_SHADER_MODEL_6_7,
D3D_SHADER_MODEL_6_6,
D3D_SHADER_MODEL_6_5,
D3D_SHADER_MODEL_6_4,
D3D_SHADER_MODEL_6_3,
D3D_SHADER_MODEL_6_2,
D3D_SHADER_MODEL_6_1,
D3D_SHADER_MODEL_6_0,
D3D_SHADER_MODEL_5_1
};
for (D3D_SHADER_MODEL candidate : shaderModelCandidates) {
shaderModel.HighestShaderModel = candidate;
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shaderModel, sizeof(shaderModel)))) {
m_capabilities.shaderModel = ShaderModelToString(shaderModel.HighestShaderModel);
break;
}
}
D3D12_FEATURE_DATA_D3D12_OPTIONS3 options3 = {};
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &options3, sizeof(options3)))) {
}
@@ -321,33 +413,35 @@ RHIBuffer* D3D12Device::CreateBuffer(const BufferDesc& desc) {
RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
auto* texture = new D3D12Texture();
D3D12_RESOURCE_DESC d3d12Desc = {};
d3d12Desc.Dimension = ToD3D12(static_cast<TextureType>(desc.textureType));
const TextureType textureType = ResolveTextureType(desc.textureType);
const Format format = static_cast<Format>(desc.format);
const bool isDepthFormat = format == Format::D24_UNorm_S8_UInt ||
format == Format::D32_Float ||
format == Format::D16_UNorm;
d3d12Desc.Dimension = ToD3D12(textureType);
d3d12Desc.Width = desc.width;
d3d12Desc.Height = desc.height;
d3d12Desc.DepthOrArraySize = desc.depth > 0 ? desc.depth : 1;
d3d12Desc.DepthOrArraySize = ResolveDepthOrArraySize(desc, textureType);
d3d12Desc.MipLevels = desc.mipLevels > 0 ? desc.mipLevels : 1;
d3d12Desc.Format = ToD3D12(static_cast<Format>(desc.format));
d3d12Desc.Format = ToD3D12(format);
d3d12Desc.SampleDesc.Count = desc.sampleCount > 0 ? desc.sampleCount : 1;
d3d12Desc.SampleDesc.Quality = desc.sampleQuality;
d3d12Desc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(desc.flags);
Format format = static_cast<Format>(desc.format);
if (format == Format::D24_UNorm_S8_UInt || format == Format::D32_Float ||
format == Format::D16_UNorm) {
if (isDepthFormat) {
d3d12Desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
} else if (d3d12Desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc.width > 0 && desc.height > 0) {
d3d12Desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
}
d3d12Desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
const bool isDepthFormat = format == Format::D24_UNorm_S8_UInt ||
format == Format::D32_Float ||
format == Format::D16_UNorm;
const D3D12_RESOURCE_STATES initialState =
isDepthFormat ? D3D12_RESOURCE_STATE_DEPTH_WRITE : D3D12_RESOURCE_STATE_COMMON;
if (texture->Initialize(m_device.Get(), d3d12Desc, initialState)) {
texture->SetFormat(format);
texture->SetTextureType(textureType);
if (isDepthFormat) {
texture->SetState(ResourceStates::DepthWrite);
}
@@ -700,8 +794,23 @@ RHIResourceView* D3D12Device::CreateRenderTargetView(RHITexture* texture, const
}
D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = {};
rtvDesc.Format = ToD3D12(static_cast<Format>(desc.format));
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
const Format format = desc.format != 0 ? static_cast<Format>(desc.format) : texture->GetFormat();
const TextureType textureType = texture->GetTextureType();
rtvDesc.Format = ToD3D12(format);
rtvDesc.ViewDimension = ResolveRTVDimension(desc, textureType);
if (rtvDesc.ViewDimension == D3D12_RTV_DIMENSION_TEXTURE2DARRAY) {
rtvDesc.Texture2DArray.MipSlice = desc.mipLevel;
rtvDesc.Texture2DArray.FirstArraySlice = desc.firstArraySlice;
rtvDesc.Texture2DArray.ArraySize = desc.arraySize > 0 ? desc.arraySize : 1;
rtvDesc.Texture2DArray.PlaneSlice = desc.planeSlice;
} else if (rtvDesc.ViewDimension == D3D12_RTV_DIMENSION_TEXTURE3D) {
rtvDesc.Texture3D.MipSlice = desc.mipLevel;
rtvDesc.Texture3D.FirstWSlice = desc.firstArraySlice;
rtvDesc.Texture3D.WSize = desc.arraySize > 0 ? desc.arraySize : 1;
} else {
rtvDesc.Texture2D.MipSlice = desc.mipLevel;
rtvDesc.Texture2D.PlaneSlice = desc.planeSlice;
}
auto heap = std::make_unique<D3D12DescriptorHeap>();
if (!heap->Initialize(m_device.Get(), DescriptorHeapType::RTV, 1, false)) {