| 2816 | } |
| 2817 | |
| 2818 | static void WebGPUUpdateProgramLayouts(WebGPUContext* context, WebGPUProgram* program) |
| 2819 | { |
| 2820 | TRACE_CALL; |
| 2821 | |
| 2822 | // update layouts |
| 2823 | ProgramResourceBindingsInfo binding_info = {}; |
| 2824 | WGPUBindGroupLayoutEntry bindings[MAX_SET_COUNT][MAX_BINDINGS_PER_SET_COUNT] = {}; |
| 2825 | |
| 2826 | WebGPUUpdateBindGroupLayouts(context, program, bindings, binding_info); |
| 2827 | |
| 2828 | // fill in program |
| 2829 | program->m_UniformData = new uint8_t[binding_info.m_UniformDataSize]; |
| 2830 | memset(program->m_UniformData, 0, binding_info.m_UniformDataSize); |
| 2831 | program->m_UniformDataSizeAligned = binding_info.m_UniformDataSizeAligned; |
| 2832 | program->m_UniformBufferCount = binding_info.m_UniformBufferCount; |
| 2833 | program->m_StorageBufferCount = binding_info.m_StorageBufferCount; |
| 2834 | program->m_TextureSamplerCount = binding_info.m_TextureCount; |
| 2835 | program->m_TotalResourcesCount = binding_info.m_UniformBufferCount + binding_info.m_TextureCount + binding_info.m_StorageBufferCount; // num actual descriptors |
| 2836 | program->m_BaseProgram.m_MaxSet = binding_info.m_MaxSet; |
| 2837 | program->m_BaseProgram.m_MaxBinding = binding_info.m_MaxBinding; |
| 2838 | |
| 2839 | // create bind group layout |
| 2840 | for (int set = 0; set < program->m_BaseProgram.m_MaxSet; ++set) |
| 2841 | { |
| 2842 | #if defined(DM_GRAPHICS_WEBGPU2) |
| 2843 | WGPUBindGroupLayoutDescriptor desc = WGPU_BIND_GROUP_LAYOUT_DESCRIPTOR_INIT; |
| 2844 | #else |
| 2845 | WGPUBindGroupLayoutDescriptor desc = {}; |
| 2846 | #endif |
| 2847 | WGPUBindGroupLayoutEntry entries[MAX_BINDINGS_PER_SET_COUNT]; |
| 2848 | desc.entries = entries; |
| 2849 | for (int binding = 0; binding < MAX_BINDINGS_PER_SET_COUNT; ++binding) |
| 2850 | { |
| 2851 | if (bindings[set][binding].visibility != WGPUShaderStage_None) |
| 2852 | entries[desc.entryCount++] = bindings[set][binding]; |
| 2853 | } |
| 2854 | program->m_BindGroupLayouts[set] = wgpuDeviceCreateBindGroupLayout(context->m_Device, &desc); |
| 2855 | } |
| 2856 | |
| 2857 | // create pipeline layout |
| 2858 | { |
| 2859 | #if defined(DM_GRAPHICS_WEBGPU2) |
| 2860 | WGPUPipelineLayoutDescriptor desc = WGPU_PIPELINE_LAYOUT_DESCRIPTOR_INIT; |
| 2861 | #else |
| 2862 | WGPUPipelineLayoutDescriptor desc = {}; |
| 2863 | #endif |
| 2864 | desc.bindGroupLayouts = program->m_BindGroupLayouts; |
| 2865 | desc.bindGroupLayoutCount = binding_info.m_MaxSet; |
| 2866 | program->m_PipelineLayout = wgpuDeviceCreatePipelineLayout(context->m_Device, &desc); |
| 2867 | } |
| 2868 | |
| 2869 | BuildUniforms(&program->m_BaseProgram); |
| 2870 | } |
| 2871 | |
| 2872 | static void WebGPUCreateComputeProgram(WebGPUContext* context, WebGPUProgram* program, WebGPUShaderModule* compute_module) |
| 2873 | { |
no test coverage detected