MCPcopy Create free account
hub / github.com/MethanePowered/MethaneKit / Init

Method Init

Apps/08-ConsoleCompute/ConsoleComputeApp.cpp:144–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144void ConsoleComputeApp::Init()
145{
146 META_FUNCTION_TASK();
147 const rhi::Device* device_ptr = GetComputeDevice();
148 m_compute_context = device_ptr->CreateComputeContext(m_parallel_executor, {});
149 m_compute_context.SetName("Game of Life");
150
151 m_compute_state = m_compute_context.CreateComputeState({
152 .program = m_compute_context.CreateProgram({
153 .shader_set = rhi::Program::ShaderSet {
154 { rhi::ShaderType::Compute, { data::ShaderProvider::Get(), { "GameOfLife", "MainCS" } } }
155 },
156 .argument_accessors = rhi::ProgramArgumentAccessors
157 {
158 META_PROGRAM_ARG_ROOT_VALUE_CONSTANT(rhi::ShaderType::Compute, "g_constants")
159 },
160 }),
161 .thread_group_size = rhi::ThreadGroupSize(16U, 16U, 1U)
162 });
163 m_compute_state.GetProgram().SetName("Game of Life Program");
164 m_compute_state.SetName("Game of Life Compute State");
165
166 m_compute_cmd_list = m_compute_context.GetComputeCommandKit().GetQueue().CreateComputeCommandList();
167 m_compute_cmd_list.SetName("Game of Life Compute");
168 m_compute_cmd_list_set = rhi::CommandListSet({ m_compute_cmd_list.GetInterface() });
169
170 rhi::TextureSettings frame_texture_settings = rhi::TextureSettings::ForImage(
171 gfx::Dimensions(GetFieldSize()),
172 std::nullopt, gfx::PixelFormat::R8Uint, false,
173 rhi::ResourceUsageMask{
174 rhi::ResourceUsage::ShaderRead,
175 rhi::ResourceUsage::ShaderWrite,
176 rhi::ResourceUsage::ReadBack
177 }
178 );
179 m_frame_texture = m_compute_context.CreateTexture(frame_texture_settings);
180 m_frame_texture.SetName("Game of Life Frame Texture");
181
182 const Constants game_constants{ static_cast<uint>(GetGameRuleIndex()) };
183 m_compute_bindings = m_compute_state.GetProgram().CreateBindings({
184 { { rhi::ShaderType::Compute, "g_constants" }, rhi::RootConstant(game_constants) },
185 { { rhi::ShaderType::Compute, "g_frame_texture" }, m_frame_texture.GetResourceView() }
186 });
187 m_compute_bindings.SetName("Game of Life Compute Bindings");
188
189 RandomizeFrameData();
190
191 // Complete bindings and texture initialization
192 m_compute_context.CompleteInitialization();
193}
194
195void ConsoleComputeApp::Release()
196{

Callers

nothing calls this directly

Calls 14

RootConstantClass · 0.85
GetQueueMethod · 0.80
CommandListSetClass · 0.50
CreateComputeContextMethod · 0.45
SetNameMethod · 0.45
CreateComputeStateMethod · 0.45
CreateProgramMethod · 0.45
GetProgramMethod · 0.45
GetComputeCommandKitMethod · 0.45
CreateTextureMethod · 0.45
CreateBindingsMethod · 0.45

Tested by

no test coverage detected