fix a lot of issues with the backend tests
With these fixes failing tests are: OpenGL: BackendTest.FeedbackLoops Metal: BackendTest.ColorResolve BackendTest.BufferObjectUpdateWithOffset BasicStencilBufferTest.StencilBufferMSAA Vulkan: Many failures still
This commit is contained in:
committed by
Mathias Agopian
parent
5aa15f061b
commit
f2f4f556b5
@@ -86,9 +86,9 @@ void BackendTest::executeCommands() {
|
||||
}
|
||||
|
||||
void BackendTest::flushAndWait() {
|
||||
auto& api = getDriverApi();
|
||||
api.finish();
|
||||
getDriverApi().finish();
|
||||
executeCommands();
|
||||
getDriver().purge();
|
||||
}
|
||||
|
||||
Handle<HwSwapChain> BackendTest::createSwapChain() {
|
||||
|
||||
@@ -193,60 +193,6 @@ static void createFaces(DriverApi& dapi, Handle<HwTexture> texture, int baseWidt
|
||||
dapi.update3DImage(texture, level, 0, 0, 0, width, height, 6, std::move(pb));
|
||||
}
|
||||
|
||||
TEST_F(BackendTest, CubemapMinify) {
|
||||
auto& api = getDriverApi();
|
||||
|
||||
Handle<HwTexture> texture = api.createTexture(
|
||||
SamplerType::SAMPLER_CUBEMAP, 4, TextureFormat::RGBA8, 1, 256, 256, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE | TextureUsage::COLOR_ATTACHMENT);
|
||||
|
||||
createFaces(api, texture, 256, 256, 0, float3(0.5, 0, 0));
|
||||
|
||||
const int srcLevel = 0;
|
||||
const int dstLevel = 1;
|
||||
|
||||
const TextureCubemapFace srcFace = TextureCubemapFace::NEGATIVE_Y;
|
||||
const TextureCubemapFace dstFace = TextureCubemapFace::NEGATIVE_Y;
|
||||
|
||||
const TargetBufferInfo srcInfo = { texture, srcLevel, +srcFace };
|
||||
const TargetBufferInfo dstInfo = { texture, dstLevel, +dstFace };
|
||||
|
||||
Handle<HwRenderTarget> srcRenderTarget;
|
||||
srcRenderTarget = api.createRenderTarget( TargetBufferFlags::COLOR,
|
||||
256 >> srcLevel, 256 >> srcLevel, 1, { srcInfo }, {}, {});
|
||||
|
||||
Handle<HwRenderTarget> dstRenderTarget;
|
||||
dstRenderTarget = api.createRenderTarget( TargetBufferFlags::COLOR,
|
||||
256 >> dstLevel, 256 >> dstLevel, 1, { dstInfo }, {}, {});
|
||||
|
||||
api.blit(TargetBufferFlags::COLOR0, dstRenderTarget,
|
||||
{0, 0, 256 >> dstLevel, 256 >> dstLevel}, srcRenderTarget,
|
||||
{0, 0, 256 >> srcLevel, 256 >> srcLevel}, SamplerMagFilter::LINEAR);
|
||||
|
||||
// Push through an empty frame. Note that this test does not do
|
||||
// makeCurrent / commit and is therefore similar to renderStandaloneView.
|
||||
api.beginFrame(0, 0);
|
||||
api.endFrame(0);
|
||||
|
||||
// Grab a screenshot.
|
||||
ScreenshotParams params { 256 >> dstLevel, 256 >> dstLevel, "CubemapMinify.png" };
|
||||
api.beginFrame(0, 0);
|
||||
dumpScreenshot(api, dstRenderTarget, ¶ms);
|
||||
api.endFrame(0);
|
||||
|
||||
// Wait for the ReadPixels result to come back.
|
||||
api.finish();
|
||||
executeCommands();
|
||||
getDriver().purge();
|
||||
|
||||
// Cleanup.
|
||||
api.destroyTexture(texture);
|
||||
api.destroyRenderTarget(srcRenderTarget);
|
||||
api.destroyRenderTarget(dstRenderTarget);
|
||||
executeCommands();
|
||||
}
|
||||
|
||||
|
||||
TEST_F(BackendTest, ColorMagnify) {
|
||||
auto& api = getDriverApi();
|
||||
|
||||
@@ -263,7 +209,7 @@ TEST_F(BackendTest, ColorMagnify) {
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
// Create a source texture.
|
||||
Handle<HwTexture> srcTexture = api.createTexture(
|
||||
Handle<HwTexture> const srcTexture = api.createTexture(
|
||||
SamplerType::SAMPLER_2D, kNumLevels, kSrcTexFormat, 1, kSrcTexWidth, kSrcTexHeight, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE | TextureUsage::COLOR_ATTACHMENT);
|
||||
const bool flipY = sBackend == Backend::OPENGL;
|
||||
@@ -271,7 +217,7 @@ TEST_F(BackendTest, ColorMagnify) {
|
||||
createBitmap(api, srcTexture, kSrcTexWidth, kSrcTexHeight, 1, float3(0, 0, 0.5), flipY);
|
||||
|
||||
// Create a destination texture.
|
||||
Handle<HwTexture> dstTexture = api.createTexture(
|
||||
Handle<HwTexture> const dstTexture = api.createTexture(
|
||||
SamplerType::SAMPLER_2D, kNumLevels, kDstTexFormat, 1, kDstTexWidth, kDstTexHeight, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::COLOR_ATTACHMENT);
|
||||
|
||||
@@ -338,7 +284,7 @@ TEST_F(BackendTest, ColorMinify) {
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
// Create a source texture.
|
||||
Handle<HwTexture> srcTexture = api.createTexture(
|
||||
Handle<HwTexture> const srcTexture = api.createTexture(
|
||||
SamplerType::SAMPLER_2D, kNumLevels, kSrcTexFormat, 1, kSrcTexWidth, kSrcTexHeight, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE | TextureUsage::COLOR_ATTACHMENT);
|
||||
const bool flipY = sBackend == Backend::OPENGL;
|
||||
@@ -346,7 +292,7 @@ TEST_F(BackendTest, ColorMinify) {
|
||||
createBitmap(api, srcTexture, kSrcTexWidth, kSrcTexHeight, 1, float3(0, 0, 0.5), flipY);
|
||||
|
||||
// Create a destination texture.
|
||||
Handle<HwTexture> dstTexture = api.createTexture(
|
||||
Handle<HwTexture> const dstTexture = api.createTexture(
|
||||
SamplerType::SAMPLER_2D, kNumLevels, kDstTexFormat, 1, kDstTexWidth, kDstTexHeight, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::COLOR_ATTACHMENT);
|
||||
|
||||
@@ -362,29 +308,20 @@ TEST_F(BackendTest, ColorMinify) {
|
||||
|
||||
// Do a "minify" blit from level 1 of the source RT to the level 0 of the destination RT.
|
||||
const int srcLevel = 1;
|
||||
api.blit(TargetBufferFlags::COLOR0, dstRenderTargets[0],
|
||||
{0, 0, kDstTexWidth, kDstTexHeight}, srcRenderTargets[srcLevel],
|
||||
{0, 0, kSrcTexWidth >> srcLevel, kSrcTexHeight >> srcLevel}, SamplerMagFilter::LINEAR);
|
||||
|
||||
// Push through an empty frame to allow the texture to upload and the blit to execute.
|
||||
api.beginFrame(0, 0);
|
||||
api.commit(swapChain);
|
||||
api.endFrame(0);
|
||||
api.blit(TargetBufferFlags::COLOR0,
|
||||
dstRenderTargets[0], {0, 0, kDstTexWidth, kDstTexHeight},
|
||||
srcRenderTargets[srcLevel], {0, 0, kSrcTexWidth >> srcLevel, kSrcTexHeight >> srcLevel},
|
||||
SamplerMagFilter::LINEAR);
|
||||
|
||||
// Grab a screenshot.
|
||||
ScreenshotParams params { kDstTexWidth, kDstTexHeight, "ColorMinify.png" };
|
||||
api.beginFrame(0, 0);
|
||||
dumpScreenshot(api, dstRenderTargets[0], ¶ms);
|
||||
api.commit(swapChain);
|
||||
api.endFrame(0);
|
||||
|
||||
// Wait for the ReadPixels result to come back.
|
||||
api.finish();
|
||||
executeCommands();
|
||||
getDriver().purge();
|
||||
flushAndWait();
|
||||
|
||||
// Check if the image matches perfectly to our golden run.
|
||||
const uint32_t expected = 0x7739bef5;
|
||||
const uint32_t expected = 0xf3d9c53f;
|
||||
printf("Computed hash is 0x%8.8x, Expected 0x%8.8x\n", params.pixelHashResult, expected);
|
||||
EXPECT_TRUE(params.pixelHashResult == expected);
|
||||
|
||||
@@ -417,8 +354,6 @@ TEST_F(BackendTest, DepthMinify) {
|
||||
{
|
||||
ShaderGenerator shaderGen(triangleVs, triangleFs, sBackend, sIsMobilePlatform);
|
||||
Program prog = shaderGen.getProgram(api);
|
||||
Program::Sampler psamplers[] = { utils::CString("tex"), 0 };
|
||||
prog.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, psamplers, sizeof(psamplers) / sizeof(psamplers[0]));
|
||||
prog.uniformBlockBindings({{"params", 1}});
|
||||
program = api.createProgram(std::move(prog));
|
||||
}
|
||||
@@ -550,85 +485,82 @@ TEST_F(BackendTest, ColorResolve) {
|
||||
constexpr auto kColorTexFormat = TextureFormat::RGBA8;
|
||||
constexpr int kSampleCount = 4;
|
||||
|
||||
// Create a SwapChain and make it current. We don't really use it so the res doesn't matter.
|
||||
auto swapChain = api.createSwapChainHeadless(256, 256, 0);
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
|
||||
// Create a program.
|
||||
ProgramHandle program;
|
||||
{
|
||||
ShaderGenerator shaderGen(triangleVs, triangleFs, sBackend, sIsMobilePlatform);
|
||||
Program prog = shaderGen.getProgram(api);
|
||||
Program::Sampler psamplers[] = { utils::CString("tex"), 0 };
|
||||
prog.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, psamplers, sizeof(psamplers) / sizeof(psamplers[0]));
|
||||
prog.uniformBlockBindings({{"params", 1}});
|
||||
program = api.createProgram(std::move(prog));
|
||||
}
|
||||
|
||||
// Create a VertexBuffer, IndexBuffer, and RenderPrimitive.
|
||||
TrianglePrimitive* triangle = new TrianglePrimitive(api);
|
||||
TrianglePrimitive const triangle(api);
|
||||
|
||||
// Create 4-sample texture.
|
||||
Handle<HwTexture> srcColorTexture = api.createTexture(
|
||||
Handle<HwTexture> const srcColorTexture = api.createTexture(
|
||||
SamplerType::SAMPLER_2D, 1, kColorTexFormat, kSampleCount, kSrcTexWidth, kSrcTexHeight, 1,
|
||||
TextureUsage::COLOR_ATTACHMENT);
|
||||
|
||||
// Create 1-sample texture.
|
||||
Handle<HwTexture> dstColorTexture = api.createTexture(
|
||||
Handle<HwTexture> const dstColorTexture = api.createTexture(
|
||||
SamplerType::SAMPLER_2D, 1, kColorTexFormat, 1, kDstTexWidth, kDstTexHeight, 1,
|
||||
TextureUsage::SAMPLEABLE | TextureUsage::COLOR_ATTACHMENT);
|
||||
|
||||
// Create a 4-sample render target with the 4-sample texture.
|
||||
Handle<HwRenderTarget> srcRenderTarget = api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR, kSrcTexWidth, kSrcTexHeight, kSampleCount,{{ srcColorTexture }}, {}, {});
|
||||
Handle<HwRenderTarget> const srcRenderTarget = api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR, kSrcTexWidth, kSrcTexHeight, kSampleCount,
|
||||
{{ srcColorTexture }}, {}, {});
|
||||
|
||||
// Create a 1-sample render target with the 1-sample texture.
|
||||
Handle<HwRenderTarget> dstRenderTarget = api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR, kDstTexWidth, kDstTexHeight, 1, {{ dstColorTexture }}, {}, {});
|
||||
Handle<HwRenderTarget> const dstRenderTarget = api.createRenderTarget(
|
||||
TargetBufferFlags::COLOR, kDstTexWidth, kDstTexHeight, 1,
|
||||
{{ dstColorTexture }}, {}, {});
|
||||
|
||||
// Prep for rendering.
|
||||
RenderPassParams params = {};
|
||||
params.flags.clear = TargetBufferFlags::COLOR;
|
||||
params.flags.discardStart = TargetBufferFlags::ALL;
|
||||
params.flags.discardEnd = TargetBufferFlags::NONE;
|
||||
params.clearColor = float4(1, 1, 0, 1);
|
||||
params.viewport.width = kSrcTexWidth;
|
||||
params.viewport.height = kSrcTexHeight;
|
||||
|
||||
PipelineState state = {};
|
||||
state.rasterState.colorWrite = true;
|
||||
state.rasterState.culling = RasterState::CullingMode::NONE;
|
||||
state.program = program;
|
||||
state.rasterState.colorWrite = true;
|
||||
state.rasterState.depthWrite = false;
|
||||
state.rasterState.depthFunc = RasterState::DepthFunc::A;
|
||||
state.rasterState.culling = CullingMode::NONE;
|
||||
|
||||
auto ubuffer = api.createBufferObject(sizeof(MaterialParams),
|
||||
BufferObjectBinding::UNIFORM, BufferUsage::STATIC);
|
||||
api.makeCurrent(swapChain, swapChain);
|
||||
api.beginFrame(0, 0);
|
||||
api.bindUniformBuffer(0, ubuffer);
|
||||
|
||||
// Draw red triangle into srcRenderTarget.
|
||||
uploadUniforms(api, ubuffer, {
|
||||
.color = float4(1, 0, 0, 1),
|
||||
.scale = float4(1, 1, 0.5, 0),
|
||||
});
|
||||
api.beginRenderPass(srcRenderTarget, params);
|
||||
api.draw(state, triangle->getRenderPrimitive(), 1);
|
||||
api.endRenderPass();
|
||||
|
||||
// FIXME: on Metal this triangle is not drawn. Can't understand why.
|
||||
api.beginFrame(0, 0);
|
||||
api.beginRenderPass(srcRenderTarget, params);
|
||||
api.bindUniformBuffer(0, ubuffer);
|
||||
api.draw(state, triangle.getRenderPrimitive(), 1);
|
||||
api.endRenderPass();
|
||||
api.endFrame(0);
|
||||
|
||||
// Resolve the MSAA render target into the single-sample render target.
|
||||
api.blit(TargetBufferFlags::COLOR, dstRenderTarget,
|
||||
{0, 0, kDstTexWidth, kDstTexHeight}, srcRenderTarget,
|
||||
{0, 0, kSrcTexWidth, kSrcTexHeight}, SamplerMagFilter::LINEAR);
|
||||
api.blit(TargetBufferFlags::COLOR,
|
||||
dstRenderTarget, {0, 0, kDstTexWidth, kDstTexHeight},
|
||||
srcRenderTarget, {0, 0, kSrcTexWidth, kSrcTexHeight},
|
||||
SamplerMagFilter::NEAREST);
|
||||
|
||||
// Grab a screenshot.
|
||||
ScreenshotParams sparams { kDstTexWidth, kDstTexHeight, "ColorResolve.png" };
|
||||
api.beginFrame(0, 0);
|
||||
ScreenshotParams sparams{ kDstTexWidth, kDstTexHeight, "ColorResolve.png" };
|
||||
dumpScreenshot(api, dstRenderTarget, &sparams);
|
||||
api.commit(swapChain);
|
||||
api.endFrame(0);
|
||||
|
||||
// Wait for the ReadPixels result to come back.
|
||||
api.finish();
|
||||
executeCommands();
|
||||
getDriver().purge();
|
||||
flushAndWait();
|
||||
|
||||
// Check if the image matches perfectly to our golden run.
|
||||
const uint32_t expected = 0xebfac2ef;
|
||||
@@ -640,11 +572,9 @@ TEST_F(BackendTest, ColorResolve) {
|
||||
api.destroyProgram(program);
|
||||
api.destroyTexture(srcColorTexture);
|
||||
api.destroyTexture(dstColorTexture);
|
||||
api.destroySwapChain(swapChain);
|
||||
api.destroyRenderTarget(srcRenderTarget);
|
||||
api.destroyRenderTarget(dstRenderTarget);
|
||||
delete triangle;
|
||||
executeCommands();
|
||||
flushAndWait();
|
||||
}
|
||||
|
||||
TEST_F(BackendTest, DepthResolve) {
|
||||
@@ -667,8 +597,6 @@ TEST_F(BackendTest, DepthResolve) {
|
||||
{
|
||||
ShaderGenerator shaderGen(triangleVs, triangleFs, sBackend, sIsMobilePlatform);
|
||||
Program prog = shaderGen.getProgram(api);
|
||||
Program::Sampler psamplers[] = { utils::CString("tex"), 0 };
|
||||
prog.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, psamplers, sizeof(psamplers) / sizeof(psamplers[0]));
|
||||
prog.uniformBlockBindings({{"params", 1}});
|
||||
program = api.createProgram(std::move(prog));
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ layout(location = 0) out vec4 fragColor;
|
||||
|
||||
// Filament's Vulkan backend requires a descriptor set index of 1 for all samplers.
|
||||
// This parameter is ignored for other backends.
|
||||
layout(location = 0, set = 1) uniform sampler2D tex;
|
||||
layout(location = 0, set = 1) uniform sampler2D test_tex;
|
||||
|
||||
uniform Params {
|
||||
highp float fbWidth;
|
||||
@@ -61,7 +61,7 @@ uniform Params {
|
||||
void main() {
|
||||
vec2 fbsize = vec2(params.fbWidth, params.fbHeight);
|
||||
vec2 uv = (gl_FragCoord.xy + 0.5) / fbsize;
|
||||
fragColor = textureLod(tex, uv, params.sourceLevel);
|
||||
fragColor = textureLod(test_tex, uv, params.sourceLevel);
|
||||
})";
|
||||
|
||||
static uint32_t sPixelHashResult = 0;
|
||||
@@ -133,24 +133,24 @@ TEST_F(BackendTest, FeedbackLoops) {
|
||||
// Create a program.
|
||||
ProgramHandle program;
|
||||
{
|
||||
SamplerInterfaceBlock sib = filament::SamplerInterfaceBlock::Builder()
|
||||
.name("backend_test_sib")
|
||||
SamplerInterfaceBlock const sib = filament::SamplerInterfaceBlock::Builder()
|
||||
.name("Test")
|
||||
.stageFlags(backend::ShaderStageFlags::ALL_SHADER_STAGE_FLAGS)
|
||||
.add( {{"tex", SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH }} )
|
||||
.build();
|
||||
ShaderGenerator shaderGen(fullscreenVs, fullscreenFs, sBackend, sIsMobilePlatform, &sib);
|
||||
Program prog = shaderGen.getProgram(api);
|
||||
Program::Sampler psamplers[] = { utils::CString("tex"), 0 };
|
||||
Program::Sampler psamplers[] = { utils::CString("test_tex"), 0 };
|
||||
prog.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, psamplers, sizeof(psamplers) / sizeof(psamplers[0]));
|
||||
prog.uniformBlockBindings({{"params", 1}});
|
||||
program = api.createProgram(std::move(prog));
|
||||
}
|
||||
|
||||
TrianglePrimitive triangle(getDriverApi());
|
||||
TrianglePrimitive const triangle(getDriverApi());
|
||||
|
||||
// Create a texture.
|
||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||
Handle<HwTexture> texture = api.createTexture(
|
||||
Handle<HwTexture> const texture = api.createTexture(
|
||||
SamplerType::SAMPLER_2D, kNumLevels, kTexFormat, 1, kTexWidth, kTexHeight, 1, usage);
|
||||
|
||||
// Create a RenderTarget for each miplevel.
|
||||
|
||||
@@ -174,6 +174,41 @@ static const char* getSamplerTypeName(TextureFormat textureFormat) {
|
||||
default:
|
||||
return "sampler2D";
|
||||
}
|
||||
|
||||
}
|
||||
static SamplerFormat getSamplerFormat(TextureFormat textureFormat) {
|
||||
switch (textureFormat) {
|
||||
case TextureFormat::R8UI:
|
||||
case TextureFormat::R16UI:
|
||||
case TextureFormat::RG8UI:
|
||||
case TextureFormat::RGB8UI:
|
||||
case TextureFormat::R32UI:
|
||||
case TextureFormat::RG16UI:
|
||||
case TextureFormat::RGBA8UI:
|
||||
case TextureFormat::RGB16UI:
|
||||
case TextureFormat::RG32UI:
|
||||
case TextureFormat::RGBA16UI:
|
||||
case TextureFormat::RGB32UI:
|
||||
case TextureFormat::RGBA32UI:
|
||||
return SamplerFormat::UINT;
|
||||
|
||||
case TextureFormat::R8I:
|
||||
case TextureFormat::R16I:
|
||||
case TextureFormat::RG8I:
|
||||
case TextureFormat::RGB8I:
|
||||
case TextureFormat::R32I:
|
||||
case TextureFormat::RG16I:
|
||||
case TextureFormat::RGBA8I:
|
||||
case TextureFormat::RGB16I:
|
||||
case TextureFormat::RG32I:
|
||||
case TextureFormat::RGBA16I:
|
||||
case TextureFormat::RGB32I:
|
||||
case TextureFormat::RGBA32I:
|
||||
return SamplerFormat::INT;
|
||||
|
||||
default:
|
||||
return SamplerFormat::FLOAT;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(BackendTest, UpdateImage2D) {
|
||||
@@ -232,9 +267,9 @@ TEST_F(BackendTest, UpdateImage2D) {
|
||||
// Test integer format uploads.
|
||||
// TODO: These cases fail on OpenGL and Vulkan.
|
||||
// TODO: These cases now also fail on Metal, but at some point previously worked.
|
||||
// testCases.emplace_back("RGB_INTEGER, UBYTE -> RGB8UI", PixelDataFormat::RGB_INTEGER, PixelDataType::UBYTE, TextureFormat::RGB8UI);
|
||||
// testCases.emplace_back("RGB_INTEGER, USHORT -> RGB16UI", PixelDataFormat::RGB_INTEGER, PixelDataType::USHORT, TextureFormat::RGB16UI);
|
||||
// testCases.emplace_back("RGB_INTEGER, INT -> RGB32I", PixelDataFormat::RGB_INTEGER, PixelDataType::INT, TextureFormat::RGB32I);
|
||||
testCases.emplace_back("RGB_INTEGER, UBYTE -> RGB8UI", PixelDataFormat::RGB_INTEGER, PixelDataType::UBYTE, TextureFormat::RGB8UI);
|
||||
testCases.emplace_back("RGB_INTEGER, USHORT -> RGB16UI", PixelDataFormat::RGB_INTEGER, PixelDataType::USHORT, TextureFormat::RGB16UI);
|
||||
testCases.emplace_back("RGB_INTEGER, INT -> RGB32I", PixelDataFormat::RGB_INTEGER, PixelDataType::INT, TextureFormat::RGB32I);
|
||||
|
||||
// Test uploads with buffer padding.
|
||||
// TODO: Vulkan crashes with "Assertion failed: (offset + size <= allocationSize)"
|
||||
@@ -262,48 +297,45 @@ TEST_F(BackendTest, UpdateImage2D) {
|
||||
auto defaultRenderTarget = api.createDefaultRenderTarget(0);
|
||||
|
||||
// Create a program.
|
||||
SamplerInterfaceBlock sib = filament::SamplerInterfaceBlock::Builder()
|
||||
SamplerInterfaceBlock const sib = filament::SamplerInterfaceBlock::Builder()
|
||||
.name("Test")
|
||||
.stageFlags(backend::ShaderStageFlags::ALL_SHADER_STAGE_FLAGS)
|
||||
.add( {{"tex", SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH }} )
|
||||
.add( {{"tex", SamplerType::SAMPLER_2D, getSamplerFormat(t.textureFormat), Precision::HIGH }} )
|
||||
.build();
|
||||
ProgramHandle program;
|
||||
std::string fragment = stringReplace("{samplerType}",
|
||||
|
||||
std::string const fragment = stringReplace("{samplerType}",
|
||||
getSamplerTypeName(t.textureFormat), fragmentTemplate);
|
||||
ShaderGenerator shaderGen(vertex, fragment, sBackend, sIsMobilePlatform, &sib);
|
||||
Program prog = shaderGen.getProgram(api);
|
||||
Program::Sampler psamplers[] = { utils::CString("tex"), 0 };
|
||||
Program::Sampler psamplers[] = { utils::CString("test_tex"), 0 };
|
||||
prog.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, psamplers, sizeof(psamplers) / sizeof(psamplers[0]));
|
||||
program = api.createProgram(std::move(prog));
|
||||
ProgramHandle const program = api.createProgram(std::move(prog));
|
||||
|
||||
// Create a Texture.
|
||||
auto usage = TextureUsage::SAMPLEABLE;
|
||||
Handle<HwTexture> texture = api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
auto usage = TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE;
|
||||
Handle<HwTexture> const texture = api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
t.textureFormat, 1, 512, 512, 1u, usage);
|
||||
|
||||
// Upload some pixel data.
|
||||
if (t.uploadSubregions) {
|
||||
const auto& pf = t.pixelFormat;
|
||||
const auto& pt = t.pixelType;
|
||||
PixelBufferDescriptor subregion1 = checkerboardPixelBuffer(pf, pt, 256, t.bufferPadding);
|
||||
PixelBufferDescriptor subregion2 = checkerboardPixelBuffer(pf, pt, 256, t.bufferPadding);
|
||||
PixelBufferDescriptor subregion3 = checkerboardPixelBuffer(pf, pt, 256, t.bufferPadding);
|
||||
PixelBufferDescriptor subregion4 = checkerboardPixelBuffer(pf, pt, 256, t.bufferPadding);
|
||||
api.update3DImage(texture, 0, 0, 0, 0, 256, 256, 1, std::move(subregion1));
|
||||
api.update3DImage(texture, 0, 256, 0, 0, 256, 256, 1, std::move(subregion2));
|
||||
api.update3DImage(texture, 0, 0, 256, 0, 256, 256, 1, std::move(subregion3));
|
||||
api.update3DImage(texture, 0, 256, 256, 0, 256, 256, 1, std::move(subregion4));
|
||||
api.update3DImage(texture, 0, 0, 0, 0, 256, 256, 1,
|
||||
checkerboardPixelBuffer(t.pixelFormat, t.pixelType, 256, t.bufferPadding));
|
||||
api.update3DImage(texture, 0, 256, 0, 0, 256, 256, 1,
|
||||
checkerboardPixelBuffer(t.pixelFormat, t.pixelType, 256, t.bufferPadding));
|
||||
api.update3DImage(texture, 0, 0, 256, 0, 256, 256, 1,
|
||||
checkerboardPixelBuffer(t.pixelFormat, t.pixelType, 256, t.bufferPadding));
|
||||
api.update3DImage(texture, 0, 256, 256, 0, 256, 256, 1,
|
||||
checkerboardPixelBuffer(t.pixelFormat, t.pixelType, 256, t.bufferPadding));
|
||||
} else {
|
||||
PixelBufferDescriptor descriptor
|
||||
= checkerboardPixelBuffer(t.pixelFormat, t.pixelType, 512, t.bufferPadding);
|
||||
api.update3DImage(texture, 0, 0, 0, 0, 512, 512, 1, std::move(descriptor));
|
||||
api.update3DImage(texture, 0, 0, 0, 0, 512, 512, 1,
|
||||
checkerboardPixelBuffer(t.pixelFormat, t.pixelType, 512, t.bufferPadding));
|
||||
}
|
||||
|
||||
SamplerGroup samplers(1);
|
||||
SamplerParams sparams = {};
|
||||
sparams.filterMag = SamplerMagFilter::LINEAR;
|
||||
sparams.filterMin = SamplerMinFilter::LINEAR_MIPMAP_NEAREST;
|
||||
samplers.setSampler(0, { texture, sparams });
|
||||
samplers.setSampler(0, { texture, {
|
||||
.filterMag = SamplerMagFilter::NEAREST,
|
||||
.filterMin = SamplerMinFilter::NEAREST_MIPMAP_NEAREST } });
|
||||
|
||||
auto sgroup = api.createSamplerGroup(samplers.getSize(), utils::FixedSizeString<32>("Test"));
|
||||
api.updateSamplerGroup(sgroup, samplers.toBufferDescriptor(api));
|
||||
|
||||
@@ -313,7 +345,6 @@ TEST_F(BackendTest, UpdateImage2D) {
|
||||
|
||||
readPixelsAndAssertHash(t.name, 512, 512, defaultRenderTarget, expectedHash);
|
||||
|
||||
api.flush();
|
||||
api.commit(swapChain);
|
||||
api.endFrame(0);
|
||||
|
||||
@@ -321,25 +352,21 @@ TEST_F(BackendTest, UpdateImage2D) {
|
||||
api.destroySwapChain(swapChain);
|
||||
api.destroyRenderTarget(defaultRenderTarget);
|
||||
api.destroyTexture(texture);
|
||||
|
||||
// This ensures all driver commands have finished before exiting the test.
|
||||
api.finish();
|
||||
}
|
||||
|
||||
api.finish();
|
||||
api.stopCapture();
|
||||
|
||||
executeCommands();
|
||||
|
||||
getDriver().purge();
|
||||
flushAndWait();
|
||||
}
|
||||
|
||||
TEST_F(BackendTest, UpdateImageSRGB) {
|
||||
auto& api = getDriverApi();
|
||||
api.startCapture();
|
||||
|
||||
PixelDataFormat pixelFormat = PixelDataFormat::RGB;
|
||||
PixelDataType pixelType = PixelDataType::UBYTE;
|
||||
TextureFormat textureFormat = TextureFormat::SRGB8_A8;
|
||||
PixelDataFormat const pixelFormat = PixelDataFormat::RGBA;
|
||||
PixelDataType const pixelType = PixelDataType::UBYTE;
|
||||
TextureFormat const textureFormat = TextureFormat::SRGB8_A8;
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = createSwapChain();
|
||||
@@ -347,22 +374,22 @@ TEST_F(BackendTest, UpdateImageSRGB) {
|
||||
auto defaultRenderTarget = api.createDefaultRenderTarget(0);
|
||||
|
||||
// Create a program.
|
||||
SamplerInterfaceBlock sib = filament::SamplerInterfaceBlock::Builder()
|
||||
SamplerInterfaceBlock const sib = filament::SamplerInterfaceBlock::Builder()
|
||||
.name("Test")
|
||||
.stageFlags(backend::ShaderStageFlags::ALL_SHADER_STAGE_FLAGS)
|
||||
.add( {{"tex", SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH }} )
|
||||
.build();
|
||||
std::string fragment = stringReplace("{samplerType}",
|
||||
std::string const fragment = stringReplace("{samplerType}",
|
||||
getSamplerTypeName(textureFormat), fragmentTemplate);
|
||||
ShaderGenerator shaderGen(vertex, fragment, sBackend, sIsMobilePlatform, &sib);
|
||||
Program prog = shaderGen.getProgram(api);
|
||||
Program::Sampler psamplers[] = { utils::CString("tex"), 0 };
|
||||
Program::Sampler psamplers[] = { utils::CString("test_tex"), 0 };
|
||||
prog.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, psamplers, sizeof(psamplers) / sizeof(psamplers[0]));
|
||||
ProgramHandle program = api.createProgram(std::move(prog));
|
||||
ProgramHandle const program = api.createProgram(std::move(prog));
|
||||
|
||||
// Create a texture.
|
||||
Handle<HwTexture> texture = api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
textureFormat, 1, 512, 512, 1, TextureUsage::SAMPLEABLE);
|
||||
Handle<HwTexture> const texture = api.createTexture(SamplerType::SAMPLER_2D, 1,
|
||||
textureFormat, 1, 512, 512, 1, TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE);
|
||||
|
||||
// Create image data.
|
||||
size_t components; int bpp;
|
||||
@@ -402,7 +429,7 @@ TEST_F(BackendTest, UpdateImageSRGB) {
|
||||
|
||||
renderTriangle(defaultRenderTarget, swapChain, program);
|
||||
|
||||
static const uint32_t expectedHash = 519370995;
|
||||
static const uint32_t expectedHash = 359858623;
|
||||
readPixelsAndAssertHash("UpdateImageSRGB", 512, 512, defaultRenderTarget, expectedHash);
|
||||
|
||||
api.flush();
|
||||
@@ -416,12 +443,9 @@ TEST_F(BackendTest, UpdateImageSRGB) {
|
||||
|
||||
// This ensures all driver commands have finished before exiting the test.
|
||||
api.finish();
|
||||
|
||||
api.stopCapture();
|
||||
|
||||
executeCommands();
|
||||
|
||||
getDriver().purge();
|
||||
flushAndWait();
|
||||
}
|
||||
|
||||
TEST_F(BackendTest, UpdateImageMipLevel) {
|
||||
@@ -443,20 +467,20 @@ TEST_F(BackendTest, UpdateImageMipLevel) {
|
||||
.stageFlags(backend::ShaderStageFlags::ALL_SHADER_STAGE_FLAGS)
|
||||
.add( {{"tex", SamplerType::SAMPLER_2D, SamplerFormat::FLOAT, Precision::HIGH }} )
|
||||
.build();
|
||||
std::string fragment = stringReplace("{samplerType}",
|
||||
std::string const fragment = stringReplace("{samplerType}",
|
||||
getSamplerTypeName(textureFormat), fragmentUpdateImageMip);
|
||||
ShaderGenerator shaderGen(vertex, fragment, sBackend, sIsMobilePlatform, &sib);
|
||||
Program prog = shaderGen.getProgram(api);
|
||||
Program::Sampler psamplers[] = { utils::CString("tex"), 0 };
|
||||
Program::Sampler psamplers[] = { utils::CString("test_tex"), 0 };
|
||||
prog.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, psamplers, sizeof(psamplers) / sizeof(psamplers[0]));
|
||||
ProgramHandle program = api.createProgram(std::move(prog));
|
||||
ProgramHandle const program = api.createProgram(std::move(prog));
|
||||
|
||||
// Create a texture with 3 mip levels.
|
||||
// Base level: 1024
|
||||
// Level 1: 512 <-- upload data and sample from this level
|
||||
// Level 2: 256
|
||||
Handle<HwTexture> texture = api.createTexture(SamplerType::SAMPLER_2D, 3,
|
||||
textureFormat, 1, 1024, 1024, 1, TextureUsage::SAMPLEABLE);
|
||||
textureFormat, 1, 1024, 1024, 1, TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE);
|
||||
|
||||
// Create image data.
|
||||
PixelBufferDescriptor descriptor = checkerboardPixelBuffer(pixelFormat, pixelType, 512);
|
||||
@@ -491,12 +515,9 @@ TEST_F(BackendTest, UpdateImageMipLevel) {
|
||||
|
||||
// This ensures all driver commands have finished before exiting the test.
|
||||
api.finish();
|
||||
|
||||
api.stopCapture();
|
||||
|
||||
executeCommands();
|
||||
|
||||
getDriver().purge();
|
||||
flushAndWait();
|
||||
}
|
||||
|
||||
TEST_F(BackendTest, UpdateImage3D) {
|
||||
@@ -507,7 +528,7 @@ TEST_F(BackendTest, UpdateImage3D) {
|
||||
PixelDataType pixelType = PixelDataType::FLOAT;
|
||||
TextureFormat textureFormat = TextureFormat::RGBA16F;
|
||||
SamplerType samplerType = SamplerType::SAMPLER_2D_ARRAY;
|
||||
TextureUsage usage = TextureUsage::SAMPLEABLE;
|
||||
TextureUsage usage = TextureUsage::SAMPLEABLE | TextureUsage::UPLOADABLE;
|
||||
|
||||
// Create a platform-specific SwapChain and make it current.
|
||||
auto swapChain = createSwapChain();
|
||||
@@ -524,9 +545,9 @@ TEST_F(BackendTest, UpdateImage3D) {
|
||||
getSamplerTypeName(samplerType), fragmentUpdateImage3DTemplate);
|
||||
ShaderGenerator shaderGen(vertex, fragment, sBackend, sIsMobilePlatform, &sib);
|
||||
Program prog = shaderGen.getProgram(api);
|
||||
Program::Sampler psamplers[] = { utils::CString("tex"), 0 };
|
||||
Program::Sampler psamplers[] = { utils::CString("test_tex"), 0 };
|
||||
prog.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, psamplers, sizeof(psamplers) / sizeof(psamplers[0]));
|
||||
ProgramHandle program = api.createProgram(std::move(prog));
|
||||
ProgramHandle const program = api.createProgram(std::move(prog));
|
||||
|
||||
// Create a texture.
|
||||
Handle<HwTexture> texture = api.createTexture(samplerType, 1,
|
||||
@@ -578,12 +599,9 @@ TEST_F(BackendTest, UpdateImage3D) {
|
||||
|
||||
// This ensures all driver commands have finished before exiting the test.
|
||||
api.finish();
|
||||
|
||||
api.stopCapture();
|
||||
|
||||
executeCommands();
|
||||
|
||||
getDriver().purge();
|
||||
flushAndWait();
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <utils/Hash.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace filament;
|
||||
using namespace filament::backend;
|
||||
@@ -107,7 +108,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
|
||||
// The size of the actual render target, taking mip level into account;
|
||||
size_t getRenderTargetSize () const {
|
||||
return renderTargetBaseSize >> mipLevel;
|
||||
return std::max(size_t(1), renderTargetBaseSize >> mipLevel);
|
||||
}
|
||||
|
||||
// The rect that read pixels will read from.
|
||||
@@ -169,7 +170,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
|
||||
// The normative read pixels test case. Render a white triangle over a blue background and read
|
||||
// the full viewport into a pixel buffer.
|
||||
TestCase t;
|
||||
TestCase const t0;
|
||||
|
||||
// Check that a subregion of the render target can be read into a pixel buffer.
|
||||
TestCase t2;
|
||||
@@ -233,7 +234,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
t8.testName = "readPixels_swapchain";
|
||||
t8.useDefaultRT = true;
|
||||
|
||||
TestCase testCases[] = { t, t2, t3, t4, t5, t6, t7, t8 };
|
||||
TestCase const testCases[] = { t0, t2, t3, t4, t5, t6, t7, t8 };
|
||||
|
||||
// Create programs.
|
||||
Handle<HwProgram> programFloat, programUint;
|
||||
@@ -264,7 +265,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
|
||||
// Create a Texture and RenderTarget to render into.
|
||||
auto usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||
Handle<HwTexture> texture = getDriverApi().createTexture(SamplerType::SAMPLER_2D,
|
||||
Handle<HwTexture> const texture = getDriverApi().createTexture(SamplerType::SAMPLER_2D,
|
||||
t.mipLevels, t.textureFormat, 1, renderTargetBaseSize, renderTargetBaseSize, 1,
|
||||
usage);
|
||||
|
||||
@@ -282,7 +283,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
{});
|
||||
}
|
||||
|
||||
TrianglePrimitive triangle(getDriverApi());
|
||||
TrianglePrimitive const triangle(getDriverApi());
|
||||
|
||||
RenderPassParams params = {};
|
||||
fullViewport(params);
|
||||
@@ -356,7 +357,6 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
getDriverApi().beginRenderPass(renderTarget, params);
|
||||
getDriverApi().endRenderPass();
|
||||
|
||||
getDriverApi().flush();
|
||||
getDriverApi().commit(swapChain);
|
||||
getDriverApi().endFrame(0);
|
||||
|
||||
@@ -369,11 +369,7 @@ TEST_F(ReadPixelsTest, ReadPixels) {
|
||||
getDriverApi().destroyProgram(programUint);
|
||||
|
||||
// This ensures all driver commands have finished before exiting the test.
|
||||
getDriverApi().finish();
|
||||
|
||||
executeCommands();
|
||||
|
||||
getDriver().purge();
|
||||
flushAndWait();
|
||||
}
|
||||
|
||||
TEST_F(ReadPixelsTest, ReadPixelsPerformance) {
|
||||
|
||||
@@ -45,10 +45,10 @@ std::string fragment (R"(#version 450 core
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
layout(location = 0) in vec2 uv;
|
||||
|
||||
layout(location = 0, set = 1) uniform sampler2D tex;
|
||||
layout(location = 0, set = 1) uniform sampler2D test_tex;
|
||||
|
||||
void main() {
|
||||
fragColor = texture(tex, uv);
|
||||
fragColor = texture(test_tex, uv);
|
||||
}
|
||||
)");
|
||||
|
||||
@@ -66,7 +66,7 @@ TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
||||
auto swapChain = createSwapChain();
|
||||
|
||||
SamplerInterfaceBlock sib = filament::SamplerInterfaceBlock::Builder()
|
||||
.name("backend_test_sib")
|
||||
.name("Test")
|
||||
.stageFlags(backend::ShaderStageFlags::ALL_SHADER_STAGE_FLAGS)
|
||||
.add( {{"tex", SamplerType::SAMPLER_EXTERNAL, SamplerFormat::FLOAT, Precision::HIGH }} )
|
||||
.build();
|
||||
@@ -74,7 +74,7 @@ TEST_F(BackendTest, RenderExternalImageWithoutSet) {
|
||||
|
||||
// Create a program that samples a texture.
|
||||
Program p = shaderGen.getProgram(getDriverApi());
|
||||
Program::Sampler sampler { utils::CString("tex"), 0 };
|
||||
Program::Sampler sampler { utils::CString("test_tex"), 0 };
|
||||
p.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, &sampler, 1);
|
||||
backend::Handle<HwProgram> program = getDriverApi().createProgram(std::move(p));
|
||||
|
||||
@@ -146,7 +146,7 @@ TEST_F(BackendTest, RenderExternalImage) {
|
||||
auto swapChain = createSwapChain();
|
||||
|
||||
SamplerInterfaceBlock sib = filament::SamplerInterfaceBlock::Builder()
|
||||
.name("backend_test_sib")
|
||||
.name("Test")
|
||||
.stageFlags(backend::ShaderStageFlags::ALL_SHADER_STAGE_FLAGS)
|
||||
.add( {{"tex", SamplerType::SAMPLER_EXTERNAL, SamplerFormat::FLOAT, Precision::HIGH }} )
|
||||
.build();
|
||||
@@ -154,7 +154,7 @@ TEST_F(BackendTest, RenderExternalImage) {
|
||||
|
||||
// Create a program that samples a texture.
|
||||
Program p = shaderGen.getProgram(getDriverApi());
|
||||
Program::Sampler sampler { utils::CString("tex"), 0 };
|
||||
Program::Sampler sampler { utils::CString("test_tex"), 0 };
|
||||
p.setSamplerGroup(0, ShaderStageFlags::ALL_SHADER_STAGE_FLAGS, &sampler, 1);
|
||||
auto program = getDriverApi().createProgram(std::move(p));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user