Files
aurora/lib/webgpu/gpu.hpp
Pieter-Jan Briers bec90f1b68 Set up dawn cache (#98)
* Set up dawn cache

Massively speeds up pipeline compilation on the second go around, especially for D3D12.

Currently, uses SQLite for the cache. SQLite is committed in as the "amalgam" blob, but I'm open for better ways to fetch it.

* Compress cache contents with zstd

More significantly for Vulkan, less so for D3D12.

* Store cache keys as XXH128 instead

This reduces the size of the D3D12 cache by a ridiculous amount

* Stop using exceptions for error handling

* FetchContent for sqlite; cleanup & make zstd optional

---------

Co-authored-by: Luke Street <luke@street.dev>
2026-04-08 13:46:51 -06:00

53 lines
1.7 KiB
C++

#pragma once
#include <aurora/aurora.h>
#include <aurora/math.hpp>
#include "wgpu.hpp"
#include <array>
#include <cstdint>
struct SDL_Window;
namespace aurora::webgpu {
struct GraphicsConfig {
wgpu::SurfaceConfiguration surfaceConfiguration;
wgpu::TextureFormat depthFormat;
uint32_t msaaSamples;
uint16_t textureAnisotropy;
};
struct TextureWithSampler {
wgpu::Texture texture;
wgpu::TextureView view;
wgpu::Extent3D size;
wgpu::TextureFormat format;
wgpu::Sampler sampler;
};
extern wgpu::Device g_device;
extern wgpu::Queue g_queue;
extern wgpu::Surface g_surface;
extern wgpu::BackendType g_backendType;
extern GraphicsConfig g_graphicsConfig;
extern TextureWithSampler g_frameBuffer;
extern TextureWithSampler g_frameBufferResolved;
extern TextureWithSampler g_depthBuffer;
extern wgpu::RenderPipeline g_CopyPipeline;
extern wgpu::BindGroup g_CopyBindGroup;
extern wgpu::Instance g_instance;
bool initialize(AuroraBackend backend);
void shutdown();
bool refresh_surface(bool recreate = true);
void resize_swapchain(uint32_t width, uint32_t height, uint32_t native_width, uint32_t native_height, bool force = false);
TextureWithSampler create_render_texture(uint32_t width, uint32_t height, bool multisampled);
void draw_clear(const wgpu::RenderPassEncoder& pass, bool clearColor, bool clearAlpha, bool clearDepth,
const Vec4<float>& clearColorValue, float clearDepthValue);
size_t load_from_cache(void const * key, size_t keySize, void * value, size_t valueSize, void * userdata);
void store_to_cache(void const * key, size_t keySize, void const * value, size_t valueSize, void * userdata);
void cache_shutdown();
} // namespace aurora::webgpu