// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once #if GRAPHICS_API_DIRECTX12 #include "GPUDeviceDX12.h" #include "Engine/Graphics/Shaders/GPUShaderProgram.h" #include "../IncludeDirectXHeaders.h" /// /// Shaders base class for DirectX 12 backend. /// template class GPUShaderProgramDX12 : public BaseType { protected: Array _data; public: /// /// Initializes a new instance of the class. /// /// The program initialization data. /// The shader data. /// The shader data size. GPUShaderProgramDX12(const GPUShaderProgramInitializer& initializer, byte* cacheBytes, uint32 cacheSize) { BaseType::Init(initializer); _data.Set(cacheBytes, cacheSize); } public: // [BaseType] void* GetBufferHandle() const override { return (void*)_data.Get(); } uint32 GetBufferSize() const override { return _data.Count(); } }; /// /// Vertex Shader for DirectX 12 backend. /// class GPUShaderProgramVSDX12 : public GPUShaderProgramDX12 { private: byte _inputLayoutSize; D3D12_INPUT_ELEMENT_DESC _inputLayout[VERTEX_SHADER_MAX_INPUT_ELEMENTS]; public: /// /// Initializes a new instance of the class. /// /// The program initialization data. /// The shader data. /// The shader data size. /// The input layout description. /// The input layout description size. GPUShaderProgramVSDX12(const GPUShaderProgramInitializer& initializer, byte* cacheBytes, uint32 cacheSize, D3D12_INPUT_ELEMENT_DESC* inputLayout, byte inputLayoutSize) : GPUShaderProgramDX12(initializer, cacheBytes, cacheSize) , _inputLayoutSize(inputLayoutSize) { for (byte i = 0; i < inputLayoutSize; i++) _inputLayout[i] = inputLayout[i]; } public: // [GPUShaderProgramDX12] void* GetInputLayout() const override { return (void*)_inputLayout; } byte GetInputLayoutSize() const override { return _inputLayoutSize; } }; /// /// Hull Shader for DirectX 12 backend. /// class GPUShaderProgramHSDX12 : public GPUShaderProgramDX12 { public: /// /// Initializes a new instance of the class. /// /// The program initialization data. /// The shader data. /// The shader data size. /// The control points used by the hull shader for processing. GPUShaderProgramHSDX12(const GPUShaderProgramInitializer& initializer, byte* cacheBytes, uint32 cacheSize, int32 controlPointsCount) : GPUShaderProgramDX12(initializer, cacheBytes, cacheSize) { _controlPointsCount = controlPointsCount; } }; /// /// Domain Shader for DirectX 12 backend. /// class GPUShaderProgramDSDX12 : public GPUShaderProgramDX12 { public: /// /// Initializes a new instance of the class. /// /// The program initialization data. /// The shader data size. GPUShaderProgramDSDX12(const GPUShaderProgramInitializer& initializer, byte* cacheBytes, uint32 cacheSize) : GPUShaderProgramDX12(initializer, cacheBytes, cacheSize) { } }; /// /// Geometry Shader for DirectX 12 backend. /// class GPUShaderProgramGSDX12 : public GPUShaderProgramDX12 { public: /// /// Initializes a new instance of the class. /// /// The program initialization data. /// The shader data. /// The shader data size. GPUShaderProgramGSDX12(const GPUShaderProgramInitializer& initializer, byte* cacheBytes, uint32 cacheSize) : GPUShaderProgramDX12(initializer, cacheBytes, cacheSize) { } }; /// /// Pixel Shader for DirectX 12 backend. /// class GPUShaderProgramPSDX12 : public GPUShaderProgramDX12 { public: /// /// Initializes a new instance of the class. /// /// The program initialization data. /// The shader data. /// The shader data size. GPUShaderProgramPSDX12(const GPUShaderProgramInitializer& initializer, byte* cacheBytes, uint32 cacheSize) : GPUShaderProgramDX12(initializer, cacheBytes, cacheSize) { } }; /// /// Compute Shader for DirectX 12 backend. /// class GPUShaderProgramCSDX12 : public GPUShaderProgramDX12 { private: GPUDeviceDX12* _device; Array _data; ID3D12PipelineState* _state; public: /// /// Initializes a new instance of the class. /// /// The graphics device. /// The program initialization data. /// The shader data. /// The shader data size. GPUShaderProgramCSDX12(GPUDeviceDX12* device, const GPUShaderProgramInitializer& initializer, byte* cacheBytes, uint32 cacheSize) : GPUShaderProgramDX12(initializer, cacheBytes, cacheSize) , _device(device) , _state(nullptr) { } /// /// Destructor /// ~GPUShaderProgramCSDX12() { _device->AddResourceToLateRelease(_state); } public: /// /// Gets DirectX 12 compute pipeline state object /// /// DirectX 12 compute pipeline state object FORCE_INLINE ID3D12PipelineState* GetState() const { return _state; } /// /// Gets or creates compute pipeline state for that compute shader. /// /// DirectX 12 compute pipeline state object ID3D12PipelineState* GetOrCreateState(); }; #endif