An ubershader archive is a bundle of filamat packages with some metadata that conveys which glTF features each material supports. This PR does three things: 1. Adds a new command line tool called `uberz` that consumes a list of filamat files and metadata text files and produces a single ubershader archive. 2. Adds a new library (also called `uberz`) that is used by `gltfio` to read ubershader archives, and used by the above command line tool to write ubershader archives. 3. Enhances `UbershaderLoader` so that it no longers uses a hardcoded set of materials, and instead takes an ubershader archive. Ubershader archives have a simple binary layout that can be memcpy'd directly into a C struct. The metadata is specified using a text file with key-value pairs. These two file formats have formal desriptions in the README in `libs/uberz`. In a subsequent PR, we will remove the `gltfio_resources` target and change the signature of `createUbershaderLoader` so that it takes an archive.
48 lines
1.7 KiB
C++
48 lines
1.7 KiB
C++
/*
|
|
* Copyright (C) 2022 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <uberz/ReadableArchive.h>
|
|
|
|
#include <utils/debug.h>
|
|
|
|
using namespace filament;
|
|
using namespace utils;
|
|
|
|
namespace filament::uberz {
|
|
|
|
static_assert(sizeof(ReadableArchive) == 4 + 4 + 8 + 8);
|
|
static_assert(sizeof(ArchiveSpec) == 1 + 1 + 2 + 4 + 8 + 8);
|
|
static_assert(sizeof(ArchiveFlag) == 8 + 8);
|
|
|
|
void convertOffsetsToPointers(ReadableArchive* archive) {
|
|
constexpr size_t wordSize = sizeof(uint64_t);
|
|
assert_invariant(archive->specsOffset % wordSize == 0);
|
|
uint64_t* basePointer = (uint64_t*) archive;
|
|
archive->specs = (ArchiveSpec*) (basePointer + archive->specsOffset / wordSize);
|
|
for (uint64_t i = 0; i < archive->specsCount; ++i) {
|
|
ArchiveSpec& spec = archive->specs[i];
|
|
assert_invariant(spec.flagsOffset % wordSize == 0);
|
|
spec.flags = (ArchiveFlag*) (basePointer + (spec.flagsOffset / wordSize));
|
|
spec.package = ((uint8_t*) basePointer) + spec.packageOffset;
|
|
for (uint64_t j = 0; j < spec.flagsCount; ++j) {
|
|
ArchiveFlag& flag = spec.flags[j];
|
|
flag.name = ((const char*) basePointer) + flag.nameOffset;
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace filament::uberz
|