| 94 | } |
| 95 | |
| 96 | void init() { |
| 97 | queue = device.GetQueue(); |
| 98 | |
| 99 | wgpu::ShaderModule shaderModule{}; |
| 100 | { |
| 101 | wgpu::ShaderSourceWGSL wgslDesc{}; |
| 102 | wgslDesc.code = shaderCode; |
| 103 | |
| 104 | wgpu::ShaderModuleDescriptor descriptor{}; |
| 105 | descriptor.nextInChain = &wgslDesc; |
| 106 | shaderModule = device.CreateShaderModule(&descriptor); |
| 107 | shaderModule.GetCompilationInfo(wgpu::CallbackMode::AllowSpontaneous, |
| 108 | [=](wgpu::CompilationInfoRequestStatus status, const wgpu::CompilationInfo* info) { |
| 109 | assert(status == wgpu::CompilationInfoRequestStatus::Success); |
| 110 | assert(info->messageCount == 0); |
| 111 | printf("Shader compile succeeded\n"); |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | { |
| 116 | wgpu::BindGroupLayoutDescriptor bglDesc{}; |
| 117 | auto bgl = device.CreateBindGroupLayout(&bglDesc); |
| 118 | wgpu::BindGroupDescriptor desc{}; |
| 119 | desc.layout = bgl; |
| 120 | desc.entryCount = 0; |
| 121 | desc.entries = nullptr; |
| 122 | device.CreateBindGroup(&desc); |
| 123 | } |
| 124 | |
| 125 | { |
| 126 | wgpu::PipelineLayoutDescriptor pl{}; |
| 127 | pl.bindGroupLayoutCount = 0; |
| 128 | pl.bindGroupLayouts = nullptr; |
| 129 | |
| 130 | wgpu::ColorTargetState colorTargetState{}; |
| 131 | colorTargetState.format = wgpu::TextureFormat::BGRA8Unorm; |
| 132 | |
| 133 | wgpu::FragmentState fragmentState{}; |
| 134 | fragmentState.module = shaderModule; |
| 135 | fragmentState.targetCount = 1; |
| 136 | fragmentState.targets = &colorTargetState; |
| 137 | |
| 138 | wgpu::DepthStencilState depthStencilState{}; |
| 139 | depthStencilState.format = wgpu::TextureFormat::Depth32Float; |
| 140 | depthStencilState.depthCompare = wgpu::CompareFunction::Always; |
| 141 | |
| 142 | wgpu::RenderPipelineDescriptor descriptor{}; |
| 143 | descriptor.layout = device.CreatePipelineLayout(&pl); |
| 144 | descriptor.vertex.module = shaderModule; |
| 145 | descriptor.fragment = &fragmentState; |
| 146 | descriptor.primitive.topology = wgpu::PrimitiveTopology::TriangleList; |
| 147 | descriptor.depthStencil = &depthStencilState; |
| 148 | pipeline = device.CreateRenderPipeline(&descriptor); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // The depth stencil attachment isn't really needed to draw the triangle |
| 153 | // and doesn't really affect the render result. |