update headers

This commit is contained in:
Nick Fisher
2022-12-05 17:51:44 +08:00
parent 8d562f1742
commit dd100653dc
234 changed files with 62619 additions and 9800 deletions

View File

@@ -0,0 +1,123 @@
/*
* Copyright (C) 2019 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.
*/
#ifndef MATDBG_DEBUGSERVER_H
#define MATDBG_DEBUGSERVER_H
#include <utils/CString.h>
#include <backend/DriverEnums.h>
#include <private/filament/Variant.h>
#include <tsl/robin_map.h>
class CivetServer;
namespace filament {
namespace matdbg {
using MaterialKey = uint32_t;
/**
* Server-side material debugger.
*
* This class manages an HTTP server and a WebSockets server that listen on a secondary thread. It
* receives material packages from the Filament C++ engine or from a standalone tool such as
* matinfo.
*/
class DebugServer {
public:
DebugServer(backend::Backend backend, int port);
~DebugServer();
/**
* Notifies the debugger that the given material package is being loaded into the engine
* and returns a unique identifier for the material.
*/
MaterialKey addMaterial(const utils::CString& name, const void* data, size_t size,
void* userdata = nullptr);
/**
* Notifies the debugger that the given material has been deleted.
*/
void removeMaterial(MaterialKey key);
using EditCallback = void(*)(void* userdata, const utils::CString& name, const void*, size_t);
using QueryCallback = void(*)(void* userdata, VariantList* variants);
/**
* Sets up a callback that allows the Filament engine to listen for shader edits. The callback
* might be triggered from a secondary thread.
*/
void setEditCallback(EditCallback callback) { mEditCallback = callback; }
/**
* Sets up a callback that can ask the Filament engine which shader variants are active. The
* callback might be triggered from a secondary thread.
*/
void setQueryCallback(QueryCallback callback) { mQueryCallback = callback; }
bool isReady() const { return mServer; }
private:
struct MaterialRecord {
void* userdata;
const uint8_t* package;
size_t packageSize;
utils::CString name;
MaterialKey key;
VariantList activeVariants;
};
const MaterialRecord* getRecord(const MaterialKey& key) const;
void updateActiveVariants();
/**
* Replaces the entire content of a particular shader variant. The given shader index uses the
* same ordering that the variants have within the package.
*/
bool handleEditCommand(const MaterialKey& mat, backend::Backend api, int shaderIndex,
const char* newShaderContent, size_t newShaderLength);
const backend::Backend mBackend;
CivetServer* mServer;
tsl::robin_map<MaterialKey, MaterialRecord> mMaterialRecords;
utils::CString mHtml;
utils::CString mJavascript;
utils::CString mCss;
utils::CString mChunkedMessage;
size_t mChunkedMessageRemaining = 0;
EditCallback mEditCallback = nullptr;
QueryCallback mQueryCallback = nullptr;
class FileRequestHandler* mFileHandler = nullptr;
class RestRequestHandler* mRestHandler = nullptr;
class WebSocketHandler* mWebSocketHandler = nullptr;
friend class FileRequestHandler;
friend class RestRequestHandler;
friend class WebSocketHandler;
};
} // namespace matdbg
} // namespace filament
#endif // MATDBG_DEBUGSERVER_H

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2019 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.
*/
#ifndef MATDBG_JSONWRITER_H
#define MATDBG_JSONWRITER_H
#include <filaflat/ChunkContainer.h>
#include <backend/DriverEnums.h>
#include <utils/CString.h>
#include <private/filament/Variant.h>
namespace filament {
namespace matdbg {
// This class generates portions of JSON messages that are sent to the web client.
// Note that some portions of these JSON strings are generated by directly in DebugServer,
// as well as CommonWriter.
class JsonWriter {
public:
// Retrieves the most recently generated string.
const char* getJsonString() const;
size_t getJsonSize() const;
// Generates a JSON string describing the given material.
bool writeMaterialInfo(const filaflat::ChunkContainer& package);
// Generates a JSON string describing the currently active variants.
//
// The array is of the form [ backend, shaderIndex0, shaderIndex1, ... ] where each
// shader index is an active variant. Each bit in the activeVariants bitmask
// represents one of the possible variant combinations.
bool writeActiveInfo(const filaflat::ChunkContainer& package, backend::Backend backend,
VariantList activeVariants);
private:
utils::CString mJsonString;
};
} // namespace matdbg
} // namespace filament
#endif // MATDBG_JSONWRITER_H

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2019 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.
*/
#ifndef MATDBG_SHADEREXTRACTOR_H
#define MATDBG_SHADEREXTRACTOR_H
#include <filaflat/ChunkContainer.h>
#include <filaflat/MaterialChunk.h>
#include <backend/DriverEnums.h>
#include <utils/CString.h>
namespace filament {
namespace matdbg {
// ShaderExtractor is a utility class for extracting shader source from a material package. It works
// in a manner similar to ShaderReplacer.
class ShaderExtractor {
public:
ShaderExtractor(backend::Backend backend, const void* data, size_t size);
bool parse() noexcept;
bool getShader(backend::ShaderModel shaderModel,
Variant variant, backend::ShaderStage stage, filaflat::ShaderContent& shader) noexcept;
bool getDictionary(filaflat::BlobDictionary& dictionary) noexcept;
static utils::CString spirvToGLSL(const uint32_t* data, size_t wordCount);
static utils::CString spirvToText(const uint32_t* data, size_t wordCount);
private:
filaflat::ChunkContainer mChunkContainer;
filaflat::MaterialChunk mMaterialChunk;
filamat::ChunkType mMaterialTag = filamat::ChunkType::Unknown;
filamat::ChunkType mDictionaryTag = filamat::ChunkType::Unknown;
};
} // namespace matdbg
} // namespace filament
#endif // MATDBG_SHADEREXTRACTOR_H

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2019 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.
*/
#ifndef MATDBG_SHADERINFO_H
#define MATDBG_SHADERINFO_H
#include <backend/DriverEnums.h>
#include <filaflat/ChunkContainer.h>
#include <filaflat/MaterialChunk.h>
#include <private/filament/Variant.h>
namespace filament {
namespace matdbg {
struct ShaderInfo {
backend::ShaderModel shaderModel;
Variant variant;
backend::ShaderStage pipelineStage;
uint32_t offset;
};
size_t getShaderCount(const filaflat::ChunkContainer& container, filamat::ChunkType type);
bool getMetalShaderInfo(const filaflat::ChunkContainer& container, ShaderInfo* info);
bool getGlShaderInfo(const filaflat::ChunkContainer& container, ShaderInfo* info);
bool getVkShaderInfo(const filaflat::ChunkContainer& container, ShaderInfo* info);
} // namespace matdbg
} // namespace filament
#endif // MATDBG_SHADERINFO_H

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2019 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.
*/
#ifndef MATDBG_SHADERREPLACER_H
#define MATDBG_SHADERREPLACER_H
#include <filaflat/ChunkContainer.h>
#include <backend/DriverEnums.h>
#include "private/filament/Variant.h"
namespace filament {
namespace matdbg {
// ShaderReplacer is a utility class for replacing shader source within a material package. It works
// in a manner similar to ShaderExtractor.
class ShaderReplacer {
public:
ShaderReplacer(backend::Backend backend, const void* data, size_t size);
~ShaderReplacer();
bool replaceShaderSource(backend::ShaderModel shaderModel, Variant variant,
backend::ShaderStage stage, const char* sourceString, size_t stringLength);
const uint8_t* getEditedPackage() const;
size_t getEditedSize() const;
private:
bool replaceSpirv(backend::ShaderModel shaderModel, Variant variant,
backend::ShaderStage stage, const char* source, size_t sourceLength);
const backend::Backend mBackend;
filaflat::ChunkContainer mOriginalPackage;
filaflat::ChunkContainer* mEditedPackage = nullptr;
filamat::ChunkType mMaterialTag = filamat::ChunkType::Unknown;
filamat::ChunkType mDictionaryTag = filamat::ChunkType::Unknown;
};
} // namespace matdbg
} // namespace filament
#endif // MATDBG_SHADERREPLACER_H

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2019 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.
*/
#ifndef MATDBG_TEXTWRITER_H
#define MATDBG_TEXTWRITER_H
#include <filaflat/ChunkContainer.h>
#include <utils/CString.h>
namespace filament {
namespace matdbg {
class TextWriter {
public:
bool writeMaterialInfo(const filaflat::ChunkContainer& package);
const char* getString() const;
size_t getSize() const;
private:
utils::CString mTextString;
};
} // namespace matdbg
} // namespace filament
#endif // MATDBG_TEXTWRITER_H