| 21 | namespace 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 | { |