backend-test: fix clean up ordering (#9353)
Previously, Cleanup is scoped to the testing function, which will go out of scope before BackendTest's destructor is called. We need to order the cleanup (destruction of resources) to after the readPixels and previous commands are complete - which is in the destructor of BackendTest. Additionally, we need to cleanup before the destruction of the driver. This means we need to be able to order the destruction of Cleanup (and not rely on RAII). This is done by having a unique_ptr holding a Cleanup instance.
This commit is contained in:
@@ -64,6 +64,7 @@ BackendTest::BackendTest() : commandBufferQueue(CONFIG_MIN_COMMAND_BUFFERS_SIZE,
|
||||
CONFIG_COMMAND_BUFFERS_SIZE, /*mPaused=*/false) {
|
||||
initializeDriver();
|
||||
mImageExpectations.emplace(getDriverApi());
|
||||
mCleanup = std::make_unique<Cleanup>(getDriverApi());
|
||||
NativeView nativeView = getNativeView();
|
||||
mScreenSize = {nativeView.width, nativeView.height};
|
||||
}
|
||||
@@ -72,12 +73,15 @@ BackendTest::~BackendTest() {
|
||||
// Ensure all graphics commands and callbacks are finished.
|
||||
flushAndWait();
|
||||
mImageExpectations->evaluate();
|
||||
// Note: Don't terminate the driver for OpenGL, as it wipes away the context and removes the buffer from the screen.
|
||||
if (sBackend != Backend::OPENGL) {
|
||||
driver->terminate();
|
||||
delete driver;
|
||||
}
|
||||
|
||||
// We need to clean up all the handles before the driver terminates. Note that this should
|
||||
// happen before the above flushAndWait, which will complete readPixels.
|
||||
mCleanup.reset();
|
||||
// This flush and wait will execute all the destroy commands.
|
||||
flushAndWait();
|
||||
|
||||
driver->terminate();
|
||||
delete driver;
|
||||
recordFailedImages();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "PlatformRunner.h"
|
||||
#include "ImageExpectations.h"
|
||||
#include "Lifetimes.h"
|
||||
|
||||
namespace test {
|
||||
|
||||
@@ -48,10 +49,13 @@ public:
|
||||
static std::filesystem::path binaryDirectory();
|
||||
|
||||
protected:
|
||||
|
||||
BackendTest();
|
||||
~BackendTest() override;
|
||||
|
||||
template<typename HandleType>
|
||||
filament::backend::Handle<HandleType> addCleanup(filament::backend::Handle<HandleType> handle) {
|
||||
return mCleanup->add(handle);
|
||||
}
|
||||
void initializeDriver();
|
||||
void executeCommands();
|
||||
void flushAndWait();
|
||||
@@ -77,6 +81,9 @@ protected:
|
||||
|
||||
static bool matchesEnvironment(Backend backend);
|
||||
static bool matchesEnvironment(OperatingSystem operatingSystem);
|
||||
|
||||
std::unique_ptr<Cleanup> mCleanup;
|
||||
|
||||
private:
|
||||
// Adds all the images that failed an ImageExpectation to the XML metadata for the current tests
|
||||
// case. Add --gtest_output=xml as a command line argument to generate a test_detail.xml file in
|
||||
|
||||
@@ -19,14 +19,12 @@
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "backend/Handle.h"
|
||||
#include "backend/DriverApiForward.h"
|
||||
#include "BackendTest.h"
|
||||
|
||||
class RenderFrame {
|
||||
public:
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "Lifetimes.h"
|
||||
#include "private/filament/SamplerInterfaceBlock.h"
|
||||
#include "private/backend/DriverApi.h"
|
||||
#include "backend/DriverEnums.h"
|
||||
|
||||
namespace test {
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
#include "SharedShaders.h"
|
||||
|
||||
#include "BackendTest.h"
|
||||
#include "Shader.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace test {
|
||||
|
||||
@@ -252,4 +252,4 @@ std::string SharedShaders::getFragmentShaderText(FragmentShaderType fragment,
|
||||
return fragmentText->withUniform(*uniformText);
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace test
|
||||
|
||||
@@ -38,18 +38,16 @@ const UniformBindingConfig kBindingConfig = {
|
||||
|
||||
class BufferUpdatesTest : public BackendTest {
|
||||
public:
|
||||
BufferUpdatesTest() : mCleanup(getDriverApi()) {}
|
||||
BufferUpdatesTest() = default;
|
||||
|
||||
protected:
|
||||
Shader createShader() {
|
||||
return SharedShaders::makeShader(getDriverApi(), mCleanup, ShaderRequest{
|
||||
return SharedShaders::makeShader(getDriverApi(), *mCleanup, ShaderRequest{
|
||||
.mVertexType = VertexShaderType::Simple,
|
||||
.mFragmentType = FragmentShaderType::SolidColored,
|
||||
.mUniformType = ShaderUniformType::SimpleWithPadding
|
||||
});
|
||||
}
|
||||
|
||||
Cleanup mCleanup;
|
||||
};
|
||||
|
||||
TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
|
||||
@@ -63,15 +61,14 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
|
||||
// executeCommands().
|
||||
{
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
Shader shader = createShader();
|
||||
|
||||
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
auto defaultRenderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
// To test large buffers (which exercise a different code path) create an extra large
|
||||
// buffer. Only the first 3 vertices will be used.
|
||||
@@ -86,7 +83,7 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
|
||||
// Create a uniform buffer.
|
||||
// We use STATIC here, even though the buffer is updated, to force the Metal backend to use
|
||||
// a GPU buffer, which is more interesting to test.
|
||||
auto ubuffer = cleanup.add(api.createBufferObject(sizeof(SimpleMaterialParams) + 64,
|
||||
auto ubuffer = addCleanup(api.createBufferObject(sizeof(SimpleMaterialParams) + 64,
|
||||
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
||||
|
||||
shader.bindUniform<SimpleMaterialParams>(api, ubuffer, kBindingConfig);
|
||||
@@ -156,12 +153,11 @@ TEST_F(BufferUpdatesTest, VertexBufferUpdate) {
|
||||
TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
const TrianglePrimitive triangle(api);
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
// Create a program.
|
||||
@@ -170,16 +166,16 @@ TEST_F(BufferUpdatesTest, BufferObjectUpdateWithOffset) {
|
||||
// Create a uniform buffer.
|
||||
// We use STATIC here, even though the buffer is updated, to force the Metal backend to use a
|
||||
// GPU buffer, which is more interesting to test.
|
||||
auto ubuffer = cleanup.add(api.createBufferObject(sizeof(SimpleMaterialParams) + 64,
|
||||
auto ubuffer = addCleanup(api.createBufferObject(sizeof(SimpleMaterialParams) + 64,
|
||||
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
||||
|
||||
shader.bindUniform<SimpleMaterialParams>(api, ubuffer, kBindingConfig);
|
||||
|
||||
// Create a render target.
|
||||
auto colorTexture = cleanup.add(
|
||||
auto colorTexture = addCleanup(
|
||||
api.createTexture(SamplerType::SAMPLER_2D, 1, TextureFormat::RGBA8, 1, screenWidth(),
|
||||
screenHeight(), 1, TextureUsage::COLOR_ATTACHMENT TEXTURE_USAGE_READ_PIXELS));
|
||||
auto renderTarget = cleanup.add(api.createRenderTarget(TargetBufferFlags::COLOR0, screenWidth(),
|
||||
auto renderTarget = addCleanup(api.createRenderTarget(TargetBufferFlags::COLOR0, screenWidth(),
|
||||
screenHeight(), 1, 1, { { colorTexture } }, {}, {}));
|
||||
|
||||
// Upload uniforms for the first triangle.
|
||||
|
||||
@@ -28,14 +28,13 @@ TEST_F(BackendTest, FrameScheduledCallback) {
|
||||
SKIP_IF(Backend::WEBGPU, "Frame callbacks are unsupported in WebGPU");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create a SwapChain.
|
||||
// In order for the frameScheduledCallback to be called, this must be a real SwapChain (not
|
||||
// headless) so we obtain a drawable.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
|
||||
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
Handle<HwRenderTarget> renderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
int callbackCountA = 0;
|
||||
api.setFrameScheduledCallback(swapChain, nullptr, [&callbackCountA](PresentCallable callable) {
|
||||
@@ -100,10 +99,9 @@ TEST_F(BackendTest, FrameCompletedCallback) {
|
||||
SKIP_IF(Backend::WEBGPU, "Frame callbacks are unsupported in WebGPU");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create a SwapChain.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
|
||||
int callbackCountA = 0;
|
||||
api.setFrameCompletedCallback(swapChain, nullptr,
|
||||
|
||||
@@ -109,19 +109,18 @@ TEST_F(BackendTest, FeedbackLoops) {
|
||||
SKIP_IF(Backend::VULKAN, "Image is unexpectedly darker, see b/453776546");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// The test is executed within this block scope to force destructors to run before
|
||||
// executeCommands().
|
||||
{
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
// Create a program.
|
||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||
SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH, false };
|
||||
Shader shader = Shader(api, cleanup, ShaderConfig {
|
||||
Shader shader = Shader(api, *mCleanup, ShaderConfig {
|
||||
.vertexShader = fullscreenVs,
|
||||
.fragmentShader = fullscreenFs,
|
||||
.uniforms = {{"test_tex", DescriptorType::SAMPLER_2D_FLOAT, samplerInfo}, {"Params"}}
|
||||
@@ -131,18 +130,18 @@ TEST_F(BackendTest, FeedbackLoops) {
|
||||
|
||||
// Create a texture.
|
||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE;
|
||||
Handle<HwTexture> const texture = cleanup.add(api.createTexture(
|
||||
Handle<HwTexture> const texture = addCleanup(api.createTexture(
|
||||
SamplerType::SAMPLER_2D, kNumLevels, kTexFormat, 1, kTexWidth, kTexHeight, 1, usage));
|
||||
|
||||
// Create ubo
|
||||
auto ubuffer = cleanup.add(api.createBufferObject(sizeof(MaterialParams),
|
||||
auto ubuffer = addCleanup(api.createBufferObject(sizeof(MaterialParams),
|
||||
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
||||
|
||||
// Create a RenderTarget for each miplevel.
|
||||
Handle<HwRenderTarget> renderTargets[kNumLevels];
|
||||
for (uint8_t level = 0; level < kNumLevels; level++) {
|
||||
LOG(INFO) << "Level " << int(level) << ": " << (kTexWidth >> level) << "x" << (kTexHeight >> level);
|
||||
renderTargets[level] = cleanup.add(api.createRenderTarget( TargetBufferFlags::COLOR,
|
||||
renderTargets[level] = addCleanup(api.createRenderTarget( TargetBufferFlags::COLOR,
|
||||
kTexWidth >> level, kTexHeight >> level, 1, 0, { texture, level, 0 }, {}, {}));
|
||||
}
|
||||
|
||||
@@ -176,13 +175,12 @@ TEST_F(BackendTest, FeedbackLoops) {
|
||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||
state.rasterState.disableBlending();
|
||||
for (int targetLevel = 1; targetLevel < kNumLevels; targetLevel++) {
|
||||
Cleanup passCleanup(api);
|
||||
const uint32_t sourceLevel = targetLevel - 1;
|
||||
params.viewport.width = kTexWidth >> targetLevel;
|
||||
params.viewport.height = kTexHeight >> targetLevel;
|
||||
|
||||
auto descriptorSet = shader.createDescriptorSet(api);
|
||||
auto textureView = passCleanup.add(api.createTextureView(texture, sourceLevel, 1));
|
||||
auto textureView = addCleanup(api.createTextureView(texture, sourceLevel, 1));
|
||||
api.updateDescriptorSetTexture(descriptorSet, 0, textureView, SamplerParams{
|
||||
.filterMag = SamplerMagFilter::LINEAR,
|
||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||
@@ -213,13 +211,12 @@ TEST_F(BackendTest, FeedbackLoops) {
|
||||
state.rasterState.blendFunctionSrcRGB = BlendFunction::ONE;
|
||||
state.rasterState.blendFunctionDstRGB = BlendFunction::ONE;
|
||||
for (int targetLevel = kNumLevels - 2; targetLevel >= 0; targetLevel--) {
|
||||
Cleanup passCleanup(api);
|
||||
const uint32_t sourceLevel = targetLevel + 1;
|
||||
params.viewport.width = kTexWidth >> targetLevel;
|
||||
params.viewport.height = kTexHeight >> targetLevel;
|
||||
|
||||
auto descriptorSet = shader.createDescriptorSet(api);
|
||||
auto textureView = passCleanup.add(api.createTextureView(texture, sourceLevel, 1));
|
||||
auto textureView = addCleanup(api.createTextureView(texture, sourceLevel, 1));
|
||||
api.updateDescriptorSetTexture(descriptorSet, 0, textureView, SamplerParams{
|
||||
.filterMag = SamplerMagFilter::LINEAR,
|
||||
.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST
|
||||
|
||||
@@ -319,19 +319,17 @@ TEST_F(LoadImageTest, UpdateImage2D) {
|
||||
// The test is executed within this block scope to force destructors to run before
|
||||
// executeCommands().
|
||||
for (const auto& t : testCases) {
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
auto defaultRenderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
// Create a program.
|
||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||
SamplerType::SAMPLER_2D, getSamplerFormat(t.textureFormat), Precision::HIGH, false };
|
||||
|
||||
std::string const fragment = getFormattedFragment(fragmentTemplate, t.textureFormat);
|
||||
Shader shader(api, cleanup, ShaderConfig{
|
||||
Shader shader(api, *mCleanup, ShaderConfig{
|
||||
.vertexShader = mVertexShader,
|
||||
.fragmentShader= fragment,
|
||||
.uniforms = {{"test_tex", DescriptorType::SAMPLER_2D_FLOAT, samplerInfo}}
|
||||
@@ -339,7 +337,7 @@ TEST_F(LoadImageTest, UpdateImage2D) {
|
||||
|
||||
// Create a Texture.
|
||||
auto usage = TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE;
|
||||
Handle<HwTexture> const texture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
Handle<HwTexture> const texture = addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
t.textureFormat, 1, kTexSize, kTexSize, 1u, usage));
|
||||
|
||||
// Upload some pixel data.
|
||||
@@ -397,7 +395,6 @@ TEST_F(LoadImageTest, UpdateImageSRGB) {
|
||||
SKIP_IF(Backend::VULKAN, "b/454040142");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
api.startCapture();
|
||||
|
||||
PixelDataFormat const pixelFormat = PixelDataFormat::RGBA;
|
||||
@@ -405,22 +402,22 @@ TEST_F(LoadImageTest, UpdateImageSRGB) {
|
||||
TextureFormat const textureFormat = TextureFormat::SRGB8_A8;
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
auto defaultRenderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
// Create a program.
|
||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||
SamplerType::SAMPLER_2D, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
||||
std::string const fragment = getFormattedFragment(fragmentTemplate, textureFormat);
|
||||
Shader shader(api, cleanup, ShaderConfig{
|
||||
Shader shader(api, *mCleanup, ShaderConfig{
|
||||
.vertexShader = mVertexShader, .fragmentShader = fragment, .uniforms = {{
|
||||
"test_tex", DescriptorType::SAMPLER_2D_FLOAT, samplerInfo
|
||||
}}});
|
||||
|
||||
// Create a texture.
|
||||
Handle<HwTexture> const texture =
|
||||
cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1, textureFormat, 1, kTexSize,
|
||||
addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1, textureFormat, 1, kTexSize,
|
||||
kTexSize, 1, TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE));
|
||||
|
||||
// Create image data.
|
||||
@@ -481,7 +478,6 @@ TEST_F(LoadImageTest, UpdateImageSRGB) {
|
||||
|
||||
TEST_F(LoadImageTest, UpdateImageMipLevel) {
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
api.startCapture();
|
||||
|
||||
PixelDataFormat pixelFormat = PixelDataFormat::RGBA;
|
||||
@@ -489,15 +485,15 @@ TEST_F(LoadImageTest, UpdateImageMipLevel) {
|
||||
TextureFormat textureFormat = TextureFormat::RGBA32F;
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
auto defaultRenderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
// Create a program.
|
||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||
SamplerType::SAMPLER_2D, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
||||
std::string const fragment = getFormattedFragment(fragmentUpdateImageMip, textureFormat);
|
||||
Shader shader(api, cleanup, ShaderConfig {
|
||||
Shader shader(api, *mCleanup, ShaderConfig {
|
||||
.vertexShader = mVertexShader,
|
||||
.fragmentShader = fragment,
|
||||
.uniforms = {{"test_tex", DescriptorType::SAMPLER_2D_FLOAT, samplerInfo}}
|
||||
@@ -507,7 +503,7 @@ TEST_F(LoadImageTest, UpdateImageMipLevel) {
|
||||
// Base level: 1024
|
||||
// Level 1: 512 <-- upload data and sample from this level
|
||||
// Level 2: 256
|
||||
Handle<HwTexture> texture = cleanup.add(
|
||||
Handle<HwTexture> texture = addCleanup(
|
||||
api.createTexture(SamplerType::SAMPLER_2D, 3, textureFormat, 1, kDoubleTexSize,
|
||||
kDoubleTexSize, 1, TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE));
|
||||
|
||||
@@ -551,7 +547,6 @@ TEST_F(LoadImageTest, UpdateImageMipLevel) {
|
||||
TEST_F(LoadImageTest, UpdateImage3D) {
|
||||
SKIP_IF(Backend::VULKAN, "b/453776983");
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
api.startCapture();
|
||||
|
||||
PixelDataFormat pixelFormat = PixelDataFormat::RGBA;
|
||||
@@ -561,22 +556,22 @@ TEST_F(LoadImageTest, UpdateImage3D) {
|
||||
TextureUsage usage = TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE | TextureUsage::COLOR_ATTACHMENT;
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
auto defaultRenderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
// Create a program.
|
||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo { "test", "tex", 0,
|
||||
SamplerType::SAMPLER_2D_ARRAY, getSamplerFormat(textureFormat), Precision::HIGH, false };
|
||||
std::string fragment = getFormattedFragment(fragmentUpdateImage3DTemplate, samplerType);
|
||||
Shader shader(api, cleanup, ShaderConfig {
|
||||
Shader shader(api, *mCleanup, ShaderConfig {
|
||||
.vertexShader = mVertexShader,
|
||||
.fragmentShader = fragment,
|
||||
.uniforms = {{"test_tex", DescriptorType::SAMPLER_2D_ARRAY_FLOAT, samplerInfo}}
|
||||
});
|
||||
|
||||
// Create a texture.
|
||||
Handle<HwTexture> texture = cleanup.add(api.createTexture(samplerType, 1,
|
||||
Handle<HwTexture> texture = addCleanup(api.createTexture(samplerType, 1,
|
||||
textureFormat, 1, kTexSize, kTexSize, 4, usage));
|
||||
|
||||
// Create image data for all 4 layers.
|
||||
|
||||
@@ -48,16 +48,15 @@ using namespace filament::backend;
|
||||
|
||||
TEST_F(BackendTest, MRT) {
|
||||
DriverApi& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// The test is executed within this block scope to force destructors to run before
|
||||
// executeCommands().
|
||||
{
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
Shader shader(api, cleanup, ShaderConfig{
|
||||
Shader shader(api, *mCleanup, ShaderConfig{
|
||||
.vertexShader = SharedShaders::getVertexShaderText(VertexShaderType::Noop,
|
||||
ShaderUniformType::None),
|
||||
.fragmentShader = fragment,
|
||||
@@ -66,11 +65,11 @@ TEST_F(BackendTest, MRT) {
|
||||
|
||||
TrianglePrimitive triangle(api);
|
||||
|
||||
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
auto defaultRenderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
// Create two Textures.
|
||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||
Handle<HwTexture> textureA = cleanup.add(api.createTexture(
|
||||
Handle<HwTexture> textureA = addCleanup(api.createTexture(
|
||||
SamplerType::SAMPLER_2D, // target
|
||||
1, // levels
|
||||
TextureFormat::RGBA8, // format
|
||||
@@ -79,7 +78,7 @@ TEST_F(BackendTest, MRT) {
|
||||
screenHeight(), // height
|
||||
1, // depth
|
||||
usage)); // usage
|
||||
Handle<HwTexture> textureB = cleanup.add(api.createTexture(
|
||||
Handle<HwTexture> textureB = addCleanup(api.createTexture(
|
||||
SamplerType::SAMPLER_2D, // target
|
||||
1, // levels
|
||||
TextureFormat::RGBA8, // format
|
||||
@@ -90,7 +89,7 @@ TEST_F(BackendTest, MRT) {
|
||||
usage)); // usage
|
||||
|
||||
// Create a RenderTarget with two attachments.
|
||||
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createRenderTarget(
|
||||
Handle<HwRenderTarget> renderTarget = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR0 | TargetBufferFlags::COLOR1,
|
||||
// The width and height must match the width and height of the respective mip
|
||||
// level (at least for OpenGL).
|
||||
|
||||
@@ -160,12 +160,11 @@ protected:
|
||||
SKIP_IF(Backend::WEBGPU, "HwMemoryMappedBuffer APIs not yet implemented");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
auto const swapChain = cleanup.add(createSwapChain());
|
||||
auto const swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
auto const renderTarget = makeRenderTarget(cleanup);
|
||||
auto const renderTarget = makeRenderTarget(*mCleanup);
|
||||
|
||||
constexpr std::array<math::float2, 3> vertices = {{
|
||||
{-0.25f, -0.25f},
|
||||
@@ -182,7 +181,7 @@ protected:
|
||||
const uint32_t baseVertex = totalOffset / stride;
|
||||
|
||||
// Create a buffer large enough to hold the offset and the vertex data.
|
||||
auto const bufferObject = cleanup.add(api.createBufferObject(vertexDataSize + totalOffset,
|
||||
auto const bufferObject = addCleanup(api.createBufferObject(vertexDataSize + totalOffset,
|
||||
BufferObjectBinding::VERTEX, BufferUsage::SHARED_WRITE_BIT));
|
||||
|
||||
int callbackExecuted = 0;
|
||||
@@ -198,11 +197,11 @@ protected:
|
||||
flushAndWait();
|
||||
EXPECT_EQ(callbackExecuted, 1);
|
||||
|
||||
auto [shader, descset] = getSimpleShader(cleanup, color);
|
||||
auto [shader, descset] = getSimpleShader(*mCleanup, color);
|
||||
|
||||
auto [vbih, vbh, ibh] = setupGeometryBuffer(cleanup, 3, stride, baseVertex, bufferObject);
|
||||
auto [vbih, vbh, ibh] = setupGeometryBuffer(*mCleanup, 3, stride, baseVertex, bufferObject);
|
||||
|
||||
auto const renderPrimitive = cleanup.add(api.createRenderPrimitive(vbh, ibh, PrimitiveType::TRIANGLES));
|
||||
auto const renderPrimitive = addCleanup(api.createRenderPrimitive(vbh, ibh, PrimitiveType::TRIANGLES));
|
||||
|
||||
PipelineState state = getColorWritePipelineState();
|
||||
shader.addProgramToPipelineState(state);
|
||||
@@ -220,10 +219,9 @@ TEST_F(MemoryMappedTest, MapCopyUnmap) {
|
||||
SKIP_IF(Backend::WEBGPU, "HwMemoryMappedBuffer APIs not yet implemented");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create a buffer object.
|
||||
BufferObjectHandle const bufferObject = cleanup.add(api.createBufferObject(1024,
|
||||
BufferObjectHandle const bufferObject = addCleanup(api.createBufferObject(1024,
|
||||
BufferObjectBinding::VERTEX, BufferUsage::DYNAMIC_BIT | BufferUsage::SHARED_WRITE_BIT));
|
||||
|
||||
// Map the buffer.
|
||||
@@ -269,12 +267,11 @@ TEST_F(MemoryMappedTest, MultipleCopies) {
|
||||
SKIP_IF(Backend::WEBGPU, "HwMemoryMappedBuffer APIs not yet implemented");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
auto const swapChain = cleanup.add(createSwapChain());
|
||||
auto const swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
auto const renderTarget = makeRenderTarget(cleanup);
|
||||
auto const renderTarget = makeRenderTarget(*mCleanup);
|
||||
|
||||
constexpr std::array<math::float2, 3> triangle1 = {{{-0.5f, 0.5f}, {-0.8f, 0.2f}, {-0.2f, 0.2f}}};
|
||||
constexpr std::array<math::float2, 3> triangle2 = {{{0.5f, 0.5f}, {0.2f, 0.2f}, {0.8f, 0.2f}}};
|
||||
@@ -282,7 +279,7 @@ TEST_F(MemoryMappedTest, MultipleCopies) {
|
||||
constexpr size_t singleTriangleSize = triangle1.size() * sizeof(math::float2);
|
||||
constexpr size_t totalDataSize = singleTriangleSize * 3;
|
||||
|
||||
auto const bufferObject = cleanup.add(api.createBufferObject(totalDataSize,
|
||||
auto const bufferObject = addCleanup(api.createBufferObject(totalDataSize,
|
||||
BufferObjectBinding::VERTEX, BufferUsage::SHARED_WRITE_BIT));
|
||||
|
||||
int callbacksExecuted = 0;
|
||||
@@ -301,11 +298,11 @@ TEST_F(MemoryMappedTest, MultipleCopies) {
|
||||
flushAndWait();
|
||||
EXPECT_EQ(callbacksExecuted, 3);
|
||||
|
||||
auto [shader, descset] = getSimpleShader(cleanup, { 1, 1, 0, 1 });
|
||||
auto [shader, descset] = getSimpleShader(*mCleanup, { 1, 1, 0, 1 });
|
||||
|
||||
auto [vbih, vbh, ibh] = setupGeometryBuffer(cleanup, 9, sizeof(math::float2), 0, bufferObject);
|
||||
auto [vbih, vbh, ibh] = setupGeometryBuffer(*mCleanup, 9, sizeof(math::float2), 0, bufferObject);
|
||||
|
||||
auto const renderPrimitive = cleanup.add(api.createRenderPrimitive(vbh, ibh, PrimitiveType::TRIANGLES));
|
||||
auto const renderPrimitive = addCleanup(api.createRenderPrimitive(vbh, ibh, PrimitiveType::TRIANGLES));
|
||||
|
||||
PipelineState state = getColorWritePipelineState();
|
||||
shader.addProgramToPipelineState(state);
|
||||
@@ -322,12 +319,11 @@ TEST_F(MemoryMappedTest, UpdatePartial) {
|
||||
SKIP_IF(Backend::WEBGPU, "HwMemoryMappedBuffer APIs not yet implemented");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
auto renderTarget = makeRenderTarget(cleanup);
|
||||
auto renderTarget = makeRenderTarget(*mCleanup);
|
||||
|
||||
constexpr std::array<math::float2, 3> triangle1 = {{{-0.5f, 0.5f}, {-0.8f, 0.2f}, {-0.2f, 0.2f}}};
|
||||
constexpr std::array<math::float2, 3> triangle2 = {{{0.5f, 0.5f}, {0.2f, 0.2f}, {0.8f, 0.2f}}};
|
||||
@@ -335,7 +331,7 @@ TEST_F(MemoryMappedTest, UpdatePartial) {
|
||||
constexpr size_t singleTriangleSize = triangle1.size() * sizeof(math::float2);
|
||||
constexpr size_t totalDataSize = singleTriangleSize * 3;
|
||||
|
||||
auto bufferObject = cleanup.add(api.createBufferObject(totalDataSize,
|
||||
auto bufferObject = addCleanup(api.createBufferObject(totalDataSize,
|
||||
BufferObjectBinding::VERTEX, BufferUsage::SHARED_WRITE_BIT));
|
||||
|
||||
int callbacksExecuted = 0;
|
||||
@@ -358,11 +354,11 @@ TEST_F(MemoryMappedTest, UpdatePartial) {
|
||||
}
|
||||
|
||||
|
||||
auto [shader, descset] = getSimpleShader(cleanup, { 1, 1, 0, 1 });
|
||||
auto [shader, descset] = getSimpleShader(*mCleanup, { 1, 1, 0, 1 });
|
||||
|
||||
auto [vbih, vbh, ibh] = setupGeometryBuffer(cleanup, 9, sizeof(math::float2), 0, bufferObject);
|
||||
auto [vbih, vbh, ibh] = setupGeometryBuffer(*mCleanup, 9, sizeof(math::float2), 0, bufferObject);
|
||||
|
||||
auto renderPrimitive = cleanup.add(api.createRenderPrimitive(vbh, ibh, PrimitiveType::TRIANGLES));
|
||||
auto renderPrimitive = addCleanup(api.createRenderPrimitive(vbh, ibh, PrimitiveType::TRIANGLES));
|
||||
|
||||
PipelineState state = getColorWritePipelineState();
|
||||
shader.addProgramToPipelineState(state);
|
||||
|
||||
@@ -57,16 +57,15 @@ using namespace filament::backend;
|
||||
TEST_F(BackendTest, TextureViewLod) {
|
||||
auto& api = getDriverApi();
|
||||
api.startCapture(0);
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// The test is executed within this block scope to force destructors to run before
|
||||
// executeCommands().
|
||||
{
|
||||
// Create a SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
Shader whiteShader = SharedShaders::makeShader(api, cleanup, ShaderRequest {
|
||||
Shader whiteShader = SharedShaders::makeShader(api, *mCleanup, ShaderRequest {
|
||||
.mVertexType = VertexShaderType::Textured,
|
||||
.mFragmentType = FragmentShaderType::White,
|
||||
.mUniformType = ShaderUniformType::Sampler
|
||||
@@ -78,7 +77,7 @@ TEST_F(BackendTest, TextureViewLod) {
|
||||
filament::SamplerInterfaceBlock::SamplerInfo samplerInfo {
|
||||
"backend_test", "sib_tex", 0,
|
||||
SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH, false };
|
||||
Shader texturedShader(api, cleanup, ShaderConfig {
|
||||
Shader texturedShader(api, *mCleanup, ShaderConfig {
|
||||
.vertexShader = vertexShader,
|
||||
.fragmentShader = fragmentTexturedLod,
|
||||
.uniforms = {{
|
||||
@@ -93,7 +92,7 @@ TEST_F(BackendTest, TextureViewLod) {
|
||||
// Level 3: 16x16 (yellow)
|
||||
const size_t kTextureSize = 128;
|
||||
const size_t kMipLevels = 4;
|
||||
Handle<HwTexture> texture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D,
|
||||
Handle<HwTexture> texture = addCleanup(api.createTexture(SamplerType::SAMPLER_2D,
|
||||
kMipLevels, TextureFormat::RGBA8, 1, kTextureSize, kTextureSize, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::COLOR_ATTACHMENT
|
||||
| TextureUsage::UPLOADABLE));
|
||||
@@ -130,11 +129,11 @@ TEST_F(BackendTest, TextureViewLod) {
|
||||
// Level 1: 64x64 (green) <-- base
|
||||
// Level 2: 32x32 (blue) <--- white triangle rendered
|
||||
// Level 3: 16x16 (yellow) <-- max
|
||||
auto texture13 = cleanup.add(api.createTextureView(texture, 1, 3));
|
||||
auto texture13 = addCleanup(api.createTextureView(texture, 1, 3));
|
||||
|
||||
// Render a white triangle into level 2.
|
||||
// We specify mip level 2, because minMaxLevels has no effect when rendering into a texture.
|
||||
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createRenderTarget(
|
||||
Handle<HwRenderTarget> renderTarget = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR, 32, 32, 1, 0,
|
||||
{texture, 2 /* level */, 0 /* layer */}, {}, {}));
|
||||
{
|
||||
@@ -154,7 +153,7 @@ TEST_F(BackendTest, TextureViewLod) {
|
||||
}
|
||||
|
||||
backend::Handle<HwRenderTarget> defaultRenderTarget =
|
||||
cleanup.add(api.createDefaultRenderTarget());
|
||||
addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
PipelineState state = getColorWritePipelineState();
|
||||
texturedShader.addProgramToPipelineState(state);
|
||||
@@ -182,7 +181,7 @@ TEST_F(BackendTest, TextureViewLod) {
|
||||
api.endRenderPass();
|
||||
|
||||
// Adjust the base mip to 2.
|
||||
auto texture22 = cleanup.add(api.createTextureView(texture, 2, 2));
|
||||
auto texture22 = addCleanup(api.createTextureView(texture, 2, 2));
|
||||
|
||||
DescriptorSetHandle descriptorSet22 = texturedShader.createDescriptorSet(api);
|
||||
api.updateDescriptorSetTexture(descriptorSet22, 0, texture22, SamplerParams{
|
||||
|
||||
@@ -63,19 +63,18 @@ TEST_F(BackendTest, MissingRequiredAttributes) {
|
||||
// executeCommands().
|
||||
{
|
||||
DriverApi& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
// Create a program.
|
||||
Shader shader(api, cleanup, ShaderConfig{
|
||||
Shader shader(api, *mCleanup, ShaderConfig{
|
||||
.vertexShader = vertex,
|
||||
.fragmentShader = SharedShaders::getFragmentShaderText(FragmentShaderType::White,
|
||||
ShaderUniformType::None),
|
||||
});
|
||||
|
||||
auto defaultRenderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
auto defaultRenderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
TrianglePrimitive triangle(api);
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ void initPushConstants() {
|
||||
}
|
||||
|
||||
TEST_F(BackendTest, PushConstants) {
|
||||
SKIP_IF(SkipEnvironment(OperatingSystem::CI, Backend::OPENGL), "see b/453757504");
|
||||
SKIP_IF(Backend::OPENGL, "see b/453757504");
|
||||
SKIP_IF(SkipEnvironment(OperatingSystem::CI, Backend::VULKAN), "see b/453776664");
|
||||
SKIP_IF(Backend::WEBGPU, "Push constants not supported on WebGPU");
|
||||
|
||||
@@ -113,22 +113,21 @@ TEST_F(BackendTest, PushConstants) {
|
||||
auto& api = getDriverApi();
|
||||
|
||||
api.startCapture(0);
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// The test is executed within this block scope to force destructors to run before
|
||||
// executeCommands().
|
||||
{
|
||||
// Create a SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
// Create a program.
|
||||
ShaderGenerator shaderGen(triangleVs, triangleFs, sBackend, sIsMobilePlatform);
|
||||
Program p =
|
||||
shaderGen.getProgramWithPushConstants(api, { gVertConstants, gFragConstants, {} });
|
||||
ProgramHandle program = cleanup.add(api.createProgram(std::move(p)));
|
||||
ProgramHandle program = addCleanup(api.createProgram(std::move(p)));
|
||||
|
||||
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
Handle<HwRenderTarget> renderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
TrianglePrimitive triangle(api);
|
||||
|
||||
|
||||
@@ -256,16 +256,15 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
TestCase const testCases[] = { t0, t2, t3, t4, t5, t6, t7, t8 };
|
||||
|
||||
DriverApi& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
std::string vertexShader = SharedShaders::getVertexShaderText(VertexShaderType::Noop,
|
||||
ShaderUniformType::None);
|
||||
Shader floatShader(api, cleanup, ShaderConfig{
|
||||
Shader floatShader(api, *mCleanup, ShaderConfig{
|
||||
.vertexShader = vertexShader,
|
||||
.fragmentShader = fragmentFloat,
|
||||
.uniforms = {}
|
||||
});
|
||||
Shader uintShader(api, cleanup, ShaderConfig{
|
||||
Shader uintShader(api, *mCleanup, ShaderConfig{
|
||||
.vertexShader = vertexShader,
|
||||
.fragmentShader = fragmentUint,
|
||||
.uniforms = {}
|
||||
@@ -275,9 +274,9 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
Handle<HwSwapChain> swapChain;
|
||||
if (t.useDefaultRT) {
|
||||
swapChain = cleanup.add(createSwapChain());
|
||||
swapChain = addCleanup(createSwapChain());
|
||||
} else {
|
||||
swapChain = cleanup.add(api.createSwapChainHeadless(t.getRenderTargetSize(),
|
||||
swapChain = addCleanup(api.createSwapChainHeadless(t.getRenderTargetSize(),
|
||||
t.getRenderTargetSize(), 0));
|
||||
}
|
||||
|
||||
@@ -285,7 +284,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
|
||||
// Create a Texture and RenderTarget to render into.
|
||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||
Handle<HwTexture> const texture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D,
|
||||
Handle<HwTexture> const texture = addCleanup(api.createTexture(SamplerType::SAMPLER_2D,
|
||||
t.mipLevels, t.textureFormat, 1, renderTargetBaseSize, renderTargetBaseSize, 1,
|
||||
usage));
|
||||
|
||||
@@ -293,11 +292,11 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
if (t.useDefaultRT) {
|
||||
// The width and height must match the width and height of the respective mip
|
||||
// level (at least for OpenGL).
|
||||
renderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
renderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
} else {
|
||||
// The width and height must match the width and height of the respective mip
|
||||
// level (at least for OpenGL).
|
||||
renderTarget = cleanup.add(api.createRenderTarget(
|
||||
renderTarget = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR, t.getRenderTargetSize(),
|
||||
t.getRenderTargetSize(), t.samples, 0, {{ texture, uint8_t(t.mipLevel) }}, {},
|
||||
{}));
|
||||
@@ -330,11 +329,10 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
api.endRenderPass();
|
||||
|
||||
if (t.mipLevel > 0) {
|
||||
Cleanup localCleanup(api);
|
||||
// Render red to the first mip level to check that the backend is actually reading the
|
||||
// correct mip.
|
||||
RenderPassParams p = params;
|
||||
Handle<HwRenderTarget> mipLevelOneRT = localCleanup.add(api.createRenderTarget(
|
||||
Handle<HwRenderTarget> mipLevelOneRT = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR, renderTargetBaseSize, renderTargetBaseSize, 1, 0,
|
||||
{{ texture }}, {}, {}));
|
||||
p.clearColor = { 1.f, 0.f, 0.f, 1.f };
|
||||
@@ -382,13 +380,12 @@ TEST_F(ReadPixelsTest, ReadPixelsPerformance) {
|
||||
const int iterationCount = 100;
|
||||
|
||||
DriverApi& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
Shader shader = SharedShaders::makeShader(api, cleanup, ShaderRequest{
|
||||
Shader shader = SharedShaders::makeShader(api, *mCleanup, ShaderRequest{
|
||||
.mVertexType = VertexShaderType::Noop,
|
||||
.mFragmentType = FragmentShaderType::White,
|
||||
.mUniformType = ShaderUniformType::None
|
||||
@@ -396,7 +393,7 @@ TEST_F(ReadPixelsTest, ReadPixelsPerformance) {
|
||||
|
||||
// Create a Texture and RenderTarget to render into.
|
||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||
Handle<HwTexture> texture = cleanup.add(api.createTexture(
|
||||
Handle<HwTexture> texture = addCleanup(api.createTexture(
|
||||
SamplerType::SAMPLER_2D, // target
|
||||
1, // levels
|
||||
TextureFormat::RGBA8, // format
|
||||
@@ -406,7 +403,7 @@ TEST_F(ReadPixelsTest, ReadPixelsPerformance) {
|
||||
1, // depth
|
||||
usage)); // usage
|
||||
|
||||
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createRenderTarget(
|
||||
Handle<HwRenderTarget> renderTarget = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR,
|
||||
renderTargetSize, // width
|
||||
renderTargetSize, // height
|
||||
|
||||
@@ -50,21 +50,20 @@ TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
||||
SKIP_IF(Backend::VULKAN, "b/453776730");
|
||||
SKIP_IF(Backend::WEBGPU, "External images aren't supported in WebGPU");
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
TrianglePrimitive triangle(api);
|
||||
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
|
||||
Shader shader = createShader(api, cleanup, sBackend);
|
||||
Shader shader = createShader(api, *mCleanup, sBackend);
|
||||
|
||||
backend::Handle<HwRenderTarget> defaultRenderTarget = cleanup.add(
|
||||
backend::Handle<HwRenderTarget> defaultRenderTarget = addCleanup(
|
||||
api.createDefaultRenderTarget());
|
||||
|
||||
// Create a texture that will be backed by an external image.
|
||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||
const NativeView& view = getNativeView();
|
||||
backend::Handle<HwTexture> texture = cleanup.add(api.createTexture(
|
||||
backend::Handle<HwTexture> texture = addCleanup(api.createTexture(
|
||||
SamplerType::SAMPLER_EXTERNAL, // target
|
||||
1, // levels
|
||||
TextureFormat::RGBA8, // format
|
||||
@@ -115,16 +114,15 @@ TEST_F(BackendTest, RenderExternalImage) {
|
||||
SKIP_IF(Backend::WEBGPU, "External images aren't supported in WebGPU");
|
||||
SKIP_IF(SkipEnvironment(OperatingSystem::CI, Backend::OPENGL), "b/453758594");
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
TrianglePrimitive triangle(api);
|
||||
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
|
||||
Shader shader = createShader(api, cleanup, sBackend);
|
||||
Shader shader = createShader(api, *mCleanup, sBackend);
|
||||
DescriptorSetHandle descriptorSet = shader.createDescriptorSet(api);
|
||||
|
||||
backend::Handle<HwRenderTarget> defaultRenderTarget = cleanup.add(
|
||||
backend::Handle<HwRenderTarget> defaultRenderTarget = addCleanup(
|
||||
api.createDefaultRenderTarget());
|
||||
|
||||
// require users to create two Filament textures and have two material parameters
|
||||
@@ -171,7 +169,7 @@ TEST_F(BackendTest, RenderExternalImage) {
|
||||
|
||||
api.setupExternalImage(pixBuffer);
|
||||
backend::Handle<HwTexture> texture =
|
||||
cleanup.add(api.createTextureExternalImage(SamplerType::SAMPLER_EXTERNAL,
|
||||
addCleanup(api.createTextureExternalImage(SamplerType::SAMPLER_EXTERNAL,
|
||||
TextureFormat::RGBA8, 1024, 1024, usage, pixBuffer));
|
||||
|
||||
// We're now free to release the buffer.
|
||||
|
||||
@@ -44,7 +44,6 @@ TEST_F(BackendTest, ScissorViewportRegion) {
|
||||
constexpr int kSrcRtHeight = kSrcTexHeight >> kSrcLevel;
|
||||
|
||||
api.startCapture(0);
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// color texture/RT (mip level 1) 512x512 depth texture (mip level 0) 512x512
|
||||
// +----------------------------------------+ +------------------------------------------+
|
||||
@@ -70,10 +69,10 @@ TEST_F(BackendTest, ScissorViewportRegion) {
|
||||
// executeCommands().
|
||||
{
|
||||
// Create a SwapChain and make it current. We don't really use it so the res doesn't matter.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
Shader shader = SharedShaders::makeShader(api, cleanup,
|
||||
Shader shader = SharedShaders::makeShader(api, *mCleanup,
|
||||
ShaderRequest{
|
||||
.mVertexType = VertexShaderType::Noop,
|
||||
.mFragmentType = FragmentShaderType::White,
|
||||
@@ -81,10 +80,10 @@ TEST_F(BackendTest, ScissorViewportRegion) {
|
||||
});
|
||||
|
||||
// Create source color and depth textures.
|
||||
Handle<HwTexture> srcTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D,
|
||||
Handle<HwTexture> srcTexture = addCleanup(api.createTexture(SamplerType::SAMPLER_2D,
|
||||
kNumLevels, kSrcTexFormat, 1, kSrcTexWidth, kSrcTexHeight, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::COLOR_ATTACHMENT TEXTURE_USAGE_READ_PIXELS));
|
||||
Handle<HwTexture> depthTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
Handle<HwTexture> depthTexture = addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
TextureFormat::DEPTH16, 1, 512, 512, 1, TextureUsage::DEPTH_ATTACHMENT));
|
||||
|
||||
// Render into the bottom-left quarter of the texture.
|
||||
@@ -103,7 +102,7 @@ TEST_F(BackendTest, ScissorViewportRegion) {
|
||||
|
||||
// We purposely set the render target width and height to smaller than the texture, to check
|
||||
// that this case is handled correctly.
|
||||
Handle<HwRenderTarget> rt = cleanup.add(api.createRenderTarget(
|
||||
Handle<HwRenderTarget> rt = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR | TargetBufferFlags::DEPTH, kSrcRtHeight, kSrcRtHeight, 1,
|
||||
1, { srcTexture, kSrcLevel, 0 }, { depthTexture, 0, 0 }, {}));
|
||||
|
||||
@@ -143,23 +142,22 @@ TEST_F(BackendTest, ScissorViewportEdgeCases) {
|
||||
auto& api = getDriverApi();
|
||||
|
||||
api.startCapture(0);
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// The test is executed within this block scope to force destructors to run before
|
||||
// executeCommands().
|
||||
{
|
||||
// Create a SwapChain and make it current. We don't really use it so the res doesn't matter.
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
Shader shader = SharedShaders::makeShader(api, cleanup, ShaderRequest{
|
||||
Shader shader = SharedShaders::makeShader(api, *mCleanup, ShaderRequest{
|
||||
.mVertexType = VertexShaderType::Noop,
|
||||
.mFragmentType = FragmentShaderType::White,
|
||||
.mUniformType = ShaderUniformType::None,
|
||||
});
|
||||
|
||||
// Create a source color textures.
|
||||
Handle<HwTexture> srcTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
Handle<HwTexture> srcTexture = addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
TextureFormat::RGBA8, 1, 512, 512, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::COLOR_ATTACHMENT TEXTURE_USAGE_READ_PIXELS));
|
||||
|
||||
@@ -183,7 +181,7 @@ TEST_F(BackendTest, ScissorViewportEdgeCases) {
|
||||
Viewport scissor = {0, 0, (uint32_t)std::numeric_limits<int32_t>::max(),
|
||||
(uint32_t)std::numeric_limits<int32_t>::max()};
|
||||
|
||||
Handle<HwRenderTarget> renderTarget = cleanup.add(api.createRenderTarget(
|
||||
Handle<HwRenderTarget> renderTarget = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR, 512, 512, 1, 1,
|
||||
{srcTexture, 0, 0}, {}, {}));
|
||||
|
||||
|
||||
@@ -38,18 +38,17 @@ public:
|
||||
|
||||
Handle <HwSwapChain> mSwapChain;
|
||||
ProgramHandle mProgram;
|
||||
Cleanup mCleanup;
|
||||
|
||||
BasicStencilBufferTest() : mCleanup(getDriverApi()) {}
|
||||
BasicStencilBufferTest() = default;
|
||||
|
||||
void SetUp() override {
|
||||
auto& api = getDriverApi();
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
mSwapChain = mCleanup.add(createSwapChain());
|
||||
mSwapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(mSwapChain, mSwapChain);
|
||||
|
||||
Shader shader = SharedShaders::makeShader(api, mCleanup, ShaderRequest{
|
||||
Shader shader = SharedShaders::makeShader(api, *mCleanup, ShaderRequest{
|
||||
.mVertexType = VertexShaderType::Noop,
|
||||
.mFragmentType = FragmentShaderType::White,
|
||||
.mUniformType = ShaderUniformType::None
|
||||
@@ -130,16 +129,15 @@ TEST_F(BasicStencilBufferTest, StencilBuffer) {
|
||||
SKIP_IF(Backend::VULKAN, "b/453776821");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create two textures: a color and a stencil, and an associated RenderTarget.
|
||||
auto colorTexture =
|
||||
cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1, TextureFormat::RGBA8, 1,
|
||||
addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1, TextureFormat::RGBA8, 1,
|
||||
screenWidth(), screenHeight(), 1, TextureUsage::COLOR_ATTACHMENT));
|
||||
auto stencilTexture =
|
||||
cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1, TextureFormat::STENCIL8, 1,
|
||||
addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1, TextureFormat::STENCIL8, 1,
|
||||
screenWidth(), screenHeight(), 1, TextureUsage::STENCIL_ATTACHMENT));
|
||||
auto renderTarget = cleanup.add(api.createRenderTarget(TargetBufferFlags::COLOR0 |
|
||||
auto renderTarget = addCleanup(api.createRenderTarget(TargetBufferFlags::COLOR0 |
|
||||
TargetBufferFlags::STENCIL,
|
||||
screenWidth(), screenHeight(), 1, 0, { { colorTexture } }, {}, { { stencilTexture } }));
|
||||
|
||||
@@ -156,16 +154,15 @@ TEST_F(BasicStencilBufferTest, DepthAndStencilBuffer) {
|
||||
SKIP_IF(Backend::WEBGPU, "test cases fail in WebGPU, see b/424157731");
|
||||
SKIP_IF(Backend::VULKAN, "b/453776965");
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create two textures: a color and a stencil, and an associated RenderTarget.
|
||||
auto colorTexture =
|
||||
cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1, TextureFormat::RGBA8, 1,
|
||||
addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1, TextureFormat::RGBA8, 1,
|
||||
screenWidth(), screenHeight(), 1, TextureUsage::COLOR_ATTACHMENT));
|
||||
auto depthStencilTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
auto depthStencilTexture = addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
TextureFormat::DEPTH24_STENCIL8, 1, screenWidth(), screenHeight(), 1,
|
||||
TextureUsage::STENCIL_ATTACHMENT | TextureUsage::DEPTH_ATTACHMENT));
|
||||
auto renderTarget = cleanup.add(api.createRenderTarget(
|
||||
auto renderTarget = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR0 | TargetBufferFlags::STENCIL, screenWidth(), screenHeight(),
|
||||
1, 0, { { colorTexture } }, { depthStencilTexture }, { { depthStencilTexture } }));
|
||||
|
||||
@@ -185,23 +182,22 @@ TEST_F(BasicStencilBufferTest, StencilBufferMSAA) {
|
||||
SKIP_IF(Backend::VULKAN, "b/453777217");
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
|
||||
// Create two textures: a single-sampled color and a MSAA stencil texture.
|
||||
// We also create two RenderTargets, one for each pass:
|
||||
// Pass 0: Render a triangle only into the MSAA stencil buffer.
|
||||
// Pass 1: Render a triangle into (an auto-created) MSAA color buffer using the stencil test.
|
||||
// Performs an auto-resolve on the color.
|
||||
auto colorTexture = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
auto colorTexture = addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
TextureFormat::RGBA8, 1, screenWidth(), screenHeight(), 1,
|
||||
TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE));
|
||||
auto depthStencilTextureMSAA = cleanup.add(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
auto depthStencilTextureMSAA = addCleanup(api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
TextureFormat::DEPTH24_STENCIL8, 4, screenWidth(), screenHeight(), 1,
|
||||
TextureUsage::STENCIL_ATTACHMENT | TextureUsage::DEPTH_ATTACHMENT));
|
||||
auto renderTarget0 = cleanup.add(api.createRenderTarget(
|
||||
auto renderTarget0 = addCleanup(api.createRenderTarget(
|
||||
TargetBufferFlags::DEPTH_AND_STENCIL, screenWidth(), screenHeight(), 4, 0,
|
||||
{{}}, { depthStencilTextureMSAA }, { depthStencilTextureMSAA }));
|
||||
auto renderTarget1 = cleanup.add(
|
||||
auto renderTarget1 = addCleanup(
|
||||
api.createRenderTarget(TargetBufferFlags::COLOR0 | TargetBufferFlags::DEPTH_AND_STENCIL,
|
||||
screenWidth(), screenHeight(), 4, 0, { { colorTexture } },
|
||||
{ depthStencilTextureMSAA }, { depthStencilTextureMSAA }));
|
||||
|
||||
@@ -32,12 +32,11 @@ TEST_F(BackendTest, TestTemplate) {
|
||||
constexpr int kRenderTargetSize = 512;
|
||||
|
||||
auto& api = getDriverApi();
|
||||
Cleanup cleanup(api);
|
||||
auto swapChain = cleanup.add(createSwapChain());
|
||||
auto swapChain = addCleanup(createSwapChain());
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
RenderTargetHandle renderTarget = cleanup.add(api.createDefaultRenderTarget());
|
||||
RenderTargetHandle renderTarget = addCleanup(api.createDefaultRenderTarget());
|
||||
|
||||
Shader shader = SharedShaders::makeShader(api, cleanup, ShaderRequest{
|
||||
Shader shader = SharedShaders::makeShader(api, *mCleanup, ShaderRequest{
|
||||
.mVertexType = VertexShaderType::Simple,
|
||||
.mFragmentType = FragmentShaderType::SolidColored,
|
||||
.mUniformType = ShaderUniformType::Simple,
|
||||
@@ -50,7 +49,7 @@ TEST_F(BackendTest, TestTemplate) {
|
||||
PipelineState ps = getColorWritePipelineState();
|
||||
shader.addProgramToPipelineState(ps);
|
||||
|
||||
auto ubuffer = cleanup.add(api.createBufferObject(sizeof(SimpleMaterialParams),
|
||||
auto ubuffer = addCleanup(api.createBufferObject(sizeof(SimpleMaterialParams),
|
||||
BufferObjectBinding::UNIFORM, BufferUsage::STATIC));
|
||||
shader.uploadUniform(api, ubuffer, SimpleMaterialParams{
|
||||
.color = float4(1, 0, 0, 1),
|
||||
|
||||
Reference in New Issue
Block a user