Repository: godotengine/godot
File: drivers/d3d12/rendering_device_driver_d3d12.h (C/C++)

Code before:
	// ----- BUFFER -----

private:
	// Belongs to RENDERING-SUBPASS, but needed here.
	struct FramebufferInfo;
	struct RenderPassInfo;
	struct RenderPassState {
		uint32_t current_subpass = UINT32_MAX;
		const FramebufferInfo *fb_info = nullptr;
		const RenderPassInfo *pass_info = nullptr;
		CD3DX12_RECT region_rect = {};
		bool region_is_all = false;

		const VertexFormatInfo *vf_info = nullptr;
		D3D12_VERTEX_BUFFER_VIEW vertex_buffer_views[8] = {};
		uint32_t vertex_buffer_count = 0;
	};

	// Leveraging knowledge of actual usage and D3D12 specifics (namely, command lists from the same allocator
	// can't be freely begun and ended), an allocator per list works better.
	struct CommandBufferInfo {
		ComPtr<ID3D12CommandAllocator> cmd_allocator;
		ComPtr<ID3D12GraphicsCommandList> cmd_list;

		ID3D12PipelineState *graphics_pso = nullptr;
		ID3D12PipelineState *compute_pso = nullptr;

		uint32_t graphics_root_signature_crc = 0;
		uint32_t compute_root_signature_crc = 0;

		RenderPassState render_pass_state;
		bool descriptor_heaps_set = false;

		HashMap<ResourceInfo::States *, BarrierRequest> res_barriers_requests;
		LocalVector<D3D12_RESOURCE_BARRIER> res_barriers;
		uint32_t res_barriers_count = 0;
		uint32_t res_barriers_batch = 0;
	};

public:
	virtual CommandBufferID command_buffer_create(CommandPoolID p_cmd_pool) override final;
	virtual bool command_buffer_begin(CommandBufferID p_cmd_buffer) override final;
	virtual bool command_buffer_begin_secondary(CommandBufferID p_cmd_buffer, RenderPassID p_render_pass, uint32_t p_subpass, FramebufferID p_framebuffer) override final;
	virtual void command_buffer_end(CommandBufferID p_cmd_buffer) override final;
	virtual void command_buffer_execute_secondary(CommandBufferID p_cmd_buffer, VectorView<CommandBufferID> p_secondary_cmd_buffers) override final;

private:
	/********************/
	/**** SWAP CHAIN ****/
	/********************/


Review comment (suggestion):
I think we can do this so you don't need to add a constructor:

```suggestion
		SelfList<CommandBufferInfo> command_buffer_info_elem(this);
```

I'd swear we are already using this pattern somewhere else. Not a big deal, in any case.

Code after:
	virtual bool command_pool_reset(CommandPoolID p_cmd_pool) override final;
	virtual void command_pool_free(CommandPoolID p_cmd_pool) override final;

	// ----- BUFFER -----

private:
	// Belongs to RENDERING-SUBPASS, but needed here.
	struct FramebufferInfo;
	struct RenderPassInfo;
	struct RenderPassState {
		uint32_t current_subpass = UINT32_MAX;
		const FramebufferInfo *fb_info = nullptr;
		const RenderPassInfo *pass_info = nullptr;
		CD3DX12_RECT region_rect = {};
		bool region_is_all = false;

		const VertexFormatInfo *vf_info = nullptr;
		D3D12_VERTEX_BUFFER_VIEW vertex_buffer_views[8] = {};
		uint32_t vertex_buffer_count = 0;
	};

	// Leveraging knowledge of actual usage and D3D12 specifics (namely, command lists from the same allocator
	// can't be freely begun and ended), an allocator per list works better.
	struct CommandBufferInfo {
		// Store a self list reference to be used by the command pool.
		SelfList<CommandBufferInfo> command_buffer_info_elem{ this };

		ComPtr<ID3D12CommandAllocator> cmd_allocator;
		ComPtr<ID3D12GraphicsCommandList> cmd_list;

		ID3D12PipelineState *graphics_pso = nullptr;
		ID3D12PipelineState *compute_pso = nullptr;

		uint32_t graphics_root_signature_crc = 0;
		uint32_t compute_root_signature_crc = 0;

		RenderPassState render_pass_state;
		bool descriptor_heaps_set = false;

		HashMap<ResourceInfo::States *, BarrierRequest> res_barriers_requests;
		LocalVector<D3D12_RESOURCE_BARRIER> res_barriers;
		uint32_t res_barriers_count = 0;
		uint32_t res_barriers_batch = 0;
	};

public:
	virtual CommandBufferID command_buffer_create(CommandPoolID p_cmd_pool) override final;
	virtual bool command_buffer_begin(CommandBufferID p_cmd_buffer) override final;
	virtual bool command_buffer_begin_secondary(CommandBufferID p_cmd_buffer, RenderPassID p_render_pass, uint32_t p_subpass, FramebufferID p_framebuffer) override final;
	virtual void command_buffer_end(CommandBufferID p_cmd_buffer) override final;
	virtual void command_buffer_execute_secondary(CommandBufferID p_cmd_buffer, VectorView<CommandBufferID> p_secondary_cmd_buffers) override final;