Compare commits

..
Author SHA1 Message Date
Sungun Park 23e1779f1e Fix a compile error
FMaterial accesses a private static method of the MaterialDefinition
class, which incurs a compile error for certain compilers.
2025-09-24 12:07:40 -07:00
78 changed files with 481 additions and 2166 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ repositories {
}
dependencies {
implementation 'com.google.android.filament:filament-android:1.65.4'
implementation 'com.google.android.filament:filament-android:1.65.2'
}
```
@@ -51,7 +51,7 @@ Here are all the libraries available in the group `com.google.android.filament`:
iOS projects can use CocoaPods to install the latest release:
```shell
pod 'Filament', '~> 1.65.4'
pod 'Filament', '~> 1.65.2'
```
## Documentation
-3
View File
@@ -7,9 +7,6 @@ A new header is inserted each time a *tag* is created.
Instead, if you are authoring a PR for the main branch, add your release note to
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
## v1.65.4
## v1.65.3
+1 -1
View File
@@ -1,5 +1,5 @@
GROUP=com.google.android.filament
VERSION_NAME=1.65.4
VERSION_NAME=1.65.2
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
+2 -2
View File
@@ -181,7 +181,7 @@ important for <code>matc</code> (material compiler).</p>
}
dependencies {
implementation 'com.google.android.filament:filament-android:1.65.2'
implementation 'com.google.android.filament:filament-android:1.65.1'
}
</code></pre>
<p>Here are all the libraries available in the group <code>com.google.android.filament</code>:</p>
@@ -196,7 +196,7 @@ dependencies {
</div>
<h3 id="ios"><a class="header" href="#ios">iOS</a></h3>
<p>iOS projects can use CocoaPods to install the latest release:</p>
<pre><code class="language-shell">pod 'Filament', '~&gt; 1.65.2'
<pre><code class="language-shell">pod 'Filament', '~&gt; 1.65.1'
</code></pre>
<h2 id="documentation"><a class="header" href="#documentation">Documentation</a></h2>
<ul>
+50 -46
View File
@@ -161,92 +161,97 @@
<h1 id="rendering-difference-test"><a class="header" href="#rendering-difference-test">Rendering Difference Test</a></h1>
<p>We created a few scripts to run <code>gltf_viewer</code> and produce headless renderings.</p>
<p>This is mainly useful for continuous integration where GPUs are generally not available on cloud
machines. To perform software rasterization, these scripts are centered around <a href="https://docs.mesa3d.org">Mesa</a>'s
software rasterizers, but nothing bars us from using another rasterizer like <a href="https://github.com/google/swiftshader">SwiftShader</a>.
Additionally, we should be able to use GPUs where available (though this is more of a future
work).</p>
machines. To perform software rasterization, these scripts are centered around <a href="https://docs.mesa3d.org">Mesa</a>'s software
rasterizers, but nothing bars us from using another rasterizer like <a href="https://github.com/google/swiftshader">SwiftShader</a>. Additionally,
we should be able to use GPUs where available (though this is more of a future work).</p>
<p>The script <code>render.py</code> contains the core logic for taking input parameters (such as the test
description file) and then running gltf_viewer to produce the renderings.</p>
<p>In the <code>test</code> directory is a list of test descriptions that are specified in json. Please see
<p>In the <code>test</code> directory is a list of test descriptions that are specified in json. Please see
<code>sample.json</code> to parse the structure.</p>
<h2 id="setting-up-python"><a class="header" href="#setting-up-python">Setting up python</a></h2>
<p>The <code>renderdiff</code> project uses <code>python</code> extensively. To install the dependencies for producing
renderings, do the following step</p>
<ul>
<li>Set up a virtual environment (from the root directory)
<pre><code>python3 -m venv venv
. ./venv/bin/activate
<pre><code> python3 -m venv venv
. ./venv/bin/activate
</code></pre>
</li>
<li>Install the rendering dependencies
<pre><code>pip install -r test/renderdiff/src/rendering_requirements.txt
<pre><code> pip install -r test/renderdiff/src/rendering_requirements.txt
</code></pre>
</li>
<li>Install the viewer depdencies
<pre><code>pip install -r test/renderdiff/src/viewer_requirements.txt
<pre><code> pip install -r test/renderdiff/src/viewer_requirements.txt
</code></pre>
</li>
<li>For the commands in the following section, do not exit the virtual environment. Once you've
completed all your work, you can exit with
<pre><code>deactivate
<pre><code> deactivate
</code></pre>
</li>
</ul>
<h2 id="running-the-test-locally"><a class="header" href="#running-the-test-locally">Running the test locally</a></h2>
<ul>
<li>To run the same presbumit as <a href="presubmit-renderdiff"><code>test-renderdiff</code></a>, you can do
<li>
<p>To run the same presbumit as <a href="presubmit-renderdiff"><code>test-renderdiff</code></a>, you can do</p>
<pre><code>bash test/renderdiff/local_test.sh
</code></pre>
</li>
<li>This script will generate the renderings based on the current state of your repo.
<li>
<p>This script will generate the renderings based on the current state of your repo.
Additionally, it will also compare the generated images with corresponding images in the
golden repo.</li>
<li>To just render without running the test, you could use the following script
golden repo.</p>
</li>
<li>
<p>To just render without running the test, you could use the following script</p>
<pre><code>bash test/renderdiff/generate.sh
</code></pre>
</li>
</ul>
<h2 id="filtering-tests"><a class="header" href="#filtering-tests">Filtering Tests</a></h2>
<p>You can run a subset of the tests by passing the <code>--test_filter</code> flag to <code>local_test.sh</code>. The
filter supports wildcards (<code>*</code>) to match test names. For example, to run all tests in the
<code>ClearCoat</code> suite, you can use the following command:</p>
<pre><code>bash test/renderdiff/local_test.sh --test_filter='ClearCoat.*.*'
</code></pre>
<h2 id="update-the-golden-images"><a class="header" href="#update-the-golden-images">Update the golden images</a></h2>
<p>The golden images are stored in a github repository:
https://github.com/google/filament-assets. Filament team members should have access to write
to the repository. A typical flow for updating the goldens is to upload your changed images
into <strong>branch</strong> of <code>filament-assets</code>. This branch is paired with a PR or commit on the
<code>filament</code> repo.</p>
<p>As an example, imagine I am working on a PR, and I've uploaded my change, which is in a
branch called <code>my-pr-branch</code>, to <code>filament</code>. This PR requires updating the golden. We would do
it in the following fashion</p>
<p>The golden images are stored in a github repository: https://github.com/google/filament-assets.
Filament team members should have access to write to the repository. A typical flow for updating
the goldens is to upload your changed images into <strong>branch</strong> of <code>filament-assets</code>. This branch is
paired with a PR or commit on the <code>filament</code> repo.</p>
<p>As an example, imagine I am working on a PR, and I've uploaded my change, which is in a branch
called <code>my-pr-branch</code>, to <code>filament</code>. This PR requires updating the golden. We would do it
in the following fashion</p>
<h3 id="using-a-script-to-update-the-golden-repo"><a class="header" href="#using-a-script-to-update-the-golden-repo">Using a script to update the golden repo</a></h3>
<ul>
<li>Run interactive mode in the <code>update_golden.py</code> script.
<li>
<p>Run interactive mode in the <code>update_golden.py</code> script.</p>
<pre><code>python3 test/renderdiff/src/update_golden.py
</code></pre>
</li>
<li>This will guide you through a series of steps to push the changes to a remote branch on
<code>filament-assets</code>.</li>
<li>
<p>This will guide you through a series of steps to push the changes to a remote branch
on <code>filament-assets</code>.</p>
</li>
</ul>
<h3 id="manually-updating-the-golden-repo"><a class="header" href="#manually-updating-the-golden-repo">Manually updating the golden repo</a></h3>
<ul>
<li>Check out the golden repo
<li>
<p>Check out the golden repo</p>
<pre><code>git clone git@github.com:google/filament-assets.git
</code></pre>
</li>
<li>Create a branch on the golden repo
<li>
<p>Create a branch on the golden repo</p>
<pre><code>cd filament-assets
git switch -c my-pr-branch-golden
</code></pre>
</li>
<li>Copy the new images to their appropriate place in <code>filament-assets</code></li>
<li>Push the <code>filament-assets</code> working branch to remote
<li>
<p>Copy the new images to their appropriate place in <code>filament-assets</code></p>
</li>
<li>
<p>Push the <code>filament-assets</code> working branch to remote</p>
<pre><code>git push origin my-pr-branch-golden
</code></pre>
</li>
<li>In the commit message of your working branch on <code>filament</code>, add the following line
<li>
<p>In the commit message of your working branch on <code>filament</code>, add the following line</p>
<pre><code>RDIFF_BBRANCH=my-pr-branch-golden
</code></pre>
</li>
@@ -255,17 +260,16 @@ git switch -c my-pr-branch-golden
<ul>
<li>The presubmit test <a href="https://github.com/google/filament/blob/e85dfe75c86106a05019e13ccdbef67e030af675/.github/workflows/presubmit.yml#L118"><code>test-renderdiff</code></a> will test against the provided
branch of the golden repo (i.e. <code>my-pr-branch-golden</code>).</li>
<li>If the PR is merged, then there is another workflow that will merge <code>my-pr-branch-golden</code>
to the <code>main</code> branch of the golden repo.</li>
<li>If the PR is merged, then there is another workflow that will merge <code>my-pr-branch-golden</code> to
the <code>main</code> branch of the golden repo.</li>
</ul>
<h2 id="viewing-test-results"><a class="header" href="#viewing-test-results">Viewing test results</a></h2>
<p>We provide a viewer for looking at the result of a test run. The viewer is a webapp that can
be used by pointing your browser to a localhost port. If you input the viewer with a PR or a
directory, it will parse the test result and show the results and the rendered and/or golden
images.</p>
<p>We provide a viewer for looking at the result of a test run. The viewer is a webapp that can be used by
pointing your browser to a localhost port. If you input the viewer with a PR or a directory, it will
parse the test result and show the results and the rendered and/or golden images.</p>
<p><img src="../images/renderdiff_example.png" alt="Viewer" /></p>
<p>To run the viewer of a test output directory that has been generated locally, you would run
the following</p>
<p>To run the viewer of a test output directory that has been generated locally, you would run the
following</p>
<pre><code>python3 test/renderdiff/src/viewer.py --diff=[test output]
</code></pre>
<p>where <code>[test output]</code> is a directory containing the <code>compare_results.json</code> of the test run.
@@ -274,8 +278,8 @@ For example, it could be <code>out/renderdiff/diffs/presubmit</code> for the sta
<p>To see the results of a Pull Request initiated test run, you would do the following</p>
<pre><code>python3 test/renderdiff/src/viewer.py --pr_number=[PR #] --github_token=[github token]
</code></pre>
<p>where <code>[PR #]</code> is the numeric ID of your pull request, and the <code>[github token]</code> is an acess
token that you (as a github user) needs to generate (<a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens">reference</a>).</p>
<p>where <code>[PR #]</code> is the numeric ID of your pull request, and the <code>[github token]</code> is an acess token
that you (as a github user) needs to generate (<a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens">reference</a>).</p>
</main>
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-5
View File
@@ -179,7 +179,6 @@ endif()
if (FILAMENT_SUPPORTS_VULKAN)
list(APPEND SRCS
include/backend/platforms/VulkanPlatform.h
src/vulkan/VulkanAsyncHandles.cpp
src/vulkan/VulkanAsyncHandles.h
src/vulkan/VulkanBlitter.cpp
src/vulkan/VulkanBlitter.h
@@ -218,10 +217,6 @@ if (FILAMENT_SUPPORTS_VULKAN)
src/vulkan/VulkanReadPixels.h
src/vulkan/VulkanSamplerCache.cpp
src/vulkan/VulkanSamplerCache.h
src/vulkan/VulkanSemaphore.cpp
src/vulkan/VulkanSemaphore.h
src/vulkan/VulkanSemaphoreManager.cpp
src/vulkan/VulkanSemaphoreManager.h
src/vulkan/VulkanStagePool.cpp
src/vulkan/VulkanStagePool.h
src/vulkan/VulkanSwapChain.cpp
@@ -197,7 +197,6 @@ constexpr std::string_view to_string(Backend const backend) noexcept {
* - The Metal backend can prefer precompiled Metal libraries, while falling back to MSL.
*/
enum class ShaderLanguage {
UNSPECIFIED = -1,
ESSL1 = 0,
ESSL3 = 1,
SPIRV = 2,
@@ -220,8 +219,6 @@ constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) noex
return "Metal precompiled library";
case ShaderLanguage::WGSL:
return "WGSL";
case ShaderLanguage::UNSPECIFIED:
return "Unspecified";
}
return "UNKNOWN";
}
@@ -27,7 +27,6 @@
#include <backend/AcquiredImage.h>
#include <utils/CString.h>
#include <utils/FixedCapacityVector.h>
#include <utils/compiler.h>
#include <functional>
@@ -72,11 +71,7 @@ public:
virtual ShaderModel getShaderModel() const noexcept = 0;
// The shader languages used for shaders for this driver in order of preference, used to inform
// matdbg.
//
// The `preferredLanguage` is only a hint. If the backend supports it, it will appear first in
// the list.
// The shader language used for shaders for this driver, used to inform matdbg.
//
// For OpenGL, this distinguishes whether the driver's shaders are powered by ESSL1 or ESSL3.
// This information is used by matdbg to display the correct shader code to the web UI and patch
@@ -84,8 +79,7 @@ public:
//
// Metal shaders can either be MSL or Metal libraries, but at time of writing, matdbg can only
// interface with MSL.
virtual utils::FixedCapacityVector<ShaderLanguage> getShaderLanguages(
ShaderLanguage preferredLanguage) const noexcept = 0;
virtual ShaderLanguage getShaderLanguage() const noexcept = 0;
// Returns the dispatcher. This is only called once during initialization of the CommandStream,
// so it doesn't matter that it's virtual.
@@ -336,7 +336,6 @@ DECL_DRIVER_API_SYNCHRONOUS_N(void, setStreamDimensions, backend::StreamHandle,
DECL_DRIVER_API_SYNCHRONOUS_N(int64_t, getStreamTimestamp, backend::StreamHandle, stream)
DECL_DRIVER_API_SYNCHRONOUS_N(void, updateStreams, backend::DriverApi*, driver)
DECL_DRIVER_API_SYNCHRONOUS_N(backend::FenceStatus, getFenceStatus, backend::FenceHandle, fh)
DECL_DRIVER_API_SYNCHRONOUS_N(backend::FenceStatus, fenceWait, backend::FenceHandle, fh, uint64_t, timeout)
DECL_DRIVER_API_SYNCHRONOUS_N(void, getPlatformSync, backend::SyncHandle, sh,
backend::CallbackHandler*, handler, backend::Platform::SyncCallback, cb, void*, userData)
DECL_DRIVER_API_SYNCHRONOUS_N(bool, isTextureFormatSupported, backend::TextureFormat, format)
+2 -4
View File
@@ -25,9 +25,8 @@
#include <backend/SamplerDescriptor.h>
#include <utils/FixedCapacityVector.h>
#include <utils/Log.h>
#include <utils/compiler.h>
#include <utils/Log.h>
#include <utils/debug.h>
#include <functional>
@@ -70,8 +69,7 @@ private:
MetalContext* mContext;
ShaderModel getShaderModel() const noexcept final;
utils::FixedCapacityVector<ShaderLanguage> getShaderLanguages(
ShaderLanguage preferredLanguage) const noexcept final;
ShaderLanguage getShaderLanguage() const noexcept final;
// Overrides the default implementation by wrapping the call to fn in an @autoreleasepool block.
void execute(std::function<void(void)> const& fn) noexcept final;
+3 -11
View File
@@ -1002,12 +1002,8 @@ ShaderModel MetalDriver::getShaderModel() const noexcept {
#endif
}
utils::FixedCapacityVector<ShaderLanguage> MetalDriver::getShaderLanguages(
ShaderLanguage preferredLanguage) const noexcept {
if (preferredLanguage == backend::ShaderLanguage::MSL) {
return { backend::ShaderLanguage::MSL, backend::ShaderLanguage::METAL_LIBRARY };
}
return { backend::ShaderLanguage::METAL_LIBRARY, backend::ShaderLanguage::MSL };
ShaderLanguage MetalDriver::getShaderLanguage() const noexcept {
return ShaderLanguage::MSL;
}
Handle<HwStream> MetalDriver::createStreamNative(void* stream, utils::CString tag) {
@@ -1042,15 +1038,11 @@ void MetalDriver::destroyFence(Handle<HwFence> fh) {
}
FenceStatus MetalDriver::getFenceStatus(Handle<HwFence> fh) {
return fenceWait(fh, 0);
}
FenceStatus MetalDriver::fenceWait(FenceHandle fh, uint64_t const timeout) {
auto* fence = handle_cast<MetalFence>(fh);
if (!fence) {
return FenceStatus::ERROR;
}
return fence->wait(timeout);
return fence->wait(0);
}
void MetalDriver::destroySync(Handle<HwSync> sh) {
@@ -134,7 +134,6 @@ bool MetalShaderCompiler::isParallelShaderCompileSupported() const noexcept {
case ShaderLanguage::ESSL3:
case ShaderLanguage::SPIRV:
case ShaderLanguage::WGSL:
case ShaderLanguage::UNSPECIFIED:
break;
}
+3 -5
View File
@@ -155,11 +155,9 @@ id<MTLSamplerState> SamplerStateCreator::operator()(id<MTLDevice> device,
// Older Apple devices (and the simulator) don't support setting a comparison function in
// MTLSamplerDescriptor.
// In practice, this means shadows are not supported when running in the simulator.
if (samplerDescriptor.compareFunction != MTLCompareFunctionNever) {
if (![device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) {
LOG(WARNING) << "Warning: sample comparison not supported by this GPU";
samplerDescriptor.compareFunction = MTLCompareFunctionNever;
}
if (![device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) {
LOG(WARNING) << "Warning: sample comparison not supported by this GPU";
samplerDescriptor.compareFunction = MTLCompareFunctionNever;
}
#endif
+2 -14
View File
@@ -45,16 +45,8 @@ ShaderModel NoopDriver::getShaderModel() const noexcept {
#endif
}
utils::FixedCapacityVector<ShaderLanguage> NoopDriver::getShaderLanguages(
ShaderLanguage /*preferredLanguage*/) const noexcept {
return {
ShaderLanguage::ESSL3,
ShaderLanguage::ESSL1,
ShaderLanguage::SPIRV,
ShaderLanguage::MSL,
ShaderLanguage::METAL_LIBRARY,
ShaderLanguage::WGSL,
};
ShaderLanguage NoopDriver::getShaderLanguage() const noexcept {
return ShaderLanguage::ESSL3;
}
// explicit instantiation of the Dispatcher
@@ -168,10 +160,6 @@ FenceStatus NoopDriver::getFenceStatus(Handle<HwFence> fh) {
return FenceStatus::CONDITION_SATISFIED;
}
FenceStatus NoopDriver::fenceWait(Handle<HwFence> fh, uint64_t timeout) {
return FenceStatus::ERROR;
}
// We create all textures using VK_IMAGE_TILING_OPTIMAL, so our definition of "supported" is that
// the GPU supports the given texture format with non-zero optimal tiling features.
bool NoopDriver::isTextureFormatSupported(TextureFormat format) {
+1 -3
View File
@@ -20,7 +20,6 @@
#include "private/backend/Driver.h"
#include "DriverBase.h"
#include <utils/FixedCapacityVector.h>
#include <utils/compiler.h>
namespace filament::backend {
@@ -35,8 +34,7 @@ public:
private:
ShaderModel getShaderModel() const noexcept final;
utils::FixedCapacityVector<ShaderLanguage> getShaderLanguages(
ShaderLanguage preferredLanguage) const noexcept final;
ShaderLanguage getShaderLanguage() const noexcept final;
uint64_t nextFakeHandle = 1;
+9 -29
View File
@@ -507,40 +507,20 @@ void OpenGLContext::initBugs(Bugs* bugs, Extensions const& exts,
} else if (strstr(renderer, "Mali")) {
// ARM GPU
bugs->vao_doesnt_store_element_array_buffer_binding = true;
// We have run into several problems with timer queries on Mali-Gxx:
// - timer queries seem to cause memory corruptions in some cases on some devices
// (see b/233754398)
// - appeared at least in: "OpenGL ES 3.2 v1.r26p0-01eac0"
// - wasn't present in: "OpenGL ES 3.2 v1.r32p1-00pxl1"
// - timer queries sometime crash with an NPE (see b/273759031)
// (see b/273759031)
// - possibly not present in: "OpenGL ES 3.2 v1.r46p0"
bugs->dont_use_timer_query = true;
// at least some version of Mali have problems with framebuffer_fetch
// (see b/445721121, https://github.com/google/filament/issues/7794)
bugs->disable_framebuffer_fetch_extension = true;
if (strstr(renderer, "Mali-T")) {
bugs->disable_glFlush = true;
bugs->disable_shared_context_draws = true;
// We have not verified that timer queries work on Mali-T, so we disable to be safe.
bugs->dont_use_timer_query = true;
}
if (strstr(renderer, "Mali-G")) {
int maj, min, driverVersion, driverRelease;
int const c = sscanf(version, "OpenGL ES %d.%d v%d.r%d",
&maj, &min, &driverVersion, &driverRelease);
if (UTILS_LIKELY(c == 4)) {
// we were able to parse the version string
if (driverVersion > 1 || (driverVersion == 1 && driverRelease >= 46)) {
// this driver version is known to be good
bugs->dont_use_timer_query = false;
}
if (driverVersion > 1 || (driverVersion == 1 && driverRelease >= 53)) {
// this driver version is known to be good
bugs->disable_framebuffer_fetch_extension = false;
}
}
// We have run into several problems with timer queries on Mali-Gxx:
// - timer queries seem to cause memory corruptions in some cases on some devices
// (see b/233754398)
// - appeared at least in: "OpenGL ES 3.2 v1.r26p0-01eac0"
// - wasn't present in: "OpenGL ES 3.2 v1.r32p1-00pxl1"
// - timer queries sometime crash with an NPE (see b/273759031)
bugs->dont_use_timer_query = true;
}
// Mali seems to have no problem with this (which is good for us)
bugs->allow_read_only_ancillary_feedback_loop = true;
@@ -338,7 +338,6 @@ public:
// 'OpenGL error 0x502 (GL_INVALID_OPERATION) in "draw2" at line 4389'
// This coincides with the use of framebuffer fetch (ColorGradingAsSubpass). We disable
// framebuffer fetch in the case of llvmpipe.
// Some Mali drivers also have problems with this (b/445721121)
bool disable_framebuffer_fetch_extension;
} bugs = {};
+34 -78
View File
@@ -368,9 +368,8 @@ ShaderModel OpenGLDriver::getShaderModel() const noexcept {
return mContext.getShaderModel();
}
utils::FixedCapacityVector<ShaderLanguage> OpenGLDriver::getShaderLanguages(
ShaderLanguage /*preferredLanguage*/) const noexcept {
return { mContext.isES2() ? ShaderLanguage::ESSL1 : ShaderLanguage::ESSL3 };
ShaderLanguage OpenGLDriver::getShaderLanguage() const noexcept {
return mContext.isES2() ? ShaderLanguage::ESSL1 : ShaderLanguage::ESSL3;
}
// ------------------------------------------------------------------------------------------------
@@ -1807,35 +1806,25 @@ void OpenGLDriver::createRenderTargetR(Handle<HwRenderTarget> rth,
void OpenGLDriver::createFenceR(Handle<HwFence> fh, CString&& tag) {
DEBUG_MARKER()
mHandleAllocator.associateTagToHandle(fh.getId(), std::move(tag));
GLFence* f = handle_cast<GLFence*>(fh);
assert_invariant(f->state);
bool const platformCanCreateFence = mPlatform.canCreateFence();
if (mContext.isES2() || platformCanCreateFence) {
std::lock_guard const lock(f->state->lock);
if (platformCanCreateFence) {
f->fence = mPlatform.createFence();
f->state->cond.notify_all();
} else {
f->state->status = FenceStatus::ERROR;
}
return;
if (mPlatform.canCreateFence() || mContext.isES2()) {
assert_invariant(mPlatform.canCreateFence());
f->fence = mPlatform.createFence();
}
// This is the case where we need to use OpenGL fences
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
std::weak_ptr<GLFence::State> const weak = f->state;
whenGpuCommandsComplete([weak] {
if (auto const state = weak.lock()) {
std::lock_guard const lock(state->lock);
state->status = FenceStatus::CONDITION_SATISFIED;
state->cond.notify_all();
}
});
else {
std::weak_ptr const weak = f->state;
whenGpuCommandsComplete([weak](){
if (auto const state = weak.lock()) {
std::lock_guard const lock(state->lock);
state->status = FenceStatus::CONDITION_SATISFIED;
state->cond.notify_all();
}
});
}
#endif
mHandleAllocator.associateTagToHandle(fh.getId(), std::move(tag));
}
void OpenGLDriver::createSyncR(Handle<HwSync> sh, CString&& tag) {
@@ -2318,62 +2307,29 @@ void OpenGLDriver::destroyFence(Handle<HwFence> fh) {
}
FenceStatus OpenGLDriver::getFenceStatus(Handle<HwFence> fh) {
return fenceWait(fh, 0);
}
FenceStatus OpenGLDriver::fenceWait(FenceHandle fh, uint64_t const timeout) {
if (fh) {
// we have to take into account that the STL's wait_for() actually works with
// time_points relative to steady_clock::now() internally.
using namespace std::chrono;
auto const now = steady_clock::now();
steady_clock::time_point until = steady_clock::time_point::max();
if (now <= steady_clock::time_point::max() - nanoseconds(timeout)) {
until = now + nanoseconds(timeout);
}
GLFence const* f = handle_cast<GLFence*>(fh);
assert_invariant(f->state);
bool const platformCanCreateFence = mPlatform.canCreateFence();
// immediately acquire a reference on our state, so that things don't go south if
// the HwFence gets destroyed (on the main thread) while we wait.
std::shared_ptr const state{ f->state };
if (mContext.isES2() || platformCanCreateFence) {
if (platformCanCreateFence) {
std::unique_lock lock(state->lock);
if (f->fence == nullptr) {
// we've been called before the fence was created asynchronously,
// so we need to wait for that, before using the real fence.
// By construction, "f" can't be destroyed while we wait, because its
// construction call is in the queue and a destroy call will have to come later.
state->cond.wait_until(lock, until, [f] {
return f->fence != nullptr;
});
if (f->fence == nullptr) {
// the only possible choice here is that we timed out
assert_invariant(state->status == FenceStatus::TIMEOUT_EXPIRED);
return FenceStatus::TIMEOUT_EXPIRED;
}
GLFence* f = handle_cast<GLFence*>(fh);
if (mPlatform.canCreateFence() || mContext.isES2()) {
if (f->fence == nullptr) {
// we can end-up here if:
// - the platform doesn't support h/w fences
if (UTILS_UNLIKELY(!mPlatform.canCreateFence())) {
return FenceStatus::ERROR;
}
lock.unlock();
// here we know that we have the platform fence
assert_invariant(f->fence);
return mPlatform.waitFence(f->fence, timeout);
// - wait() was called before the fence was asynchronously created.
return FenceStatus::TIMEOUT_EXPIRED;
}
// platform doesn't support fences -- nothing we can do.
return FenceStatus::ERROR;
return mPlatform.waitFence(f->fence, 0);
}
// This is the case where we need to use OpenGL fences
#ifndef FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2
std::unique_lock lock(state->lock);
state->cond.wait_until(lock, until, [&state] {
return state->status != FenceStatus::TIMEOUT_EXPIRED;
});
return state->status;
else {
assert_invariant(f->state);
std::unique_lock lock(f->state->lock);
f->state->cond.wait_for(lock, std::chrono::nanoseconds(0), [&state = f->state]() {
return state->status != FenceStatus::TIMEOUT_EXPIRED;
});
return f->state->status;
}
#endif
}
return FenceStatus::ERROR;
+3 -4
View File
@@ -194,8 +194,8 @@ public:
struct GLFence : public HwFence {
using HwFence::HwFence;
struct State {
utils::Mutex lock; // NOLINT(*-include-cleaner)
utils::Condition cond; // NOLINT(*-include-cleaner)
std::mutex lock;
std::condition_variable cond;
FenceStatus status{ FenceStatus::TIMEOUT_EXPIRED };
};
std::shared_ptr<State> state{ std::make_shared<State>() };
@@ -233,8 +233,7 @@ private:
}
ShaderModel getShaderModel() const noexcept override;
utils::FixedCapacityVector<ShaderLanguage> getShaderLanguages(
ShaderLanguage preferredLanguage) const noexcept override;
ShaderLanguage getShaderLanguage() const noexcept override;
/*
* OpenGLDriver interface
@@ -1,82 +0,0 @@
/*
* Copyright (C) 2025 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 "VulkanAsyncHandles.h"
#include <backend/DriverEnums.h>
#include <utils/debug.h>
#include <cstdint>
#include <mutex>
#include <shared_mutex>
#include <chrono>
using namespace bluevk;
namespace filament::backend {
FenceStatus VulkanCmdFence::wait(VkDevice device, uint64_t const timeout,
std::chrono::steady_clock::time_point const until) {
std::shared_lock l(mLock);
// If the vulkan fence has not been submitted yet, we need to wait for that before we
// can use vkWaitForFences()
if (mStatus == VK_INCOMPLETE) {
bool const success = mCond.wait_until(l, until, [this] {
// Internally we use the VK_INCOMPLETE status to mean "not yet submitted".
// When this fence gets submitted, its status changes to VK_NOT_READY.
return mStatus != VK_INCOMPLETE;
});
if (!success) {
// !success indicates a timeout
return FenceStatus::TIMEOUT_EXPIRED;
}
}
// The fence could have already signaled, avoid calling into vkWaitForFences()
if (mStatus == VK_SUCCESS) {
return FenceStatus::CONDITION_SATISFIED;
}
// If we're here, we know that vkQueueSubmit has been called (because it sets the status
// to VK_NOT_READY).
// Now really wait for the fence while holding the shared_lock, this allows several
// threads to call vkWaitForFences(), but will prevent vkResetFence from taking
// place simultaneously. vkResetFence is only called once it knows the fence has signaled,
// which guaranties that vkResetFence won't have to wait too long, just enough for
// all the vkWaitForFences() to return.
mStatus = vkWaitForFences(device, 1, &mFence, VK_TRUE, timeout);
if (mStatus == VK_SUCCESS) {
return FenceStatus::CONDITION_SATISFIED;
}
if (mStatus == VK_TIMEOUT) {
return FenceStatus::TIMEOUT_EXPIRED;
}
return FenceStatus::ERROR; // not supported
}
void VulkanCmdFence::resetFence(VkDevice device) {
// This lock prevents vkResetFences() from being called simultaneously with vkWaitForFences(),
// but by construction, when we're here, we know that the fence has signaled and
// vkWaitForFences() will return shortly.
std::lock_guard const l(mLock);
assert_invariant(mStatus == VK_SUCCESS);
vkResetFences(device, 1, &mFence);
}
} // namespace filament::backend
@@ -20,81 +20,37 @@
#include <bluevk/BlueVK.h>
#include "DriverBase.h"
#include "backend/DriverEnums.h"
#include "backend/Platform.h"
#include "vulkan/memory/Resource.h"
#include <chrono>
#include <cstdint>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <utility>
#include <vector>
#include <utils/Mutex.h>
#include <utils/Condition.h>
namespace filament::backend {
// Wrapper to enable use of shared_ptr for implementing shared ownership of low-level Vulkan fences.
struct VulkanCmdFence {
explicit VulkanCmdFence(VkFence fence) : mFence(fence) { }
VulkanCmdFence(VkResult initialStatus) {
// Internally we use the VK_INCOMPLETE status to mean "not yet submitted". When this fence
// gets submitted, its status changes to VK_NOT_READY. Finally, when the GPU actually
// finishes executing the command buffer, the status changes to VK_SUCCESS.
status.store(initialStatus);
}
~VulkanCmdFence() = default;
void setStatus(VkResult const value) {
std::lock_guard const l(mLock);
mStatus = value;
mCond.notify_all();
}
void setStatus(VkResult value) { status.store(value); }
VkResult getStatus() {
std::shared_lock const l(mLock);
return mStatus;
}
void resetFence(VkDevice device);
FenceStatus wait(VkDevice device, uint64_t timeout,
std::chrono::steady_clock::time_point until);
VkResult getStatus() { return status.load(std::memory_order_acquire); }
private:
std::shared_mutex mLock; // NOLINT(*-include-cleaner)
std::condition_variable_any mCond;
// Internally we use the VK_INCOMPLETE status to mean "not yet submitted". When this fence
// gets submitted, its status changes to VK_NOT_READY. Finally, when the GPU actually
// finishes executing the command buffer, the status changes to VK_SUCCESS.
VkResult mStatus{ VK_INCOMPLETE };
VkFence mFence;
std::atomic<VkResult> status;
};
struct VulkanFence : public HwFence, fvkmemory::ThreadSafeResource {
VulkanFence() {}
void setFence(std::shared_ptr<VulkanCmdFence> fence) {
std::lock_guard lock(mState->lock);
mState->sharedFence = std::move(fence);
mState->cond.notify_all();
}
std::shared_ptr<VulkanCmdFence>& getSharedFence() {
std::lock_guard lock(mState->lock);
return mState->sharedFence;
}
std::shared_ptr<VulkanCmdFence> wait(std::chrono::steady_clock::time_point const until) {
// hold a reference so that our state doesn't disappear while we wait
std::shared_ptr state{ mState };
std::unique_lock lock(state->lock);
state->cond.wait_until(lock, until, [&state] { return bool(state->sharedFence); });
// here mSharedFence will be null if we timed out
return state->sharedFence;
}
private:
struct State {
std::mutex lock;
std::condition_variable cond;
std::shared_ptr<VulkanCmdFence> sharedFence;
};
std::shared_ptr<State> mState{ std::make_shared<State>() };
std::shared_ptr<VulkanCmdFence> fence;
};
struct VulkanSync : fvkmemory::ThreadSafeResource, public HwSync {
@@ -116,12 +72,12 @@ struct VulkanTimerQuery : public HwTimerQuery, fvkmemory::ThreadSafeResource {
mStoppingQueryIndex(stoppingIndex) {}
void setFence(std::shared_ptr<VulkanCmdFence> fence) noexcept {
std::unique_lock const lock(mFenceMutex);
mFence = std::move(fence);
std::unique_lock<utils::Mutex> lock(mFenceMutex);
mFence = fence;
}
bool isCompleted() noexcept {
std::unique_lock const lock(mFenceMutex);
std::unique_lock<utils::Mutex> lock(mFenceMutex);
// QueryValue is a synchronous call and might occur before beginTimerQuery has written
// anything into the command buffer, which is an error according to the validation layer
// that ships in the Android NDK. Even when AVAILABILITY_BIT is set, validation seems to
@@ -28,24 +28,24 @@ namespace filament::backend {
namespace {
VkBufferUsageFlags getVkBufferUsage(VulkanBufferBinding usage) {
VkBufferUsageFlags getVkBufferUsage(VulkanBufferUsage usage) {
switch (usage) {
case VulkanBufferBinding::VERTEX:
case VulkanBufferUsage::VERTEX:
return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
case VulkanBufferBinding::INDEX:
case VulkanBufferUsage::INDEX:
return VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
case VulkanBufferBinding::UNIFORM:
case VulkanBufferUsage::UNIFORM:
return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
case VulkanBufferBinding::SHADER_STORAGE:
case VulkanBufferUsage::SHADER_STORAGE:
return VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
case VulkanBufferBinding::UNKNOWN:
case VulkanBufferUsage::UNKNOWN:
return 0;
}
return 0;
}
} // namespace
}// namespace
VulkanBufferCache::VulkanBufferCache(VulkanContext const& context,
fvkmemory::ResourceManager& resourceManager, VmaAllocator allocator)
@@ -53,11 +53,11 @@ VulkanBufferCache::VulkanBufferCache(VulkanContext const& context,
mResourceManager(resourceManager),
mAllocator(allocator) {}
fvkmemory::resource_ptr<VulkanBuffer> VulkanBufferCache::acquire(VulkanBufferBinding binding,
fvkmemory::resource_ptr<VulkanBuffer> VulkanBufferCache::acquire(VulkanBufferUsage usage,
uint32_t numBytes) noexcept {
assert_invariant(binding != VulkanBufferBinding::UNKNOWN);
assert_invariant(usage != VulkanBufferUsage::UNKNOWN);
BufferPool& bufferPool = getPool(binding);
BufferPool& bufferPool = getPool(usage);
// First check if an allocation exists whose capacity is greater than or equal to the requested
// size.
@@ -71,7 +71,7 @@ fvkmemory::resource_ptr<VulkanBuffer> VulkanBufferCache::acquire(VulkanBufferBin
// We were not able to find a sufficiently large allocation, so create a new one that is
// recycled after being yielded.
VulkanGpuBuffer const* gpuBuffer = allocate(binding, numBytes);
VulkanGpuBuffer const* gpuBuffer = allocate(usage, numBytes);
return fvkmemory::resource_ptr<VulkanBuffer>::construct(&mResourceManager, gpuBuffer,
[this](VulkanGpuBuffer const* gpuBuffer) { this->release(gpuBuffer); });
}
@@ -93,10 +93,9 @@ void VulkanBufferCache::gc() noexcept {
if (poolIter->second.lastAccessed < evictionTime) {
#if FVK_ENABLED(FVK_DEBUG_VULKAN_BUFFER_CACHE)
FVK_LOGD << "VulkanBufferCache - Destroyed vkBuffer "
<< poolIter->second.gpuBuffer->vkbuffer << " with binding "
<< static_cast<int>(poolIter->second.gpuBuffer->binding)
<< utils::io::endl;
#endif // FVK_DEBUG_VULKAN_BUFFER_CACHE
<< poolIter->second.gpuBuffer->vkbuffer << " with usage "
<< static_cast<int>(poolIter->second.gpuBuffer->usage) << utils::io::endl;
#endif// FVK_DEBUG_VULKAN_BUFFER_CACHE
destroy(poolIter->second.gpuBuffer);
poolIter = bufferPool.erase(poolIter);
@@ -121,33 +120,35 @@ void VulkanBufferCache::terminate() noexcept {
void VulkanBufferCache::release(VulkanGpuBuffer const* gpuBuffer) noexcept {
assert_invariant(gpuBuffer != nullptr);
BufferPool& bufferPool = getPool(gpuBuffer->binding);
BufferPool& bufferPool = getPool(gpuBuffer->usage);
bufferPool.insert(std::make_pair(gpuBuffer->numBytes, UnusedGpuBuffer{
.lastAccessed = mCurrentFrame,
.gpuBuffer = gpuBuffer,
}));
}
VulkanGpuBuffer const* VulkanBufferCache::allocate(VulkanBufferBinding binding,
VulkanGpuBuffer const* VulkanBufferCache::allocate(VulkanBufferUsage usage,
uint32_t numBytes) noexcept {
VkBufferCreateInfo const bufferInfo{
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.size = numBytes,
// `VK_BUFFER_USAGE_TRANSFER_DST_BIT` is needed to allow updating the buffer through
// a staging using `vkCmdCopyBuffer`.
.usage = getVkBufferUsage(binding) | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
.usage = getVkBufferUsage(usage) | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
};
VmaAllocationCreateFlags vmaFlags = 0;
// In the case of UMA, the buffers will always be mappable
if (mContext.isUnifiedMemoryArchitecture()) {
vmaFlags |= VMA_ALLOCATION_CREATE_MAPPED_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
if (usage == VulkanBufferUsage::UNIFORM) {
// In the case of UMA, the uniform buffers will always be mappable
if (mContext.isUnifiedMemoryArchitecture()) {
vmaFlags |= VMA_ALLOCATION_CREATE_MAPPED_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
}
}
VulkanGpuBuffer* gpuBuffer = new VulkanGpuBuffer{
.numBytes = numBytes,
.binding = binding,
.usage = usage,
};
VmaAllocationCreateInfo const allocInfo{
.flags = vmaFlags,
@@ -160,14 +161,14 @@ VulkanGpuBuffer const* VulkanBufferCache::allocate(VulkanBufferBinding binding,
#if FVK_ENABLED(FVK_DEBUG_VULKAN_BUFFER_CACHE)
if (result != VK_SUCCESS) {
FVK_LOGE << "VulkanBufferCache - failed to allocate a new vkBuffer of size " << numBytes
<< " and binding " << static_cast<int>(binding) << ", error: " << result
<< " and usage " << static_cast<int>(usage) << ", error: " << result
<< utils::io::endl;
} else {
FVK_LOGD << "VulkanBufferCache - allocated a vkBuffer " << gpuBuffer->vkbuffer
<< " of size " << numBytes << " and binding = " << static_cast<int>(binding)
<< " of size " << numBytes << " and usage = " << static_cast<int>(usage)
<< " successfully" << utils::io::endl;
}
#endif // FVK_DEBUG_VULKAN_BUFFER_CACHE
#endif// FVK_DEBUG_VULKAN_BUFFER_CACHE
return gpuBuffer;
}
@@ -178,24 +179,24 @@ void VulkanBufferCache::destroy(VulkanGpuBuffer const* gpuBuffer) noexcept {
gpuBuffer = nullptr;
}
VulkanBufferCache::BufferPool& VulkanBufferCache::getPool(VulkanBufferBinding binding) noexcept {
VulkanBufferCache::BufferPool& VulkanBufferCache::getPool(VulkanBufferUsage usage) noexcept {
int poolIndex = -1;
switch (binding) {
case VulkanBufferBinding::VERTEX:
switch (usage) {
case VulkanBufferUsage::VERTEX:
poolIndex = 0;
break;
case VulkanBufferBinding::INDEX:
case VulkanBufferUsage::INDEX:
poolIndex = 1;
break;
case VulkanBufferBinding::UNIFORM:
case VulkanBufferUsage::UNIFORM:
poolIndex = 2;
break;
case VulkanBufferBinding::SHADER_STORAGE:
case VulkanBufferUsage::SHADER_STORAGE:
poolIndex = 3;
break;
case VulkanBufferBinding::UNKNOWN:
PANIC_LOG("There's no pool for buffers with unkown binding.");
case VulkanBufferUsage::UNKNOWN:
PANIC_LOG("There's no pool for buffers with unkown usage.");
break;
}
@@ -203,4 +204,4 @@ VulkanBufferCache::BufferPool& VulkanBufferCache::getPool(VulkanBufferBinding bi
return mGpuBufferPools[poolIndex];
}
} // namespace filament::backend
}// namespace filament::backend
@@ -38,7 +38,7 @@ public:
// Allocates or reuse a new VkBuffer that is device local.
// In the case of Unified memory architecture, uniform buffers are also host visible.
fvkmemory::resource_ptr<VulkanBuffer> acquire(VulkanBufferBinding binding,
fvkmemory::resource_ptr<VulkanBuffer> acquire(VulkanBufferUsage usage,
uint32_t numBytes) noexcept;
// Evicts old unused `VulkanGpuBuffer` and bumps the current frame number
@@ -60,12 +60,12 @@ private:
void release(VulkanGpuBuffer const* gpuBuffer) noexcept;
// Allocate a new VkBuffer from the VMA pool of the corresponding `numBytes` and `usage`.
VulkanGpuBuffer const* allocate(VulkanBufferBinding binding, uint32_t numBytes) noexcept;
VulkanGpuBuffer const* allocate(VulkanBufferUsage usage, uint32_t numBytes) noexcept;
// Destroy the corresponding VkBuffer and return the VkDeviceMemory to the VMA pool.
void destroy(VulkanGpuBuffer const* gpuBuffer) noexcept;
BufferPool& getPool(VulkanBufferBinding binding) noexcept;
BufferPool& getPool(VulkanBufferUsage usage) noexcept;
VulkanContext const& mContext;
fvkmemory::ResourceManager& mResourceManager;
@@ -19,25 +19,22 @@
#include "VulkanBufferCache.h"
#include "VulkanCommands.h"
#include "VulkanContext.h"
#include "VulkanHandles.h"
#include "VulkanMemory.h"
#include <backend/DriverEnums.h>
#include "VulkanHandles.h"
using namespace bluevk;
namespace filament::backend {
VulkanBufferProxy::VulkanBufferProxy(VulkanContext const& context, VmaAllocator allocator,
VulkanStagePool& stagePool, VulkanBufferCache& bufferCache, VulkanBufferBinding binding,
BufferUsage usage, uint32_t numBytes)
VulkanStagePool& stagePool, VulkanBufferCache& bufferCache, VulkanBufferUsage usage,
uint32_t numBytes)
: mStagingBufferBypassEnabled(context.stagingBufferBypassEnabled()),
mAllocator(allocator),
mStagePool(stagePool),
mBufferCache(bufferCache),
mBuffer(mBufferCache.acquire(binding, numBytes)),
mLastReadAge(0),
mUsage(usage) {}
mBuffer(mBufferCache.acquire(usage, numBytes)),
mLastReadAge(0) {}
void VulkanBufferProxy::loadFromCpu(VulkanCommandBuffer& commands, const void* cpuData,
uint32_t byteOffset, uint32_t numBytes) {
@@ -52,18 +49,12 @@ void VulkanBufferProxy::loadFromCpu(VulkanCommandBuffer& commands, const void* c
commands.acquire(mBuffer);
// Check if we can just memcpy directly to the GPU memory.
// This is only allowed for UNIFORMS that are AVAILABLE and the memory is HOST_VISIBLE
// (supports memcpy from host). This works regardless if it's a full or partial update of the
// buffer.
bool const isMemcopyable = mBuffer->getGpuBuffer()->allocationInfo.pMappedData != nullptr;
// In the case of UNIFORMS, check that is available to see to know if a memcpy is possible.
// This works regardless if it's a full or partial update of the buffer.
bool const isUniformAndAvailable = getBinding() == VulkanBufferBinding::UNIFORM && isAvailable;
// In the case the content is marked as memory mapped or static, is guaranteed to be safe to do
// a memcpy if its available.
bool const isStaticOrShared =
any(mUsage & (BufferUsage::STATIC | BufferUsage::SHARED_WRITE_BIT));
bool const useMemcpy = (isUniformAndAvailable || isStaticOrShared) && isMemcopyable &&
mStagingBufferBypassEnabled;
bool const isUniform = getUsage() == VulkanBufferUsage::UNIFORM;
bool const useMemcpy = isUniform && isMemcopyable && isAvailable && mStagingBufferBypassEnabled;
if (useMemcpy) {
char* dest = static_cast<char*>(mBuffer->getGpuBuffer()->allocationInfo.pMappedData) +
byteOffset;
@@ -90,13 +81,13 @@ void VulkanBufferProxy::loadFromCpu(VulkanCommandBuffer& commands, const void* c
if (!isAvailable) {
VkAccessFlags srcAccess = 0;
VkPipelineStageFlags srcStage = 0;
if (getBinding() == VulkanBufferBinding::UNIFORM) {
if (getUsage() == VulkanBufferUsage::UNIFORM) {
srcAccess = VK_ACCESS_SHADER_READ_BIT;
srcStage = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
} else if (getBinding() == VulkanBufferBinding::VERTEX) {
} else if (getUsage() == VulkanBufferUsage::VERTEX) {
srcAccess = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
srcStage = VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
} else if (getBinding() == VulkanBufferBinding::INDEX) {
} else if (getUsage() == VulkanBufferUsage::INDEX) {
srcAccess = VK_ACCESS_INDEX_READ_BIT;
srcStage = VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
}
@@ -129,16 +120,16 @@ void VulkanBufferProxy::loadFromCpu(VulkanCommandBuffer& commands, const void* c
VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
if (getBinding() == VulkanBufferBinding::VERTEX) {
if (getUsage() == VulkanBufferUsage::VERTEX) {
dstAccessMask |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
dstStageMask |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
} else if (getBinding() == VulkanBufferBinding::INDEX) {
} else if (getUsage() == VulkanBufferUsage::INDEX) {
dstAccessMask |= VK_ACCESS_INDEX_READ_BIT;
dstStageMask |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
} else if (getBinding() == VulkanBufferBinding::UNIFORM) {
} else if (getUsage() == VulkanBufferUsage::UNIFORM) {
dstAccessMask |= VK_ACCESS_SHADER_READ_BIT;
dstStageMask |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
} else if (getBinding() == VulkanBufferBinding::SHADER_STORAGE) {
} else if (getUsage() == VulkanBufferUsage::SHADER_STORAGE) {
// TODO: implement me
}
@@ -161,8 +152,8 @@ VkBuffer VulkanBufferProxy::getVkBuffer() const noexcept {
return mBuffer->getGpuBuffer()->vkbuffer;
}
VulkanBufferBinding VulkanBufferProxy::getBinding() const noexcept {
return mBuffer->getGpuBuffer()->binding;
VulkanBufferUsage VulkanBufferProxy::getUsage() const noexcept {
return mBuffer->getGpuBuffer()->usage;
}
void VulkanBufferProxy::referencedBy(VulkanCommandBuffer& commands) {
@@ -23,8 +23,6 @@
#include "VulkanMemory.h"
#include "VulkanStagePool.h"
#include <backend/DriverEnums.h>
namespace filament::backend {
struct VulkanDescriptorSet;
@@ -35,8 +33,8 @@ struct VulkanCommandBuffer;
class VulkanBufferProxy {
public:
VulkanBufferProxy(VulkanContext const& context, VmaAllocator allocator,
VulkanStagePool& stagePool, VulkanBufferCache& bufferCache, VulkanBufferBinding binding,
BufferUsage usage, uint32_t numBytes);
VulkanStagePool& stagePool, VulkanBufferCache& bufferCache, VulkanBufferUsage usage,
uint32_t numBytes);
void loadFromCpu(VulkanCommandBuffer& commands, const void* cpuData, uint32_t byteOffset,
uint32_t numBytes);
@@ -46,7 +44,7 @@ public:
void referencedBy(VulkanCommandBuffer& commands);
private:
VulkanBufferBinding getBinding() const noexcept;
VulkanBufferUsage getUsage() const noexcept;
bool const mStagingBufferBypassEnabled;
VmaAllocator mAllocator;
@@ -56,7 +54,6 @@ private:
fvkmemory::resource_ptr<VulkanBuffer> mBuffer;
uint32_t mLastReadAge;
BufferUsage mUsage;
};
} // namespace filament::backend
+27 -36
View File
@@ -90,17 +90,18 @@ bool VulkanGroupMarkers::empty() const noexcept {
uint32_t VulkanCommandBuffer::sAgeCounter = 0;
VulkanCommandBuffer::VulkanCommandBuffer(VulkanContext const& context, VkDevice device,
VkQueue queue, VkCommandPool pool, VulkanSemaphoreManager* semaphoreManager,
bool isProtected)
VkQueue queue, VkCommandPool pool, bool isProtected)
: mContext(context),
mMarkerCount(0),
isProtected(isProtected),
mDevice(device),
mQueue(queue),
mSemaphoreManager(semaphoreManager),
mBuffer(createCommandBuffer(device, pool)),
mSubmission(semaphoreManager->acquire()),
mFenceStatus(std::make_shared<VulkanCmdFence>(VK_INCOMPLETE)),
mAge(++sAgeCounter) {
VkSemaphoreCreateInfo sci{.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
vkCreateSemaphore(mDevice, &sci, VKALLOC, &mSubmission);
VkFenceCreateInfo fenceCreateInfo{.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
VkExportFenceCreateInfo exportFenceCreateInfo{
.sType = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO,
@@ -112,11 +113,10 @@ VulkanCommandBuffer::VulkanCommandBuffer(VulkanContext const& context, VkDevice
fenceCreateInfo.pNext = &exportFenceCreateInfo;
}
vkCreateFence(device, &fenceCreateInfo, VKALLOC, &mFence);
mFenceStatus = std::make_shared<VulkanCmdFence>(mFence);
}
VulkanCommandBuffer::~VulkanCommandBuffer() {
vkDestroySemaphore(mDevice, mSubmission, VKALLOC);
vkDestroyFence(mDevice, mFence, VKALLOC);
}
@@ -126,15 +126,12 @@ void VulkanCommandBuffer::reset() noexcept {
mWaitSemaphores.clear();
mWaitSemaphoreStages.clear();
mAge = ++sAgeCounter;
mSubmission = mSemaphoreManager->acquire();
// reset the fence with proper host synchronization
mFenceStatus->resetFence(mDevice);
// Internally we use the VK_INCOMPLETE status to mean "not yet submitted". When this fence
// gets, gets submitted, its status changes to VK_NOT_READY. Finally, when the GPU actually
// finishes executing the command buffer, the status changes to VK_SUCCESS.
mFenceStatus = std::make_shared<VulkanCmdFence>(mFence);
mFenceStatus = std::make_shared<VulkanCmdFence>(VK_INCOMPLETE);
vkResetFences(mDevice, 1, &mFence);
}
void VulkanCommandBuffer::pushMarker(char const* marker) noexcept {
@@ -193,14 +190,13 @@ void VulkanCommandBuffer::begin() noexcept {
vkBeginCommandBuffer(mBuffer, &binfo);
}
fvkmemory::resource_ptr<VulkanSemaphore> VulkanCommandBuffer::submit() {
VkSemaphore VulkanCommandBuffer::submit() {
while (mMarkerCount > 0) {
popMarker();
}
vkEndCommandBuffer(mBuffer);
VkSemaphore submissionSemaphore = mSubmission->getVkSemaphore();
VkSubmitInfo submitInfo{
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.waitSemaphoreCount = mWaitSemaphores.size(),
@@ -209,7 +205,7 @@ fvkmemory::resource_ptr<VulkanSemaphore> VulkanCommandBuffer::submit() {
.commandBufferCount = 1u,
.pCommandBuffers = &mBuffer,
.signalSemaphoreCount = 1u,
.pSignalSemaphores = &submissionSemaphore,
.pSignalSemaphores = &mSubmission,
};
// add submit protection if needed
VkProtectedSubmitInfo protectedSubmitInfo{
@@ -230,13 +226,13 @@ fvkmemory::resource_ptr<VulkanSemaphore> VulkanCommandBuffer::submit() {
<< (s < mWaitSemaphores.size() - 1 ? "\n" : "");
}
FVK_LOGI << ") "
<< " signal=" << submissionSemaphore
<< " signal=" << mSubmission
<< " fence=" << mFence;
#endif
mFenceStatus->setStatus(VK_NOT_READY);
UTILS_UNUSED_IN_RELEASE VkResult result =
vkQueueSubmit(mQueue, 1, &submitInfo, mFence);
mFenceStatus->setStatus(VK_NOT_READY);
#if FVK_ENABLED(FVK_DEBUG_COMMAND_BUFFER)
if (result != VK_SUCCESS) {
@@ -249,7 +245,7 @@ fvkmemory::resource_ptr<VulkanSemaphore> VulkanCommandBuffer::submit() {
}
CommandBufferPool::CommandBufferPool(VulkanContext const& context, VkDevice device, VkQueue queue,
uint8_t queueFamilyIndex, VulkanSemaphoreManager* semaphoreManager, bool isProtected)
uint8_t queueFamilyIndex, bool isProtected)
: mDevice(device),
mRecording(INVALID) {
VkCommandPoolCreateInfo createInfo = {
@@ -262,8 +258,8 @@ CommandBufferPool::CommandBufferPool(VulkanContext const& context, VkDevice devi
vkCreateCommandPool(device, &createInfo, VKALLOC, &mPool);
for (size_t i = 0; i < CAPACITY; ++i) {
mBuffers.emplace_back(std::make_unique<VulkanCommandBuffer>(
context, device, queue, mPool, semaphoreManager, isProtected));
mBuffers.emplace_back(
std::make_unique<VulkanCommandBuffer>(context, device, queue, mPool, isProtected));
}
}
@@ -335,10 +331,10 @@ void CommandBufferPool::update() {
});
}
fvkmemory::resource_ptr<VulkanSemaphore> CommandBufferPool::flush() {
VkSemaphore CommandBufferPool::flush() {
// We're not recording right now.
if (!isRecording()) {
return {};
return VK_NULL_HANDLE;
}
auto submitSemaphore = mBuffers[mRecording]->submit();
mSubmitted.set(mRecording, true);
@@ -400,21 +396,16 @@ void CommandBufferPool::insertEvent(char const* marker) {
#endif // FVK_DEBUG_GROUP_MARKERS
VulkanCommands::VulkanCommands(VkDevice device, VkQueue queue, uint32_t queueFamilyIndex,
VkQueue protectedQueue, uint32_t protectedQueueFamilyIndex, VulkanContext const& context,
VulkanSemaphoreManager* semaphoreManager)
VkQueue protectedQueue, uint32_t protectedQueueFamilyIndex, VulkanContext const& context)
: mDevice(device),
mProtectedQueue(protectedQueue),
mProtectedQueueFamilyIndex(protectedQueueFamilyIndex),
mContext(context),
mSemaphoreManager(semaphoreManager),
mPool(std::make_unique<CommandBufferPool>(
context, device, queue, queueFamilyIndex, semaphoreManager, false)) {}
mPool(std::make_unique<CommandBufferPool>(context, device, queue, queueFamilyIndex, false)) {}
void VulkanCommands::terminate() {
mPool.reset();
mProtectedPool.reset();
mLastSubmit = {};
mLastFenceStatus = {};
}
VulkanCommandBuffer& VulkanCommands::get() {
@@ -427,7 +418,7 @@ VulkanCommandBuffer& VulkanCommands::getProtected() {
if (!mProtectedPool) {
mProtectedPool = std::make_unique<CommandBufferPool>(mContext, mDevice, mProtectedQueue,
mProtectedQueueFamilyIndex, mSemaphoreManager, true);
mProtectedQueueFamilyIndex, true);
}
auto& ret = mProtectedPool->getRecording();
return ret;
@@ -439,8 +430,8 @@ bool VulkanCommands::flush() {
return false;
}
VkSemaphore injectedDependency = mInjectedDependency;
fvkmemory::resource_ptr<VulkanSemaphore> dependency;
VkSemaphore dependency = mInjectedDependency;
VkSemaphore lastSubmit = mLastSubmit;
bool hasFlushed = false;
VkFence flushedFence = VK_NULL_HANDLE;
@@ -453,19 +444,19 @@ bool VulkanCommands::flush() {
if (!pool || !pool->isRecording()) {
continue;
}
if (injectedDependency != VK_NULL_HANDLE) {
pool->waitFor(injectedDependency, mInjectedDependencyWaitStage);
if (dependency != VK_NULL_HANDLE) {
pool->waitFor(dependency, mInjectedDependencyWaitStage);
}
if (mLastSubmit) {
if (lastSubmit != VK_NULL_HANDLE) {
// Note that the stage we're waiting on is the fragment shader stage. This assumes
// that the subsequent command buffer will only depend on
// 1) fragment output of the previous command buffer
// 2) reading/writing of buffers (i.e. UBO) of the previous command buffer
// Restricting the wait stages will allow for vertex work to proceed (more overlapping
// vertex/fragment work).
pool->waitFor(mLastSubmit->getVkSemaphore(),
pool->waitFor(lastSubmit,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT);
mLastSubmit = {};
lastSubmit = VK_NULL_HANDLE;
}
flushedFence = pool->getRecording().getVkFence();
flushedFenceStatus = pool->getRecording().getFenceStatus();
+12 -15
View File
@@ -24,7 +24,6 @@
#include "VulkanAsyncHandles.h"
#include "VulkanConstants.h"
#include "VulkanContext.h"
#include "VulkanSemaphoreManager.h"
#include "vulkan/memory/ResourcePointer.h"
#include "vulkan/utils/StaticVector.h"
@@ -64,8 +63,8 @@ private:
// DriverApi fence object and should not be destroyed until both the DriverApi object is freed and
// we're done waiting on the most recent submission of the given command buffer.
struct VulkanCommandBuffer {
VulkanCommandBuffer(VulkanContext const& mContext, VkDevice device, VkQueue queue,
VkCommandPool pool, VulkanSemaphoreManager* semaphoreManager, bool isProtected);
VulkanCommandBuffer(VulkanContext const& mContext,
VkDevice device, VkQueue queue, VkCommandPool pool, bool isProtected);
VulkanCommandBuffer(VulkanCommandBuffer const&) = delete;
VulkanCommandBuffer& operator=(VulkanCommandBuffer const&) = delete;
@@ -88,7 +87,7 @@ struct VulkanCommandBuffer {
void insertEvent(char const* marker) noexcept;
void begin() noexcept;
fvkmemory::resource_ptr<VulkanSemaphore> submit();
VkSemaphore submit();
inline void setComplete() {
mFenceStatus->setStatus(VK_SUCCESS);
@@ -122,11 +121,10 @@ private:
bool const isProtected;
VkDevice mDevice;
VkQueue mQueue;
VulkanSemaphoreManager* mSemaphoreManager;
fvkutils::StaticVector<VkSemaphore, 2> mWaitSemaphores;
fvkutils::StaticVector<VkPipelineStageFlags, 2> mWaitSemaphoreStages;
VkCommandBuffer mBuffer;
fvkmemory::resource_ptr<VulkanSemaphore> mSubmission;
VkSemaphore mSubmission;
VkFence mFence;
std::shared_ptr<VulkanCmdFence> mFenceStatus;
std::vector<fvkmemory::resource_ptr<Resource>> mResources;
@@ -138,14 +136,14 @@ struct CommandBufferPool {
static constexpr int8_t INVALID = -1;
CommandBufferPool(VulkanContext const& context, VkDevice device, VkQueue queue,
uint8_t queueFamilyIndex, VulkanSemaphoreManager* semaphoreManager, bool isProtected);
uint8_t queueFamilyIndex, bool isProtected);
~CommandBufferPool();
VulkanCommandBuffer& getRecording();
void gc();
void update();
fvkmemory::resource_ptr<VulkanSemaphore> flush();
VkSemaphore flush();
void wait();
void waitFor(VkSemaphore previousAction, VkPipelineStageFlags waitStage);
@@ -206,7 +204,7 @@ class VulkanCommands {
public:
VulkanCommands(VkDevice device, VkQueue queue, uint32_t queueFamilyIndex,
VkQueue protectedQueue, uint32_t protectedQueueFamilyIndex,
VulkanContext const& context, VulkanSemaphoreManager* semaphoreManager);
VulkanContext const& context);
void terminate();
@@ -224,10 +222,10 @@ public:
// Returns the "rendering finished" semaphore for the most recent flush and removes
// it from the existing dependency chain. This is especially useful for setting up
// vkQueuePresentKHR.
fvkmemory::resource_ptr<VulkanSemaphore> acquireFinishedSignal() {
fvkmemory::resource_ptr<VulkanSemaphore> sem = mLastSubmit;
mLastSubmit = {};
return sem;
VkSemaphore acquireFinishedSignal() {
VkSemaphore ret = mLastSubmit;
mLastSubmit = VK_NULL_HANDLE;
return ret;
}
VkFence getMostRecentFence() {
@@ -268,13 +266,12 @@ private:
// For defered initialization if/when we need protected content
uint32_t const mProtectedQueueFamilyIndex;
VulkanContext const& mContext;
VulkanSemaphoreManager* mSemaphoreManager;
std::unique_ptr<CommandBufferPool> mPool;
std::unique_ptr<CommandBufferPool> mProtectedPool;
VkSemaphore mInjectedDependency = VK_NULL_HANDLE;
fvkmemory::resource_ptr<VulkanSemaphore> mLastSubmit;
VkSemaphore mLastSubmit = VK_NULL_HANDLE;
VkFence mLastFence = VK_NULL_HANDLE;
std::shared_ptr<VulkanCmdFence> mLastFenceStatus;
+22 -30
View File
@@ -43,8 +43,6 @@
#include <set> // For VulkanDriver::debugCommandBegin
#endif
#include <chrono>
using namespace bluevk;
#if defined(__clang__)
@@ -224,10 +222,9 @@ VulkanDriver::VulkanDriver(VulkanPlatform* platform, VulkanContext& context,
mAllocator(createAllocator(mPlatform->getInstance(), mPlatform->getPhysicalDevice(),
mPlatform->getDevice())),
mContext(context),
mSemaphoreManager(mPlatform->getDevice(), &mResourceManager),
mCommands(mPlatform->getDevice(), mPlatform->getGraphicsQueue(),
mPlatform->getGraphicsQueueFamilyIndex(), mPlatform->getProtectedGraphicsQueue(),
mPlatform->getProtectedGraphicsQueueFamilyIndex(), mContext, &mSemaphoreManager),
mPlatform->getProtectedGraphicsQueueFamilyIndex(), mContext),
mPipelineLayoutCache(mPlatform->getDevice()),
mPipelineCache(mPlatform->getDevice()),
mStagePool(mAllocator, &mResourceManager, &mCommands, &mContext.getPhysicalDeviceLimits()),
@@ -322,9 +319,8 @@ ShaderModel VulkanDriver::getShaderModel() const noexcept {
#endif
}
utils::FixedCapacityVector<ShaderLanguage> VulkanDriver::getShaderLanguages(
ShaderLanguage /*prefferedLanguage*/) const noexcept {
return { ShaderLanguage::SPIRV };
ShaderLanguage VulkanDriver::getShaderLanguage() const noexcept {
return ShaderLanguage::SPIRV;
}
void VulkanDriver::terminate() {
@@ -369,9 +365,6 @@ void VulkanDriver::terminate() {
// reclaimed, as they perform cleanup within the stage pool.
mStagePool.terminate();
// By this point, all of the VkSemaphores should have been returned to the pool.
mSemaphoreManager.terminate();
#if FVK_ENABLED(FVK_DEBUG_RESOURCE_LEAK)
mResourceManager.print();
#endif
@@ -602,7 +595,7 @@ void VulkanDriver::createBufferObjectR(Handle<HwBufferObject> boh, uint32_t byte
BufferObjectBinding bindingType, BufferUsage usage, utils::CString&& tag) {
FVK_SYSTRACE_SCOPE();
auto bo = resource_ptr<VulkanBufferObject>::make(&mResourceManager, boh, mContext, mAllocator,
mStagePool, mBufferCache, byteCount, bindingType, usage);
mStagePool, mBufferCache, byteCount, bindingType);
bo.inc();
mResourceManager.associateHandle(boh.getId(), std::move(tag));
}
@@ -857,7 +850,7 @@ void VulkanDriver::createFenceR(Handle<HwFence> fh, utils::CString&& tag) {
// it with appropriate VulkanCmdFence, which is associated with the current, recording command
// buffer.
auto fence = resource_ptr<VulkanFence>::cast(&mResourceManager, fh);
fence->setFence(cmdbuf->getFenceStatus());
fence->fence = cmdbuf->getFenceStatus();
mResourceManager.associateHandle(fh.getId(), std::move(tag));
}
@@ -1158,30 +1151,29 @@ void VulkanDriver::destroyFence(Handle<HwFence> fh) {
fence.dec();
}
FenceStatus VulkanDriver::getFenceStatus(Handle<HwFence> const fh) {
return fenceWait(fh, 0);
}
FenceStatus VulkanDriver::fenceWait(FenceHandle const fh, uint64_t const timeout) {
FenceStatus VulkanDriver::getFenceStatus(Handle<HwFence> fh) {
auto fence = resource_ptr<VulkanFence>::cast(&mResourceManager, fh);
// we have to take into account that the STL's wait_for() actually works with
// time_points relative to steady_clock::now() internally.
using namespace std::chrono;
auto const now = steady_clock::now();
steady_clock::time_point until = steady_clock::time_point::max();
if (now <= steady_clock::time_point::max() - nanoseconds(timeout)) {
until = now + nanoseconds(timeout);
}
std::shared_ptr const cmdfence = fence->wait(until);
auto& cmdfence = fence->fence;
if (!cmdfence) {
// If wait is called before a fence actually exists, we return timeout. This matches the
// current behavior in OpenGLDriver, but we should eventually reconsider a different error
// code.
return FenceStatus::TIMEOUT_EXPIRED;
}
// now we are holding a reference to our VulkanCmdFence, so we know it can't
// disappear while we wait
return cmdfence->wait(mPlatform->getDevice(), timeout, until);
// Internally we use the VK_INCOMPLETE status to mean "not yet submitted".
// When this fence gets submitted, its status changes to VK_NOT_READY.
if (cmdfence->getStatus() == VK_SUCCESS) {
return FenceStatus::CONDITION_SATISFIED;
}
// Two other states are possible:
// - VK_INCOMPLETE: the corresponding buffer has not yet been submitted.
// - VK_NOT_READY: the buffer has been submitted but not yet signaled.
// In either case, we return TIMEOUT_EXPIRED to indicate the fence has not been signaled.
return FenceStatus::TIMEOUT_EXPIRED;
}
void VulkanDriver::getPlatformSync(Handle<HwSync> sh, CallbackHandler* handler,
+1 -5
View File
@@ -28,7 +28,6 @@
#include "VulkanQueryManager.h"
#include "VulkanReadPixels.h"
#include "VulkanSamplerCache.h"
#include "VulkanSemaphoreManager.h"
#include "VulkanStagePool.h"
#include "VulkanYcbcrConversionCache.h"
#include "vulkan/VulkanDescriptorSetCache.h"
@@ -44,7 +43,6 @@
#include "DriverBase.h"
#include "private/backend/Driver.h"
#include <utils/FixedCapacityVector.h>
#include <utils/Allocator.h>
#include <utils/compiler.h>
@@ -102,8 +100,7 @@ private:
Dispatcher getDispatcher() const noexcept final;
ShaderModel getShaderModel() const noexcept final;
utils::FixedCapacityVector<ShaderLanguage> getShaderLanguages(
ShaderLanguage preferredLanguage) const noexcept final;
ShaderLanguage getShaderLanguage() const noexcept final;
template<typename T>
friend class ConcreteDispatcher;
@@ -142,7 +139,6 @@ private:
VulkanContext& mContext;
VulkanSemaphoreManager mSemaphoreManager;
VulkanCommands mCommands;
VulkanPipelineLayoutCache mPipelineLayoutCache;
VulkanPipelineCache mPipelineCache;
@@ -40,18 +40,18 @@ namespace filament::backend {
namespace {
inline VulkanBufferBinding getBufferObjectBinding(BufferObjectBinding bindingType) noexcept {
inline VulkanBufferUsage getBufferObjectUsage(BufferObjectBinding bindingType) noexcept {
switch (bindingType) {
case BufferObjectBinding::VERTEX:
return VulkanBufferBinding::VERTEX;
return VulkanBufferUsage::VERTEX;
case BufferObjectBinding::UNIFORM:
return VulkanBufferBinding::UNIFORM;
return VulkanBufferUsage::UNIFORM;
case BufferObjectBinding::SHADER_STORAGE:
return VulkanBufferBinding::SHADER_STORAGE;
return VulkanBufferUsage::SHADER_STORAGE;
// when adding more buffer-types here, make sure to update VulkanBuffer::loadFromCpu()
// if necessary.
}
return VulkanBufferBinding::UNKNOWN;
return VulkanBufferUsage::UNKNOWN;
}
void flipVertically(VkViewport* rect, uint32_t framebufferHeight) {
@@ -614,11 +614,10 @@ void VulkanVertexBuffer::setBuffer(fvkmemory::resource_ptr<VulkanBufferObject> b
VulkanBufferObject::VulkanBufferObject(VulkanContext const& context, VmaAllocator allocator,
VulkanStagePool& stagePool, VulkanBufferCache& bufferCache, uint32_t byteCount,
BufferObjectBinding bindingType, BufferUsage usage)
BufferObjectBinding bindingType)
: HwBufferObject(byteCount),
bindingType(bindingType),
mBuffer(context, allocator, stagePool, bufferCache, getBufferObjectBinding(bindingType),
usage, byteCount) {}
mBuffer(context, allocator, stagePool, bufferCache, getBufferObjectUsage(bindingType), byteCount) {}
VulkanRenderPrimitive::VulkanRenderPrimitive(PrimitiveType pt,
fvkmemory::resource_ptr<VulkanVertexBuffer> vb,
+3 -3
View File
@@ -477,8 +477,8 @@ struct VulkanIndexBuffer : public HwIndexBuffer, fvkmemory::Resource {
uint32_t indexCount)
: HwIndexBuffer(elementSize, indexCount),
indexType(elementSize == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32),
mBuffer(context, allocator, stagePool, bufferCache, VulkanBufferBinding::INDEX,
BufferUsage::STATIC, elementSize * indexCount) {}
mBuffer(context, allocator, stagePool, bufferCache, VulkanBufferUsage::INDEX,
elementSize * indexCount) {}
inline void loadFromCpu(VulkanCommandBuffer& commands, const void* cpuData, uint32_t byteOffset,
uint32_t numBytes) {
@@ -496,7 +496,7 @@ private:
struct VulkanBufferObject : public HwBufferObject, fvkmemory::Resource {
VulkanBufferObject(VulkanContext const& context, VmaAllocator allocator,
VulkanStagePool& stagePool, VulkanBufferCache& bufferCache, uint32_t byteCount,
BufferObjectBinding bindingType, BufferUsage usage);
BufferObjectBinding bindingType);
inline void loadFromCpu(VulkanCommandBuffer& commands, const void* cpuData, uint32_t byteOffset,
uint32_t numBytes) {
+2 -2
View File
@@ -39,7 +39,7 @@ VK_DEFINE_HANDLE(VmaPool)
namespace filament::backend {
enum class VulkanBufferBinding : uint8_t {
enum class VulkanBufferUsage : uint8_t {
UNKNOWN,
VERTEX,
INDEX,
@@ -52,7 +52,7 @@ struct VulkanGpuBuffer {
VmaAllocation vmaAllocation = VK_NULL_HANDLE;
VmaAllocationInfo allocationInfo;
uint32_t numBytes = 0;
VulkanBufferBinding binding = VulkanBufferBinding::UNKNOWN;
VulkanBufferUsage usage = VulkanBufferUsage::UNKNOWN;
};
} // namespace filament::backend
@@ -1,29 +0,0 @@
/*
* Copyright (C) 2025 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 "vulkan/VulkanSemaphore.h"
#include "vulkan/VulkanSemaphoreManager.h"
namespace filament::backend {
VulkanSemaphore::VulkanSemaphore(VulkanSemaphoreManager* manager, VkSemaphore semaphore)
: mManager(manager), mSemaphore(semaphore) {}
VulkanSemaphore::~VulkanSemaphore() {
mManager->recycle(mSemaphore);
}
} // namespace filament::backend
@@ -1,42 +0,0 @@
/*
* Copyright (C) 2025 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 TNT_FILAMENT_BACKEND_VULKAN_VULKANSEMAPHORE_H
#define TNT_FILAMENT_BACKEND_VULKAN_VULKANSEMAPHORE_H
#include "memory/Resource.h"
#include <bluevk/BlueVK.h>
namespace filament::backend {
class VulkanSemaphoreManager;
struct VulkanSemaphore : public fvkmemory::Resource {
public:
VulkanSemaphore(VulkanSemaphoreManager* manager, VkSemaphore semaphore);
~VulkanSemaphore();
VkSemaphore getVkSemaphore() const { return mSemaphore; }
private:
VulkanSemaphoreManager* mManager;
VkSemaphore mSemaphore;
};
} // namespace filament::backend
#endif // TNT_FILAMENT_BACKEND_VULKAN_VULKANSEMAPHORE_H
@@ -1,70 +0,0 @@
/*
* Copyright (C) 2025 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 "VulkanSemaphoreManager.h"
#include "VulkanConstants.h"
using namespace bluevk;
namespace {
constexpr size_t INITIAL_POOL_SIZE = FVK_MAX_COMMAND_BUFFERS;
VkSemaphore createSemaphore(VkDevice device) {
VkSemaphore semaphore;
VkSemaphoreCreateInfo semaphoreInfo = {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
};
vkCreateSemaphore(device, &semaphoreInfo, VKALLOC, &semaphore);
return semaphore;
}
} // namespace
namespace filament::backend {
VulkanSemaphoreManager::VulkanSemaphoreManager(VkDevice device,
fvkmemory::ResourceManager* resourceManager)
: mDevice(device),
mResourceManager(resourceManager) {
for (size_t i= 0; i < INITIAL_POOL_SIZE; ++i) {
mPool.push_back(createSemaphore(mDevice));
}
}
void VulkanSemaphoreManager::terminate() {
for (VkSemaphore semaphore : mPool) {
vkDestroySemaphore(mDevice, semaphore, VKALLOC);
}
mPool.clear();
}
VulkanSemaphoreManager::Semaphore VulkanSemaphoreManager::acquire() {
VkSemaphore semaphore;
if (!mPool.empty()) {
semaphore = mPool.back();
mPool.pop_back();
} else {
semaphore = createSemaphore(mDevice);
}
return Semaphore::construct(mResourceManager, this, semaphore);
}
void VulkanSemaphoreManager::recycle(VkSemaphore semaphore) {
mPool.push_back(semaphore);
}
} // namespace filament::backend
@@ -1,51 +0,0 @@
/*
* Copyright (C) 2025 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 TNT_FILAMENT_BACKEND_VULKAN_VULKANSEMAPHOREMANAGER_H
#define TNT_FILAMENT_BACKEND_VULKAN_VULKANSEMAPHOREMANAGER_H
#include "vulkan/VulkanSemaphore.h"
#include "vulkan/memory/ResourceManager.h"
#include "vulkan/memory/ResourcePointer.h"
#include <bluevk/BlueVK.h>
#include <vector>
namespace filament::backend {
class VulkanSemaphoreManager {
public:
using Semaphore = fvkmemory::resource_ptr<VulkanSemaphore>;
VulkanSemaphoreManager(VkDevice device, fvkmemory::ResourceManager* resourceManager);
~VulkanSemaphoreManager() = default;
void terminate();
Semaphore acquire();
private:
friend struct VulkanSemaphore;
void recycle(VkSemaphore semaphore);
VkDevice mDevice;
fvkmemory::ResourceManager* mResourceManager;
std::vector<VkSemaphore> mPool;
};
} // namespace filament::backend
#endif // TNT_FILAMENT_BACKEND_VULKAN_VULKANSEMAPHOREMANAGER_H
@@ -59,10 +59,7 @@ VulkanSwapChain::~VulkanSwapChain() {
mColors = {};
mDepth = {};
for (auto& semaphore : mFinishedDrawing) {
semaphore = {};
}
mFinishedDrawing.clear();
mPlatform->destroy(swapChain);
}
@@ -70,17 +67,9 @@ void VulkanSwapChain::update() {
mColors.clear();
auto const bundle = mPlatform->getSwapChainBundle(swapChain);
size_t const swapChainCount = bundle.colors.size();
mColors.reserve(bundle.colors.size());
VkDevice const device = mPlatform->getDevice();
mFinishedDrawing.clear();
mFinishedDrawing.reserve(swapChainCount);
mFinishedDrawing.resize(swapChainCount);
for (size_t i = 0; i < swapChainCount; ++i) {
mFinishedDrawing[i] = {};
}
TextureUsage depthUsage = TextureUsage::DEPTH_ATTACHMENT;
TextureUsage colorUsage = TextureUsage::COLOR_ATTACHMENT;
if (bundle.isProtected) {
@@ -121,10 +110,8 @@ void VulkanSwapChain::present(DriverBase& driver) {
// We only present if it is not headless. No-op for headless.
if (!mHeadless) {
auto finishedDrawing = mCommands->acquireFinishedSignal();
mFinishedDrawing[mCurrentSwapIndex] = finishedDrawing;
VkResult const result =
mPlatform->present(swapChain, mCurrentSwapIndex, finishedDrawing->getVkSemaphore());
VkSemaphore const finishedDrawing = mCommands->acquireFinishedSignal();
VkResult const result = mPlatform->present(swapChain, mCurrentSwapIndex, finishedDrawing);
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR ||
result == VK_ERROR_OUT_OF_DATE_KHR)
<< "Cannot present in swapchain. error=" << static_cast<int32_t>(result);
@@ -162,7 +149,6 @@ void VulkanSwapChain::acquire(bool& resized) {
VulkanPlatform::ImageSyncData imageSyncData;
VkResult const result = mPlatform->acquire(swapChain, &imageSyncData);
mCurrentSwapIndex = imageSyncData.imageIndex;
mFinishedDrawing[mCurrentSwapIndex] = {};
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)
<< "Cannot acquire in swapchain. error=" << static_cast<int32_t>(result);
if (imageSyncData.imageReadySemaphore != VK_NULL_HANDLE) {
@@ -116,7 +116,6 @@ private:
// We create VulkanTextures based on VkImages. VulkanTexture has facilities for doing layout
// transitions, which are useful here.
utils::FixedCapacityVector<fvkmemory::resource_ptr<VulkanTexture>> mColors;
utils::FixedCapacityVector<fvkmemory::resource_ptr<VulkanSemaphore>> mFinishedDrawing;
fvkmemory::resource_ptr<VulkanTexture> mDepth;
VkExtent2D mExtent;
uint32_t mLayerCount;
@@ -40,7 +40,6 @@ template ResourceType getTypeEnum<VulkanFence>() noexcept;
template ResourceType getTypeEnum<VulkanBuffer>() noexcept;
template ResourceType getTypeEnum<VulkanSync>() noexcept;
template ResourceType getTypeEnum<VulkanMemoryMappedBuffer>() noexcept;
template ResourceType getTypeEnum<VulkanSemaphore>() noexcept;
template<typename D>
ResourceType getTypeEnum() noexcept {
@@ -101,9 +100,6 @@ ResourceType getTypeEnum() noexcept {
if constexpr (std::is_same_v<D, VulkanMemoryMappedBuffer>) {
return ResourceType::MEMORY_MAPPED_BUFFER;
}
if constexpr (std::is_same_v<D, VulkanSemaphore>) {
return ResourceType::SEMAPHORE;
}
return ResourceType::UNDEFINED_TYPE;
}
@@ -147,8 +143,6 @@ std::string_view getTypeStr(ResourceType type) {
return "Sync";
case ResourceType::MEMORY_MAPPED_BUFFER:
return "VulkanMemoryMappedBuffer";
case ResourceType::SEMAPHORE:
return "Semaphore";
case ResourceType::UNDEFINED_TYPE:
return "";
}
@@ -54,8 +54,7 @@ enum class ResourceType : uint8_t {
STAGE_IMAGE = 16,
SYNC = 17,
MEMORY_MAPPED_BUFFER = 18,
SEMAPHORE = 19,
UNDEFINED_TYPE = 20, // Must be the last enum because we use it for iterating over the enums.
UNDEFINED_TYPE = 19, // Must be the last enum because we use it for iterating over the enums.
};
template<typename D>
@@ -120,9 +120,6 @@ void ResourceManager::destroyWithType(ResourceType type, HandleId id) {
case ResourceType::MEMORY_MAPPED_BUFFER:
destruct<VulkanMemoryMappedBuffer>(Handle<VulkanMemoryMappedBuffer>(id));
break;
case ResourceType::SEMAPHORE:
destruct<VulkanSemaphore>(Handle<VulkanSemaphore>(id));
break;
case ResourceType::UNDEFINED_TYPE:
break;
}
@@ -201,9 +201,7 @@ ExtensionSet getInstanceExtensions(ExtensionSet const& externallyRequiredExts =
fvkutils::enumerate(vkEnumerateInstanceExtensionProperties,
static_cast<char const*>(nullptr) /* pLayerName */);
for (auto const& extension: availableExts) {
// The cast is to force the non-literal constructor of CString, which assumes
// null-terminated strings.
utils::CString name{ (char const*) extension.extensionName };
utils::CString name { extension.extensionName };
// To workaround an Adreno bug where the extension name could be of 0 length.
if (name.size() == 0) {
@@ -245,9 +243,7 @@ ExtensionSet getDeviceExtensions(VkPhysicalDevice device) {
= fvkutils::enumerate(vkEnumerateDeviceExtensionProperties, device,
static_cast<const char*>(nullptr) /* pLayerName */);
for (auto const& extension: extensions) {
// The cast is to force the non-literal constructor of CString, which assumes
// null-terminated strings.
utils::CString name { (char const*) extension.extensionName };
utils::CString name { extension.extensionName };
// To workaround an Adreno bug where the extension name could be of 0 length.
if (name.size() == 0) {
+3 -12
View File
@@ -132,9 +132,8 @@ ShaderModel WebGPUDriver::getShaderModel() const noexcept {
#endif
}
utils::FixedCapacityVector<ShaderLanguage> WebGPUDriver::getShaderLanguages(
ShaderLanguage /*preferredLanguage*/) const noexcept {
return { ShaderLanguage::WGSL };
ShaderLanguage WebGPUDriver::getShaderLanguage() const noexcept {
return ShaderLanguage::WGSL;
}
// explicit instantiation of the Dispatcher
@@ -733,14 +732,6 @@ FenceStatus WebGPUDriver::getFenceStatus(Handle<HwFence> fenceHandle) {
return fence->getStatus();
}
FenceStatus WebGPUDriver::fenceWait(FenceHandle fenceHandle, uint64_t const timeout) {
const auto fence = handleCast<WebGPUFence>(fenceHandle);
if (!fence) {
return FenceStatus::ERROR;
}
return fence->wait(timeout);
}
void WebGPUDriver::destroySync(Handle<HwSync> syncHandle) {
if (syncHandle) {
destructHandle<WebGPUSync>(syncHandle);
@@ -791,7 +782,7 @@ bool WebGPUDriver::isFrameBufferFetchMultiSampleSupported() {
}
bool WebGPUDriver::isFrameTimeSupported() {
return false;
return true;
}
bool WebGPUDriver::isAutoDepthResolveSupported() {
+1 -3
View File
@@ -33,7 +33,6 @@
#include "private/backend/HandleAllocator.h"
#include <backend/DriverEnums.h>
#include <utils/FixedCapacityVector.h>
#include <utils/compiler.h>
#include "SpdMipmapGenerator/SpdMipmapGenerator.h"
@@ -66,8 +65,7 @@ public:
private:
WebGPUDriver(WebGPUPlatform& platform, const Platform::DriverConfig& driverConfig) noexcept;
[[nodiscard]] ShaderModel getShaderModel() const noexcept final;
[[nodiscard]] utils::FixedCapacityVector<ShaderLanguage> getShaderLanguages(
ShaderLanguage preferredLanguage) const noexcept final;
[[nodiscard]] ShaderLanguage getShaderLanguage() const noexcept final;
[[nodiscard]] wgpu::Sampler makeSampler(SamplerParams const& params);
[[nodiscard]] static wgpu::AddressMode fWrapModeToWAddressMode(const filament::backend::SamplerWrapMode& fUsage);
void setDebugTag(HandleBase::HandleId handleId, utils::CString&& tag);
+15 -56
View File
@@ -19,72 +19,31 @@
#include <backend/DriverEnums.h>
#include <memory>
#include <webgpu/webgpu_cpp.h>
#include <condition_variable>
#include <chrono>
#include <cstdint>
#include <mutex>
#include <atomic>
namespace filament::backend {
WebGPUFence::~WebGPUFence() noexcept {
// if the fence was being waited on, make sure to return with an error
std::lock_guard const lock(state->lock);
state->status = FenceStatus::ERROR;
state->cond.notify_all();
}
FenceStatus WebGPUFence::getStatus() const {
std::lock_guard const lock(state->lock);
return state->status;
}
FenceStatus WebGPUFence::wait(uint64_t const timeout) {
// we have to take into account that the STL's wait_for() actually works with
// time_points relative to steady_clock::now() internally.
using namespace std::chrono;
auto const now = steady_clock::now();
steady_clock::time_point until = steady_clock::time_point::max();
if (now <= steady_clock::time_point::max() - nanoseconds(timeout)) {
until = now + nanoseconds(timeout);
}
std::unique_lock lock(state->lock);
state->cond.wait_until(lock, until,
[state = state] { return state->status != FenceStatus::TIMEOUT_EXPIRED; });
return state->status;
}
FenceStatus WebGPUFence::getStatus() { return mStatus.load(); }
void WebGPUFence::addMarkerToQueueState(wgpu::Queue const& queue) {
// The lambda function is called when the work is done. It updates the fence status based on the
// result of the work.
// Because the callback holds a weak_ptr to the state of the HwFence object, it can be
// destroyed before the fence signals.
std::weak_ptr const weak = state;
queue.OnSubmittedWorkDone(
wgpu::CallbackMode::AllowSpontaneous,
[weak](const wgpu::QueueWorkDoneStatus status, wgpu::StringView message) {
if (auto const state = weak.lock()) {
std::unique_lock const lock(state->lock);
if (state->status != FenceStatus::ERROR) {
switch (status) {
case wgpu::QueueWorkDoneStatus::Success:
state->status = FenceStatus::CONDITION_SATISFIED;
state->cond.notify_all();
break;
case wgpu::QueueWorkDoneStatus::CallbackCancelled:
case wgpu::QueueWorkDoneStatus::Error:
state->status = FenceStatus::ERROR;
state->cond.notify_all();
FWGPU_LOGW << "WebGPUFence: wgpu::QueueWorkDoneStatus::Error. " <<
message;
break;
}
}
}
});
wgpu::CallbackMode::AllowSpontaneous,
[this](const wgpu::QueueWorkDoneStatus status, wgpu::StringView message) {
switch (status) {
case wgpu::QueueWorkDoneStatus::Success:
mStatus.store(FenceStatus::CONDITION_SATISFIED);
break;
case wgpu::QueueWorkDoneStatus::CallbackCancelled:
case wgpu::QueueWorkDoneStatus::Error:
mStatus.store(FenceStatus::ERROR);
FWGPU_LOGW << "WebGPUFence: wgpu::QueueWorkDoneStatus::Error. " << message;
break;
}
});
}
} // namespace filament::backend
+6 -16
View File
@@ -18,14 +18,9 @@
#define TNT_FILAMENT_BACKEND_WEBGPUFENCE_H
#include "DriverBase.h"
#include <backend/DriverEnums.h>
#include <utils/Mutex.h> // NOLINT(*-include-cleaner)
#include <utils/Condition.h> // NOLINT(*-include-cleaner)
#include <cstdint>
#include <memory>
#include <atomic>
namespace wgpu {
class Queue;
@@ -40,20 +35,15 @@ namespace filament::backend {
*/
class WebGPUFence final : public HwFence {
public:
~WebGPUFence() noexcept;
[[nodiscard]] FenceStatus getStatus() const;
[[nodiscard]] FenceStatus wait(uint64_t timeout);
[[nodiscard]] FenceStatus getStatus();
void addMarkerToQueueState(wgpu::Queue const&);
private:
struct State {
utils::Mutex lock; // NOLINT(*-include-cleaner)
utils::Condition cond; // NOLINT(*-include-cleaner)
FenceStatus status{ FenceStatus::TIMEOUT_EXPIRED };
};
// we need a shared_ptr because the Fence could be destroyed while we're waiting
std::shared_ptr<State> state{ std::make_shared<State>() };
// The current status of the fence.
// This is atomic because it can be updated by a WebGPU callback thread and read from the main
// thread.
std::atomic<FenceStatus> mStatus{ FenceStatus::TIMEOUT_EXPIRED };
};
} // namespace filament::backend
+5 -13
View File
@@ -51,23 +51,15 @@ MaterialDefinition* UTILS_NULLABLE MaterialCache::acquire(FEngine& engine,
engine.getShaderLanguage(), data, size);
assert_invariant(parser);
// The `key` must be constructed using parser.get() before parser is moved into the lambda
// function. This prevents a potential crash or undefined behavior, as accessing a moved-from
// object is unsafe. The validity of the generated key is guaranteed because the
// MaterialDefinition object (which owns the same parser object) created within the lambda is
// subsequently used as the associated value in the map.
const Key key{ parser.get() };
return mDefinitions.acquire(key, [&engine, parser = std::move(parser)]() mutable {
return mDefinitions.acquire(Key{parser.get()}, [&engine, parser = std::move(parser)]() mutable {
return MaterialDefinition::create(engine, std::move(parser));
});
}
void MaterialCache::release(FEngine& engine, MaterialDefinition const& definition) noexcept {
mDefinitions.release(Key{ &definition.getMaterialParser() },
[&engine](MaterialDefinition& definition) {
definition.terminate(engine);
});
void MaterialCache::release(FEngine& engine, MaterialParser const& parser) noexcept {
mDefinitions.release(Key{&parser}, [&engine](MaterialDefinition& definition) {
definition.terminate(engine);
});
}
} // namespace filament
+3 -3
View File
@@ -47,12 +47,12 @@ class MaterialCache {
public:
~MaterialCache();
// Acquire or create a new entry in the cache for the given material data.
/** Acquire or create a new entry in the cache for the given material data. */
MaterialDefinition* UTILS_NULLABLE acquire(FEngine& engine, const void* UTILS_NONNULL data,
size_t size) noexcept;
// Release an entry in the cache, potentially freeing its GPU resources.
void release(FEngine& engine, MaterialDefinition const& definition) noexcept;
/** Release an entry in the cache, potentially freeing its GPU resources. */
void release(FEngine& engine, MaterialParser const& parser) noexcept;
private:
// We use unique_ptr here because we need these pointers to be stable.
-15
View File
@@ -1,18 +1,3 @@
/*
* Copyright (C) 2025 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 "MaterialDefinition.h"
#include "Froxelizer.h"
+1 -1
View File
@@ -109,7 +109,7 @@ struct MaterialDefinition {
private:
friend class MaterialCache;
friend class FMaterial; // for onEditCallback
friend class FMaterial;
static std::unique_ptr<MaterialParser> createParser(backend::Backend const backend,
utils::FixedCapacityVector<backend::ShaderLanguage> languages,
+2 -35
View File
@@ -41,14 +41,12 @@
#include <utils/Hash.h>
#include <array>
#include <atomic>
#include <optional>
#include <tuple>
#include <utility>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
using namespace utils;
using namespace filament::backend;
@@ -71,8 +69,6 @@ constexpr std::pair<ChunkType, ChunkType> shaderLanguageToTags(ShaderLanguage co
return { MaterialSpirv, DictionarySpirv };
case ShaderLanguage::METAL_LIBRARY:
return { MaterialMetalLibrary, DictionaryMetalLibrary };
case ShaderLanguage::UNSPECIFIED:
return {};
}
}
@@ -112,20 +108,10 @@ MaterialParser::MaterialParserDetails::ManagedBuffer::~ManagedBuffer() noexcept
// ------------------------------------------------------------------------------------------------
bool MaterialParser::operator==(MaterialParser const& rhs) const noexcept {
if (this == &rhs) {
return true;
}
if (mImpl.mManagedBuffer.size() != rhs.mImpl.mManagedBuffer.size()) {
return false;
}
std::optional<uint32_t> lhsCrc32 = getPrecomputedCrc32();
if (lhsCrc32) {
std::optional<uint32_t> rhsCrc32 = rhs.getPrecomputedCrc32();
if (rhsCrc32 && *lhsCrc32 != *rhsCrc32) {
return false;
}
}
return !memcmp(mImpl.mManagedBuffer.data(), rhs.mImpl.mManagedBuffer.data(),
return !std::memcmp(mImpl.mManagedBuffer.data(), rhs.mImpl.mManagedBuffer.data(),
mImpl.mManagedBuffer.size());
}
@@ -186,11 +172,6 @@ MaterialParser::ParseResult MaterialParser::parse() noexcept {
}
uint32_t MaterialParser::computeCrc32() const noexcept {
uint32_t crc32 = mCrc32.load(std::memory_order_relaxed);
if (crc32) {
return crc32;
}
const size_t size = mImpl.mManagedBuffer.size();
const void* const UTILS_NONNULL payload = mImpl.mManagedBuffer.data();
@@ -200,21 +181,7 @@ uint32_t MaterialParser::computeCrc32() const noexcept {
std::vector<uint32_t> crc32Table;
utils::hash::crc32GenerateTable(crc32Table);
crc32 = utils::hash::crc32Update(0, payload, originalSize, crc32Table);
mCrc32.store(crc32, std::memory_order_relaxed);
return crc32;
}
std::optional<uint32_t> MaterialParser::getPrecomputedCrc32() const noexcept {
std::optional<uint32_t> cachedCrc32 = mCrc32.load(std::memory_order_relaxed);
if (cachedCrc32) {
return cachedCrc32;
}
uint32_t parsedCrc32;
if (getMaterialCrc32(&parsedCrc32)) {
return parsedCrc32;
}
return std::nullopt;
return utils::hash::crc32Update(0, payload, originalSize, crc32Table);
}
ShaderLanguage MaterialParser::getShaderLanguage() const noexcept {
-8
View File
@@ -32,7 +32,6 @@
#include <utils/FixedCapacityVector.h>
#include <array>
#include <optional>
#include <tuple>
#include <utility>
@@ -70,11 +69,7 @@ public:
ParseResult parse() noexcept;
// Compute the CRC32 of the material or return the cached value.
uint32_t computeCrc32() const noexcept;
// Return the cached computed CRC32 or the CRC32 built into the material file if one exists.
std::optional<uint32_t> getPrecomputedCrc32() const noexcept;
backend::ShaderLanguage getShaderLanguage() const noexcept;
// Accessors
@@ -192,9 +187,6 @@ private:
filaflat::ChunkContainer& getChunkContainer() noexcept;
filaflat::ChunkContainer const& getChunkContainer() const noexcept;
MaterialParserDetails mImpl;
// 0 == not cached. This technically means that a file with a CRC32 of 0 will never be cached,
// but this is unlikely, and keeping it a 32-bit value guarantees that it will be lockless.
mutable std::atomic<uint32_t> mCrc32 = 0;
};
struct ChunkUniformInterfaceBlock {
+1 -2
View File
@@ -787,8 +787,7 @@ int FEngine::loop() {
#endif
if (portString != nullptr) {
const int port = atoi(portString);
debug.server = new matdbg::DebugServer(mBackend,
mDriver->getShaderLanguages(ShaderLanguage::UNSPECIFIED).front(),
debug.server = new matdbg::DebugServer(mBackend, mDriver->getShaderLanguage(),
matdbg::DbgShaderModel((uint8_t) mDriver->getShaderModel()), port);
// Sometimes the server can fail to spin up (e.g. if the above port is already in use).
+9 -15
View File
@@ -271,22 +271,16 @@ public:
// Return a vector of shader languages, in order of preference.
utils::FixedCapacityVector<backend::ShaderLanguage> getShaderLanguage() const noexcept {
backend::ShaderLanguage preferredLanguage;
switch (mConfig.preferredShaderLanguage) {
case Config::ShaderLanguage::DEFAULT:
preferredLanguage = backend::ShaderLanguage::UNSPECIFIED;
break;
case Config::ShaderLanguage::MSL:
preferredLanguage = backend::ShaderLanguage::MSL;
break;
case Config::ShaderLanguage::METAL_LIBRARY:
preferredLanguage = backend::ShaderLanguage::METAL_LIBRARY;
break;
switch (mBackend) {
default:
return { getDriver().getShaderLanguage() };
case Backend::METAL:
const auto& lang = mConfig.preferredShaderLanguage;
if (lang == Config::ShaderLanguage::MSL) {
return { backend::ShaderLanguage::MSL, backend::ShaderLanguage::METAL_LIBRARY};
}
return { backend::ShaderLanguage::METAL_LIBRARY, backend::ShaderLanguage::MSL };
}
return getDriver().getShaderLanguages(preferredLanguage);
}
ResourceAllocatorDisposer& getResourceAllocatorDisposer() noexcept {
+1 -1
View File
@@ -213,7 +213,7 @@ void FMaterial::terminate(FEngine& engine) {
#endif
destroyPrograms(engine);
engine.getMaterialCache().release(engine, mDefinition);
engine.getMaterialCache().release(engine, mDefinition.getMaterialParser());
}
filament::DescriptorSetLayout const& FMaterial::getPerViewDescriptorSetLayout(
+2 -2
View File
@@ -1,12 +1,12 @@
Pod::Spec.new do |spec|
spec.name = "Filament"
spec.version = "1.65.4"
spec.version = "1.65.2"
spec.license = { :type => "Apache 2.0", :file => "LICENSE" }
spec.homepage = "https://google.github.io/filament"
spec.authors = "Google LLC."
spec.summary = "Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WASM/WebGL."
spec.platform = :ios, "11.0"
spec.source = { :http => "https://github.com/google/filament/releases/download/v1.65.4/filament-v1.65.4-ios.tgz" }
spec.source = { :http => "https://github.com/google/filament/releases/download/v1.65.2/filament-v1.65.2-ios.tgz" }
# Fix linking error with Xcode 12; we do not yet support the simulator on Apple silicon.
spec.pod_target_xcconfig = {
-4
View File
@@ -40,7 +40,6 @@ namespace matdbg {
ShaderExtractor::ShaderExtractor(backend::ShaderLanguage target, const void* data, size_t size)
: mChunkContainer(data, size), mMaterialChunk(mChunkContainer) {
assert_invariant(target != ShaderLanguage::UNSPECIFIED);
switch (target) {
case backend::ShaderLanguage::ESSL1:
mMaterialTag = ChunkType::MaterialEssl1;
@@ -66,9 +65,6 @@ ShaderExtractor::ShaderExtractor(backend::ShaderLanguage target, const void* dat
mMaterialTag = ChunkType::MaterialSpirv;
mDictionaryTag = ChunkType::DictionarySpirv;
break;
case backend::ShaderLanguage::UNSPECIFIED:
// that cannot happen
break;
}
}
-4
View File
@@ -118,7 +118,6 @@ private:
ShaderReplacer::ShaderReplacer(Backend backend, ShaderLanguage language,
const void* data, size_t size) :
mBackend(backend), mOriginalPackage(data, size) {
assert_invariant(language != ShaderLanguage::UNSPECIFIED);
switch (language) {
// ESSL1 and ESSL3 share the same dictionary, and replacing either will corrupt the other.
// If replacing one, delete both.
@@ -148,9 +147,6 @@ ShaderReplacer::ShaderReplacer(Backend backend, ShaderLanguage language,
mMaterialTag = ChunkType::MaterialMetalLibrary;
mDictionaryTag = ChunkType::DictionaryMetalLibrary;
break;
case backend::ShaderLanguage::UNSPECIFIED:
// can never happen
break;
}
}
+8 -64
View File
@@ -85,10 +85,7 @@ public:
// Allocates memory and copies traditional C string content. Unlike the above constructor, this
// does not allow embedded nulls. This is explicit because this operation is costly.
// This is a template to ensure it's not preferred over the string literal constructor below.
template<typename T, typename = std::enable_if_t<details::is_char_pointer_v<T>>>
explicit CString(T cstr) : CString(cstr, cstr ? strlen(cstr) : 0) {
}
explicit CString(const char* cstr);
template<size_t N>
CString(StringLiteral<N> const& other) noexcept // NOLINT(google-explicit-constructor)
@@ -174,7 +171,7 @@ public:
// insert
CString& insert(size_type const pos, char const c) & noexcept {
CString& insert(size_type pos, char c) & noexcept {
const char s[1] = { c };
return replace(pos, 0, s, 1);
}
@@ -196,7 +193,7 @@ public:
return *this;
}
CString&& insert(size_type const pos, char const c) && noexcept {
CString&& insert(size_type pos, char c) && noexcept {
this->insert(pos, c);
return std::move(*this);
}
@@ -220,7 +217,7 @@ public:
// append
CString& append(char const c) & noexcept {
CString& append(char c) & noexcept {
return insert(length(), c);
}
@@ -238,7 +235,7 @@ public:
return insert(length(), str);
}
CString&& append(char const c) && noexcept {
CString&& append(char c) && noexcept {
this->append(c);
return std::move(*this);
}
@@ -261,7 +258,7 @@ public:
}
// operator+=
CString& operator+=(char const c) & noexcept {
CString& operator+=(char c) & noexcept {
return append(c);
}
@@ -390,69 +387,16 @@ inline CString operator+(const char* lhs, CString rhs) {
return rhs;
}
inline CString operator+(CString lhs, char const rhs) {
inline CString operator+(CString lhs, char rhs) {
lhs += rhs;
return lhs;
}
inline CString operator+(char const lhs, CString rhs) {
inline CString operator+(char lhs, CString rhs) {
rhs.insert(0, lhs);
return rhs;
}
// CString vs StringLiteral
template<size_t N>
bool operator==(CString const& lhs, const StringLiteral<N>& rhs) noexcept {
return std::string_view{lhs.data(), lhs.size()} == std::string_view{rhs, N - 1};
}
template<size_t N>
bool operator!=(CString const& lhs, const StringLiteral<N>& rhs) noexcept {
return std::string_view{lhs.data(), lhs.size()} != std::string_view{rhs, N - 1};
}
template<size_t N>
bool operator<(CString const& lhs, const StringLiteral<N>& rhs) noexcept {
return std::string_view{lhs.data(), lhs.size()} < std::string_view{rhs, N - 1};
}
template<size_t N>
bool operator>(CString const& lhs, const StringLiteral<N>& rhs) noexcept {
return std::string_view{lhs.data(), lhs.size()} > std::string_view{rhs, N - 1};
}
template<size_t N>
bool operator<=(CString const& lhs, const StringLiteral<N>& rhs) noexcept {
return std::string_view{lhs.data(), lhs.size()} <= std::string_view{rhs, N - 1};
}
template<size_t N>
bool operator>=(CString const& lhs, const StringLiteral<N>& rhs) noexcept {
return std::string_view{lhs.data(), lhs.size()} >= std::string_view{rhs, N - 1};
}
// StringLiteral vs CString
template<size_t M>
bool operator==(const StringLiteral<M>& lhs, CString const& rhs) noexcept {
return std::string_view{lhs, M - 1} == std::string_view{rhs.data(), rhs.size()};
}
template<size_t M>
bool operator!=(const StringLiteral<M>& lhs, CString const& rhs) noexcept {
return std::string_view{lhs, M - 1} != std::string_view{rhs.data(), rhs.size()};
}
template<size_t M>
bool operator<(const StringLiteral<M>& lhs, CString const& rhs) noexcept {
return std::string_view{lhs, M - 1} < std::string_view{rhs.data(), rhs.size()};
}
template<size_t M>
bool operator>(const StringLiteral<M>& lhs, CString const& rhs) noexcept {
return std::string_view{lhs, M - 1} > std::string_view{rhs.data(), rhs.size()};
}
template<size_t M>
bool operator<=(const StringLiteral<M>& lhs, CString const& rhs) noexcept {
return std::string_view{lhs, M - 1} <= std::string_view{rhs.data(), rhs.size()};
}
template<size_t M>
bool operator>=(const StringLiteral<M>& lhs, CString const& rhs) noexcept {
return std::string_view{lhs, M - 1} >= std::string_view{rhs.data(), rhs.size()};
}
// Implement this for your type for automatic conversion to CString. Failing to do so leads
// to a compile-time failure.
template<typename T>
+15 -18
View File
@@ -22,31 +22,22 @@
#include <tsl/robin_map.h>
#include <optional>
#include <type_traits>
#include <utility>
namespace utils {
namespace refcountedmap {
template <typename T, typename = void>
struct is_pointer_like_trait : std::false_type {};
template <typename T>
struct is_pointer_like_trait<T, std::void_t<decltype(*std::declval<T&>())>> : std::true_type {};
template<typename T>
inline constexpr bool IsPointer = is_pointer_like_trait<T>::value;
concept IsPointer = requires(T a) { *a; };
template<typename T, typename = void>
// If T is a pointer type, get the type of the value it points to; otherwise, T.
template<typename T>
struct PointerTraits {
using element_type = T;
};
template<typename T>
struct PointerTraits<T, std::enable_if_t<IsPointer<T>>> {
using element_type = typename std::pointer_traits<T>::element_type;
template<typename T> requires IsPointer<T>
struct PointerTraits<T> {
using element_type = std::pointer_traits<T>::element_type;
};
} // namespace refcountedmap
@@ -60,7 +51,7 @@ template<typename Key, typename T, typename Hash = std::hash<Key>>
class RefCountedMap {
// Use references for the key if the size of the key type is greater than the size of a pointer.
using KeyRef = std::conditional_t<(sizeof(Key) > sizeof(void*)), const Key&, Key>;
using TValue = typename refcountedmap::PointerTraits<T>::element_type;
using TValue = refcountedmap::PointerTraits<T>::element_type;
struct Entry {
uint32_t referenceCount;
@@ -107,14 +98,20 @@ public:
T r = factory();
if (r) {
// TODO: how to use above computed hash here?
return &*mMap.insert({key, Entry{ 1, std::move(r) }}).first.value().value;
return &*mMap.insert({key, Entry{
.referenceCount = 1,
.value = std::move(r),
}}).first.value().value;
}
return nullptr;
} else {
std::optional<T> r = factory();
if (r) {
// TODO: how to use above computed hash here?
return &mMap.insert({key, Entry{ 1, std::move(r.value()) }}).first.value().value;
return &mMap.insert({key, Entry{
.referenceCount = 1,
.value = std::move(r.value()),
}}).first.value().value;
}
return nullptr;
}
+5 -16
View File
@@ -53,6 +53,10 @@ CString::CString(size_t const length) {
}
}
CString::CString(const char* cstr)
: CString(cstr, size_type(cstr ? strlen(cstr) : 0)) {
}
CString::CString(const CString& rhs)
: CString(rhs.c_str(), rhs.size()) {
}
@@ -77,24 +81,9 @@ CString& CString::replace(size_type const pos, size_type len, char const* str, s
len = std::min(len, size() - pos);
// The new size of the string, after the replacement.
const size_type newSize = size() - len + l;
// if the new string is not longer, we can do it in-place, which is much faster.
if (newSize <= size()) {
if (mCStr) {
// This is equivalent to l <= len because capacity() == size()
// move the tail of the string. +1 to move the null-terminator
std::copy(mCStr + pos + len, mCStr + size() + 1, mCStr + pos + l);
// copy the new content
std::copy_n(str, l, mCStr + pos);
// update the size
(mData - 1)->length = newSize;
}
// if mCStr is null, newSize<=size() implies l<=len and since size is 0, len is 0, so l is 0.
// so we're replacing nothing with nothing and there is nothing to do.
return *this;
}
// Allocate enough memory to hold the new string.
Data* const p = static_cast<Data*>(std::malloc(sizeof(Data) + newSize + 1));
assert(p);
+1 -103
View File
@@ -21,7 +21,6 @@
#include <algorithm>
#include <climits>
#include <utility>
#include <type_traits>
using namespace utils;
@@ -57,8 +56,7 @@ TEST(CString, Constructors) {
}
// CString(const char* cstr)
{
const char* hello_cstr = "hello";
CString str(hello_cstr);
CString str("hello");
EXPECT_STREQ("hello", str.c_str());
EXPECT_EQ(5, str.length());
}
@@ -86,50 +84,6 @@ TEST(CString, Constructors) {
}
}
TEST(CString, LiteralConstructor) {
// This test verifies that CString can be constructed from a string literal,
// and that this uses the desired template constructor, not the explicit
// (and costly) `const char*` constructor.
// Test copy-initialization. CString should be convertible from a string literal.
// This works because "literal" has type `const char[N]` which matches
// `StringLiteral<N>` and calls the non-explicit template constructor.
static_assert(std::is_convertible_v<decltype("literal"), CString>,
"CString should be convertible from a string literal.");
CString s_copy = "literal";
EXPECT_STREQ("literal", s_copy.c_str());
EXPECT_EQ(7, s_copy.length());
// Test direct-initialization. This should also use the same efficient constructor.
static_assert(std::is_constructible_v<CString, decltype("literal")>,
"CString should be constructible from a string literal.");
CString s_direct("literal");
EXPECT_STREQ("literal", s_direct.c_str());
EXPECT_EQ(7, s_direct.length());
// Verify that direct-initialization uses the sized constructor by using an embedded null.
// If the strlen() constructor were used, the length would be 3.
// The size of "abc\0def" is 8 (including the terminating null). The constructor
// calculates the length as N-1 = 7.
CString const s_direct_null("abc\0def");
EXPECT_EQ(7, s_direct_null.length());
// CString should NOT be convertible from a `const char*`.
// This is because the `const char*` constructor is explicit.
static_assert(!std::is_convertible_v<const char*, CString>,
"CString should not be convertible from a const char*.");
// This demonstrates the non-convertibility. The following line would fail to compile:
// const char* cstr = "hello";
// CString s2 = cstr;
// Explicit construction from a const char* should still work (via direct-initialization).
const char* cstr = "explicit";
CString s2(cstr);
EXPECT_STREQ("explicit", s2.c_str());
EXPECT_EQ(8, s2.length());
}
TEST(CString, Assignment) {
// Copy assignment
{
@@ -477,62 +431,6 @@ TEST(CString, Replace) {
}
}
TEST(CString, ReplaceInPlace) {
// Shrinking replacement
{
CString str("0123456789");
const char* const original_cstr = str.c_str();
str.replace(3, 3, "ab");
EXPECT_STREQ("012ab6789", str.c_str());
EXPECT_EQ(9, str.length());
EXPECT_EQ(original_cstr, str.c_str());
}
{
CString str("0123456789");
const char* const original_cstr = str.c_str();
str.replace(0, 3, "ab");
EXPECT_STREQ("ab3456789", str.c_str());
EXPECT_EQ(9, str.length());
EXPECT_EQ(original_cstr, str.c_str());
}
{
CString str("0123456789");
const char* const original_cstr = str.c_str();
str.replace(7, 3, "ab");
EXPECT_STREQ("0123456ab", str.c_str());
EXPECT_EQ(9, str.length());
EXPECT_EQ(original_cstr, str.c_str());
}
{
CString str("0123456789");
const char* const original_cstr = str.c_str();
str.replace(0, 10, "ab");
EXPECT_STREQ("ab", str.c_str());
EXPECT_EQ(2, str.length());
EXPECT_EQ(original_cstr, str.c_str());
}
// Same size replacement
{
CString str("0123456789");
const char* const original_cstr = str.c_str();
str.replace(0, 10, "abcdefghij");
EXPECT_STREQ("abcdefghij", str.c_str());
EXPECT_EQ(10, str.length());
EXPECT_EQ(original_cstr, str.c_str());
}
// Shrink to empty
{
CString str("0123456789");
const char* const original_cstr = str.c_str();
str.replace(3, 3, "");
EXPECT_STREQ("0126789", str.c_str());
EXPECT_EQ(7, str.length());
EXPECT_EQ(original_cstr, str.c_str());
}
}
TEST(CString, ReplaceZeroLength) {
{
std::string str("foobar");
+85 -91
View File
@@ -3,128 +3,122 @@
We created a few scripts to run `gltf_viewer` and produce headless renderings.
This is mainly useful for continuous integration where GPUs are generally not available on cloud
machines. To perform software rasterization, these scripts are centered around [Mesa]'s
software rasterizers, but nothing bars us from using another rasterizer like [SwiftShader].
Additionally, we should be able to use GPUs where available (though this is more of a future
work).
machines. To perform software rasterization, these scripts are centered around [Mesa]'s software
rasterizers, but nothing bars us from using another rasterizer like [SwiftShader]. Additionally,
we should be able to use GPUs where available (though this is more of a future work).
The script `render.py` contains the core logic for taking input parameters (such as the test
description file) and then running gltf_viewer to produce the renderings.
In the `test` directory is a list of test descriptions that are specified in json. Please see
In the `test` directory is a list of test descriptions that are specified in json. Please see
`sample.json` to parse the structure.
## Setting up python
The `renderdiff` project uses `python` extensively. To install the dependencies for producing
renderings, do the following step
- Set up a virtual environment (from the root directory)
```
python3 -m venv venv
. ./venv/bin/activate
```
- Install the rendering dependencies
```
pip install -r test/renderdiff/src/rendering_requirements.txt
```
- Install the viewer depdencies
```
pip install -r test/renderdiff/src/viewer_requirements.txt
```
- For the commands in the following section, do not exit the virtual environment. Once you've
completed all your work, you can exit with
```
deactivate
```
- Set up a virtual environment (from the root directory)
```
python3 -m venv venv
. ./venv/bin/activate
```
- Install the rendering dependencies
```
pip install -r test/renderdiff/src/rendering_requirements.txt
```
- Install the viewer depdencies
```
pip install -r test/renderdiff/src/viewer_requirements.txt
```
- For the commands in the following section, do not exit the virtual environment. Once you've
completed all your work, you can exit with
```
deactivate
```
## Running the test locally
- To run the same presbumit as [`test-renderdiff`](presubmit-renderdiff), you can do
- To run the same presbumit as [`test-renderdiff`](presubmit-renderdiff), you can do
```
bash test/renderdiff/local_test.sh
```
- This script will generate the renderings based on the current state of your repo.
Additionally, it will also compare the generated images with corresponding images in the
golden repo.
- To just render without running the test, you could use the following script
```
bash test/renderdiff/generate.sh
```
```
bash test/renderdiff/local_test.sh
```
## Filtering Tests
- This script will generate the renderings based on the current state of your repo.
Additionally, it will also compare the generated images with corresponding images in the
golden repo.
- To just render without running the test, you could use the following script
You can run a subset of the tests by passing the `--test_filter` flag to `local_test.sh`. The
filter supports wildcards (`*`) to match test names. For example, to run all tests in the
`ClearCoat` suite, you can use the following command:
```
bash test/renderdiff/local_test.sh --test_filter='ClearCoat.*.*'
```
```
bash test/renderdiff/generate.sh
```
## Update the golden images
The golden images are stored in a github repository: https://github.com/google/filament-assets.
Filament team members should have access to write to the repository. A typical flow for updating
the goldens is to upload your changed images into **branch** of `filament-assets`. This branch is
paired with a PR or commit on the `filament` repo.
The golden images are stored in a github repository:
https://github.com/google/filament-assets. Filament team members should have access to write
to the repository. A typical flow for updating the goldens is to upload your changed images
into **branch** of `filament-assets`. This branch is paired with a PR or commit on the
`filament` repo.
As an example, imagine I am working on a PR, and I've uploaded my change, which is in a
branch called `my-pr-branch`, to `filament`. This PR requires updating the golden. We would do
it in the following fashion
As an example, imagine I am working on a PR, and I've uploaded my change, which is in a branch
called `my-pr-branch`, to `filament`. This PR requires updating the golden. We would do it
in the following fashion
### Using a script to update the golden repo
- Run interactive mode in the `update_golden.py` script.
```
python3 test/renderdiff/src/update_golden.py
```
- This will guide you through a series of steps to push the changes to a remote branch on
`filament-assets`.
- Run interactive mode in the `update_golden.py` script.
```
python3 test/renderdiff/src/update_golden.py
```
- This will guide you through a series of steps to push the changes to a remote branch
on `filament-assets`.
### Manually updating the golden repo
- Check out the golden repo
```
git clone git@github.com:google/filament-assets.git
```
- Create a branch on the golden repo
```
cd filament-assets
git switch -c my-pr-branch-golden
```
- Copy the new images to their appropriate place in `filament-assets`
- Push the `filament-assets` working branch to remote
```
git push origin my-pr-branch-golden
```
- In the commit message of your working branch on `filament`, add the following line
```
RDIFF_BBRANCH=my-pr-branch-golden
```
- Check out the golden repo
```
git clone git@github.com:google/filament-assets.git
```
- Create a branch on the golden repo
```
cd filament-assets
git switch -c my-pr-branch-golden
```
- Copy the new images to their appropriate place in `filament-assets`
- Push the `filament-assets` working branch to remote
```
git push origin my-pr-branch-golden
```
- In the commit message of your working branch on `filament`, add the following line
```
RDIFF_BBRANCH=my-pr-branch-golden
```
Doing the above has multiple effects:
- The presubmit test [`test-renderdiff`][presubmit-renderdiff] will test against the provided
branch of the golden repo (i.e. `my-pr-branch-golden`).
- If the PR is merged, then there is another workflow that will merge `my-pr-branch-golden`
to the `main` branch of the golden repo.
- The presubmit test [`test-renderdiff`][presubmit-renderdiff] will test against the provided
branch of the golden repo (i.e. `my-pr-branch-golden`).
- If the PR is merged, then there is another workflow that will merge `my-pr-branch-golden` to
the `main` branch of the golden repo.
## Viewing test results
We provide a viewer for looking at the result of a test run. The viewer is a webapp that can
be used by pointing your browser to a localhost port. If you input the viewer with a PR or a
directory, it will parse the test result and show the results and the rendered and/or golden
images.
We provide a viewer for looking at the result of a test run. The viewer is a webapp that can be used by
pointing your browser to a localhost port. If you input the viewer with a PR or a directory, it will
parse the test result and show the results and the rendered and/or golden images.
![Viewer](docs/images/renderdiff_example.png)
To run the viewer of a test output directory that has been generated locally, you would run
the following
To run the viewer of a test output directory that has been generated locally, you would run the
following
```
python3 test/renderdiff/src/viewer.py --diff=[test output]
```
where `[test output]` is a directory containing the `compare_results.json` of the test run.
For example, it could be `out/renderdiff/diffs/presubmit` for the standard path to the
`presubmit` test output.
@@ -135,10 +129,10 @@ To see the results of a Pull Request initiated test run, you would do the follow
python3 test/renderdiff/src/viewer.py --pr_number=[PR #] --github_token=[github token]
```
where `[PR #]` is the numeric ID of your pull request, and the `[github token]` is an acess
token that you (as a github user) needs to generate ([reference][github_token_ref]).
where `[PR #]` is the numeric ID of your pull request, and the `[github token]` is an acess token
that you (as a github user) needs to generate ([reference][github_token_ref]).
[github_token_ref]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
[Mesa]: https://docs.mesa3d.org
[SwiftShader]: https://github.com/google/swiftshader
[presubmit-renderdiff]: https://github.com/google/filament/blob/e85dfe75c86106a05019e13ccdbef67e030af675/.github/workflows/presubmit.yml#L118
[presubmit-renderdiff]: https://github.com/google/filament/blob/e85dfe75c86106a05019e13ccdbef67e030af675/.github/workflows/presubmit.yml#L118
+1 -16
View File
@@ -56,26 +56,11 @@ function end_render_() {
# - Build gltf_viewer
# - Run a test
for i in "$@"
do
case $i in
--test_filter=*)
TEST_FILTER="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
start_render_ && \
python3 ${RENDERDIFF_TEST_DIR}/src/render.py \
--gltf_viewer="$(pwd)/out/cmake-debug/samples/gltf_viewer" \
--test="${RENDERDIFF_TEST_DIR}/tests/presubmit.json" \
--output_dir="${RENDER_OUTPUT_DIR}" \
--opengl_lib="${MESA_LIB_DIR}" \
--vk_icd="${MESA_VK_ICD_PATH}" \
${TEST_FILTER:+--test_filter="$TEST_FILTER"} && \
--vk_icd="${MESA_VK_ICD_PATH}" && \
end_render_
+2 -5
View File
@@ -25,15 +25,12 @@ else
GOLDEN_BRANCH=$(git log -1 | python3 test/renderdiff/src/commit_msg.py)
fi
bash `dirname $0`/generate.sh "$@" && \
bash `dirname $0`/generate.sh && \
python3 ${RENDERDIFF_TEST_DIR}/src/golden_manager.py \
--branch=${GOLDEN_BRANCH} \
--output=${GOLDEN_OUTPUT_DIR} && \
python3 ${RENDERDIFF_TEST_DIR}/src/compare.py \
--src=${GOLDEN_OUTPUT_DIR} \
--dest=${RENDER_OUTPUT_DIR} \
--out=${DIFF_OUTPUT_DIR} \
--test="${RENDERDIFF_TEST_DIR}/tests/presubmit.json" "$@"
# $@ Pass arguments to compare.py, e.g. --test_filter
--out=${DIFF_OUTPUT_DIR}
end_
+17 -165
View File
@@ -3,104 +3,17 @@ import os
import sys
import pprint
import json
import fnmatch
from utils import execute, ArgParseImpl, important_print, mkdir_p
from image_diff import same_image, output_image_diff
from results import RESULT_OK, RESULT_FAILED, RESULT_MISSING, GOLDEN_MISSING
import test_config
def _get_tolerance_for_test_case(test_case_name, test_config_obj):
if not test_config_obj:
return None
# Extract test name from test case (remove backend and model)
# Format: TestName.backend.model -> TestName
test_name = test_case_name.split('.')[0]
for test in test_config_obj.tests:
if test.name == test_name:
return test.tolerance
return None
def _format_tolerance_summary(stats):
"""
Create human-readable summary of tolerance statistics.
Args:
stats: Statistics dictionary from tolerance evaluation
Returns:
str: Formatted summary string
"""
if 'error' in stats:
return f"Error: {stats['error']}"
if 'operator' in stats:
# Nested criteria with operator
operator = stats['operator']
criteria_count = len(stats['criteria_results'])
passed_count = sum(1 for c in stats['criteria_results'] if c.get('passed', False))
summary = f"{operator} of {criteria_count} criteria: {passed_count} passed, {criteria_count - passed_count} failed"
# Add details for each criteria
details = []
for i, criteria_stats in enumerate(stats['criteria_results']):
details.append(f" Criteria {i+1}: {_format_tolerance_summary(criteria_stats)}")
return summary + "\n" + "\n".join(details)
else:
# Single criteria
total_pixels = stats.get('total_pixels', 0)
failing_pixels = stats.get('failing_pixels', 0)
failing_percentage = stats.get('failing_percentage', 0.0)
allowed_percentage = stats.get('allowed_percentage', 0.0)
max_abs_diff = stats.get('max_abs_diff', 0)
mean_abs_diff = stats.get('mean_abs_diff', 0)
max_diff_per_channel = stats.get('max_diff_per_channel', [])
criteria = stats.get('criteria', {})
criteria_desc = []
if 'max_pixel_diff' in criteria:
criteria_desc.append(f"max_pixel_diff: {criteria['max_pixel_diff']}")
if 'max_pixel_diff_percent' in criteria:
criteria_desc.append(f"max_pixel_diff_percent: {criteria['max_pixel_diff_percent']}%")
if 'allowed_diff_pixels' in criteria:
criteria_desc.append(f"allowed_diff_pixels: {criteria['allowed_diff_pixels']}%")
summary_lines = [
f"Tolerance: {', '.join(criteria_desc)}",
f"Pixels: {failing_pixels:,} / {total_pixels:,} ({failing_percentage:.2f}%) exceed tolerance",
f"Allowed: {allowed_percentage:.2f}% - {'PASS' if stats.get('passed', False) else 'FAIL'}",
f"Max difference: {max_abs_diff} (mean: {mean_abs_diff:.1f})"
]
if len(max_diff_per_channel) > 1:
channel_info = ", ".join(f"Ch{i}: {diff}" for i, diff in enumerate(max_diff_per_channel))
summary_lines.append(f"Per-channel max: {channel_info}")
return "\n".join(summary_lines)
def _compare_goldens(base_dir, comparison_dir, out_dir=None, test_filter=None, test_config_path=None):
def test_name(p):
return p.replace('.tif', '')
def _compare_goldens(base_dir, comparison_dir, out_dir=None):
all_files = glob.glob(os.path.join(base_dir, "./**/*.tif"), recursive=True)
all_files = [os.path.abspath(f) for f in all_files \
if not test_filter or fnmatch.fnmatch(test_name(os.path.basename(f)), test_filter)]
test_dirs = set(os.path.abspath(os.path.dirname(f)).replace(os.path.abspath(base_dir) + '/', '') \
for f in all_files)
all_results = []
# Parse test configuration if provided
test_config_obj = None
if test_config_path and os.path.exists(test_config_path):
try:
test_config_obj = test_config.parse_from_path(test_config_path)
except Exception as e:
important_print(f"Warning: Could not parse test config {test_config_path}: {e}")
def single_test(src_dir, dest_dir, src_fname):
src_fname = os.path.abspath(src_fname)
test_case = src_fname.replace(f'{src_dir}/', '')
@@ -108,41 +21,17 @@ def _compare_goldens(base_dir, comparison_dir, out_dir=None, test_filter=None, t
result = {
'name': test_case,
}
if not os.path.exists(dest_fname):
result['result'] = RESULT_MISSING
elif not same_image(src_fname, dest_fname):
result['result'] = RESULT_FAILED
if output_test_dir:
# just the file name
diff_fname = f"{test_case.replace('.tif', '_diff.tif')}"
output_image_diff(src_fname, dest_fname, os.path.join(output_test_dir, diff_fname))
result['diff'] = diff_fname
else:
# Get tolerance configuration for this test case
tolerance = _get_tolerance_for_test_case(test_case.replace('.tif', ''), test_config_obj)
# Compare images and get detailed statistics
comparison_result, stats = same_image(src_fname, dest_fname, tolerance)
if not comparison_result:
result['result'] = RESULT_FAILED
if output_test_dir:
# just the file name
diff_fname = f"{test_case.replace('.tif', '_diff.tif')}"
output_image_diff(src_fname, dest_fname, os.path.join(output_test_dir, diff_fname))
result['diff'] = diff_fname
else:
result['result'] = RESULT_OK
# Add detailed tolerance information to result
if tolerance:
result['tolerance_used'] = True
result['tolerance_config'] = tolerance
if stats:
result['tolerance_stats'] = stats
# Add human-readable summary
result['tolerance_summary'] = _format_tolerance_summary(stats)
elif stats is None and comparison_result:
result['comparison_type'] = 'exact_match'
elif stats and 'error' in stats:
result['error'] = stats['error']
if 'details' in stats:
result['error_details'] = stats['details']
result['result'] = RESULT_OK
return result
for test_dir in test_dirs:
@@ -154,17 +43,13 @@ def _compare_goldens(base_dir, comparison_dir, out_dir=None, test_filter=None, t
comp_test_dir = os.path.abspath(os.path.join(comparison_dir, test_dir))
results = [
single_test(base_test_dir, comp_test_dir, golden_file) \
for golden_file in all_files if os.path.dirname(golden_file) == base_test_dir
for golden_file in glob.glob(os.path.join(base_test_dir, "*.tif"))
]
seen_test_cases = set([r['name'] for r in results])
# For files that are rendered but not in the golden directory
comparison_files = glob.glob(os.path.join(comp_test_dir, "*.tif"))
if test_filter:
comparison_files = [f for f in comparison_files \
if fnmatch.fnmatch(test_name(os.path.basename(f)), test_filter)]
for base_file in comparison_files:
for base_file in \
glob.glob(os.path.join(comp_test_dir, "*.tif")):
src_fname = os.path.abspath(base_file)
test_case = base_file.replace(f'{comp_test_dir}/', '')
if test_case not in seen_test_cases:
@@ -191,8 +76,6 @@ if __name__ == '__main__':
parser.add_argument('--src', help='Directory of the base of the diff.', required=True)
parser.add_argument('--dest', help='Directory of the comparison of the diff.')
parser.add_argument('--out', help='Directory of output for the result of the diff.')
parser.add_argument('--test_filter', help='Filter for the tests to run')
parser.add_argument('--test', help='Path to test configuration JSON file for tolerance settings.')
args, _ = parser.parse_known_args(sys.argv[1:])
@@ -202,42 +85,11 @@ if __name__ == '__main__':
dest = os.path.join(os.getcwd(), './out/renderdiff')
assert os.path.exists(dest), f"Destination folder={dest} does not exist."
results = _compare_goldens(args.src, dest, out_dir=args.out,
test_filter=args.test_filter, test_config_path=args.test)
results = _compare_goldens(args.src, dest, out_dir=args.out)
# Categorize results
failed = [k for k in results if k['result'] != RESULT_OK]
passed = [k for k in results if k['result'] == RESULT_OK]
tolerance_used_count = len([k for k in results if k.get('tolerance_used', False)])
# Create detailed failure report
failed_details = []
for k in failed:
failure_line = f" {k['name']} ({k['result']})"
if 'tolerance_summary' in k:
failure_line += f"\n {k['tolerance_summary'].replace(chr(10), chr(10) + ' ')}"
failed_details.append(failure_line)
# Create success report with tolerance details
tolerance_used_details = []
for k in passed:
if k.get('tolerance_used', False) and 'tolerance_summary' in k:
tolerance_used_details.append(f" {k['name']}: {k['tolerance_summary'].split(chr(10))[0]}")
# Main summary
success_count = len(passed)
important_print(f'Successfully compared {success_count} / {len(results)} images')
if tolerance_used_details:
pstr = 'Tolerance-based passes:'
for detail in tolerance_used_details:
pstr += '\n' + detail
important_print(pstr)
if failed_details:
pstr = 'Failed:'
for detail in failed_details:
pstr = '\n' + detail
important_print(pstr)
failed = [f" {k['name']} ({k['result']})" for k in results if k['result'] != RESULT_OK]
success_count = len(results) - len(failed)
important_print(f'Successfully compared {success_count} / {len(results)} images' +
('\nFailed:\n' + ('\n'.join(failed)) if len(failed) > 0 else ''))
if len(failed) > 0:
exit(1)
+11 -150
View File
@@ -15,144 +15,7 @@
import tifffile
import numpy as np
def evaluate_tolerance_criteria(img1_data, img2_data, tolerance_spec):
"""
Recursively evaluate tolerance criteria with AND/OR logic.
Args:
img1_data: First image array
img2_data: Second image array
tolerance_spec: Dictionary containing tolerance criteria with structure:
{
"operator": "AND" | "OR", # How to combine criteria results
"criteria": [...] # List of criteria or nested tolerance specs
}
OR for leaf criteria:
{
"max_pixel_diff": int, # Max absolute difference per channel (0-255)
"max_pixel_diff_percent": float, # Max difference as percentage (0-100%)
"allowed_diff_pixels": float # Percentage of pixels allowed to exceed (0-100%)
}
Returns:
tuple: (bool: pass/fail, dict: detailed statistics)
"""
if 'criteria' not in tolerance_spec:
# Leaf criteria - evaluate single condition
return evaluate_single_criteria(img1_data, img2_data, tolerance_spec)
operator = tolerance_spec.get('operator', 'AND').upper()
criteria_list = tolerance_spec['criteria']
results_and_stats = [evaluate_tolerance_criteria(img1_data, img2_data, criteria)
for criteria in criteria_list]
results = [r[0] for r in results_and_stats] # Extract pass/fail results
all_stats = [r[1] for r in results_and_stats] # Extract statistics
if operator == 'AND':
final_result = all(results)
elif operator == 'OR':
final_result = any(results)
else:
raise ValueError(f"Unknown operator: {operator}")
# Combine statistics
combined_stats = {
'operator': operator,
'criteria_results': all_stats,
'passed': bool(final_result)
}
return final_result, combined_stats
def evaluate_single_criteria(img1_data, img2_data, criteria):
"""
Evaluate a single tolerance criteria.
Args:
img1_data: First image array
img2_data: Second image array
criteria: Dictionary with tolerance parameters:
- max_pixel_diff: Maximum absolute difference per channel (0-255 range)
- max_pixel_diff_percent: Maximum difference as percentage (0-100%)
- allowed_diff_pixels: Percentage of pixels allowed to exceed tolerance (0-100%)
Returns:
tuple: (bool: pass/fail, dict: detailed statistics)
"""
diff_abs = np.abs(img1_data.astype(np.int16) - img2_data.astype(np.int16))
max_diff = criteria.get('max_pixel_diff', float('inf'))
max_diff_percent = criteria.get('max_pixel_diff_percent', float('inf'))
allowed_diff_pixels = criteria.get('allowed_diff_pixels', 0.0)
# Calculate which pixels exceed absolute threshold
exceeds_abs = diff_abs > max_diff if max_diff < float('inf') else np.zeros_like(diff_abs, dtype=bool)
# Calculate which pixels exceed percentage threshold
if max_diff_percent < float('inf'):
max_val = np.maximum(img1_data, img2_data)
# Avoid division by zero
diff_percent = np.divide(diff_abs * 100.0, np.maximum(max_val, 1),
out=np.zeros_like(diff_abs, dtype=np.float32),
where=max_val!=0)
exceeds_percent = diff_percent > max_diff_percent
else:
exceeds_percent = np.zeros_like(diff_abs, dtype=bool)
# A pixel fails if it exceeds either threshold (OR logic at pixel level)
exceeds_tolerance = exceeds_abs | exceeds_percent
# Check per-pixel: pixel fails if ANY channel exceeds tolerance
exceeds_per_pixel = np.any(exceeds_tolerance, axis=-1) if len(exceeds_tolerance.shape) > 2 else exceeds_tolerance
# Calculate detailed statistics
total_pixels = exceeds_per_pixel.size
failing_pixels = np.sum(exceeds_per_pixel)
failing_percentage = (failing_pixels / total_pixels) * 100.0
# Distribution analysis
max_abs_diff = np.max(diff_abs) if diff_abs.size > 0 else 0
mean_abs_diff = np.mean(diff_abs) if diff_abs.size > 0 else 0
# Per-channel max differences
if len(diff_abs.shape) > 2:
max_diff_per_channel = [np.max(diff_abs[:, :, c]) for c in range(diff_abs.shape[2])]
else:
max_diff_per_channel = [max_abs_diff]
stats = {
'criteria': criteria,
'total_pixels': int(total_pixels),
'failing_pixels': int(failing_pixels),
'failing_percentage': float(failing_percentage),
'allowed_percentage': float(allowed_diff_pixels),
'max_abs_diff': int(max_abs_diff),
'mean_abs_diff': float(mean_abs_diff),
'max_diff_per_channel': [int(x) for x in max_diff_per_channel],
'passed': bool(failing_percentage <= allowed_diff_pixels)
}
return failing_percentage <= allowed_diff_pixels, stats
def same_image(tiff_file_a, tiff_file_b, tolerance=None):
"""
Compare two TIFF images for equality with optional tolerance.
Args:
tiff_file_a: Path to first TIFF file
tiff_file_b: Path to second TIFF file
tolerance: Optional tolerance specification dictionary. If None, performs exact comparison.
Can be either:
1. Single criteria: {"max_pixel_diff": 5, "allowed_diff_pixels": 1.0}
2. Nested criteria: {"operator": "OR", "criteria": [...]}
Returns:
tuple: (bool: pass/fail, dict: detailed statistics or None)
For exact comparison, returns (bool, None)
"""
def same_image(tiff_file_a, tiff_file_b):
try:
img1_data = tifffile.imread(tiff_file_a)
img2_data = tifffile.imread(tiff_file_b)
@@ -161,25 +24,23 @@ def same_image(tiff_file_a, tiff_file_b, tolerance=None):
# are different, the images are not the same.
if img1_data.shape != img2_data.shape:
print(f"Images have different shapes: {img1_data.shape} vs {img2_data.shape}")
return False, {'error': 'Shape mismatch', 'shape1': img1_data.shape, 'shape2': img2_data.shape}
return False
# If no tolerance specified, use exact comparison
if tolerance is None:
exact_match = np.array_equal(img1_data, img2_data)
return exact_match, None
# Use tolerance-based comparison
return evaluate_tolerance_criteria(img1_data, img2_data, tolerance)
# numpy.array_equal() checks if two arrays have the same shape and elements.
if np.array_equal(img1_data, img2_data):
return True
else:
return False
except FileNotFoundError:
print(f"Error: One or both files not found ('{tiff_file_a}', '{tiff_file_b}').")
return False, {'error': 'File not found'}
print(f"Error: One or both files not found ('{file_path1}', '{file_path2}').")
return False
except tifffile.TiffFileError as e:
print(f"Error: One or both files are not valid TIFF files or could not be read. Details: {e}")
return False, {'error': 'Invalid TIFF file', 'details': str(e)}
return False
except Exception as e:
print(f"An unexpected error occurred: {e}")
return False, {'error': 'Unexpected error', 'details': str(e)}
return False
def output_image_diff(tiff_file_a, tiff_file_b, output_path):
try:
-1
View File
@@ -28,7 +28,6 @@ BUILD_COMMON_DIR="$(pwd)/build/common"
os_name=$(uname -s)
if [[ "$os_name" == "Linux" ]]; then
MESA_LIB_DIR="${MESA_DIR}lib/x86_64-linux-gnu"
MESA_VK_ICD_PATH="${MESA_DIR}share/vulkan/icd.d/lvp_icd.x86_64.json"
elif [[ "$os_name" == "Darwin" ]]; then
MESA_LIB_DIR="${MESA_DIR}lib"
MESA_VK_ICD_PATH="${MESA_DIR}share/vulkan/icd.d/lvp_icd.aarch64.json"
+2 -11
View File
@@ -18,8 +18,6 @@ import json
import glob
import shutil
import concurrent.futures
import fnmatch
from utils import execute, ArgParseImpl, mkdir_p, mv_f, important_print
@@ -82,8 +80,7 @@ def _render_test_config(gltf_viewer,
output_dir,
local_only=False,
opengl_lib=None,
vk_icd=None,
test_filter=None):
vk_icd=None):
assert os.path.isdir(output_dir), f"output directory {output_dir} does not exist"
assert os.access(gltf_viewer, os.X_OK)
@@ -106,10 +103,6 @@ def _render_test_config(gltf_viewer,
if backend == 'vulkan':
assert vk_icd, "VK ICD must be specified when testing vulkan backend"
for model in test.models:
test_name = f'{test.name}.{backend}.{model}'
if test_filter and not fnmatch.fnmatch(test_name, test_filter):
print(f'Skipping {test_name} because it does not match filter')
continue
model_path = os.path.abspath(test_config.models[model])
futures.append(
executor.submit(_render_single_model, gltf_viewer_abs,
@@ -129,7 +122,6 @@ if __name__ == "__main__":
parser.add_argument('--output_dir', help='Output Directory', required=True)
parser.add_argument('--opengl_lib', help='Path to the folder containing OpenGL driver lib (for LD_LIBRARY_PATH)')
parser.add_argument('--vk_icd', help='Path to VK ICD file')
parser.add_argument('--test_filter', help='Filter for the tests to run')
args, _ = parser.parse_known_args(sys.argv[1:])
test = test_config.parse_from_path(args.test)
@@ -139,8 +131,7 @@ if __name__ == "__main__":
test,
args.output_dir,
opengl_lib=args.opengl_lib,
vk_icd=args.vk_icd,
test_filter=args.test_filter)
vk_icd=args.vk_icd)
with open(f'{output_dir}/render_results.json', 'w') as f:
f.write(json.dumps(results, indent=2))
-68
View File
@@ -61,54 +61,6 @@ class PresetConfig(RenderingConfig):
_check(models)
self.models += models
# Parse tolerance configuration from preset
tolerance = data.get('tolerance')
if tolerance:
assert _is_dict(tolerance)
self._validate_tolerance(tolerance)
self.tolerance = tolerance
else:
self.tolerance = None
def _validate_tolerance(self, tolerance):
"""
Validate tolerance configuration structure.
Tolerance can be:
1. Single criteria: {"max_pixel_diff": 5, "allowed_diff_pixels": 1.0}
2. Nested criteria: {"operator": "OR", "criteria": [...]}
"""
if 'criteria' in tolerance:
# Nested structure with operator
operator = tolerance.get('operator', 'AND')
assert operator.upper() in ['AND', 'OR'], f"Invalid operator: {operator}"
criteria_list = tolerance['criteria']
assert isinstance(criteria_list, list), "criteria must be a list"
assert len(criteria_list) > 0, "criteria list cannot be empty"
# Recursively validate each criteria
for criteria in criteria_list:
self._validate_tolerance(criteria)
else:
# Leaf criteria - validate individual parameters
valid_keys = {'max_pixel_diff', 'max_pixel_diff_percent', 'allowed_diff_pixels'}
tolerance_keys = set(tolerance.keys())
invalid_keys = tolerance_keys - valid_keys
assert len(invalid_keys) == 0, f"Invalid tolerance keys: {invalid_keys}"
if 'max_pixel_diff' in tolerance:
assert isinstance(tolerance['max_pixel_diff'], (int, float)), "max_pixel_diff must be numeric"
assert 0 <= tolerance['max_pixel_diff'] <= 255, "max_pixel_diff must be 0-255"
if 'max_pixel_diff_percent' in tolerance:
assert isinstance(tolerance['max_pixel_diff_percent'], (int, float)), "max_pixel_diff_percent must be numeric"
assert 0 <= tolerance['max_pixel_diff_percent'] <= 100, "max_pixel_diff_percent must be 0-100%"
if 'allowed_diff_pixels' in tolerance:
assert isinstance(tolerance['allowed_diff_pixels'], (int, float)), "allowed_diff_pixels must be numeric"
assert 0 <= tolerance['allowed_diff_pixels'] <= 100, "allowed_diff_pixels must be 0-100%"
class TestConfig(RenderingConfig):
def __init__(self, data, existing_models, presets):
RenderingConfig.__init__(self, data)
@@ -120,7 +72,6 @@ class TestConfig(RenderingConfig):
apply_presets = data.get('apply_presets')
rendering = {}
preset_models = []
preset_tolerance = None
if apply_presets:
given_presets = {p.name: p for p in presets}
assert all((name in given_presets) for name in apply_presets),\
@@ -128,12 +79,9 @@ class TestConfig(RenderingConfig):
# Note that this needs to applied in order. Models will be overwritten.
# Properties will be "added" in order.
# Tolerance is inherited from the LAST preset that has one defined
for preset in apply_presets:
rendering.update(given_presets[preset].rendering)
preset_models = given_presets[preset].models
if given_presets[preset].tolerance:
preset_tolerance = given_presets[preset].tolerance
assert 'rendering' in data
rendering.update(data['rendering'])
@@ -146,22 +94,6 @@ class TestConfig(RenderingConfig):
assert all(m in existing_models for m in models)
self.models = set(models + self.models)
# Parse tolerance configuration - test-level tolerance overrides preset tolerance
tolerance = data.get('tolerance')
if tolerance:
assert _is_dict(tolerance)
self._validate_tolerance(tolerance)
self.tolerance = tolerance
else:
# Use tolerance inherited from presets
self.tolerance = preset_tolerance
def _validate_tolerance(self, tolerance):
"""Use the same validation logic as PresetConfig."""
# Create a temporary PresetConfig instance to reuse validation logic
temp_preset = PresetConfig({'name': 'temp', 'rendering': {}}, {})
return temp_preset._validate_tolerance(tolerance)
def to_filament_format(self):
json_out = {
'name': self.name,
+6 -272
View File
@@ -53,27 +53,10 @@ class ExpandedPassedResult extends LitElement {
render() {
if (this.content) {
const url = getGoldenUrl(this.content);
return html`
<div>
<div style="margin-bottom: 10px;">
<label>
<input type="checkbox" id="magnifierToggle" checked @change="${this._onMagnifierToggle}">
Enable Magnifier
</label>
</div>
<tiff-viewer fileurl="${url}" magnifier-enabled id="passedViewer"></tiff-viewer>
</div>
`;
return html`<tiff-viewer fileurl="${url}"></tiff-viewer>`;
}
return html``;
}
_onMagnifierToggle(ev) {
const viewer = this.shadowRoot.getElementById('passedViewer');
if (viewer) {
viewer.magnifierEnabled = ev.target.checked;
}
}
}
customElements.define('expanded-passed-result', ExpandedPassedResult);
@@ -114,7 +97,6 @@ class ExpandedComparisonResult extends LitElement {
leftViewType: { type: String },
rightViewType: { type: String },
disableDropdowns: { type: Boolean },
magnifierEnabled: { type: Boolean },
};
}
@@ -134,12 +116,6 @@ class ExpandedComparisonResult extends LitElement {
margin-top: 22px;
margin-bottom: 5px;
}
.diff-container {
position: relative;
}
.viewer-container {
position: relative;
}
.selector {
margin: 8px 0;
}
@@ -156,10 +132,6 @@ class ExpandedComparisonResult extends LitElement {
this.leftViewType = 'golden';
this.rightViewType = 'golden';
this.disableDropdowns = false;
this.magnifierEnabled = true;
this.diffCanvasRect = null;
this.originalDiffImageData = null;
this.globalMousePosition = null;
this.addEventListener(
'image-loaded',
@@ -184,9 +156,7 @@ class ExpandedComparisonResult extends LitElement {
<div>${current.name}</div>
<tiff-viewer id="viewer-${name}" class="viewer"
name="${current.name}"
fileurl="${url}"
?magnifier-enabled="${this.magnifierEnabled}"
disable-mouse-handlers></tiff-viewer>
fileurl="${url}"></tiff-viewer>
</div>
`;
}
@@ -263,8 +233,6 @@ class ExpandedComparisonResult extends LitElement {
if (diff.result == RES_DIFFERENT_PIXELS) {
this.diffResult = diff;
this.showDiff = true;
// Reset original diff data when new diff is computed
this.originalDiffImageData = null;
}
}
@@ -295,228 +263,6 @@ class ExpandedComparisonResult extends LitElement {
// Create the ImageData from the modified copy.
const imgData = new ImageData(diffImgCopy, diffResult.dim.width, diffResult.dim.height);
diffCtx.putImageData(imgData, 0, 0);
// Store both original and current diff image data for magnifier
if (!this.originalDiffImageData) {
this.originalDiffImageData = new ImageData(diffResult.diffImg.slice(), diffResult.dim.width, diffResult.dim.height);
}
this.currentDiffImageData = imgData;
}
_onDiffMouseEnter(event) {
if (!this.showDiff || !this.currentDiffImageData) return;
this.diffCanvasRect = event.target.getBoundingClientRect();
}
_onGlobalMouseLeave(event) {
// Hide all magnifiers when mouse leaves the viewer container
const leftViewer = this.shadowRoot.querySelector('#viewer-left');
const rightViewer = this.shadowRoot.querySelector('#viewer-right');
const diffMagnifier = this.shadowRoot.getElementById('diffMagnifier');
if (leftViewer) {
const leftMagnifier = leftViewer.shadowRoot?.getElementById('magnifier');
if (leftMagnifier) leftMagnifier.hide();
}
if (rightViewer) {
const rightMagnifier = rightViewer.shadowRoot?.getElementById('magnifier');
if (rightMagnifier) rightMagnifier.hide();
}
if (diffMagnifier) diffMagnifier.hide();
}
_onGlobalMouseMove(event) {
this.globalMousePosition = { clientX: event.clientX, clientY: event.clientY };
// Update all three magnifiers
this._updateLeftMagnifier(event);
this._updateRightMagnifier(event);
this._updateDiffMagnifier(event);
}
_updateLeftMagnifier(event) {
if (!this.magnifierEnabled) return;
const leftViewer = this.shadowRoot.querySelector('#viewer-left');
if (!leftViewer) return;
const canvas = leftViewer.shadowRoot?.querySelector('canvas');
if (!canvas) return;
const rect = canvas.getBoundingClientRect();
const leftMagnifier = leftViewer.shadowRoot?.getElementById('magnifier');
if (!leftMagnifier) return;
// Get image data from the viewer
const imageData = leftViewer.imageData;
if (!imageData) {
leftMagnifier.hide();
return;
}
// Check if mouse is over any of the three views (left, right, or diff)
if (!this._isMouseOverAnyView(event)) {
leftMagnifier.hide();
return;
}
// Calculate the equivalent position on the left image
const { imageX, imageY, mouseX, mouseY } = this._calculateEquivalentPosition(event, rect, imageData);
// Position magnifier relative to the canvas within the left viewer
leftMagnifier.updateMagnifier(imageData, imageX, imageY, mouseX, mouseY, rect);
}
_updateRightMagnifier(event) {
if (!this.magnifierEnabled) return;
const rightViewer = this.shadowRoot.querySelector('#viewer-right');
if (!rightViewer) return;
const canvas = rightViewer.shadowRoot?.querySelector('canvas');
if (!canvas) return;
const rect = canvas.getBoundingClientRect();
const rightMagnifier = rightViewer.shadowRoot?.getElementById('magnifier');
if (!rightMagnifier) return;
// Get image data from the viewer
const imageData = rightViewer.imageData;
if (!imageData) {
rightMagnifier.hide();
return;
}
// Check if mouse is over any of the three views (left, right, or diff)
if (!this._isMouseOverAnyView(event)) {
rightMagnifier.hide();
return;
}
// Calculate the equivalent position on the right image
const { imageX, imageY, mouseX, mouseY } = this._calculateEquivalentPosition(event, rect, imageData);
// Position magnifier relative to the canvas within the right viewer
rightMagnifier.updateMagnifier(imageData, imageX, imageY, mouseX, mouseY, rect);
}
_updateDiffMagnifier(event) {
if (!this.magnifierEnabled || !this.showDiff || !this.currentDiffImageData || !this.diffCanvasRect) return;
const rect = this.diffCanvasRect;
const diffMagnifier = this.shadowRoot.getElementById('diffMagnifier');
if (!diffMagnifier) return;
// Check if mouse is over any of the three views (left, right, or diff)
if (!this._isMouseOverAnyView(event)) {
diffMagnifier.hide();
return;
}
// Calculate the equivalent position on the diff image
const { imageX, imageY, mouseX, mouseY } = this._calculateEquivalentPosition(event, rect, this.currentDiffImageData);
// Position magnifier relative to the diff canvas
diffMagnifier.updateMagnifier(this.currentDiffImageData, imageX, imageY, mouseX, mouseY, rect, 8, this.originalDiffImageData);
}
_isMouseOverElement(event, rect) {
return event.clientX >= rect.left &&
event.clientX <= rect.right &&
event.clientY >= rect.top &&
event.clientY <= rect.bottom;
}
_isMouseOverAnyView(event) {
// Check if mouse is over left viewer
const leftViewer = this.shadowRoot.querySelector('#viewer-left');
if (leftViewer) {
const leftCanvas = leftViewer.shadowRoot?.querySelector('canvas');
if (leftCanvas && this._isMouseOverElement(event, leftCanvas.getBoundingClientRect())) {
return true;
}
}
// Check if mouse is over right viewer
const rightViewer = this.shadowRoot.querySelector('#viewer-right');
if (rightViewer) {
const rightCanvas = rightViewer.shadowRoot?.querySelector('canvas');
if (rightCanvas && this._isMouseOverElement(event, rightCanvas.getBoundingClientRect())) {
return true;
}
}
// Check if mouse is over diff canvas
if (this.showDiff && this.diffCanvasRect) {
if (this._isMouseOverElement(event, this.diffCanvasRect)) {
return true;
}
}
return false;
}
_calculateEquivalentPosition(event, targetRect, targetImageData) {
// Find which view the mouse is actually over and calculate the equivalent position
const leftViewer = this.shadowRoot.querySelector('#viewer-left');
const rightViewer = this.shadowRoot.querySelector('#viewer-right');
let sourceRect = null;
let sourceImageData = null;
// Determine source view
if (leftViewer) {
const leftCanvas = leftViewer.shadowRoot?.querySelector('canvas');
if (leftCanvas && this._isMouseOverElement(event, leftCanvas.getBoundingClientRect())) {
sourceRect = leftCanvas.getBoundingClientRect();
sourceImageData = leftViewer.imageData;
}
}
if (!sourceRect && rightViewer) {
const rightCanvas = rightViewer.shadowRoot?.querySelector('canvas');
if (rightCanvas && this._isMouseOverElement(event, rightCanvas.getBoundingClientRect())) {
sourceRect = rightCanvas.getBoundingClientRect();
sourceImageData = rightViewer.imageData;
}
}
if (!sourceRect && this.showDiff && this.diffCanvasRect) {
if (this._isMouseOverElement(event, this.diffCanvasRect)) {
sourceRect = this.diffCanvasRect;
sourceImageData = this.currentDiffImageData;
}
}
if (!sourceRect || !sourceImageData) {
// Fallback to target rect
sourceRect = targetRect;
sourceImageData = targetImageData;
}
// Calculate relative position in source
const sourceMouseX = event.clientX - sourceRect.left;
const sourceMouseY = event.clientY - sourceRect.top;
const sourceScaleX = sourceImageData.width / sourceRect.width;
const sourceScaleY = sourceImageData.height / sourceRect.height;
const sourceImageX = Math.floor(sourceMouseX * sourceScaleX);
const sourceImageY = Math.floor(sourceMouseY * sourceScaleY);
// Convert to target coordinates
const targetScaleX = targetImageData.width / targetRect.width;
const targetScaleY = targetImageData.height / targetRect.height;
const targetMouseX = sourceImageX / targetScaleX;
const targetMouseY = sourceImageY / targetScaleY;
return {
imageX: sourceImageX,
imageY: sourceImageY,
mouseX: targetMouseX,
mouseY: targetMouseY
};
}
render() {
@@ -528,34 +274,22 @@ class ExpandedComparisonResult extends LitElement {
const v1 = this._viewer("left", this.tests, this.left, this.leftViewType);
const v2 = this._viewer("right", this.tests, this.right, this.rightViewType);
const onMultiplierChange = (ev) => {
const multiplierValue = this.shadowRoot.querySelector('#multiplierValue');
multiplierValue.textContent = ev.target.value;
this._updateDiffCanvas(this.diffResult, ev.target.value);
};
const onMagnifierToggle = (ev) => {
this.magnifierEnabled = ev.target.checked;
};
return html`
<div class="main-container">
<div class="viewer-container" @mousemove="${this._onGlobalMouseMove}" @mouseleave="${this._onGlobalMouseLeave}">
<div class="viewer-container">
${v1}
<div style="flex: 1; ${diffStyle}" class="diff-container">
<canvas id="diffCanvas" @mouseenter="${this._onDiffMouseEnter}"></canvas>
<image-magnifier id="diffMagnifier"></image-magnifier>
<div style="flex: 1; ${diffStyle}">
<canvas id="diffCanvas"></canvas>
</div>
${v2}
</div>
<div class="control" style="${diffStyle}">
<div>
<div>Difference Multiplier: <span id="multiplierValue">1</span></div>
<div>Difference Multiplier</div>
<input type="range" min="1" max="100" value="1" id="diffMultiplier" @input=${onMultiplierChange}>
</div>
<div style="margin-top: 10px;">
<label>
<input type="checkbox" .checked="${this.magnifierEnabled}" @change=${onMagnifierToggle}>
Enable Magnifier
</label>
</div>
</div>
</div>
`;
+1 -183
View File
@@ -14,154 +14,11 @@
import { LitElement, html, css } from "https://cdn.jsdelivr.net/gh/lit/dist@3/all/lit-all.min.js";
class ImageMagnifier extends LitElement {
static styles = css`
:host {
position: absolute;
pointer-events: none;
z-index: 1000;
display: none;
}
:host([visible]) {
display: block;
}
.magnifier {
width: 150px;
height: 150px;
border: 2px solid #000;
border-radius: 75px;
background: white;
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
position: relative;
}
.magnifier-canvas {
width: 100%;
height: 100%;
border-radius: 73px;
}
.pixel-info {
position: absolute;
top: -65px;
left: 0;
background: rgba(0,0,0,0.8);
color: white;
padding: 4px 8px;
border-radius: 4px;
font-family: monospace;
font-size: 11px;
white-space: pre-line;
max-width: 250px;
}
`;
static properties = {
visible: {type: Boolean, reflect: true},
};
constructor() {
super();
this.visible = false;
}
render() {
return html`
<div class="magnifier">
<canvas class="magnifier-canvas" id="magnifierCanvas"></canvas>
<div class="pixel-info" id="pixelInfo"></div>
</div>
`;
}
updateMagnifier(imageData, imageX, imageY, mouseX, mouseY, canvasRect, zoomFactor = 8, originalImageData = null) {
if (!imageData) return;
if (imageX < 0 || imageX >= imageData.width || imageY < 0 || imageY >= imageData.height) {
this.visible = false;
return;
}
const pixelIndex = (imageY * imageData.width + imageX) * 4;
const r = imageData.data[pixelIndex];
const g = imageData.data[pixelIndex + 1];
const b = imageData.data[pixelIndex + 2];
const a = imageData.data[pixelIndex + 3];
let pixelInfoText = `RGBA(${r}, ${g}, ${b}, ${a})\n@ (${imageX}, ${imageY})`;
// If original image data is provided, show the unmultiplied values too
if (originalImageData) {
const origR = originalImageData.data[pixelIndex];
const origG = originalImageData.data[pixelIndex + 1];
const origB = originalImageData.data[pixelIndex + 2];
const origA = originalImageData.data[pixelIndex + 3];
pixelInfoText = `Diff: RGBA(${origR}, ${origG}, ${origB}, ${origA})\nDisplay: RGBA(${r}, ${g}, ${b}, ${a})\n@ (${imageX}, ${imageY})`;
}
const magnifierSize = 150;
const sourceSize = magnifierSize / zoomFactor;
const halfSource = sourceSize / 2;
const sourceX = Math.max(0, Math.min(imageData.width - sourceSize, imageX - halfSource));
const sourceY = Math.max(0, Math.min(imageData.height - sourceSize, imageY - halfSource));
const magnifierCanvas = this.shadowRoot.getElementById('magnifierCanvas');
const pixelInfo = this.shadowRoot.getElementById('pixelInfo');
magnifierCanvas.width = magnifierSize;
magnifierCanvas.height = magnifierSize;
const magnifierCtx = magnifierCanvas.getContext('2d');
magnifierCtx.imageSmoothingEnabled = false;
const tempCanvas = document.createElement('canvas');
tempCanvas.width = imageData.width;
tempCanvas.height = imageData.height;
const tempCtx = tempCanvas.getContext('2d');
tempCtx.putImageData(imageData, 0, 0);
magnifierCtx.drawImage(
tempCanvas,
sourceX, sourceY, sourceSize, sourceSize,
0, 0, magnifierSize, magnifierSize
);
const centerX = magnifierSize / 2;
const centerY = magnifierSize / 2;
magnifierCtx.strokeStyle = 'red';
magnifierCtx.lineWidth = 1;
magnifierCtx.beginPath();
magnifierCtx.moveTo(centerX - 5, centerY);
magnifierCtx.lineTo(centerX + 5, centerY);
magnifierCtx.moveTo(centerX, centerY - 5);
magnifierCtx.lineTo(centerX, centerY + 5);
magnifierCtx.stroke();
// Position relative to the TiffViewer container
this.style.left = (mouseX - magnifierSize / 2) + 'px';
this.style.top = (mouseY - magnifierSize / 2) + 'px';
pixelInfo.textContent = pixelInfoText;
this.visible = true;
}
hide() {
this.visible = false;
}
}
customElements.define('image-magnifier', ImageMagnifier);
// Generated by Gemini with some modifications
export class TiffViewer extends LitElement {
static styles = css`
:host {
display: block;
position: relative;
}
canvas {
border: 1px solid #ccc;
@@ -174,8 +31,6 @@ export class TiffViewer extends LitElement {
fileurl: {type: String, attribute: 'fileurl'},
name: {type: String, attribute: 'name'},
failedToFetch: {type: Boolean },
magnifierEnabled: {type: Boolean, attribute: 'magnifier-enabled'},
disableMouseHandlers: {type: Boolean, attribute: 'disable-mouse-handlers'},
};
constructor() {
@@ -183,20 +38,13 @@ export class TiffViewer extends LitElement {
this.fileurl = null;
this.name = null;
this.failedToFetch = false;
this.magnifierEnabled = false;
this.disableMouseHandlers = false;
this.imageData = null;
this.canvasRect = null;
}
render() {
if (this.failedToFetch) {
return html``;
}
return html`
<canvas id="tiffCanvas" @mousemove="${this._onMouseMove}" @mouseenter="${this._onMouseEnter}" @mouseleave="${this._onMouseLeave}"></canvas>
<image-magnifier id="magnifier"></image-magnifier>
`;
return html`<canvas id="tiffCanvas"></canvas>`;
}
updated(props) {
@@ -264,8 +112,6 @@ export class TiffViewer extends LitElement {
const imageData = new ImageData(new Uint8ClampedArray(rgba), firstImage.width, firstImage.height);
ctx.putImageData(imageData, 0, 0);
this.imageData = imageData;
this.dispatchEvent(new CustomEvent('image-loaded', {
bubbles: true,
composed: true,
@@ -287,34 +133,6 @@ export class TiffViewer extends LitElement {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
}
_onMouseEnter(event) {
if (this.disableMouseHandlers || !this.magnifierEnabled || !this.imageData) return;
this.canvasRect = event.target.getBoundingClientRect();
}
_onMouseLeave(event) {
if (this.disableMouseHandlers || !this.magnifierEnabled) return;
const magnifier = this.shadowRoot.getElementById('magnifier');
magnifier.hide();
}
_onMouseMove(event) {
if (this.disableMouseHandlers || !this.magnifierEnabled || !this.imageData || !this.canvasRect) return;
const rect = this.canvasRect;
const scaleX = this.imageData.width / rect.width;
const scaleY = this.imageData.height / rect.height;
const mouseX = event.clientX - rect.left;
const mouseY = event.clientY - rect.top;
const imageX = Math.floor(mouseX * scaleX);
const imageY = Math.floor(mouseY * scaleY);
const magnifier = this.shadowRoot.getElementById('magnifier');
magnifier.updateMagnifier(this.imageData, imageX, imageY, event.clientX, event.clientY, rect);
}
}
customElements.define('tiff-viewer', TiffViewer);
-4
View File
@@ -10,10 +10,6 @@
"viewer.cameraFocusDistance": 0,
"view.postProcessingEnabled": true,
"view.dithering": "NONE"
},
"tolerance": { // [optional] Simple tolerance - single criteria
"max_pixel_diff": 5, // Max absolute difference per channel (0-255)
"allowed_diff_pixels": 0.1 // Percentage of pixels allowed to exceed (0-100%)
}
},
{
-13
View File
@@ -25,19 +25,6 @@
// 'presets' field in the top-level struct.
"model": [], // [optional] List of models used in this test. The list is
// *appended* onto the lists provided by the presets.
"tolerance": { // [optional] Image comparison tolerance specification
"operator": "OR", // [optional] How to combine criteria: "AND" or "OR" (default: "AND")
"criteria": [
{
"max_pixel_diff": 3, // [optional] Max absolute difference per channel (0-255)
"allowed_diff_pixels": 1.0 // [optional] Percentage of pixels allowed to exceed (0-100%)
},
{
"max_pixel_diff_percent": 2.0, // [optional] Max difference as percentage (0-100%)
"allowed_diff_pixels": 0.5 // [optional] Percentage of pixels allowed to exceed (0-100%)
}
]
},
"rendering": { // [required] See description in 'presets'
"view.bloom.enabled": true,
"view.bloom.lensFlare": true
+4 -32
View File
@@ -20,41 +20,14 @@
#include <string>
#include <signal.h>
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#include <signal.h>
#define STDOUT_FILENO _fileno(stdout)
#define write _write
static void setSigintHandler(void (*handler)(int)) {
signal(SIGINT, handler);
}
#else
#include <unistd.h>
#include <signal.h>
static void setSigintHandler(void (*handler)(int)) {
struct sigaction sa;
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, nullptr);
}
#endif
static void moveCursorUp(size_t n) {
std::cout << "\033[" << n << "F";
}
static void write_safe(const char* seq, size_t len) {
write(STDOUT_FILENO, seq, len);
}
static void showCursor() {
setSigintHandler(SIG_DFL);
const char* show_cursor_seq = "\033[?25h";
write_safe(show_cursor_seq, 6);
signal(SIGINT, SIG_DFL);
std::cout << "\033[?25h" << std::flush;
}
static void showCursorFromSignal(int) {
@@ -63,9 +36,8 @@ static void showCursorFromSignal(int) {
}
static void hideCursor() {
setSigintHandler(showCursorFromSignal);
const char* hide_cursor_seq = "\033[?25l";
write_safe(hide_cursor_seq, 6);
signal(SIGINT, showCursorFromSignal);
std::cout << "\033[?25l" << std::flush;
}
static inline void printProgress(float v, size_t width) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "filament",
"version": "1.65.4",
"version": "1.65.2",
"description": "Real-time physically based rendering engine",
"main": "filament.js",
"module": "filament.js",