3333#include " core/templates/hash_map.h"
3434#include " core/templates/paged_allocator.h"
3535#include " core/templates/self_list.h"
36+ #include " rendering_shader_container_d3d12.h"
3637#include " servers/rendering/rendering_device_driver.h"
3738
3839#ifndef _MSC_VER
5455
5556using Microsoft::WRL::ComPtr;
5657
57- #define D3D12_BITCODE_OFFSETS_NUM_STAGES 3
58-
5958#ifdef DEV_ENABLED
6059#define CUSTOM_INFO_QUEUE_ENABLED 0
6160#endif
@@ -131,6 +130,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
131130 FormatCapabilities format_capabilities;
132131 BarrierCapabilities barrier_capabilities;
133132 MiscFeaturesSupport misc_features_support;
133+ RenderingShaderContainerFormatD3D12 shader_container_format;
134134 String pipeline_cache_id;
135135
136136 class DescriptorsHeap {
@@ -518,6 +518,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
518518 /* ***************/
519519 /* *** SHADER ****/
520520 /* ***************/
521+
521522private:
522523 static const uint32_t ROOT_SIGNATURE_SIZE = 256 ;
523524 static const uint32_t PUSH_CONSTANT_SIZE = 128 ; // Mimicking Vulkan.
@@ -535,82 +536,6 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
535536 MAX_UNIFORM_SETS = (ROOT_SIGNATURE_SIZE - PUSH_CONSTANT_SIZE) / sizeof (uint32_t ),
536537 };
537538
538- enum RootSignatureLocationType {
539- RS_LOC_TYPE_RESOURCE,
540- RS_LOC_TYPE_SAMPLER,
541- };
542-
543- enum ResourceClass {
544- RES_CLASS_INVALID,
545- RES_CLASS_CBV,
546- RES_CLASS_SRV,
547- RES_CLASS_UAV,
548- };
549-
550- struct ShaderBinary {
551- // Version 1: Initial.
552- // Version 2: 64-bit vertex input mask.
553- // Version 3: Added SC stage mask.
554- static const uint32_t VERSION = 3 ;
555-
556- // Phase 1: SPIR-V reflection, where the Vulkan/RD interface of the shader is discovered.
557- // Phase 2: SPIR-V to DXIL translation, where the DXIL interface is discovered, which may have gaps due to optimizations.
558-
559- struct DataBinding {
560- // - Phase 1.
561- uint32_t type = 0 ;
562- uint32_t binding = 0 ;
563- uint32_t stages = 0 ;
564- uint32_t length = 0 ; // Size of arrays (in total elements), or ubos (in bytes * total elements).
565- uint32_t writable = 0 ;
566- // - Phase 2.
567- uint32_t res_class = 0 ;
568- uint32_t has_sampler = 0 ;
569- uint32_t dxil_stages = 0 ;
570- struct RootSignatureLocation {
571- uint32_t root_param_idx = UINT32_MAX; // UINT32_MAX if unused.
572- uint32_t range_idx = UINT32_MAX; // UINT32_MAX if unused.
573- };
574- RootSignatureLocation root_sig_locations[2 ]; // Index is RootSignatureLocationType.
575-
576- // We need to sort these to fill the root signature locations properly.
577- bool operator <(const DataBinding &p_other) const {
578- return binding < p_other.binding ;
579- }
580- };
581-
582- struct SpecializationConstant {
583- // - Phase 1.
584- uint32_t type = 0 ;
585- uint32_t constant_id = 0 ;
586- union {
587- uint32_t int_value = 0 ;
588- float float_value;
589- bool bool_value;
590- };
591- uint32_t stage_flags = 0 ;
592- // - Phase 2.
593- uint64_t stages_bit_offsets[D3D12_BITCODE_OFFSETS_NUM_STAGES] = {};
594- };
595-
596- struct Data {
597- uint64_t vertex_input_mask = 0 ;
598- uint32_t fragment_output_mask = 0 ;
599- uint32_t specialization_constants_count = 0 ;
600- uint32_t spirv_specialization_constants_ids_mask = 0 ;
601- uint32_t is_compute = 0 ;
602- uint32_t compute_local_size[3 ] = {};
603- uint32_t set_count = 0 ;
604- uint32_t push_constant_size = 0 ;
605- uint32_t dxil_push_constant_stages = 0 ; // Phase 2.
606- uint32_t nir_runtime_data_root_param_idx = 0 ; // Phase 2.
607- uint32_t stage_count = 0 ;
608- uint32_t shader_name_len = 0 ;
609- uint32_t root_signature_len = 0 ;
610- uint32_t root_signature_crc = 0 ;
611- };
612- };
613-
614539 struct ShaderInfo {
615540 uint32_t dxil_push_constant_size = 0 ;
616541 uint32_t nir_runtime_data_root_param_idx = UINT32_MAX;
@@ -661,22 +586,13 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
661586 uint32_t root_signature_crc = 0 ;
662587 };
663588
664- uint32_t _shader_patch_dxil_specialization_constant (
665- PipelineSpecializationConstantType p_type,
666- const void *p_value,
667- const uint64_t (&p_stages_bit_offsets)[D3D12_BITCODE_OFFSETS_NUM_STAGES],
668- HashMap<ShaderStage, Vector<uint8_t>> &r_stages_bytecodes,
669- bool p_is_first_patch);
670589 bool _shader_apply_specialization_constants (
671590 const ShaderInfo *p_shader_info,
672591 VectorView<PipelineSpecializationConstant> p_specialization_constants,
673592 HashMap<ShaderStage, Vector<uint8_t >> &r_final_stages_bytecode);
674- void _shader_sign_dxil_bytecode (ShaderStage p_stage, Vector<uint8_t > &r_dxil_blob);
675593
676594public:
677- virtual String shader_get_binary_cache_key () override final ;
678- virtual Vector<uint8_t > shader_compile_binary_from_spirv (VectorView<ShaderStageSPIRVData> p_spirv, const String &p_shader_name) override final ;
679- virtual ShaderID shader_create_from_bytecode (const Vector<uint8_t > &p_shader_binary, ShaderDescription &r_shader_desc, String &r_name, const Vector<ImmutableSampler> &p_immutable_samplers) override final ;
595+ virtual ShaderID shader_create_from_container (const Ref<RenderingShaderContainer> &p_shader_container, const Vector<ImmutableSampler> &p_immutable_samplers) override final ;
680596 virtual uint32_t shader_get_layout_hash (ShaderID p_shader) override final ;
681597 virtual void shader_free (ShaderID p_shader) override final ;
682598 virtual void shader_destroy_modules (ShaderID p_shader) override final ;
@@ -979,6 +895,7 @@ class RenderingDeviceDriverD3D12 : public RenderingDeviceDriver {
979895 virtual String get_api_version () const override final ;
980896 virtual String get_pipeline_cache_uuid () const override final ;
981897 virtual const Capabilities &get_capabilities () const override final ;
898+ virtual const RenderingShaderContainerFormat &get_shader_container_format () const override final ;
982899
983900 virtual bool is_composite_alpha_supported (CommandQueueID p_queue) const override final ;
984901
0 commit comments