|
|
|
|
@@ -41,6 +41,8 @@ bool D3D12Device::Initialize(const RHIDeviceDesc& desc) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_deviceDesc = desc;
|
|
|
|
|
|
|
|
|
|
if (!CreateDXGIFactory(desc.enableDebugLayer)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@@ -75,12 +77,24 @@ bool D3D12Device::Initialize(const RHIDeviceDesc& desc) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
|
|
|
|
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
|
|
|
|
queueDesc.Priority = 0;
|
|
|
|
|
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
|
|
|
|
queueDesc.NodeMask = 0;
|
|
|
|
|
if (FAILED(m_device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue)))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QueryAdapterInfo();
|
|
|
|
|
m_initialized = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void D3D12Device::Shutdown() {
|
|
|
|
|
if (m_commandQueue) {
|
|
|
|
|
m_commandQueue.Reset();
|
|
|
|
|
}
|
|
|
|
|
if (m_device) {
|
|
|
|
|
m_device.Reset();
|
|
|
|
|
}
|
|
|
|
|
@@ -134,13 +148,54 @@ void D3D12Device::QueryAdapterInfo() {
|
|
|
|
|
m_adapterInfo.description = desc.Description;
|
|
|
|
|
m_adapterInfo.isSoftware = (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0;
|
|
|
|
|
|
|
|
|
|
m_deviceInfo.description = desc.Description;
|
|
|
|
|
m_deviceInfo.vendorId = desc.VendorId;
|
|
|
|
|
m_deviceInfo.deviceId = desc.DeviceId;
|
|
|
|
|
m_deviceInfo.dedicatedVideoMemory = desc.DedicatedVideoMemory;
|
|
|
|
|
m_deviceInfo.dedicatedSystemMemory = desc.DedicatedSystemMemory;
|
|
|
|
|
m_deviceInfo.sharedSystemMemory = desc.SharedSystemMemory;
|
|
|
|
|
m_deviceInfo.isSoftware = (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0;
|
|
|
|
|
|
|
|
|
|
switch (desc.VendorId) {
|
|
|
|
|
case 0x10DE: m_deviceInfo.vendor = L"NVIDIA"; break;
|
|
|
|
|
case 0x1002: m_deviceInfo.vendor = L"AMD"; break;
|
|
|
|
|
case 0x8086: m_deviceInfo.vendor = L"Intel"; break;
|
|
|
|
|
default: m_deviceInfo.vendor = L"Unknown"; break;
|
|
|
|
|
}
|
|
|
|
|
m_deviceInfo.renderer = desc.Description;
|
|
|
|
|
|
|
|
|
|
D3D12_FEATURE_DATA_D3D12_OPTIONS5 options5 = {};
|
|
|
|
|
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &options5, sizeof(options5)))) {
|
|
|
|
|
m_capabilities.bSupportsRayTracing = options5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12_FEATURE_DATA_D3D12_OPTIONS7 options7 = {};
|
|
|
|
|
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &options7, sizeof(options7)))) {
|
|
|
|
|
m_capabilities.bSupportsMeshShaders = options7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12_FEATURE_DATA_D3D12_OPTIONS options = {};
|
|
|
|
|
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options)))) {
|
|
|
|
|
m_capabilities.bSupportsConservativeRasterization = options.ConservativeRasterizationTier != D3D12_CONSERVATIVE_RASTERIZATION_TIER_NOT_SUPPORTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12_FEATURE_DATA_D3D12_OPTIONS3 options3 = {};
|
|
|
|
|
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &options3, sizeof(options3)))) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3D12_FEATURE_DATA_D3D12_OPTIONS4 options4 = {};
|
|
|
|
|
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS4, &options4, sizeof(options4)))) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_capabilities.maxRenderTargets = 8;
|
|
|
|
|
m_capabilities.maxViewports = 16;
|
|
|
|
|
m_capabilities.maxVertexAttribs = 8;
|
|
|
|
|
m_capabilities.maxColorAttachments = 8;
|
|
|
|
|
m_capabilities.maxConstantBufferSize = D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 16;
|
|
|
|
|
m_capabilities.maxAnisotropy = D3D12_MAX_MAXANISOTROPY;
|
|
|
|
|
m_capabilities.maxTexture2DSize = D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
|
|
|
|
m_capabilities.maxTexture3DSize = D3D12_REQ_TEXTURE3D_U_V_OR_W_DIMENSION;
|
|
|
|
|
m_capabilities.maxTextureCubeSize = D3D12_REQ_TEXTURECUBE_DIMENSION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool D3D12Device::CheckFeatureSupport(D3D12_FEATURE feature, void* featureSupportData, uint32_t featureSupportDataSize) {
|
|
|
|
|
@@ -202,7 +257,9 @@ RHIBuffer* D3D12Device::CreateBuffer(const BufferDesc& desc) {
|
|
|
|
|
D3D12_HEAP_TYPE heapType = D3D12_HEAP_TYPE_DEFAULT;
|
|
|
|
|
if (desc.bufferType == static_cast<uint32_t>(BufferType::ReadBack)) {
|
|
|
|
|
heapType = D3D12_HEAP_TYPE_READBACK;
|
|
|
|
|
} else if (desc.bufferType == static_cast<uint32_t>(BufferType::Constant)) {
|
|
|
|
|
} else if (desc.bufferType == static_cast<uint32_t>(BufferType::Constant) ||
|
|
|
|
|
desc.bufferType == static_cast<uint32_t>(BufferType::Vertex) ||
|
|
|
|
|
desc.bufferType == static_cast<uint32_t>(BufferType::Index)) {
|
|
|
|
|
heapType = D3D12_HEAP_TYPE_UPLOAD;
|
|
|
|
|
}
|
|
|
|
|
if (buffer->Initialize(m_device.Get(), desc.size, D3D12_RESOURCE_STATE_COMMON, heapType)) {
|
|
|
|
|
@@ -280,14 +337,38 @@ RHIFence* D3D12Device::CreateFence(const FenceDesc& desc) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RHISwapChain* D3D12Device::CreateSwapChain(const SwapChainDesc& desc) {
|
|
|
|
|
auto* swapChain = new D3D12SwapChain();
|
|
|
|
|
HWND hwnd = static_cast<HWND>(m_deviceDesc.windowHandle);
|
|
|
|
|
if (swapChain->Initialize(m_factory.Get(), m_commandQueue.Get(), hwnd,
|
|
|
|
|
desc.width, desc.height, desc.bufferCount)) {
|
|
|
|
|
return swapChain;
|
|
|
|
|
}
|
|
|
|
|
delete swapChain;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RHICommandList* D3D12Device::CreateCommandList(const CommandListDesc& desc) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
auto* allocator = new D3D12CommandAllocator();
|
|
|
|
|
if (!allocator->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.commandListType))) {
|
|
|
|
|
delete allocator;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto* cmdList = new D3D12CommandList();
|
|
|
|
|
if (!cmdList->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.commandListType), allocator->GetCommandAllocator())) {
|
|
|
|
|
delete allocator;
|
|
|
|
|
delete cmdList;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return cmdList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RHICommandQueue* D3D12Device::CreateCommandQueue(const CommandQueueDesc& desc) {
|
|
|
|
|
auto* queue = new D3D12CommandQueue();
|
|
|
|
|
if (queue->Initialize(m_device.Get(), static_cast<CommandQueueType>(desc.queueType))) {
|
|
|
|
|
return queue;
|
|
|
|
|
}
|
|
|
|
|
delete queue;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|