diff options
Diffstat (limited to 'src/3d')
| -rw-r--r-- | src/3d/renderer_pipelines.cc | 85 | ||||
| -rw-r--r-- | src/3d/visual_debug.cc | 3 |
2 files changed, 76 insertions, 12 deletions
diff --git a/src/3d/renderer_pipelines.cc b/src/3d/renderer_pipelines.cc index 1fdf30d..54499af 100644 --- a/src/3d/renderer_pipelines.cc +++ b/src/3d/renderer_pipelines.cc @@ -44,29 +44,43 @@ WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) { bgl_entries.push_back( {.binding = 0, // B0: uniforms .visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment, - .buffer = {.type = WGPUBufferBindingType_Uniform}}); + .buffer = {.type = WGPUBufferBindingType_Uniform, + .minBindingSize = sizeof(GlobalUniforms)}, + .sampler = {}, + .texture = {}}); bgl_entries.push_back( {.binding = 1, // B1: object storage .visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment, - .buffer = {.type = WGPUBufferBindingType_ReadOnlyStorage}}); + .buffer = {.type = WGPUBufferBindingType_ReadOnlyStorage, + .minBindingSize = sizeof(ObjectData) * kMaxObjects}, + .sampler = {}, + .texture = {}}); if (use_bvh) { bgl_entries.push_back( {.binding = 2, // B2: bvh storage .visibility = WGPUShaderStage_Fragment, - .buffer = {.type = WGPUBufferBindingType_ReadOnlyStorage}}); + .buffer = {.type = WGPUBufferBindingType_ReadOnlyStorage, + .minBindingSize = sizeof(BVHNode) * kMaxObjects * 2}, + .sampler = {}, + .texture = {}}); } bgl_entries.push_back( {.binding = 3, // B3: noise texture .visibility = WGPUShaderStage_Fragment, + .buffer = {}, + .sampler = {}, .texture = {.sampleType = WGPUTextureSampleType_Float, .viewDimension = WGPUTextureViewDimension_2D}}); - bgl_entries.push_back( - {.binding = 4, // B4: default sampler - .visibility = WGPUShaderStage_Fragment, - .sampler = {.type = WGPUSamplerBindingType_Filtering}}); + bgl_entries.push_back({.binding = 4, // B4: default sampler + .visibility = WGPUShaderStage_Fragment, + .buffer = {}, + .sampler = {.type = WGPUSamplerBindingType_Filtering}, + .texture = {}}); bgl_entries.push_back( {.binding = 5, // B5: sky texture .visibility = WGPUShaderStage_Fragment, + .buffer = {}, + .sampler = {}, .texture = {.sampleType = WGPUTextureSampleType_Float, .viewDimension = WGPUTextureViewDimension_2D}}); @@ -140,13 +154,61 @@ void Renderer3D::create_mesh_pipeline() { WGPUShaderModule shader_module = wgpuDeviceCreateShaderModule(device_, &shader_desc); - WGPUBindGroupLayout bgl = wgpuRenderPipelineGetBindGroupLayout(pipeline_, 0); + // BIND GROUP LAYOUT (matches create_pipeline_impl) + std::vector<WGPUBindGroupLayoutEntry> bgl_entries; + bgl_entries.push_back( + {.binding = 0, // B0: uniforms + .visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment, + .buffer = {.type = WGPUBufferBindingType_Uniform, + .minBindingSize = sizeof(GlobalUniforms)}, + .sampler = {}, + .texture = {}}); + bgl_entries.push_back( + {.binding = 1, // B1: object storage + .visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment, + .buffer = {.type = WGPUBufferBindingType_ReadOnlyStorage, + .minBindingSize = sizeof(ObjectData) * kMaxObjects}, + .sampler = {}, + .texture = {}}); + if (bvh_enabled_) { + bgl_entries.push_back( + {.binding = 2, // B2: bvh storage + .visibility = WGPUShaderStage_Fragment, + .buffer = {.type = WGPUBufferBindingType_ReadOnlyStorage, + .minBindingSize = sizeof(BVHNode) * kMaxObjects * 2}}); + } + bgl_entries.push_back( + {.binding = 3, // B3: noise texture + .visibility = WGPUShaderStage_Fragment, + .buffer = {}, + .sampler = {}, + .texture = {.sampleType = WGPUTextureSampleType_Float, + .viewDimension = WGPUTextureViewDimension_2D}}); + bgl_entries.push_back({.binding = 4, // B4: default sampler + .visibility = WGPUShaderStage_Fragment, + .buffer = {}, + .sampler = {.type = WGPUSamplerBindingType_Filtering}, + .texture = {}}); + bgl_entries.push_back( + {.binding = 5, // B5: sky texture + .visibility = WGPUShaderStage_Fragment, + .buffer = {}, + .sampler = {}, + .texture = {.sampleType = WGPUTextureSampleType_Float, + .viewDimension = WGPUTextureViewDimension_2D}}); + + WGPUBindGroupLayoutDescriptor bgl_desc = {}; + bgl_desc.entryCount = bgl_entries.size(); + bgl_desc.entries = bgl_entries.data(); + WGPUBindGroupLayout bind_group_layout = + wgpuDeviceCreateBindGroupLayout(device_, &bgl_desc); + WGPUPipelineLayoutDescriptor pl_desc = {}; pl_desc.bindGroupLayoutCount = 1; - pl_desc.bindGroupLayouts = &bgl; + pl_desc.bindGroupLayouts = &bind_group_layout; WGPUPipelineLayout pipeline_layout = wgpuDeviceCreatePipelineLayout(device_, &pl_desc); - wgpuBindGroupLayoutRelease(bgl); + wgpuBindGroupLayoutRelease(bind_group_layout); WGPUDepthStencilState depth_stencil = {}; depth_stencil.format = WGPUTextureFormat_Depth24Plus; @@ -223,7 +285,8 @@ void Renderer3D::create_skybox_pipeline() { .sampler = {.type = WGPUSamplerBindingType_Filtering}}; bgl_entries[2] = {.binding = 2, .visibility = WGPUShaderStage_Fragment, - .buffer = {.type = WGPUBufferBindingType_Uniform}}; + .buffer = {.type = WGPUBufferBindingType_Uniform, + .minBindingSize = sizeof(GlobalUniforms)}}; WGPUBindGroupLayoutDescriptor bgl_desc = {}; bgl_desc.entryCount = 3; diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc index 35ab60d..77311f6 100644 --- a/src/3d/visual_debug.cc +++ b/src/3d/visual_debug.cc @@ -5,6 +5,7 @@ #if !defined(STRIP_ALL) +#include "3d/renderer.h" #include "generated/assets.h" #include "util/asset_manager_utils.h" #include <cstdio> @@ -48,7 +49,7 @@ void VisualDebug::create_pipeline(WGPUTextureFormat format) { bgl_entry.binding = 0; bgl_entry.visibility = WGPUShaderStage_Vertex; bgl_entry.buffer.type = WGPUBufferBindingType_Uniform; - bgl_entry.buffer.minBindingSize = sizeof(mat4); + bgl_entry.buffer.minBindingSize = sizeof(GlobalUniforms); WGPUBindGroupLayoutDescriptor bgl_desc = {}; bgl_desc.entryCount = 1; |
