Make some GMs compatible with the *ooprddl configs

The more we can test these configs the better.

Change-Id: I2d86985770047937d7f31c9659ad6984caafe11d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305569
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
This commit is contained in:
Robert Phillips 2020-07-28 09:57:26 -04:00 committed by Skia Commit-Bot
parent 3557ab4dc3
commit a84caa3a5f
3 changed files with 134 additions and 78 deletions

View File

@ -14,6 +14,7 @@
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/image/SkImage_Base.h"
#include "src/image/SkImage_GpuBase.h"
constexpr int kImgWidth = 16;
constexpr int kImgHeight = 8;
@ -115,12 +116,12 @@ static sk_sp<SkImage> data_to_img(GrDirectContext *direct, sk_sp<SkData> data,
}
}
static void draw_image(GrRecordingContext* context, SkCanvas* canvas,
sk_sp<SkImage> image, int x, int y) {
static void draw_image(SkCanvas* canvas, sk_sp<SkImage> image, int x, int y) {
bool isCompressed = false;
if (image && image->isTextureBacked()) {
const GrCaps* caps = context->priv().caps();
GrRecordingContext* rContext = ((SkImage_GpuBase*) image.get())->context();
const GrCaps* caps = rContext->priv().caps();
GrTextureProxy* proxy = as_IB(image)->peekProxy();
isCompressed = caps->isFormatCompressed(proxy->backendFormat());
@ -175,25 +176,39 @@ protected:
return SkISize::Make(kImgWidth + 2 * kPad, 2 * kImgHeight + 3 * kPad);
}
void onOnceBeforeDraw() override {
fBC1Data = make_compressed_data();
DrawResult onGpuSetup(GrDirectContext* dContext, SkString* errorMsg) override {
if (dContext && dContext->abandoned()) {
// This isn't a GpuGM so a null 'context' is okay but an abandoned context
// if forbidden.
return DrawResult::kSkip;
}
sk_sp<SkData> bc1Data = make_compressed_data();
fRGBImage = data_to_img(dContext, bc1Data, SkImage::CompressionType::kBC1_RGB8_UNORM);
fRGBAImage = data_to_img(dContext, std::move(bc1Data),
SkImage::CompressionType::kBC1_RGBA8_UNORM);
if (!fRGBImage || !fRGBAImage) {
*errorMsg = "Failed to create BC1 images.";
return DrawResult::kFail;
}
return DrawResult::kOk;
}
void onGpuTeardown() override {
fRGBImage = nullptr;
fRGBAImage = nullptr;
}
void onDraw(SkCanvas* canvas) override {
auto direct = GrAsDirectContext(canvas->recordingContext());
sk_sp<SkImage> rgbImg = data_to_img(direct, fBC1Data,
SkImage::CompressionType::kBC1_RGB8_UNORM);
sk_sp<SkImage> rgbaImg = data_to_img(direct, fBC1Data,
SkImage::CompressionType::kBC1_RGBA8_UNORM);
draw_image(direct, canvas, rgbImg, kPad, kPad);
draw_image(direct, canvas, rgbaImg, kPad, 2 * kPad + kImgHeight);
draw_image(canvas, fRGBImage, kPad, kPad);
draw_image(canvas, fRGBAImage, kPad, 2 * kPad + kImgHeight);
}
private:
sk_sp<SkData> fBC1Data;
sk_sp<SkImage> fRGBImage;
sk_sp<SkImage> fRGBAImage;
typedef GM INHERITED;
};

View File

@ -29,6 +29,7 @@
#include "src/gpu/GrDataUtils.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/image/SkImage_Base.h"
#include "src/image/SkImage_GpuBase.h"
#include "third_party/etc1/etc1.h"
class GrRenderTargetContext;
@ -98,10 +99,11 @@ SkBitmap render_level(SkISize dimensions, SkColor color, SkColorType colorType,
// compression format. In this case 2-color means either opaque black or transparent black plus
// one other color.
// Note that ETC1/ETC2_RGB8_UNORM only supports 565 opaque textures.
static sk_sp<SkData> make_compressed_data(SkISize dimensions,
SkColorType colorType,
bool opaque,
SkImage::CompressionType compression) {
static sk_sp<SkImage> make_compressed_image(GrDirectContext* dContext,
const SkISize dimensions,
SkColorType colorType,
bool opaque,
SkImage::CompressionType compression) {
size_t totalSize = SkCompressedDataSize(compression, dimensions, nullptr, true);
sk_sp<SkData> tmp = SkData::MakeUninitialized(totalSize);
@ -122,10 +124,11 @@ static sk_sp<SkData> make_compressed_data(SkISize dimensions,
SK_ColorWHITE,
};
SkISize levelDims = dimensions;
for (int i = 0; i < numMipLevels; ++i) {
size_t levelSize = SkCompressedDataSize(compression, dimensions, nullptr, false);
size_t levelSize = SkCompressedDataSize(compression, levelDims, nullptr, false);
SkBitmap bm = render_level(dimensions, kColors[i%7], colorType, opaque);
SkBitmap bm = render_level(levelDims, kColors[i%7], colorType, opaque);
if (compression == SkImage::CompressionType::kETC2_RGB8_UNORM) {
SkASSERT(bm.colorType() == kRGB_565_SkColorType);
SkASSERT(opaque);
@ -140,10 +143,22 @@ static sk_sp<SkData> make_compressed_data(SkISize dimensions,
}
offset += levelSize;
dimensions = {std::max(1, dimensions.width()/2), std::max(1, dimensions.height()/2)};
levelDims = {std::max(1, levelDims.width()/2), std::max(1, levelDims.height()/2)};
}
return tmp;
sk_sp<SkImage> image;
if (dContext) {
image = SkImage::MakeTextureFromCompressed(dContext, std::move(tmp),
dimensions.width(),
dimensions.height(),
compression, GrMipmapped::kYes);
} else {
image = SkImage::MakeRasterFromCompressed(std::move(tmp),
dimensions.width(),
dimensions.height(),
compression);
}
return image;
}
// Basic test of Ganesh's ETC1 and BC1 support
@ -200,50 +215,56 @@ protected:
return SkISize::Make(2*kCellWidth + 3*kPad, 2*kBaseTexHeight + 3*kPad);
}
void onOnceBeforeDraw() override {
fOpaqueETC2Data = make_compressed_data(fImgDimensions, kRGB_565_SkColorType, true,
SkImage::CompressionType::kETC2_RGB8_UNORM);
DrawResult onGpuSetup(GrDirectContext* dContext, SkString* errorMsg) override {
if (dContext && dContext->abandoned()) {
// This isn't a GpuGM so a null 'context' is okay but an abandoned context
// if forbidden.
return DrawResult::kSkip;
}
fOpaqueBC1Data = make_compressed_data(fImgDimensions, kRGBA_8888_SkColorType, true,
SkImage::CompressionType::kBC1_RGB8_UNORM);
if (dContext &&
dContext->backend() == GrBackendApi::kDirect3D && fType == Type::kNonMultipleOfFour) {
// skbug.com/10541 - Are non-multiple-of-four BC1 textures supported in D3D?
return DrawResult::kSkip;
}
fTransparentBC1Data = make_compressed_data(fImgDimensions, kRGBA_8888_SkColorType, false,
SkImage::CompressionType::kBC1_RGBA8_UNORM);
fOpaqueETC2Image = make_compressed_image(dContext, fImgDimensions,
kRGB_565_SkColorType, true,
SkImage::CompressionType::kETC2_RGB8_UNORM);
fOpaqueBC1Image = make_compressed_image(dContext, fImgDimensions,
kRGBA_8888_SkColorType, true,
SkImage::CompressionType::kBC1_RGB8_UNORM);
fTransparentBC1Image = make_compressed_image(dContext, fImgDimensions,
kRGBA_8888_SkColorType, false,
SkImage::CompressionType::kBC1_RGBA8_UNORM);
if (!fOpaqueETC2Image || !fOpaqueBC1Image || !fTransparentBC1Image) {
*errorMsg = "Failed to create compressed images.";
return DrawResult::kFail;
}
return DrawResult::kOk;
}
void onGpuTeardown() override {
fOpaqueETC2Image = nullptr;
fOpaqueBC1Image = nullptr;
fTransparentBC1Image = nullptr;
}
void onDraw(SkCanvas* canvas) override {
auto direct = GrAsDirectContext(canvas->recordingContext());
this->drawCell(canvas, fOpaqueETC2Image.get(), { kPad, kPad });
this->drawCell(direct, canvas, fOpaqueETC2Data,
SkImage::CompressionType::kETC2_RGB8_UNORM, { kPad, kPad });
this->drawCell(canvas, fOpaqueBC1Image.get(), { 2*kPad + kCellWidth, kPad });
this->drawCell(direct, canvas, fOpaqueBC1Data,
SkImage::CompressionType::kBC1_RGB8_UNORM, { 2*kPad + kCellWidth, kPad });
this->drawCell(direct, canvas, fTransparentBC1Data,
SkImage::CompressionType::kBC1_RGBA8_UNORM,
this->drawCell(canvas, fTransparentBC1Image.get(),
{ 2*kPad + kCellWidth, 2*kPad + kBaseTexHeight });
}
private:
void drawCell(GrDirectContext* direct, SkCanvas* canvas, sk_sp<SkData> data,
SkImage::CompressionType compression, SkIVector offset) {
sk_sp<SkImage> image;
if (direct) {
image = SkImage::MakeTextureFromCompressed(direct, std::move(data),
fImgDimensions.width(),
fImgDimensions.height(),
compression, GrMipmapped::kYes);
} else {
image = SkImage::MakeRasterFromCompressed(std::move(data),
fImgDimensions.width(),
fImgDimensions.height(),
compression);
}
if (!image) {
return;
}
void drawCell(SkCanvas* canvas, SkImage* image, SkIVector offset) {
SkISize levelDimensions = fImgDimensions;
int numMipLevels = SkMipmap::ComputeLevelCount(levelDimensions.width(),
@ -254,7 +275,8 @@ private:
bool isCompressed = false;
if (image->isTextureBacked()) {
const GrCaps* caps = direct->priv().caps();
GrRecordingContext* rContext = ((SkImage_GpuBase*) image)->context();
const GrCaps* caps = rContext->priv().caps();
GrTextureProxy* proxy = as_IB(image)->peekProxy();
isCompressed = caps->isFormatCompressed(proxy->backendFormat());
@ -290,11 +312,12 @@ private:
static const int kCellWidth = 1.5f * kBaseTexWidth;
static const int kBaseTexHeight = 64;
Type fType;
SkISize fImgDimensions;
sk_sp<SkData> fOpaqueETC2Data;
sk_sp<SkData> fOpaqueBC1Data;
sk_sp<SkData> fTransparentBC1Data;
Type fType;
SkISize fImgDimensions;
sk_sp<SkImage> fOpaqueETC2Image;
sk_sp<SkImage> fOpaqueBC1Image;
sk_sp<SkImage> fTransparentBC1Image;
typedef GM INHERITED;
};

View File

@ -16,6 +16,7 @@
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/gl/GrGLDefines.h"
#include "src/image/SkImage_Base.h"
#include "src/image/SkImage_GpuBase.h"
#include "tools/Resources.h"
@ -336,9 +337,10 @@ protected:
return SkISize::Make(2*kImgWidthHeight + 3 * kPad, kImgWidthHeight + 2 * kPad);
}
void loadImages(GrDirectContext *direct) {
bool loadImages(GrDirectContext *direct) {
SkASSERT(!fETC1Image && !fBC1Image);
if (!fETC1Image) {
{
ImageInfo info;
sk_sp<SkData> data = load_ktx(GetResourcePath("images/flower-etc1.ktx").c_str(), &info);
if (data) {
@ -349,10 +351,11 @@ protected:
fETC1Image = data_to_img(direct, std::move(data), info);
} else {
SkDebugf("failed to load flower-etc1.ktx\n");
return false;
}
}
if (!fBC1Image) {
{
ImageInfo info;
sk_sp<SkData> data = load_dds(GetResourcePath("images/flower-bc1.dds").c_str(), &info);
if (data) {
@ -363,19 +366,22 @@ protected:
fBC1Image = data_to_img(direct, std::move(data), info);
} else {
SkDebugf("failed to load flower-bc1.dds\n");
return false;
}
}
return true;
}
void drawImage(GrRecordingContext* context, SkCanvas* canvas, SkImage* image, int x, int y) {
void drawImage(SkCanvas* canvas, SkImage* image, int x, int y) {
if (!image) {
return;
}
bool isCompressed = false;
if (image->isTextureBacked()) {
const GrCaps* caps = context->priv().caps();
GrRecordingContext* rContext = ((SkImage_GpuBase*) image)->context();
const GrCaps* caps = rContext->priv().caps();
GrTextureProxy* proxy = as_IB(image)->peekProxy();
isCompressed = caps->isFormatCompressed(proxy->backendFormat());
@ -394,19 +400,31 @@ protected:
}
}
void onDraw(SkCanvas* canvas) override {
auto recording = canvas->recordingContext();
auto direct = GrAsDirectContext(recording);
// In DDL mode, these draws will be dropped.
if (recording && !direct) {
return;
DrawResult onGpuSetup(GrDirectContext* dContext, SkString* errorMsg) override {
if (dContext && dContext->abandoned()) {
// This isn't a GpuGM so a null 'context' is okay but an abandoned context
// if forbidden.
return DrawResult::kSkip;
}
this->loadImages(direct);
if (!this->loadImages(dContext)) {
*errorMsg = "Failed to create images.";
return DrawResult::kFail;
}
this->drawImage(direct, canvas, fETC1Image.get(), kPad, kPad);
this->drawImage(direct, canvas, fBC1Image.get(), kImgWidthHeight + 2 * kPad, kPad);
return DrawResult::kOk;
}
void onGpuTeardown() override {
fETC1Image = nullptr;
fBC1Image = nullptr;
}
void onDraw(SkCanvas* canvas) override {
SkASSERT(fETC1Image && fBC1Image);
this->drawImage(canvas, fETC1Image.get(), kPad, kPad);
this->drawImage(canvas, fBC1Image.get(), kImgWidthHeight + 2 * kPad, kPad);
}
private: