Program Listing for File d3d12-device.h

Return to documentation for file (include\d3d12-state-tracking\d3d12-device.h)

/******************************************************************************
© Intel Corporation.

This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.


 This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.

******************************************************************************/

#pragma once
#include "d3d12-object.h"
#include "concurrent/critical-section.h"
#include <guiddef.h>
#include "utility/guid_hash.h"
#include <atlbase.h>
#include <d3d12.h>
#include <gpgmm_d3d12.h>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <vector>

namespace gpa {
namespace d3d12_state_tracker {

using ParameterDescsVector = std::vector<D3D12_META_COMMAND_PARAMETER_DESC>;

struct MetaCommandStageInfo
{
    UINT TotalStructureSizeInBytes;
    ParameterDescsVector Parameters;
    bool ContainsOpaqueHandles;
};

struct MetaCommandInfo
{
    std::wstring Name;
    D3D12_GRAPHICS_STATES InitializationDirtyState;
    D3D12_GRAPHICS_STATES ExecutionDirtyState;
    std::array<MetaCommandStageInfo, D3D12_META_COMMAND_PARAMETER_STAGE_EXECUTION + 1> Stages;
};

using MetaCommandsMap = std::unordered_map<GUID, MetaCommandInfo>;

class D3D12DeviceState : public D3D12ObjectState
{
private:
    D3D_FEATURE_LEVEL mFeatureLevel;
    IUnknown* mAdapter;
    CComPtr<gpgmm::d3d12::IResourceAllocator> mResourceAllocator;
    CComPtr<gpgmm::d3d12::IResidencyManager> mResidencyManager;

    MetaCommandsMap mMetaCommands;

    concurrent::CriticalSection mQueuesCriticalSection;
    std::unordered_set<ID3D12CommandQueue*> mQueues;

public:
    static constexpr GUID sGUID = {0xc88081f1, 0x573c, 0x4276, {0x9a, 0x12, 0xb0, 0xf, 0xfd, 0x2e, 0xb9, 0xef}};

public:
    D3D12DeviceState(ID3D12Device* runtimeObj, IUnknown* pAdapter, D3D_FEATURE_LEVEL MinimumFeatureLevel);
    virtual ~D3D12DeviceState();

    GUID GetGUID() override;

    D3D_FEATURE_LEVEL GetFeatureLevel() const;

    MetaCommandInfo const& GetMetaCommandInfo(GUID commandId);

    void RegisterCommandQueue(ID3D12CommandQueue* queue);
    void UnregisterCommandQueue(ID3D12CommandQueue* queue);
    std::vector<ID3D12CommandQueue*> GetCommandQueues();
    gpgmm::d3d12::IResourceAllocator* GetResourceAllocator() const;
    gpgmm::d3d12::IResidencyManager* GetResidencyManager() const;
    gpgmm::d3d12::ALLOCATOR_DESC D3D12DeviceState::GetResourceAllocatorDesc() const;

private:
    void CollectMetaDataInfo();
    gpgmm::d3d12::ALLOCATOR_DESC mResourceAllocatorDesc = {};
};

}  // namespace d3d12_state_tracker
}  // namespace gpa