载入中...
搜索中...
未找到
GraphicsPbr.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <array>
5#include <map>
6#include <tuple>
7
8#include "common/Exception.h"
13
14namespace eve::graphics::webgpu {
15namespace {
16using SamplerKey = std::array<std::uint32_t, 4>;
17
18wgpu::AddressMode addressMode(std::uint32_t value) {
19 return value == 33071 ? wgpu::AddressMode::ClampToEdge
20 : value == 33648 ? wgpu::AddressMode::MirrorRepeat
21 : wgpu::AddressMode::Repeat;
22}
23
24wgpu::Sampler makePbrSampler(const wgpu::Device& device, const PbrTextureBinding& binding) {
25 const auto nearestMin = binding.minFilter == 9728 || binding.minFilter == 9984 || binding.minFilter == 9986;
26 return SamplerBuilder()
27 .address(addressMode(binding.wrapS), addressMode(binding.wrapT), wgpu::AddressMode::Repeat)
28 .filter(binding.magFilter == 9728 ? wgpu::FilterMode::Nearest : wgpu::FilterMode::Linear,
29 nearestMin ? wgpu::FilterMode::Nearest : wgpu::FilterMode::Linear)
30 .mipmap(binding.minFilter >= 9986 ? wgpu::MipmapFilterMode::Linear : wgpu::MipmapFilterMode::Nearest,
31 0.f, binding.minFilter >= 9984 ? 1000.f : 0.f)
32 .build(device);
33}
34
35std::size_t rasterKey(BlendMode blend, bool depthWrite, PbrCullMode cull, bool alphaToCoverage) {
36 return std::size_t(blend) * 16u + (depthWrite ? 8u : 0u) + (alphaToCoverage ? 4u : 0u) +
37 std::size_t(cull);
38}
39} // namespace
40
42 struct Pipeline {
44 WGPUTextureFormat format = WGPUTextureFormat_Undefined;
45 std::uint32_t samples = 1;
46 std::size_t raster = 0;
47 wgpu::RenderPipeline pipeline;
48 wgpu::BindGroupLayout layout;
49 };
50 std::vector<Pipeline> pipelines;
51 std::map<SamplerKey, wgpu::Sampler> samplers;
52};
53
54void Graphics::deletePbrResources(PbrResources* resources) { delete resources; }
55
57 if (!surface) {
58 mesh3dPbrSurface.reset();
59 return Result<void>::success();
60 }
61 auto valid = validatePbrSurface(*surface);
62 if (!valid) return valid;
63 const auto requireGpu = [&](Texture* texture, const char* role) -> Result<void> {
64 if (!texture) return Result<void>::success();
65 const auto ownedTexture =
66 std::find_if(ownedTextures.begin(), ownedTextures.end(),
67 [texture](const std::unique_ptr<Texture>& candidate) { return candidate.get() == texture; });
68 if (ownedTexture == ownedTextures.end())
70 Diagnostic::error(DiagnosticCode::InvalidArgument, std::string(role) + " is not an owned GPU texture"));
71 auto* gpu = gpuForTexture(texture);
72 const auto ownedGpu =
73 std::find_if(ownedGpuTextures.begin(), ownedGpuTextures.end(),
74 [gpu](const std::unique_ptr<GpuTexture>& candidate) { return candidate.get() == gpu; });
75 if (!gpu || ownedGpu == ownedGpuTextures.end())
77 Diagnostic::error(DiagnosticCode::InvalidArgument, std::string(role) + " is not an owned GPU texture"));
78 return Result<void>::success();
79 };
80 const auto requireKind = [&](Texture* texture, const char* role, bool array, bool volume,
81 std::uint32_t minimumLayers = 1u) -> Result<void> {
82 if (!texture) return Result<void>::success();
83 auto* gpu = gpuForTexture(texture);
84 if (!gpu || gpu->isCube || gpu->isVolume != volume || (!volume && gpu->isArray != array) ||
85 (array && std::uint32_t(texture->layers) < minimumLayers))
87 DiagnosticCode::InvalidArgument, std::string(role) + " has an incompatible texture dimension"));
88 return Result<void>::success();
89 };
90 for (const auto& binding : surface->textures) {
91 auto ready = requireGpu(binding.texture, "PBR texture");
92 if (!ready) return ready;
93 ready = requireKind(binding.texture, "PBR texture", false, false);
94 if (!ready) return ready;
95 }
96 for (const auto& binding : surface->vegetationDetail.textures) {
97 auto ready = requireGpu(binding.texture, "PBR detail texture");
98 if (!ready) return ready;
99 ready = requireKind(binding.texture, "PBR detail texture", false, false);
100 if (!ready) return ready;
101 }
102 for (auto [texture, role] : std::array<std::pair<Texture*, const char*>, 6>{
103 {{surface->vegetationExtras.texture, "PBR Extras texture"},
104 {surface->vegetationColors.texture, "PBR Colors texture"},
105 {surface->vegetationVertex.texture, "PBR Vertex texture"},
106 {surface->vegetationMotion.texture, "PBR Motion texture"},
107 {surface->vegetationMotion.noise, "PBR motion noise"},
108 {surface->vegetationAlpha.noise, "PBR fade noise"}}}) {
109 auto ready = requireGpu(texture, role);
110 if (!ready) return ready;
111 }
112 for (auto [texture, role, layer] :
113 std::array<std::tuple<Texture*, const char*, std::uint32_t>, 4>{
114 {{surface->vegetationExtras.texture, "PBR Extras texture", surface->vegetationExtras.layer},
115 {surface->vegetationColors.texture, "PBR Colors texture", surface->vegetationColors.layer},
116 {surface->vegetationVertex.texture, "PBR Vertex texture", surface->vegetationVertex.layer},
117 {surface->vegetationMotion.texture, "PBR Motion texture", surface->vegetationMotion.layer}}}) {
118 auto ready = requireKind(texture, role, true, false, layer + 1u);
119 if (!ready) return ready;
120 }
121 auto ready = requireKind(surface->vegetationMotion.noise, "PBR motion noise", false, false);
122 if (!ready) return ready;
123 ready = requireKind(surface->vegetationAlpha.noise, "PBR fade noise", false, true);
124 if (!ready) return ready;
127 auto planned = planPbrVariant(*surface, false, false, limits);
128 if (!planned) return Result<void>::failure(planned.status());
129 mesh3dPbrSurface = *surface;
130 return Result<void>::success();
131}
132
133bool Graphics::drawPbrMesh(wgpu::RenderPassEncoder pass, WGPUTextureFormat format, bool canvasTarget,
134 Mesh3dDraw& draw, GpuMesh& mesh) {
135 const auto& surface = *draw.pbrSurface;
136 const bool gbuffer = draw.gbufferClip.has_value();
137 const bool environment =
138 !gbuffer && draw.environment && gpuForTexture(draw.environment) && gpuForTexture(draw.environment)->isCube;
139 const bool shadows = !gbuffer && draw.shadows.active && draw.shadowReceive && shadowDepthArray;
142 auto evaluationSurface = surface;
143 if (gbuffer) {
144 // Specular color, anisotropy and clearcoat remain on the forward path;
145 // the five MRTs represent the core surface plus scalar specular weight.
146 for (size_t slot = size_t(PbrTextureSlot::SpecularColor); slot < evaluationSurface.textures.size(); ++slot)
147 evaluationSurface.textures[slot].texture = nullptr;
148 }
149 auto planned = planPbrVariant(evaluationSurface, environment, shadows, limits);
150 if (!planned) throw Exception("%s", planned.error()->message().c_str());
151 const auto& plan = planned.value();
152
153 if (!pbrResources_) pbrResources_.reset(new PbrResources());
154 auto& resources = *pbrResources_;
155 const bool transparent = draw.surfaceMode == SurfaceMode::Transparent;
156 const BlendMode blend = transparent ? draw.surfaceBlend : BlendMode::Opaque;
157 const bool depthWrite = !transparent || draw.depthWrite;
158 const auto cull = surface.cullMode == PbrCullMode::Inherit
159 ? (draw.doubleSided ? PbrCullMode::None : PbrCullMode::Back)
160 : surface.cullMode;
161 const bool alphaToCoverage = !gbuffer && surface.alphaToCoverage && draw.surfaceMode == SurfaceMode::Masked;
162 const std::uint32_t samples = canvasTarget ? 1u : sceneColorSamples;
163 const auto raster = rasterKey(blend, depthWrite, cull, alphaToCoverage) | (gbuffer ? 256u : 0u);
164 auto found = std::find_if(resources.pipelines.begin(), resources.pipelines.end(), [&](const auto& candidate) {
165 return candidate.plan == plan && candidate.format == format && candidate.samples == samples &&
166 candidate.raster == raster;
167 });
168 if (found == resources.pipelines.end()) {
169 auto source = specializePbrVariantSources(plan, gbuffer);
170 wgpu::ShaderSourceWGSL vertexWgsl{};
171 vertexWgsl.code = source.vertex.c_str();
172 wgpu::ShaderModuleDescriptor vertexDescriptor{};
173 vertexDescriptor.nextInChain = &vertexWgsl;
174 auto vertex = device.CreateShaderModule(&vertexDescriptor);
175 wgpu::ShaderSourceWGSL fragmentWgsl{};
176 fragmentWgsl.code = source.fragment.c_str();
177 wgpu::ShaderModuleDescriptor fragmentDescriptor{};
178 fragmentDescriptor.nextInChain = &fragmentWgsl;
179 auto fragment = device.CreateShaderModule(&fragmentDescriptor);
180
181 std::array<wgpu::VertexAttribute, 16> attributes{};
182 auto attribute = [&](std::size_t index, wgpu::VertexFormat vertexFormat, std::uint64_t offset,
183 std::uint32_t location) {
184 attributes[index].format = vertexFormat;
185 attributes[index].offset = offset;
186 attributes[index].shaderLocation = location;
187 };
188 attribute(0, wgpu::VertexFormat::Float32x3, 0, 0);
189 attribute(1, wgpu::VertexFormat::Float32x3, 12, 1);
190 attribute(2, wgpu::VertexFormat::Float32x2, 24, 2);
191 attribute(3, wgpu::VertexFormat::Uint16x4, 32, 3);
192 attribute(4, wgpu::VertexFormat::Float32x4, 40, 4);
193 for (std::uint32_t index = 0; index < 11; ++index)
194 attribute(index + 5, wgpu::VertexFormat::Float32x2, std::uint64_t(index) * 8u, index + 5);
195 std::array<wgpu::VertexBufferLayout, 2> buffers{};
196 buffers[0].arrayStride = sizeof(MeshVertex);
197 buffers[0].attributeCount = 5;
198 buffers[0].attributes = attributes.data();
199 buffers[1].arrayStride = 11u * 2u * sizeof(float);
200 buffers[1].attributeCount = 11;
201 buffers[1].attributes = attributes.data() + 5;
202
203 wgpu::BlendState blendState{};
204 blendState.color.operation = wgpu::BlendOperation::Add;
205 blendState.alpha.operation = wgpu::BlendOperation::Add;
206 blendState.color.srcFactor = blend == BlendMode::Additive ? wgpu::BlendFactor::One
207 : blend == BlendMode::Premultiplied ? wgpu::BlendFactor::One
208 : wgpu::BlendFactor::SrcAlpha;
209 blendState.color.dstFactor = blend == BlendMode::Multiply ? wgpu::BlendFactor::Zero
210 : wgpu::BlendFactor::OneMinusSrcAlpha;
211 blendState.alpha.srcFactor = wgpu::BlendFactor::One;
212 blendState.alpha.dstFactor = wgpu::BlendFactor::OneMinusSrcAlpha;
213 if (blend == BlendMode::Multiply) {
214 blendState.color.srcFactor = wgpu::BlendFactor::Dst;
215 blendState.color.dstFactor = wgpu::BlendFactor::Zero;
216 }
217 wgpu::ColorTargetState target{};
218 target.format = wgpu::TextureFormat(format);
219 target.blend = blend == BlendMode::Opaque ? nullptr : &blendState;
220 target.writeMask = wgpu::ColorWriteMask::All;
221 wgpu::FragmentState fragmentState{};
222 fragmentState.module = fragment;
223 fragmentState.entryPoint = "main";
224 std::array<wgpu::ColorTargetState, 5> targets;
225 targets.fill(target);
226 if (gbuffer) targets[4].format = wgpu::TextureFormat::RGBA16Float;
227 fragmentState.targetCount = gbuffer ? 5u : 1u;
228 fragmentState.targets = targets.data();
229 wgpu::DepthStencilState depth{};
230 depth.format = wgpu::TextureFormat::Depth32Float;
231 depth.depthWriteEnabled = depthWrite ? wgpu::OptionalBool::True : wgpu::OptionalBool::False;
232 // Match built-in Vulkan opaque replacement of Hybrid's stored depth.
233 depth.depthCompare =
234 blend == BlendMode::Opaque && depthWrite ? wgpu::CompareFunction::LessEqual : wgpu::CompareFunction::Less;
235 wgpu::RenderPipelineDescriptor descriptor{};
236 descriptor.vertex.module = vertex;
237 descriptor.vertex.entryPoint = "main";
238 descriptor.vertex.bufferCount = buffers.size();
239 descriptor.vertex.buffers = buffers.data();
240 descriptor.fragment = &fragmentState;
241 descriptor.primitive.topology = wgpu::PrimitiveTopology::TriangleList;
242 descriptor.primitive.frontFace = wgpu::FrontFace::CCW;
243 descriptor.primitive.cullMode = cull == PbrCullMode::None ? wgpu::CullMode::None
244 : cull == PbrCullMode::Front ? wgpu::CullMode::Front
245 : wgpu::CullMode::Back;
246 descriptor.depthStencil = &depth;
247 descriptor.multisample.count = samples;
248 descriptor.multisample.mask = 0xffffffffu;
249 descriptor.multisample.alphaToCoverageEnabled = alphaToCoverage;
250 PbrResources::Pipeline candidate{plan, format, samples, raster};
251 candidate.pipeline = device.CreateRenderPipeline(&descriptor);
252 candidate.layout = candidate.pipeline.GetBindGroupLayout(0);
253 resources.pipelines.push_back(std::move(candidate));
254 found = std::prev(resources.pipelines.end());
255 }
256
257 float surfaceCode = float(int(draw.surfaceMode));
258 if (draw.surfaceMode == SurfaceMode::Transparent && draw.surfaceBlend == BlendMode::Premultiplied)
259 surfaceCode = 3.f;
260 const std::uint32_t skinCount = draw.mesh->hasGpuSkinning() ? draw.mesh->getSkinPaletteCount() : 0;
261 detail::PbrUniformGpu uniform = detail::buildPbrUniformGpu(
262 {surface, draw.viewProj * draw.model, draw.model, draw.view, draw.cameraPos,
263 glm::vec4(draw.tint.r, draw.tint.g, draw.tint.b, draw.tint.a), draw.lighting.ambient,
264 draw.lighting, draw.metallic, draw.roughness, surfaceCode, draw.alphaCutoff,
265 environment ? draw.environmentIntensity : 0.f, skinCount});
266
267 if (gbuffer) {
268 uniform.mvp = draw.gbufferMvp;
269 uniform.lights[0].posRadius = *draw.gbufferClip;
270 }
271 const auto vertexCount = std::size_t(mesh.vertexCount);
272 std::vector<float> uv(vertexCount * 22u, 0.f);
273 for (std::size_t slot = 0; slot < surface.textures.size(); ++slot) {
274 const auto& binding = surface.textures[slot];
275 auto values = draw.mesh->texcoordSet(binding.texcoord);
276 if (binding.texture && values.empty() && binding.texcoord != 0)
277 throw Exception("PBR texture references missing mesh UV channel");
278 if (!values.empty()) uniform.uvInfo[slot].offset = 0u;
279 for (std::size_t vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex) {
280 const auto fallback = mesh.cpuVertices[vertexIndex].uv;
281 uv[vertexIndex * 22u + slot * 2u] = values.empty() ? fallback.x : values[vertexIndex * 2u];
282 uv[vertexIndex * 22u + slot * 2u + 1u] = values.empty() ? fallback.y : values[vertexIndex * 2u + 1u];
283 }
284 }
285
286 std::vector<float> attributes(2u, 0.f);
287 if (surface.normalMode != PbrNormalMode::TangentXYZ && draw.mesh->hasImportedTangents()) {
288 uniform.tangentInfo = {std::uint32_t(attributes.size()), 1u, 0u, 0u};
289 const auto& tangents = draw.mesh->importedTangents();
290 const auto& bitangents = draw.mesh->importedBitangents();
291 for (std::size_t index = 0; index < tangents.size(); index += 3u) {
292 attributes.insert(attributes.end(), tangents.begin() + index, tangents.begin() + index + 3u);
293 attributes.insert(attributes.end(), bitangents.begin() + index, bitangents.begin() + index + 3u);
294 }
295 }
296 const auto highlights = draw.mesh->motionHighlights();
297 if (!highlights.empty()) {
298 uniform.tangentInfo.z = std::uint32_t(attributes.size());
299 uniform.tangentInfo.w = 1u;
300 attributes.insert(attributes.end(), highlights.begin(), highlights.end());
301 }
302 const auto factors = draw.mesh->vegetationFactors();
303 if (!factors.empty()) {
304 uniform.vegetationInfo.x = std::uint32_t(attributes.size());
305 uniform.vegetationInfo.y = 1u;
306 attributes.insert(attributes.end(), factors.begin(), factors.end());
307 }
308 const auto deformation = draw.mesh->vegetationDeformationFactors();
309 if (!deformation.empty()) {
310 uniform.vertexInfo.z = std::uint32_t(attributes.size());
311 uniform.vertexInfo.w = 1u;
312 attributes.insert(attributes.end(), deformation.begin(), deformation.end());
313 }
314 if (surface.vegetationMotion.mode == PbrVegetationMotionMode::Object && deformation.empty())
315 throw Exception("PBR GPU vegetation motion requires a nine-float rest-deformation stream");
316
317 auto& arena = currentUboArena();
318 const auto uniformOffset = arena.alloc(sizeof(uniform), 256);
319 const auto shadowOffset = arena.alloc(sizeof(ShadowUBO), 256);
320 queue.WriteBuffer(arena.buffer, uniformOffset, &uniform, sizeof(uniform));
321 auto shadow = draw.shadows.ubo;
322 if (!shadows) {
323 shadow.bias.y = 0.f;
324 shadow.splits.w = 0.f;
325 }
326 shadow.bias.z = draw.shadowReceive ? 1.f : 0.f;
327 queue.WriteBuffer(arena.buffer, shadowOffset, &shadow, sizeof(shadow));
328
329 const auto allocateAux = [&](const void* data, std::uint64_t bytes) {
330 const auto index = arena.paletteIndex++;
331 if (arena.palettes.size() <= index) arena.palettes.resize(index + 1u);
332 auto& buffer = arena.palettes[index];
333 if (!buffer || buffer.GetSize() < bytes) {
334 wgpu::BufferDescriptor descriptor{};
335 descriptor.size = std::max<std::uint64_t>(bytes, 4u);
336 descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Storage | wgpu::BufferUsage::Vertex;
337 buffer = device.CreateBuffer(&descriptor);
338 }
339 queue.WriteBuffer(buffer, 0, data, bytes);
340 return buffer;
341 };
342 auto uvBuffer = allocateAux(uv.data(), uv.size() * sizeof(float));
343 auto attributeBuffer = allocateAux(attributes.data(), attributes.size() * sizeof(float));
344 auto skinBuffer = uploadSkinPalette(draw.mesh);
345
346 std::vector<wgpu::BindGroupEntry> entries;
347 const auto addBuffer = [&](std::uint32_t binding, const wgpu::Buffer& buffer, std::uint64_t offset,
348 std::uint64_t size) {
349 wgpu::BindGroupEntry entry{};
350 entry.binding = binding;
351 entry.buffer = buffer;
352 entry.offset = offset;
353 entry.size = size;
354 entries.push_back(entry);
355 };
356 const auto addTexture = [&](std::uint32_t binding, GpuTexture* texture) {
357 wgpu::BindGroupEntry entry{};
358 entry.binding = binding;
359 entry.textureView = texture->view;
360 entries.push_back(entry);
361 };
362 const auto addSampler = [&](std::uint32_t binding, const wgpu::Sampler& sampler) {
363 wgpu::BindGroupEntry entry{};
364 entry.binding = binding;
365 entry.sampler = sampler;
366 entries.push_back(entry);
367 };
368 addBuffer(0, arena.buffer, uniformOffset, sizeof(uniform));
369 addBuffer(2, attributeBuffer, 0, attributes.size() * sizeof(float));
370 addBuffer(3, skinBuffer, 0, skinBuffer.GetSize());
371 if (!gbuffer) addBuffer(6, arena.buffer, shadowOffset, sizeof(shadow));
372
373 const auto samplerFor = [&](const PbrTextureBinding& binding) -> const wgpu::Sampler& {
374 const SamplerKey key{binding.wrapS, binding.wrapT, binding.minFilter, binding.magFilter};
375 auto sampler = resources.samplers.find(key);
376 if (sampler == resources.samplers.end())
377 sampler = resources.samplers.emplace(key, makePbrSampler(device, binding)).first;
378 return sampler->second;
379 };
380 for (std::uint32_t slot = 0; slot < std::uint32_t(surface.textures.size()); ++slot) {
381 if ((plan.canonicalTextureMask & (1u << slot)) == 0u) continue;
382 addTexture(20u + slot * 2u, gpuForTexture(surface.textures[slot].texture));
383 if (plan.canonicalSamplerRepresentatives[slot] == slot)
384 addSampler(21u + slot * 2u, samplerFor(surface.textures[slot]));
385 }
386 for (std::uint32_t slot = 0; slot < std::uint32_t(surface.vegetationDetail.textures.size()); ++slot) {
387 if ((plan.detailTextureMask & (1u << slot)) == 0u) continue;
388 addTexture(42u + slot * 2u, gpuForTexture(surface.vegetationDetail.textures[slot].texture));
389 if (plan.detailSamplerRepresentatives[slot] == std::uint32_t(PbrTextureSlot::Count) + slot)
390 addSampler(43u + slot * 2u, samplerFor(surface.vegetationDetail.textures[slot]));
391 }
392 if (plan.fragmentFlags & PbrEnvironment) {
393 auto* texture = gpuForTexture(draw.environment);
394 addTexture(4, texture);
395 addSampler(5, texture->sampler);
396 }
397 if (plan.fragmentFlags & PbrShadows) {
398 addTexture(7, shadowDepthArray);
399 addSampler(8, shadowDepthArray->sampler);
400 }
401 if (plan.fragmentFlags & PbrExtras) {
402 auto* texture = gpuForTexture(surface.vegetationExtras.texture);
403 addTexture(9, texture);
404 addSampler(10, texture->sampler);
405 }
406 if (plan.fragmentFlags & PbrColors) {
407 auto* texture = gpuForTexture(surface.vegetationColors.texture);
408 addTexture(11, texture);
409 addSampler(12, texture->sampler);
410 }
411 if (plan.fragmentFlags & PbrFadeNoise) {
412 auto* texture = gpuForTexture(surface.vegetationAlpha.noise);
413 addTexture(13, texture);
414 addSampler(14, texture->sampler);
415 }
416 if (plan.vertexFlags & PbrVertexField) {
417 auto* texture = gpuForTexture(surface.vegetationVertex.texture);
418 addTexture(50, texture);
419 addSampler(51, texture->sampler);
420 }
421 if (plan.vertexFlags & PbrMotionField) {
422 auto* texture = gpuForTexture(surface.vegetationMotion.texture);
423 addTexture(52, texture);
424 addSampler(53, texture->sampler);
425 }
426 if (plan.vertexFlags & PbrMotionNoise) {
427 auto* texture = gpuForTexture(surface.vegetationMotion.noise);
428 addTexture(54, texture);
429 addSampler(55, texture->sampler);
430 }
431
432 wgpu::BindGroupDescriptor bindDescriptor{};
433 bindDescriptor.layout = found->layout;
434 bindDescriptor.entryCount = entries.size();
435 bindDescriptor.entries = entries.data();
436 auto bindGroup = device.CreateBindGroup(&bindDescriptor);
437 pass.SetPipeline(found->pipeline);
438 pass.SetBindGroup(0, bindGroup);
439 pass.SetVertexBuffer(0, mesh.vertexBuffer, 0, std::uint64_t(mesh.vertexCount) * mesh.vertexStride);
440 pass.SetVertexBuffer(1, uvBuffer, 0, uv.size() * sizeof(float));
441 if (mesh.indexBuffer) {
442 const auto indexBytes = mesh.indexFormat == wgpu::IndexFormat::Uint16 ? 2u : 4u;
443 pass.SetIndexBuffer(mesh.indexBuffer, mesh.indexFormat, 0, std::uint64_t(mesh.indexCount) * indexBytes);
444 pass.DrawIndexed(mesh.indexCount, 1, 0, 0, 0);
445 } else {
446 pass.Draw(mesh.vertexCount, 1, 0, 0);
447 }
448 return true;
449}
450
451} // namespace eve::graphics::webgpu
LogicalId target
std::string descriptor
double volume
std::unordered_map< std::string, QuestRuntime > entries
float uv
SQObjectPtr key
Definition ECS.cpp:155
std::vector< FieldTarget > targets
std::uint32_t vertexCount
vkb::Device & device
vk::UniqueSampler sampler
float u
Definition Grass.cpp:233
std::int32_t first
float blend
size_t offset
std::uint64_t bytes
bool valid
MeshVfxBatchedDraw draw
OceanMeshSettings mesh
std::shared_ptr< OceanGpuSpectrum > gpu
std::vector< std::weak_ptr< DeviceBytes > > resources
Definition OnnxGpgpu.cpp:55
std::unique_ptr< gpgpu::GpuBuffer > buffer
Definition OnnxGpgpu.cpp:26
eve::action::ActionVfxBinding binding
Texture * texture
TileLayer * layer
std::set< std::string > values
Object::Ptr value
std::map< std::string, double > attributes
std::string build
std::string slot
std::string attribute
bool found
std::string mipmap
std::string_view source
float size
Definition TreeMesh.cpp:158
std::uint32_t depth
const AssetImportLimits & limits
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
uint32_t maxSamplersPerShaderStage() const
Maximum samplers visible to one shader stage.
uint32_t maxSampledTexturesPerShaderStage() const
Maximum sampled textures visible to one shader stage.
Result< void > setMesh3DPbrSurface(const PbrSurface *surface) override
Sets the mesh 3 d pbr surface.
PbrUniformGpu buildPbrUniformGpu(const PbrUniformBuildInputs &inputs)
Build all material and scene fields; mesh stream offsets remain disabled for the backend to fill.
WGPUBlendState blendState(BlendMode mode)
Internal WebGPU pipeline/descriptor helper; render-thread only.
PbrSpecializedSources specializePbrVariantSources(const PbrVariantPlan &plan, bool gbuffer)
Specialize the generated WGSL for the resource reachability encoded by a checked plan.
Result< PbrVariantPlan > planPbrVariant(const PbrSurface &surface, bool environment, bool shadows, const PbrVariantLimits &limits)
Plan only resources reachable for an immutable PBR draw snapshot.
FilterMode
Mag/min filter for texture sampling.
PbrCullMode
Raster face culling requested by a PBR material.
Definition PbrSurface.h:20
Result< void > validatePbrSurface(const PbrSurface &s)
Validate finite material factors and sampler enums without changing the input.
eve::BlendMode BlendMode
Compatibility alias for the shared 2D blend mode.
Definition BlendMode.h:8
BlendMode
Render-neutral 2D blend mode shared by graphics-facing modules.
Definition RenderTypes.h:11
Owning material parameter snapshot; texture pointers remain borrowed. Base color/metallic/roughness c...
Definition PbrSurface.h:240
PbrVegetationMotion vegetationMotion
Definition PbrSurface.h:281
PbrVegetationExtras vegetationExtras
Definition PbrSurface.h:278
std::array< PbrTextureBinding, std::size_t(PbrTextureSlot::Count)> textures
Definition PbrSurface.h:241
PbrVegetationVertex vegetationVertex
Definition PbrSurface.h:280
PbrVegetationColors vegetationColors
Definition PbrSurface.h:279
PbrVegetationDetail vegetationDetail
Definition PbrSurface.h:277
PbrVegetationAlpha vegetationAlpha
Definition PbrSurface.h:282
std::array< PbrTextureBinding, 3 > textures
Definition PbrSurface.h:110
Vertex/index buffers for one mesh.
Definition Graphics.h:159
std::map< SamplerKey, wgpu::Sampler > samplers
Device resource limits relevant to one extended PBR shader variant.
Stable resource-layout key and checked stage counts for a PBR snapshot.