@@ -11,16 +11,27 @@ namespace nbl::video
1111
1212class NBL_API2 CComputeBlit : public core::IReferenceCounted
1313{
14- private:
15- struct vec3 { float x, y, z; };
16- struct uvec3 { uint32_t x, y, z; };
17-
18-
1914 public:
20- struct dispatch_info_t
15+ // manual encode type: TODO replace with `hlsl::format` utils when they're ready
16+ static inline asset::E_FORMAT getCompatClassFormat (const asset::E_FORMAT format)
2117 {
22- uint32_t wgCount[3 ];
23- };
18+ const asset::E_FORMAT_CLASS formatClass = asset::getFormatClass (format);
19+ switch (formatClass)
20+ {
21+ case asset::EFC_8_BIT:
22+ return asset::EF_R8_UINT;
23+ case asset::EFC_16_BIT:
24+ return asset::EF_R16_UINT;
25+ case asset::EFC_32_BIT:
26+ return asset::EF_R32_UINT;
27+ case asset::EFC_64_BIT:
28+ return asset::EF_R32G32_UINT;
29+ case asset::EFC_128_BIT:
30+ return asset::EF_R32G32B32A32_UINT;
31+ default :
32+ return asset::EF_UNKNOWN;
33+ }
34+ }
2435
2536 // Coverage adjustment needs alpha to be stored in HDR with high precision
2637 static inline asset::E_FORMAT getCoverageAdjustmentIntermediateFormat (const asset::E_FORMAT format)
@@ -51,67 +62,9 @@ class NBL_API2 CComputeBlit : public core::IReferenceCounted
5162 }
5263 }
5364
54- static core::smart_refctd_ptr<CComputeBlit> create (core::smart_refctd_ptr<video::ILogicalDevice>&& logicalDevice)
55- {
56- if (!logicalDevice)
57- return nullptr ;
58- /*
59- auto result = core::smart_refctd_ptr<CComputeBlitCComputeBlit>(new CComputeBlit(std::move(logicalDevice)), core::dont_grab);
60-
61- if (smemSize == ~0u)
62- m_availableSharedMemory = m_device->getPhysicalDevice()->getProperties().limits.maxComputeSharedMemorySize;
63- else
64- m_availableSharedMemory = core::min(core::roundUp(smemSize, static_cast<uint32_t>(sizeof(float) * 64)), m_device->getPhysicalDevice()->getLimits().maxComputeSharedMemorySize);
65-
66- asset::SPushConstantRange pcRange = {};
67- {
68- pcRange.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE;
69- pcRange.offset = 0u;
70- pcRange.size = sizeof(nbl::hlsl::blit::parameters_t);
71- }
72-
73- for (auto i = 0; i < static_cast<uint8_t>(EBT_COUNT); ++i)
74- {
75- result->m_blitPipelineLayout[i] = result->m_device->createPipelineLayout({ &pcRange, &pcRange + 1ull }, core::smart_refctd_ptr(result->m_blitDSLayout[i]), core::smart_refctd_ptr(result->m_kernelWeightsDSLayout));
76- if (!result->m_blitPipelineLayout[i])
77- return nullptr;
78- }
79-
80- result->m_coverageAdjustmentPipelineLayout = result->m_device->createPipelineLayout({ &pcRange, &pcRange + 1ull }, core::smart_refctd_ptr(result->m_blitDSLayout[EBT_COVERAGE_ADJUSTMENT]));
81- if (!result->m_coverageAdjustmentPipelineLayout)
82- return nullptr;
83-
84- return result;
85- */
86- return nullptr ;
87- }
65+ // ctor
66+ CComputeBlit (core::smart_refctd_ptr<ILogicalDevice>&& logicalDevice) : m_device(std::move(logicalDevice)) {}
8867#if 0
89- inline core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> getDefaultBlitDescriptorSetLayout(const asset::IBlitUtilities::E_ALPHA_SEMANTIC alphaSemantic) const
90- {
91- if (alphaSemantic == asset::IBlitUtilities::EAS_REFERENCE_OR_COVERAGE)
92- return m_blitDSLayout[EBT_COVERAGE_ADJUSTMENT];
93- else
94- return m_blitDSLayout[EBT_REGULAR];
95- }
96-
97- inline core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> getDefaultKernelWeightsDescriptorSetLayout() const
98- {
99- return m_kernelWeightsDSLayout;
100- }
101-
102- inline core::smart_refctd_ptr<video::IGPUPipelineLayout> getDefaultBlitPipelineLayout(const asset::IBlitUtilities::E_ALPHA_SEMANTIC alphaSemantic) const
103- {
104- if (alphaSemantic == asset::IBlitUtilities::EAS_REFERENCE_OR_COVERAGE)
105- return m_blitPipelineLayout[EBT_COVERAGE_ADJUSTMENT];
106- else
107- return m_blitPipelineLayout[EBT_REGULAR];
108- }
109-
110- inline core::smart_refctd_ptr<video::IGPUPipelineLayout> getDefaultCoverageAdjustmentPipelineLayout() const
111- {
112- return m_coverageAdjustmentPipelineLayout;
113- }
114- #endif
11568 // @param `alphaBinCount` is only required to size the histogram present in the default nbl_glsl_blit_AlphaStatistics_t in default_compute_common.comp
11669 core::smart_refctd_ptr<video::IGPUShader> createAlphaTestSpecializedShader(const asset::IImage::E_TYPE inImageType, const uint32_t alphaBinCount = asset::IBlitUtilities::DefaultAlphaBinCount);
11770
@@ -705,6 +658,8 @@ class NBL_API2 CComputeBlit : public core::IReferenceCounted
705658 return compatFormat;
706659 }
707660 }
661+ #endif
662+
708663
709664 private:
710665 enum E_BLIT_TYPE : uint8_t
@@ -714,112 +669,7 @@ class NBL_API2 CComputeBlit : public core::IReferenceCounted
714669 EBT_COUNT
715670 };
716671
717- core::smart_refctd_ptr<video::IGPUComputePipeline> m_alphaTestPipelines[asset::IBlitUtilities::MaxAlphaBinCount / asset::IBlitUtilities::MinAlphaBinCount][asset::IImage::ET_COUNT] = { nullptr };
718-
719- struct SNormalizationCacheKey
720- {
721- asset::IImage::E_TYPE imageType;
722- uint32_t alphaBinCount;
723- asset::E_FORMAT outFormat;
724-
725- inline bool operator ==(const SNormalizationCacheKey& other) const
726- {
727- return (imageType == other.imageType ) && (alphaBinCount == other.alphaBinCount ) && (outFormat == other.outFormat );
728- }
729- };
730- struct SNormalizationCacheHash
731- {
732- inline size_t operator () (const SNormalizationCacheKey& key) const
733- {
734- return
735- std::hash<decltype (key.imageType )>{}(key.imageType ) ^
736- std::hash<decltype (key.alphaBinCount )>{}(key.alphaBinCount ) ^
737- std::hash<decltype (key.outFormat )>{}(key.outFormat );
738- }
739- };
740- core::unordered_map<SNormalizationCacheKey, core::smart_refctd_ptr<video::IGPUComputePipeline>, SNormalizationCacheHash> m_normalizationPipelines;
741-
742- struct SBlitCacheKey
743- {
744- uint32_t wgSize;
745- asset::IImage::E_TYPE imageType;
746- uint32_t alphaBinCount;
747- asset::E_FORMAT outFormat;
748- uint32_t smemSize;
749- bool coverageAdjustment;
750-
751- inline bool operator ==(const SBlitCacheKey& other) const
752- {
753- return (wgSize == other.wgSize ) && (imageType == other.imageType ) && (alphaBinCount == other.alphaBinCount ) && (outFormat == other.outFormat )
754- && (smemSize == other.smemSize ) && (coverageAdjustment == other.coverageAdjustment );
755- }
756- };
757- struct SBlitCacheHash
758- {
759- inline size_t operator ()(const SBlitCacheKey& key) const
760- {
761- return
762- std::hash<decltype (key.wgSize )>{}(key.wgSize ) ^
763- std::hash<decltype (key.imageType )>{}(key.imageType ) ^
764- std::hash<decltype (key.alphaBinCount )>{}(key.alphaBinCount ) ^
765- std::hash<decltype (key.outFormat )>{}(key.outFormat ) ^
766- std::hash<decltype (key.smemSize )>{}(key.smemSize ) ^
767- std::hash<decltype (key.coverageAdjustment )>{}(key.coverageAdjustment );
768- }
769- };
770- core::unordered_map<SBlitCacheKey, core::smart_refctd_ptr<video::IGPUComputePipeline>, SBlitCacheHash> m_blitPipelines;
771-
772- uint32_t m_availableSharedMemory;
773- core::smart_refctd_ptr<video::ILogicalDevice> m_device;
774-
775- core::smart_refctd_ptr<video::IGPUSampler> samplers[video::IGPUSampler::ETC_COUNT][video::IGPUSampler::ETC_COUNT][video::IGPUSampler::ETC_COUNT][video::IGPUSampler::ETBC_COUNT] = { nullptr };
776-
777- CComputeBlit (core::smart_refctd_ptr<video::ILogicalDevice>&& logicalDevice) : m_device(std::move(logicalDevice)) {}
778-
779- static inline void dispatchHelper (video::IGPUCommandBuffer* cmdbuf, const video::IGPUPipelineLayout* pipelineLayout, const nbl::hlsl::blit::parameters_t & pushConstants, const dispatch_info_t & dispatchInfo)
780- {
781- cmdbuf->pushConstants (pipelineLayout, IGPUShader::E_SHADER_STAGE::ESS_COMPUTE, 0u , sizeof (nbl::hlsl::blit::parameters_t ), &pushConstants);
782- cmdbuf->dispatch (dispatchInfo.wgCount [0 ], dispatchInfo.wgCount [1 ], dispatchInfo.wgCount [2 ]);
783- }
784-
785- core::smart_refctd_ptr<video::IGPUDescriptorSetLayout> createDSLayout (const uint32_t descriptorCount, const asset::IDescriptor::E_TYPE* descriptorTypes, video::ILogicalDevice* logicalDevice) const
786- {
787- constexpr uint32_t MAX_DESCRIPTOR_COUNT = 5 ;
788- assert (descriptorCount < MAX_DESCRIPTOR_COUNT);
789-
790- video::IGPUDescriptorSetLayout::SBinding bindings[MAX_DESCRIPTOR_COUNT] = {};
791-
792- for (uint32_t i = 0u ; i < descriptorCount; ++i)
793- {
794- bindings[i].binding = i;
795- bindings[i].count = 1u ;
796- bindings[i].stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE;
797- bindings[i].type = descriptorTypes[i];
798- }
799-
800- auto dsLayout = logicalDevice->createDescriptorSetLayout ({ bindings, bindings + descriptorCount });
801- return dsLayout;
802- }
803-
804- static inline asset::E_FORMAT getCompatClassFormat (const asset::E_FORMAT format)
805- {
806- const asset::E_FORMAT_CLASS formatClass = asset::getFormatClass (format);
807- switch (formatClass)
808- {
809- case asset::EFC_8_BIT:
810- return asset::EF_R8_UINT;
811- case asset::EFC_16_BIT:
812- return asset::EF_R16_UINT;
813- case asset::EFC_32_BIT:
814- return asset::EF_R32_UINT;
815- case asset::EFC_64_BIT:
816- return asset::EF_R32G32_UINT;
817- case asset::EFC_128_BIT:
818- return asset::EF_R32G32B32A32_UINT;
819- default :
820- return asset::EF_UNKNOWN;
821- }
822- }
672+ core::smart_refctd_ptr<ILogicalDevice> m_device;
823673
824674 // ! This calculates the inclusive upper bound on the preload region i.e. it will be reachable for some cases. For the rest it will be bigger
825675 // ! by a pixel in each dimension.
0 commit comments