MCPcopy Create free account
hub / github.com/defold/defold / NewComputeProgram

Function NewComputeProgram

engine/render/src/render/compute.cpp:23–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21namespace dmRender
22{
23 HComputeProgram NewComputeProgram(HRenderContext render_context, dmGraphics::HProgram compute_program)
24 {
25 if (!dmGraphics::IsContextFeatureSupported(render_context->m_GraphicsContext, dmGraphics::CONTEXT_FEATURE_COMPUTE_SHADER))
26 {
27 dmLogError("Compute programs are not supported on this context.");
28 return 0;
29 }
30
31 ComputeProgram* program = new ComputeProgram();
32 program->m_RenderContext = render_context;
33 program->m_Program = compute_program;
34 uint32_t total_constants_count = dmGraphics::GetUniformCount(program->m_Program);
35
36 uint32_t constants_count = 0;
37 uint32_t samplers_count = 0;
38 GetProgramUniformCount(program->m_Program, total_constants_count, &constants_count, &samplers_count);
39 uint32_t total_uniforms_count = constants_count + samplers_count;
40
41 if (total_uniforms_count > 0)
42 {
43 program->m_NameHashToLocation.SetCapacity(total_uniforms_count, total_uniforms_count * 2);
44 program->m_Constants.SetCapacity(total_uniforms_count);
45 }
46
47 if (samplers_count > 0)
48 {
49 program->m_Samplers.SetCapacity(samplers_count);
50 for (uint32_t i = 0; i < samplers_count; ++i)
51 {
52 program->m_Samplers.Push(Sampler());
53 }
54 }
55
56 SetProgramConstantValues(render_context->m_GraphicsContext, program->m_Program, total_constants_count, program->m_NameHashToLocation, program->m_Constants, program->m_Samplers);
57
58 bool has_light_buffer;
59 uint16_t light_buffer_set;
60 uint16_t light_buffer_binding;
61 GetProgramLightBufferBinding(render_context, program->m_Program, &has_light_buffer, &light_buffer_set, &light_buffer_binding);
62 program->m_HasLightBuffer = has_light_buffer;
63 program->m_LightBufferSet = light_buffer_set;
64 program->m_LightBufferBinding = light_buffer_binding;
65
66 return (HComputeProgram) program;
67 }
68
69 void ApplyComputeProgramConstants(dmRender::HRenderContext render_context, HComputeProgram compute_program)
70 {

Callers 3

SetUpMethod · 0.85
TEST_FFunction · 0.85
ResComputeCreateFunction · 0.85

Calls 8

GetUniformCountFunction · 0.85
GetProgramUniformCountFunction · 0.85
SetProgramConstantValuesFunction · 0.85
SamplerClass · 0.70
SetCapacityMethod · 0.45
PushMethod · 0.45

Tested by 2

SetUpMethod · 0.68
TEST_FFunction · 0.68