[graphite] Begin making UniformManager more incremental

Once the UniformManager is moved into the SkPipelineDataGatherer, it
will need to be reset-able and write{Uniforms} will need to be able
to be called repeatedly. This CL starts setting up for that future.

Bug: skia:12701
Change-Id: Ia652c05b4eb508dce12c66b2298930d799d1e445
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527280
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2022-04-04 14:11:54 -04:00 committed by SkCQ
parent 8bc46f3cd2
commit 9fbd4984c8
2 changed files with 58 additions and 26 deletions

View File

@ -22,9 +22,6 @@ static_assert(sizeof(SkHalf) == 2);
namespace skgpu {
//////////////////////////////////////////////////////////////////////////////
UniformManager::UniformManager(Layout layout) : fLayout(layout) {}
template<typename BaseType>
static constexpr size_t tight_vec_size(int vecLength) {
return sizeof(BaseType) * vecLength;
@ -493,51 +490,66 @@ SkSLType UniformManager::getUniformTypeForLayout(SkSLType type) {
return type;
}
uint32_t UniformManager::writeUniforms(SkSpan<const SkUniform> uniforms,
const void** srcs,
char *dst) {
decltype(&Writer<Rules140>::WriteUniform) write;
UniformManager::UniformManager(Layout layout) : fLayout(layout) {
switch (fLayout) {
case Layout::kStd140:
write = Writer<Rules140>::WriteUniform;
fWriteUniform = Writer<Rules140>::WriteUniform;
break;
case Layout::kStd430:
write = Writer<Rules430>::WriteUniform;
fWriteUniform = Writer<Rules430>::WriteUniform;
break;
case Layout::kMetal:
write = Writer<RulesMetal>::WriteUniform;
fWriteUniform = Writer<RulesMetal>::WriteUniform;
break;
}
#ifdef SK_DEBUG
uint32_t curUBOOffset = 0;
uint32_t curUBOMaxAlignment = 0;
#endif // SK_DEBUG
this->reset();
}
uint32_t offset = 0;
void UniformManager::reset() {
#ifdef SK_DEBUG
fCurUBOOffset = 0;
fCurUBOMaxAlignment = 0;
#endif
fOffset = 0;
}
#ifdef SK_DEBUG
void UniformManager::checkReset() const {
SkASSERT(fCurUBOOffset == 0);
SkASSERT(fCurUBOMaxAlignment == 0);
SkASSERT(fOffset == 0);
}
#endif
uint32_t UniformManager::writeUniforms(SkSpan<const SkUniform> uniforms,
const void** srcs,
char *dst) {
this->reset();
for (int i = 0; i < (int) uniforms.size(); ++i) {
const SkUniform& u = uniforms[i];
SkSLType uniformType = this->getUniformTypeForLayout(u.type());
#ifdef SK_DEBUG
uint32_t debugOffset = get_ubo_aligned_offset(&curUBOOffset,
&curUBOMaxAlignment,
uint32_t debugOffset = get_ubo_aligned_offset(&fCurUBOOffset,
&fCurUBOMaxAlignment,
uniformType,
u.count());
#endif // SK_DEBUG
uint32_t bytesWritten = write(uniformType,
CType::kDefault,
dst ? &dst[offset] : nullptr,
u.count(),
srcs ? srcs[i] : nullptr);
SkASSERT(debugOffset == offset);
uint32_t bytesWritten = fWriteUniform(uniformType,
CType::kDefault,
dst ? &dst[fOffset] : nullptr,
u.count(),
srcs ? srcs[i] : nullptr);
SkASSERT(debugOffset == fOffset);
offset += bytesWritten;
fOffset += bytesWritten;
}
return offset;
return fOffset;
}
} // namespace skgpu

View File

@ -15,6 +15,8 @@ class SkUniform;
namespace skgpu {
enum class CType : unsigned;
enum class Layout {
kStd140,
kStd430,
@ -25,6 +27,11 @@ class UniformManager {
public:
UniformManager(Layout layout);
void reset();
#ifdef SK_DEBUG
void checkReset() const;
#endif
/*
* Use the uniform 'definitions' to write the data in 'srcs' into 'dst' (if it is non-null).
* The number of bytes that was written (or would've been written) to 'dst' is returned.
@ -40,7 +47,20 @@ public:
private:
SkSLType getUniformTypeForLayout(SkSLType type);
Layout fLayout;
using WriteUniformFn = uint32_t(*)(SkSLType type,
CType ctype,
void *dest,
int n,
const void *src);
WriteUniformFn fWriteUniform;
Layout fLayout; // TODO: eventually 'fLayout' will not need to be stored
#ifdef SK_DEBUG
uint32_t fCurUBOOffset;
uint32_t fCurUBOMaxAlignment;
#endif // SK_DEBUG
uint32_t fOffset;
};
} // namespace skgpu