载入中...
搜索中...
未找到
GraphicsShaderResources.cpp
浏览该文件的文档.
1#include <algorithm>
2#include <cstring>
3#include <set>
4#include <stdexcept>
6#include "graphics/shaders/mesh3d_vert_spv.inc"
9
10namespace eve::graphics::vulkan {
11namespace {
12struct ResourceImage {
13 vk::UniqueDeviceMemory memory;
14 vk::UniqueImage image;
15 vk::UniqueImageView view;
16 vk::UniqueSampler sampler;
17 ShaderImageInput shape;
18 std::weak_ptr<const void> contentOwner;
19};
20vk::Format imageFormat(ShaderImageFormat value) {
21 switch (value) {
22 case ShaderImageFormat::R8: return vk::Format::eR8Unorm;
23 case ShaderImageFormat::RG8: return vk::Format::eR8G8Unorm;
24 case ShaderImageFormat::R16: return vk::Format::eR16Unorm;
25 case ShaderImageFormat::RGBA8: return vk::Format::eR8G8B8A8Unorm;
26 case ShaderImageFormat::BGRA8: return vk::Format::eB8G8R8A8Unorm;
27 case ShaderImageFormat::RGBA8Srgb: return vk::Format::eR8G8B8A8Srgb;
28 case ShaderImageFormat::BGRA8Srgb: return vk::Format::eB8G8R8A8Srgb;
29 case ShaderImageFormat::BC1: return vk::Format::eBc1RgbaUnormBlock;
30 case ShaderImageFormat::BC1Srgb: return vk::Format::eBc1RgbaSrgbBlock;
31 case ShaderImageFormat::BC3: return vk::Format::eBc3UnormBlock;
32 case ShaderImageFormat::BC3Srgb: return vk::Format::eBc3SrgbBlock;
33 case ShaderImageFormat::BC7: return vk::Format::eBc7UnormBlock;
34 case ShaderImageFormat::BC7Srgb: return vk::Format::eBc7SrgbBlock;
35 case ShaderImageFormat::RGBA16Unorm: return vk::Format::eR16G16B16A16Unorm;
36 case ShaderImageFormat::RGBA16Float: return vk::Format::eR16G16B16A16Sfloat;
37 case ShaderImageFormat::RGBA32Float: return vk::Format::eR32G32B32A32Sfloat;
38 }
39 return vk::Format::eUndefined;
40}
41} // namespace
42
44 std::vector<std::shared_ptr<ResourceImage>> images;
45 std::unique_ptr<vkb::GenericBuffer> constants;
46 std::vector<ShaderImageInput> shapes; // Byte spans are cleared; only reload ABI metadata remains.
47 std::size_t constantSize = 0;
48 std::vector<std::byte> constantBytes;
49 std::unique_ptr<vkb::GenericBuffer> instances;
50 std::vector<std::byte> instanceBytes;
51 vk::UniqueDescriptorSetLayout frameSetLayout;
52 vk::UniqueDescriptorSetLayout setLayout;
53 vk::UniqueDescriptorPool pool;
54 vk::UniquePipelineLayout pipelineLayout;
55};
57bool isMeshResourceImageShared(const GpuShader& first, std::uint32_t firstSlot, const GpuShader& second,
58 std::uint32_t secondSlot) {
59 return first.resources && second.resources && firstSlot < first.resources->images.size() &&
60 secondSlot < second.resources->images.size() &&
61 first.resources->images[firstSlot] == second.resources->images[secondSlot];
62}
63
64Result<void> validateMeshResourceShaderReload(const GpuShader& shader, std::span<const uint32_t> vertex,
65 std::span<const uint32_t> fragment) {
66 if (!shader.resources) return Result<void>::success();
68 vertex, fragment,
69 ShaderResourceInputs{shader.resources->shapes, shader.resources->constantBytes,
70 shader.resources->instanceBytes});
71}
72
74 return shader.resources ? static_cast<std::uint32_t>(shader.resources->instanceBytes.size() / 64) : 0;
75}
76
77Result<void> Graphics::replaceMeshShaderResources(Shader& shader, const std::vector<uint32_t>& vertSpv,
78 const std::vector<uint32_t>& fragSpv,
80 auto found = std::find_if(ownedGpuShaders.begin(), ownedGpuShaders.end(),
81 [&](const auto& gpu) { return gpu->owner == &shader; });
82 if (!initialized || found == ownedGpuShaders.end() || !(*found)->isMesh3D || (*found)->isHair3D ||
83 shader.isXray() || swapchainPassOpen || offscreen3DPassOpen)
84 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "Expected an owned, ordinary mesh shader outside frame submission", "shader.resources"));
85 if ((inputs.images.empty() && inputs.constants.empty() && inputs.instanceMatrices.empty()) ||
86 inputs.images.size() > 16 || inputs.constants.size() > 65536 || inputs.constants.size() % 16 != 0)
89 "Expected resource inputs, at most 16 images and 64 KiB of aligned uniform bytes", "shader.resources"));
90 std::set<uint32_t> bindings;
91 std::vector<std::vector<ShaderImageRegion>> regions;
92 const auto& limits = device.physical_device.properties.limits;
93 auto instanceCount = shaderInstanceMatrixCount(inputs.instanceMatrices);
95 if (inputs.instanceMatrices.size() > limits.maxStorageBufferRange ||
96 (!inputs.instanceMatrices.empty() &&
97 (limits.maxPerStageDescriptorStorageBuffers < 2 || limits.maxDescriptorSetStorageBuffers < 2)))
98 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Unsupported, "Instance matrix buffer exceeds device limits", "shader.resources"));
99 if (inputs.images.size() + 2 > limits.maxPerStageDescriptorSamplers ||
100 inputs.images.size() + 2 > limits.maxPerStageDescriptorSampledImages ||
101 inputs.constants.size() > limits.maxUniformBufferRange)
102 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Unsupported, "Resource program exceeds device descriptor or uniform limits", "shader.resources"));
103 for (const auto& image : inputs.images) {
104 if (!bindings.insert(image.binding).second) return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "Duplicate resource image binding", "shader.resources"));
106 if (!layout) return Result<void>::failure(layout.status());
107 const auto dimensionLimit = image.dimension == ShaderImageDimension::Image3D ? limits.maxImageDimension3D
108 : image.dimension == ShaderImageDimension::Cube ? limits.maxImageDimensionCube
109 : limits.maxImageDimension2D;
110 if (image.width > dimensionLimit || image.height > dimensionLimit || image.depth > limits.maxImageDimension3D ||
111 image.layers > limits.maxImageArrayLayers)
112 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Unsupported, "Resource image exceeds device dimensions", "shader.resources"));
113 const auto flags = device.physical_device->getFormatProperties(imageFormat(image.format)).optimalTilingFeatures;
114 const auto required = vk::FormatFeatureFlagBits::eSampledImage | vk::FormatFeatureFlagBits::eTransferDst;
115 if ((flags & required) != required ||
116 ((image.sampler.min == FilterMode::Linear || image.sampler.mag == FilterMode::Linear ||
117 image.sampler.mipmap == MipmapMode::Linear) &&
118 !(flags & vk::FormatFeatureFlagBits::eSampledImageFilterLinear)))
119 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Unsupported, "Device cannot sample the requested image format/filter", "shader.resources"));
120 regions.push_back(std::move(layout).takeValue());
121 }
122 auto admitted = detail::validateResourceShaderStages(vertSpv, fragSpv, inputs);
123 if (!admitted) return admitted;
124 auto candidate = std::make_unique<GpuShader>();
125 candidate->isMesh3D = true;
126 candidate->owner = &shader;
127 candidate->resources.reset(new MeshShaderResources);
128 auto& resources = *candidate->resources;
129 std::vector<uint32_t> vertex = vertSpv;
130 std::vector<uint32_t> fragment = fragSpv;
131 if (vertex.empty()) vertex.assign(mesh3d_vert_spv, mesh3d_vert_spv + mesh3d_vert_spv_count);
132 try {
133 const auto stages = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment;
134 std::vector<vk::DescriptorSetLayoutBinding> layout;
135 for (const auto& image : inputs.images)
136 layout.emplace_back(image.binding, vk::DescriptorType::eCombinedImageSampler, 1, stages);
137 if (!inputs.constants.empty()) layout.emplace_back(32, vk::DescriptorType::eUniformBuffer, 1, stages);
138 if (!inputs.instanceMatrices.empty())
139 layout.emplace_back(33, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eVertex);
140 resources.setLayout = device->createDescriptorSetLayoutUnique(vk::DescriptorSetLayoutCreateInfo{{}, layout});
141 std::vector<vk::DescriptorPoolSize> poolSizes;
142 if (!inputs.images.empty())
143 poolSizes.emplace_back(vk::DescriptorType::eCombinedImageSampler, uint32_t(inputs.images.size()));
144 if (!inputs.constants.empty()) poolSizes.emplace_back(vk::DescriptorType::eUniformBuffer, 1);
145 if (!inputs.instanceMatrices.empty()) poolSizes.emplace_back(vk::DescriptorType::eStorageBuffer, 1);
146 resources.pool = device->createDescriptorPoolUnique(vk::DescriptorPoolCreateInfo{{}, 1, poolSizes});
147 const auto setLayout = *resources.setLayout;
148 candidate->resourceSet =
149 device->allocateDescriptorSets(vk::DescriptorSetAllocateInfo{*resources.pool, 1, &setLayout})[0];
150 // Resource programs admit only albedo/scene-color images from set 0.
151 // Keep the two dynamic UBOs and default vertex skin palette ABI, without
152 // charging these programs for eleven unrelated material samplers.
153 vkb::DescriptorSetLayoutBuilder frameLayout;
154 resources.frameSetLayout =
155 frameLayout.buffer(0, vk::DescriptorType::eUniformBufferDynamic, stages, 1)
156 .image(1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, 1)
157 .buffer(4, vk::DescriptorType::eUniformBufferDynamic, vk::ShaderStageFlagBits::eFragment, 1)
158 .image(18, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, 1)
159 .buffer(21, vk::DescriptorType::eStorageBuffer, vk::ShaderStageFlagBits::eVertex, 1)
160 .createUnique(device.instance);
161 candidate->resourceFrameLayout = *resources.frameSetLayout;
162 const vk::DescriptorSetLayout layouts[] = {candidate->resourceFrameLayout, setLayout};
163 const vk::PushConstantRange push{stages, 0, Shader::kPushConstantBytes};
164 resources.pipelineLayout =
165 device->createPipelineLayoutUnique(vk::PipelineLayoutCreateInfo{{}, 2, layouts, 1, &push});
166 candidate->pipelineLayout = *resources.pipelineLayout;
167 resources.images.reserve(inputs.images.size());
168 std::vector<std::unique_ptr<vkb::GenericBuffer>> pendingStaging;
169 std::vector<std::function<void(vk::CommandBuffer)>> uploadCommands;
170 size_t pendingBytes = 0;
171 auto flushUploads = [&] {
172 if (uploadCommands.empty()) return;
173 vkb::executeImmediately(device.instance, uploadPool, device.getQueue(vkb::QueueType::graphics),
174 [&](vk::CommandBuffer command) {
175 for (auto& record : uploadCommands) record(command);
176 });
177 uploadCommands.clear();
178 pendingStaging.clear();
179 pendingBytes = 0;
180 };
181 for (size_t index = 0; index < inputs.images.size(); ++index) {
182 const auto& input = inputs.images[index];
183 std::shared_ptr<ResourceImage> output;
184 if (input.contentOwner) {
185 for (const auto& prior : ownedGpuShaders) {
186 if (!prior->resources) continue;
187 for (const auto& image : prior->resources->images) {
188 auto owner = image->contentOwner.lock();
189 const auto& shape = image->shape;
190 const auto& a = shape.sampler;
191 const auto& b = input.sampler;
192 if (owner && !owner.owner_before(input.contentOwner) &&
193 !input.contentOwner.owner_before(owner) && shape.format == input.format &&
194 shape.dimension == input.dimension && shape.width == input.width &&
195 shape.height == input.height && shape.layers == input.layers &&
196 shape.depth == input.depth && shape.mipLevels == input.mipLevels && a.min == b.min &&
197 a.mag == b.mag && a.mipmap == b.mipmap && a.repeatU == b.repeatU &&
198 a.repeatV == b.repeatV && a.repeatW == b.repeatW && a.maxAnisotropy == b.maxAnisotropy &&
199 a.lodBias == b.lodBias && a.minLod == b.minLod && a.maxLod == b.maxLod) {
200 output = image;
201 break;
202 }
203 }
204 if (output) break;
205 }
206 }
207 if (!output) {
208 output = std::make_shared<ResourceImage>();
209 output->shape = input;
210 output->shape.bytes = {};
211 output->shape.contentOwner.reset();
212 output->contentOwner = input.contentOwner;
213 vk::ImageCreateInfo info{};
214 info.imageType =
215 input.dimension == ShaderImageDimension::Image3D ? vk::ImageType::e3D : vk::ImageType::e2D;
216 info.format = imageFormat(input.format);
217 info.extent = vk::Extent3D{input.width, input.height, input.depth};
218 info.mipLevels = input.mipLevels;
219 info.arrayLayers = input.layers;
220 info.samples = vk::SampleCountFlagBits::e1;
221 info.tiling = vk::ImageTiling::eOptimal;
222 info.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst;
223 if (input.dimension == ShaderImageDimension::Cube)
224 info.flags = vk::ImageCreateFlagBits::eCubeCompatible;
225 output->image = device->createImageUnique(info);
226 const auto memory = device->getImageMemoryRequirements(*output->image);
227 uint32_t type = UINT32_MAX;
228 const auto& props = device.physical_device.memory_properties;
229 for (uint32_t i = 0; i < props.memoryTypeCount; ++i)
230 if ((memory.memoryTypeBits & (1u << i)) &&
231 (props.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal)) {
232 type = i;
233 break;
234 }
235 if (type == UINT32_MAX) throw std::runtime_error("No device-local image memory type");
236 output->memory = device->allocateMemoryUnique(vk::MemoryAllocateInfo{memory.size, type});
237 device->bindImageMemory(*output->image, *output->memory, 0);
238 const vk::ImageSubresourceRange range{vk::ImageAspectFlagBits::eColor, 0, input.mipLevels, 0,
239 input.layers};
240 const auto viewType = input.dimension == ShaderImageDimension::Cube ? vk::ImageViewType::eCube
241 : input.dimension == ShaderImageDimension::Array2D ? vk::ImageViewType::e2DArray
242 : input.dimension == ShaderImageDimension::Image3D ? vk::ImageViewType::e3D
243 : vk::ImageViewType::e2D;
244 output->view = device->createImageViewUnique(
245 vk::ImageViewCreateInfo{{}, *output->image, viewType, info.format, {}, range});
246 // A dedicated immutable sampler; use the same normalization as ordinary textures.
247 output->sampler = vk::UniqueSampler(createVkSampler(input.sampler, input.mipLevels), device.instance);
248 size_t stagingSize = 0;
249 std::vector<vk::BufferImageCopy> copies;
250 for (const auto& region : regions[index]) {
251 const auto offset = (stagingSize + 15) & ~size_t(15);
252 stagingSize = offset + region.size;
253 copies.emplace_back(
254 offset, 0, 0,
255 vk::ImageSubresourceLayers{vk::ImageAspectFlagBits::eColor, region.mip, region.layer, 1},
256 vk::Offset3D{}, vk::Extent3D{region.width, region.height, region.depth});
257 }
258 auto staging = std::make_unique<vkb::GenericBuffer>(
259 device, vk::BufferUsageFlagBits::eTransferSrc, stagingSize,
260 vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
261 // Copy directly into the new, unmapped upload allocation. Only the
262 // recorded regions are read by the GPU; alignment gaps need no initialization.
263 auto* mapped = static_cast<std::byte*>(staging->map());
264 for (size_t regionIndex = 0; regionIndex < regions[index].size(); ++regionIndex) {
265 const auto& region = regions[index][regionIndex];
266 std::memcpy(mapped + copies[regionIndex].bufferOffset, input.bytes.data() + region.offset,
267 region.size);
268 }
269 staging->unmap();
270 const auto buffer = staging->buffer;
271 pendingBytes += stagingSize;
272 pendingStaging.push_back(std::move(staging));
273 uploadCommands.push_back(
274 [output, range, buffer, copies = std::move(copies)](vk::CommandBuffer command) {
275 vk::ImageMemoryBarrier barrier{{},
276 vk::AccessFlagBits::eTransferWrite,
277 vk::ImageLayout::eUndefined,
278 vk::ImageLayout::eTransferDstOptimal,
279 VK_QUEUE_FAMILY_IGNORED,
280 VK_QUEUE_FAMILY_IGNORED,
281 *output->image,
282 range};
283 command.pipelineBarrier(vk::PipelineStageFlagBits::eTopOfPipe,
284 vk::PipelineStageFlagBits::eTransfer, {}, {}, {}, barrier);
285 command.copyBufferToImage(buffer, *output->image, vk::ImageLayout::eTransferDstOptimal, copies);
286 barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
287 barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;
288 barrier.oldLayout = vk::ImageLayout::eTransferDstOptimal;
289 barrier.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
290 command.pipelineBarrier(
291 vk::PipelineStageFlagBits::eTransfer,
292 vk::PipelineStageFlagBits::eVertexShader | vk::PipelineStageFlagBits::eFragmentShader, {},
293 {}, {}, barrier);
294 });
295 if (pendingBytes >= 64ull * 1024 * 1024) flushUploads();
296 }
297 const vk::DescriptorImageInfo descriptor{*output->sampler, *output->view,
298 vk::ImageLayout::eShaderReadOnlyOptimal};
299 device->updateDescriptorSets(vk::WriteDescriptorSet{candidate->resourceSet, input.binding, 0, 1,
300 vk::DescriptorType::eCombinedImageSampler, &descriptor},
301 {});
302 resources.images.push_back(std::move(output));
303 resources.shapes.push_back(input);
304 resources.shapes.back().bytes = {};
305 resources.shapes.back().contentOwner.reset();
306 }
307 flushUploads();
308 if (!inputs.constants.empty()) {
309 resources.constants = std::make_unique<vkb::GenericBuffer>(
310 device, vk::BufferUsageFlagBits::eUniformBuffer, inputs.constants.size(),
311 vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
312 resources.constants->updateLocal(vkb::FrameSlot::gpuIdle(), inputs.constants.data(),
313 inputs.constants.size());
314 resources.constantSize = inputs.constants.size();
315 resources.constantBytes.assign(inputs.constants.begin(), inputs.constants.end());
316 const vk::DescriptorBufferInfo descriptor{resources.constants->buffer, 0, inputs.constants.size()};
317 device->updateDescriptorSets(
318 vk::WriteDescriptorSet{candidate->resourceSet, 32, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr,
319 &descriptor},
320 {});
321 }
322 if (!inputs.instanceMatrices.empty()) {
323 resources.instances = std::make_unique<vkb::GenericBuffer>(
324 device, vk::BufferUsageFlagBits::eStorageBuffer, inputs.instanceMatrices.size(),
325 vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
326 resources.instances->updateLocal(vkb::FrameSlot::gpuIdle(), inputs.instanceMatrices.data(),
327 inputs.instanceMatrices.size());
328 resources.instanceBytes.assign(inputs.instanceMatrices.begin(), inputs.instanceMatrices.end());
329 const vk::DescriptorBufferInfo descriptor{resources.instances->buffer, 0, inputs.instanceMatrices.size()};
330 device->updateDescriptorSets(
331 vk::WriteDescriptorSet{candidate->resourceSet, 33, 0, 1, vk::DescriptorType::eStorageBuffer, nullptr,
332 &descriptor},
333 {});
334 }
335 candidate->mesh3dPipeline = createMesh3DStylePipeline(
336 vertex, fragSpv, candidate->pipelineLayout, activeScenePass(), activeSceneSamples(), shader.meshBlend,
337 shader.meshDepthWrite, shader.meshDoubleSided, shader.meshRasterState());
338 candidate->mesh3dOffscreenPipeline = createMesh3DStylePipeline(
339 vertex, fragSpv, candidate->pipelineLayout, offscreen3DRenderPass, vk::SampleCountFlagBits::e1,
340 shader.meshBlend, shader.meshDepthWrite, shader.meshDoubleSided, shader.meshRasterState());
341 candidate->mesh3dHdrOffscreenPipeline = createMesh3DStylePipeline(
342 vertex, fragSpv, candidate->pipelineLayout, hdrOffscreen3DRenderPass, vk::SampleCountFlagBits::e1,
343 shader.meshBlend, shader.meshDepthWrite, shader.meshDoubleSided, shader.meshRasterState());
345 } catch (const std::exception& error) {
346 for (auto pipeline :
347 {candidate->mesh3dPipeline, candidate->mesh3dOffscreenPipeline, candidate->mesh3dHdrOffscreenPipeline})
348 if (pipeline) device->destroyPipeline(pipeline);
349 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Failed, error.what(), "shader.resources"));
350 }
351 auto& old = **found;
352 for (auto pipeline :
353 {old.mesh3dPipeline, old.mesh3dXrayPipeline, old.mesh3dOffscreenPipeline, old.mesh3dHdrOffscreenPipeline})
354 if (pipeline) device->destroyPipeline(pipeline);
355 old = std::move(*candidate);
356 shader.gpuHandle = &old;
357 shader.setSpirv(std::move(vertex), std::move(fragment));
358 lastMesh3dPipeline = nullptr;
359 return Result<void>::success();
360}
361} // namespace eve::graphics::vulkan
std::string output
std::string descriptor
EvpackChunkInput input
Definition Evpack.cpp:170
std::string layout
ScriptFieldRegion region
std::uint32_t instanceCount
std::weak_ptr< const void > contentOwner
vk::UniqueSampler sampler
ShaderImageInput shape
vk::UniqueImage image
vk::UniqueDeviceMemory memory
int inputs
Definition GridGraph.cpp:23
std::int32_t second
std::int32_t first
size_t offset
Range range
bool required
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::shared_ptr< OceanGpuSpectrum > owner
std::shared_ptr< OceanGpuSpectrum > gpu
OceanSprayView view
std::vector< std::weak_ptr< DeviceBytes > > resources
Definition OnnxGpgpu.cpp:55
std::unique_ptr< gpgpu::GpuBuffer > buffer
Definition OnnxGpgpu.cpp:26
std::string error
Definition Package.cpp:174
std::vector< ParticleBakeMaterial > bindings
Object::Ptr value
Shader * shader
bool found
const AssetImportLimits & limits
uint32_t index
uint32_t flags
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
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
void push(bool all)
Pushes .
Custom GPU program.
Definition Shader.h:41
static constexpr uint32_t kPushConstantBytes
Definition Shader.h:45
Result< void > replaceMeshShaderResources(Shader &shader, const std::vector< uint32_t > &vertSpv, const std::vector< uint32_t > &fragSpv, const ShaderResourceInputs &resources) override
Replace mesh shader resources.
void waitForSharedGpuResources()
Block until all in-flight GPU work (all frames) has completed.
Definition Graphics.cpp:943
Result< void > validateResourceShaderStages(std::span< const uint32_t > vertex, std::span< const uint32_t > fragment, const ShaderResourceInputs &inputs)
Validate resource shader stages.
Result< void > validateMeshResourceShaderReload(const GpuShader &shader, std::span< const uint32_t > vertex, std::span< const uint32_t > fragment)
Validate mesh resource shader reload.
bool isMeshResourceImageShared(const GpuShader &first, std::uint32_t firstSlot, const GpuShader &second, std::uint32_t secondSlot)
Query whether two live shader image slots share immutable GPU storage. @ownership Borrows both shader...
std::uint32_t meshResourceInstanceCount(const GpuShader &shader)
Immutable uploaded instance count; render-thread read, no retained borrow.
ShaderImageFormat
Explicit sampled-image storage; sRGB conversion never affects alpha.
EVENGINE_API_BACKENDS Result< std::vector< ShaderImageRegion > > shaderImageRegions(const ShaderImageInput &image)
Validate layout, dimensions, sampler compatibility and exact payload size.
EVENGINE_API_BACKENDS Result< std::uint32_t > shaderInstanceMatrixCount(std::span< const std::byte > bytes)
Validate packed instance records without GPU access; returns the record count.
Inputs for descriptor set 1 of a resource mesh program.
GpuShader public API.
Definition Graphics.h:335
void operator()(MeshShaderResources *resources) const noexcept
Operator .
std::vector< std::shared_ptr< ResourceImage > > images
std::unique_ptr< vkb::GenericBuffer > constants
std::unique_ptr< vkb::GenericBuffer > instances
glm::uvec4 info