23#include <unordered_map>
119template <
typename Record>
123 const u32 id =
static_cast<u32>(slots_.size()) + 1;
124 slots_.emplace_back(std::move(record));
130 if (
id == 0 ||
id > slots_.size())
return nullptr;
131 auto& slot = slots_[
id - 1];
132 return slot ? &*slot :
nullptr;
136 if (
id == 0 ||
id > slots_.size())
return nullptr;
137 const auto& slot = slots_[
id - 1];
138 return slot ? &*slot :
nullptr;
142 if (
id == 0 ||
id > slots_.size() || !slots_[
id - 1])
return false;
143 slots_[
id - 1].reset();
151 template <
typename Slots,
typename Ref>
156 iterator(Slots* slots,
size_t at) : slots_(slots), at_(at) { skip(); }
158 std::pair<u32, Ref>&
operator*()
const { current_.emplace(
static_cast<u32>(at_ + 1), *(*slots_)[at_]);
return *current_; }
163 void skip() {
while (at_ < slots_->
size() && !(*slots_)[at_]) ++at_; }
166 mutable std::optional<std::pair<u32, Ref>> current_;
168 explicit View(Slots* slots) : slots_(slots) {}
181 std::deque<std::optional<Record>> slots_;
190 mix(
static_cast<u32>(d.program));
191 mix(
static_cast<u32>(d.vertexLayout));
192 mix(
static_cast<u32>(d.blend));
193 mix(
static_cast<u32>(d.stencil));
194 mix(
static_cast<u32>(d.topology));
195 mix(
static_cast<u16>(d.depthBias));
196 mix((
u64(d.blendEnabled) << 0) | (
u64(d.depthTest) << 1) | (
u64(d.depthWrite) << 2) | (
u64(d.cullEnabled) << 3)
197 | (
u64(d.cullFront) << 4) | (
u64(d.alphaToCoverage) << 5) | (
u64(d.gbuffer) << 6) | (
u64(d.albedo) << 7)
198 | (
u64(d.colorWrite) << 8) | (
u64(d.depthEqual) << 9) | (
u64(d.layerAlpha) << 10));
199 return static_cast<size_t>(h);
225 const auto it = pipelineIndex_.find(desc);
226 return it != pipelineIndex_.end() ? it->second : 0;
233 pipelineIndex_.emplace(desc,
id);
237 std::vector<GfxOwedContent>
owed()
const {
238 std::vector<GfxOwedContent> out;
239 for (
const auto& [
id, record] :
buffers.all()) {
242 record.content.provider(), record.content.key()});
245 for (
const auto& [
id, record] :
textures.all()) {
248 record.content.provider(), record.content.key()});
255 std::unordered_map<PipelineDesc, u32, PipelineDescHash> pipelineIndex_;
Who restores a GPU object's contents after the device is lost.
Backend-agnostic graphics enumerations.
Immutable GPU pipeline state — the backend-agnostic unit of "how to draw".
What a resource's content is, as a number that changes whenever it does.
A content policy. provider names who refills a Sourced object and key what it refills; both are the p...
iterator(Slots *slots, size_t at)
bool operator==(const iterator &other) const
std::pair< u32, Ref > & operator*() const
bool operator!=(const iterator &other) const
One kind of object, by id, in creation order.
View< const std::deque< std::optional< Record > >, const Record & > all() const
const Record * find(u32 id) const
u32 insert(Record record)
View< std::deque< std::optional< Record > >, Record & > all()
GfxRecordTable< GfxFramebufferRecord > framebuffers
std::vector< GfxOwedContent > owed() const
GfxRecordTable< GfxTimerQueryRecord > timerQueries
GfxRecordTable< GfxComputeRecord > computes
u32 internPipeline(const PipelineDesc &desc)
The pipeline with this description, made if there is none. Pipelines are never erased,...
GfxRecordTable< GfxProgramRecord > programs
GfxRecordTable< GfxBufferRecord > buffers
GfxRecordTable< GfxPipelineRecord > pipelines
GfxRecordTable< GfxTextureRecord > textures
u32 findPipeline(const PipelineDesc &desc) const
An existing pipeline with this description, or 0. A hash lookup: a pipeline is asked for at every cha...
GfxRecordTable< GfxLayoutRecord > layouts
2D texture for GPU rendering
constexpr u64 fnv1aWord(u64 h, u64 word)
constexpr u64 kFnv64Offset
std::int32_t i32
Signed 32-bit integer.
std::uint64_t u64
Unsigned 64-bit integer.
GfxShaderLanguage
Shader source language a backend consumes.
GfxCompressedFormat
GPU-compressed texture internal formats for createCompressedTexture.
@ ETC2_RGBA8
GL_COMPRESSED_RGBA8_ETC2_EAC (core).
std::uint32_t u32
Unsigned 32-bit integer.
std::uint8_t u8
Unsigned 8-bit integer.
std::uint16_t u16
Unsigned 16-bit integer.
constexpr u32 GFX_UNBOUND_BLOCK
u64 nextRevision()
A revision no content has had before. Never 0, which reads as "none".
float f32
32-bit floating point
Immutable creation parameters of a GPU buffer.
Attachments of an offscreen render target. The attach point of depthStencil follows its texture's pix...
std::vector< u8 > bytes
Retained content, or the initial bytes of a buffer created while the device was lost.
GfxBufferRecord(const BufferDesc &d, GfxContent c)
A Sourced object that has storage again and is waiting for its contents.
std::vector< std::string > uniformNames
A location handed out is an index here; the backend's own is resolved per generation.
std::vector< GfxUniformValue > uniformValues
std::vector< std::string > blockNames
std::function< void()> onLinked
What the owner of a program created with GfxShaderSource::deferLink does once it has linked (the bloc...
std::vector< std::pair< u32, std::string > > attribBindings
GfxShaderLanguage language
std::vector< u32 > blockBindings
Binding point per block name, or GFX_UNBOUND_BLOCK.
GfxCompressedFormat compressedFormat
GfxTextureRecord(const TextureDesc &d, GfxContent c)
bool externallyWritable
Attached for rendering or backed by a host texture.
size_t operator()(const PipelineDesc &d) const noexcept
Immutable description of a draw pipeline. Equality keys the pipeline cache, so two draws with the sam...
Immutable creation parameters of a 2D texture or 2D texture array.
Describes how vertex-buffer bytes map to shader attributes.