8
8
9
9
namespace nbl ::ext::FullScreenTriangle
10
10
{
11
-
12
- #if 0
13
- inline NBL_PROTO_PIPELINE createProtoPipeline(, uint32_t pushConstantOffset)
14
- {
15
- if (!cpu2gpuParams.assetManager)
16
- assert(false);
17
-
18
- nbl::video::IGPUObjectFromAssetConverter cpu2gpu;
19
- auto* assetManager = cpu2gpuParams.assetManager;
20
-
21
- NBL_PROTO_PIPELINE protoPipeline;
22
-
23
- asset::IAsset::E_TYPE types[] = { asset::IAsset::ET_SPECIALIZED_SHADER,static_cast<asset::IAsset::E_TYPE>(0u) };
24
- auto found = assetManager->findAssets("nbl/builtin/specialized_shader/fullscreentriangle.vert", types);
25
- assert(found->size());
26
- auto contents = found->begin()->getContents();
27
- assert(!contents.empty());
28
- auto pShader = static_cast<asset::ICPUSpecializedShader*>((contents.begin()->get()));
29
-
30
- auto& gpuSpecializedShader = std::get<core::smart_refctd_ptr<video::IGPUSpecializedShader>>(protoPipeline);
31
- {
32
- auto gpu_array = cpu2gpu.getGPUObjectsFromAssets(&pShader, &pShader + 1, cpu2gpuParams);
33
- if (!gpu_array || gpu_array->size() < 1u || !(*gpu_array)[0])
34
- assert(false);
35
-
36
- gpuSpecializedShader = (*gpu_array)[0];
37
- }
38
-
39
- auto& inputParams = std::get<asset::SVertexInputParams>(protoPipeline);
40
- {
41
- inputParams.enabledBindingFlags = inputParams.enabledAttribFlags = 0u;
42
- for (size_t i=0ull; i<asset::SVertexInputParams::MAX_VERTEX_ATTRIB_COUNT; i++)
43
- inputParams.attributes[i] = {0u,asset::EF_UNKNOWN,0u};
44
- for (size_t i=0ull; i<asset::SVertexInputParams::MAX_ATTR_BUF_BINDING_COUNT; i++)
45
- inputParams.bindings[i] = {0u,asset::EVIR_PER_VERTEX};
46
- }
47
-
48
- auto& assemblyParams = std::get<asset::SPrimitiveAssemblyParams>(protoPipeline);
49
- assemblyParams.primitiveRestartEnable = false;
50
- assemblyParams.primitiveType = asset::EPT_TRIANGLE_LIST;
51
- assemblyParams.tessPatchVertCount = 3u;
52
-
53
- auto& blendParams = std::get<asset::SBlendParams>(protoPipeline);
54
- blendParams.logicOpEnable = false;
55
- blendParams.logicOp = nbl::asset::ELO_NO_OP;
56
-
57
- auto& rasterParams = std::get<asset::SRasterizationParams>(protoPipeline);
58
- rasterParams.faceCullingMode = nbl::asset::EFCM_NONE;
59
- rasterParams.depthCompareOp = nbl::asset::ECO_ALWAYS;
60
- rasterParams.minSampleShading = 1.f;
61
- rasterParams.depthWriteEnable = false;
62
- rasterParams.depthTestEnable = false;
63
-
64
- // Push constant for surface transform and screen size, used in VS
65
- auto& swapchainOrientationConstants = std::get<asset::SPushConstantRange>(protoPipeline);
66
- swapchainOrientationConstants.stageFlags = asset::IShader::ESS_VERTEX;
67
- swapchainOrientationConstants.offset = pushConstantOffset;
68
- swapchainOrientationConstants.size = 1 * sizeof(uint32_t);
69
-
70
- return protoPipeline;
71
- }
72
-
73
- inline core::smart_refctd_ptr<video::IGPURenderpassIndependentPipeline> createRenderpassIndependentPipeline(video::ILogicalDevice* logicalDevice, NBL_PROTO_PIPELINE& protoPipeline, core::smart_refctd_ptr<video::IGPUSpecializedShader>&& gpuFragmentShader, core::smart_refctd_ptr<video::IGPUPipelineLayout>&& pipelineLayout)
11
+ struct ProtoPipeline final
12
+ {
13
+ inline core::smart_refctd_ptr<video::IGPUShader> createDefaultVertexShader (asset::IAssetManager* assMan, video::ILogicalDevice* device, system::ILogger* logger=nullptr )
14
+ {
15
+ if (!assMan || !device)
16
+ return nullptr ;
17
+
18
+ using namespace ::nbl::asset;
19
+ IAssetLoader::SAssetLoadParams lp = {};
20
+ lp.logger = logger;
21
+ lp.workingDirectory = " " ; // virtual root
22
+ auto assetBundle = assMan->getAsset (" nbl/builtin/hlsl/ext/FullScreenTriangle/default.vert.hlsl" ,lp);
23
+ const auto assets = assetBundle.getContents ();
24
+ if (assets.empty ())
25
+ return nullptr ;
26
+
27
+ auto source = IAsset::castDown<ICPUShader>(assets[0 ]);
28
+ if (!source)
29
+ return nullptr ;
30
+
31
+ return device->createShader (source.get ());
32
+ }
33
+
34
+ public:
35
+ inline ProtoPipeline (asset::IAssetManager* assMan, video::ILogicalDevice* device, system::ILogger* logger=nullptr )
36
+ {
37
+ m_vxShader = createDefaultVertexShader (assMan,device,logger);
38
+ }
39
+
40
+ inline operator bool () const {return m_vxShader.get ();}
41
+
42
+ inline core::smart_refctd_ptr<video::IGPUGraphicsPipeline> createPipeline (
43
+ const video::IGPUShader::SSpecInfo& fragShader,
44
+ video::IGPUPipelineLayout* layout,
45
+ video::IGPURenderpass* renderpass,
46
+ const uint32_t subpassIx=0 ,
47
+ const hlsl::SurfaceTransform::FLAG_BITS swapchainTransform=hlsl::SurfaceTransform::FLAG_BITS::IDENTITY_BIT
48
+ )
49
+ {
50
+ if (!renderpass || !bool (*this ) || hlsl::bitCount (swapchainTransform)!=1 )
51
+ return nullptr ;
52
+
53
+ using namespace ::nbl::video;
54
+ auto device = const_cast <ILogicalDevice*>(renderpass->getOriginDevice ());
55
+
56
+ core::smart_refctd_ptr<IGPUGraphicsPipeline> m_retval;
74
57
{
75
- if (!logicalDevice)
76
- assert(false);
77
-
78
- video::IGPUSpecializedShader* gpuShaders[] = { std::get<core::smart_refctd_ptr<video::IGPUSpecializedShader>>(protoPipeline).get(), gpuFragmentShader.get() };
79
- auto gpuRenderpassIndependentPipeline = logicalDevice->createRenderpassIndependentPipeline
80
- (
81
- nullptr,
82
- std::move(pipelineLayout),
83
- gpuShaders,
84
- gpuShaders + 2,
85
- std::get<asset::SVertexInputParams>(protoPipeline),
86
- std::get<asset::SBlendParams>(protoPipeline),
87
- std::get<asset::SPrimitiveAssemblyParams>(protoPipeline),
88
- std::get<asset::SRasterizationParams>(protoPipeline)
89
- );
90
-
91
- return gpuRenderpassIndependentPipeline;
58
+ const auto orientationAsUint32 = static_cast <uint32_t >(swapchainTransform);
59
+
60
+ IGPUShader::SSpecInfo::spec_constant_map_t specConstants;
61
+ specConstants[0 ] = {.data =&orientationAsUint32,.size =sizeof (orientationAsUint32)};
62
+
63
+ const IGPUShader::SSpecInfo shaders[2 ] = {
64
+ {.shader =m_vxShader.get (),.entries =&specConstants},
65
+ fragShader
66
+ };
67
+
68
+ IGPUGraphicsPipeline::SCreationParams params[1 ];
69
+ params[0 ].layout = layout;
70
+ params[0 ].shaders = shaders;
71
+ params[0 ].cached = {
72
+ .vertexInput = inputParams,
73
+ .primitiveAssembly = assemblyParams,
74
+ .rasterization = rasterParams,
75
+ .blend = blendParams,
76
+ .subpassIx = subpassIx
77
+ };
78
+ params[0 ].renderpass = renderpass;
79
+
80
+ if (!device->createGraphicsPipelines (nullptr ,params,&m_retval))
81
+ return nullptr ;
92
82
}
93
-
94
- /*
95
- Helper function for drawing full screen triangle.
96
- It should be called between command buffer render pass
97
- records.
98
- */
99
-
100
- inline bool recordDrawCalls(
101
- core::smart_refctd_ptr<nbl::video::IGPUGraphicsPipeline> gpuGraphicsPipeline,
102
- uint32_t pushConstantOffset,
103
- video::ISurface::E_SURFACE_TRANSFORM_FLAGS swapchainTransform,
104
- video::IGPUCommandBuffer* commandBuffer
105
- ) {
106
- _NBL_STATIC_INLINE_CONSTEXPR auto VERTEX_COUNT = 3;
107
- _NBL_STATIC_INLINE_CONSTEXPR auto INSTANCE_COUNT = 1;
108
-
109
- auto layout = gpuGraphicsPipeline->getRenderpassIndependentPipeline()->getLayout();
110
- uint32_t surfaceTransform = uint32_t(swapchainTransform);
111
- commandBuffer->pushConstants(layout, asset::IShader::ESS_VERTEX, pushConstantOffset, 1 * sizeof(uint32_t), &surfaceTransform);
112
-
113
- return commandBuffer->draw(VERTEX_COUNT, INSTANCE_COUNT, 0, 0);
114
- }
115
- #endif
83
+ return m_retval;
84
+ }
85
+
86
+
87
+ core::smart_refctd_ptr<video::IGPUShader> m_vxShader;
88
+ // The Full Screen Triangle doesn't use any HW vertex input state
89
+ constexpr static inline asset::SVertexInputParams inputParams = {};
90
+ // The default is correct for us
91
+ constexpr static inline asset::SPrimitiveAssemblyParams assemblyParams = {};
92
+ // Default is no blending, also ok.
93
+ constexpr static inline asset::SBlendParams blendParams = {};
94
+ constexpr static inline asset::SRasterizationParams rasterParams = {
95
+ .faceCullingMode = asset::EFCM_NONE,
96
+ .depthWriteEnable = false ,
97
+ .depthCompareOp = asset::ECO_ALWAYS
98
+ };
99
+ };
100
+
101
+
102
+ /*
103
+ Helper function for drawing full screen triangle.
104
+ It should be called between command buffer render pass
105
+ records.
106
+ */
107
+ static inline bool recordDrawCall (video::IGPUCommandBuffer* commandBuffer)
108
+ {
109
+ constexpr auto VERTEX_COUNT = 3 ;
110
+ constexpr auto INSTANCE_COUNT = 1 ;
111
+ return commandBuffer->draw (VERTEX_COUNT,INSTANCE_COUNT,0 ,0 );
112
+ }
116
113
}
117
114
#endif
0 commit comments