32 bpp floating point textures

This is VERY preliminary, but it was sufficient for me to get 32 bit floating point textures in a sample app

BUG=skia:
R=bsalomon@chromium.org, bsalomon@google.com

Author: joshualitt@chromium.org

Review URL: https://codereview.chromium.org/359803003
This commit is contained in:
joshualitt 2014-07-16 13:32:56 -07:00 коммит произвёл Commit bot
Родитель 2ec93fc1d3
Коммит ee5da55477
9 изменённых файлов: 139 добавлений и 8 удалений

Просмотреть файл

@ -75,6 +75,7 @@
'../tests/FitsInTest.cpp',
'../tests/FlatDataTest.cpp',
'../tests/FlateTest.cpp',
'../tests/FloatingPointTextureTest.cpp',
'../tests/FontHostStreamTest.cpp',
'../tests/FontHostTest.cpp',
'../tests/FontMgrTest.cpp',

Просмотреть файл

@ -135,6 +135,7 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) {
kRGB_GrColorComponentFlags, // kETC1_GrPixelConfig
kA_GrColorComponentFlag, // kLATC_GrPixelConfig
kA_GrColorComponentFlag, // kR11_EAC_GrPixelConfig
kRGBA_GrColorComponentFlags, // kRGBA_float_GrPixelConfig
};
return kFlags[config];
@ -148,6 +149,7 @@ static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) {
GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
GR_STATIC_ASSERT(10 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt);
}

Просмотреть файл

@ -274,7 +274,7 @@ enum GrPixelConfig {
* Premultiplied. Byte order is b,g,r,a.
*/
kBGRA_8888_GrPixelConfig,
/**
/**
* ETC1 Compressed Data
*/
kETC1_GrPixelConfig,
@ -282,14 +282,16 @@ enum GrPixelConfig {
* LATC/RGTC/3Dc/BC4 Compressed Data
*/
kLATC_GrPixelConfig,
/**
* R11 EAC Compressed Data
* (Corresponds to section C.3.5 of the OpenGL 4.4 core profile spec)
*/
kR11_EAC_GrPixelConfig,
kLast_GrPixelConfig = kR11_EAC_GrPixelConfig
/**
* Byte order is r, g, b, a. This color format is 32 bits per channel
*/
kRGBA_float_GrPixelConfig,
kLast_GrPixelConfig = kRGBA_float_GrPixelConfig
};
static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
@ -353,6 +355,25 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
return 4;
case kRGBA_float_GrPixelConfig:
return 16;
default:
return 0;
}
}
static inline size_t GrUnpackAlignment(GrPixelConfig config) {
switch (config) {
case kAlpha_8_GrPixelConfig:
case kIndex_8_GrPixelConfig:
return 1;
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
return 2;
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kRGBA_float_GrPixelConfig:
return 4;
default:
return 0;
}
@ -644,7 +665,7 @@ enum GrGLBackendState {
/**
* Returns the data size for the given compressed pixel config
*/
*/
static inline size_t GrCompressedFormatDataSize(GrPixelConfig config,
int width, int height) {
SkASSERT(GrPixelConfigIsCompressed(config));

Просмотреть файл

@ -1135,6 +1135,7 @@ SkString GrDrawTargetCaps::dump() const {
"ETC1", // kETC1_GrPixelConfig,
"LATC", // kLATC_GrPixelConfig,
"R11EAC", // kR11_EAC_GrPixelConfig,
"RGBAFloat", // kRGBA_float_GrPixelConfig
};
GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
@ -1146,6 +1147,7 @@ SkString GrDrawTargetCaps::dump() const {
GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
GR_STATIC_ASSERT(10 == kRGBA_float_GrPixelConfig);
GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);

Просмотреть файл

@ -68,7 +68,7 @@ size_t GrRenderTarget::gpuMemorySize() const {
if (kUnknown_GrPixelConfig == fDesc.fConfig) {
colorBits = 32; // don't know, make a guess
} else {
colorBits = GrBytesPerPixel(fDesc.fConfig);
colorBits = GrBytesPerPixel(fDesc.fConfig) * 8;
}
uint64_t size = fDesc.fWidth;
size *= fDesc.fHeight;

Просмотреть файл

@ -444,6 +444,10 @@ void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
}
}
if (this->isConfigTexturable(kRGBA_float_GrPixelConfig)) {
fConfigRenderSupport[kRGBA_float_GrPixelConfig][kNo_MSAA] = true;
}
// If we don't support MSAA then undo any places above where we set a config as renderable with
// msaa.
if (kNone_MSFBOType == fMSFBOType) {
@ -504,7 +508,7 @@ void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const G
// First check version for support
if (kGL_GrGLStandard == standard) {
hasETC1 = hasCompressTex2D &&
(version >= GR_GL_VER(4, 3) ||
(version >= GR_GL_VER(4, 3) ||
ctxInfo.hasExtension("GL_ARB_ES3_compatibility"));
} else {
hasETC1 = hasCompressTex2D &&
@ -558,6 +562,19 @@ void GrGLCaps::initConfigTexturableTable(const GrGLContextInfo& ctxInfo, const G
} else {
fConfigTextureSupport[kR11_EAC_GrPixelConfig] = version >= GR_GL_VER(3, 0);
}
// Check for floating point texture support
// NOTE: We disallow floating point textures on ES devices if linear
// filtering modes are not supported. This is for simplicity, but a more
// granular approach is possible. Coincidentally, floating point textures became part of
// the standard in ES3.1 / OGL 3.1, hence the shorthand
bool hasFPTextures = version >= GR_GL_VER(3, 1);
if (!hasFPTextures) {
hasFPTextures = ctxInfo.hasExtension("GL_ARB_texture_float") ||
(ctxInfo.hasExtension("OES_texture_float_linear") &&
ctxInfo.hasExtension("GL_OES_texture_float"));
}
fConfigTextureSupport[kRGBA_float_GrPixelConfig] = hasFPTextures;
}
bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,

Просмотреть файл

@ -731,6 +731,7 @@
#define GR_GL_RGB5_A1 0x8057
#define GR_GL_RGB565 0x8D62
#define GR_GL_RGBA8 0x8058
#define GR_GL_RGBA32F 0x8814
#define GR_GL_RGB8 0x8051
#define GR_GL_BGRA8 0x93A1
#define GR_GL_SRGB 0x8C40

Просмотреть файл

@ -639,7 +639,8 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
if (glFlipY) {
GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
}
GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, static_cast<GrGLint>(bpp)));
GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT,
static_cast<GrGLint>(GrUnpackAlignment(dataConfig))));
}
bool succeeded = true;
if (isNewTexture &&
@ -2697,6 +2698,11 @@ bool GrGpuGL::configToGLFormats(GrPixelConfig config,
case kR11_EAC_GrPixelConfig:
*internalFormat = GR_GL_COMPRESSED_R11;
break;
case kRGBA_float_GrPixelConfig:
*internalFormat = GR_GL_RGBA32F;
*externalFormat = GR_GL_RGBA;
*externalType = GR_GL_FLOAT;
break;
default:
return false;
}

Просмотреть файл

@ -0,0 +1,81 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
* This is a straightforward test of floating point textures, which are
* supported on some platforms. As of right now, this test only supports
* 32 bit floating point textures, and indeed floating point test values
* have been selected to require 32 bits of precision and full IEEE conformance
*/
#if SK_SUPPORT_GPU
#include <float.h>
#include "Test.h"
#include "GrContext.h"
#include "GrTexture.h"
#include "GrContextFactory.h"
#include "SkGpuDevice.h"
static const int DEV_W = 100, DEV_H = 100;
static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * sizeof(float);
static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^ 24
static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) {
float controlPixelData[FP_CONTROL_ARRAY_SIZE];
float readBuffer[FP_CONTROL_ARRAY_SIZE];
for (int i = 0; i < FP_CONTROL_ARRAY_SIZE; i += 4) {
controlPixelData[i] = FLT_MIN;
controlPixelData[i + 1] = FLT_MAX;
controlPixelData[i + 2] = FLT_EPSILON;
controlPixelData[i + 3] = kMaxIntegerRepresentableInSPFloatingPoint;
}
for (int origin = 0; origin < 2; ++origin) {
int glCtxTypeCnt = 1;
glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
GrTextureDesc desc;
desc.fFlags = kRenderTarget_GrTextureFlagBit;
desc.fWidth = DEV_W;
desc.fHeight = DEV_H;
desc.fConfig = kRGBA_float_GrPixelConfig;
desc.fOrigin = 0 == origin ?
kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
GrContext* context = NULL;
GrContextFactory::GLContextType type =
static_cast<GrContextFactory::GLContextType>(glCtxType);
if (!GrContextFactory::IsRenderingGLContext(type)) {
continue;
}
context = factory->get(type);
if (NULL == context){
continue;
}
SkAutoTUnref<GrTexture> fpTexture(context->createUncachedTexture(desc,
NULL,
0));
// Floating point textures are NOT supported everywhere
if (NULL == fpTexture) {
continue;
}
// write square
context->writeTexturePixels(fpTexture, 0, 0, DEV_W, DEV_H, desc.fConfig,
controlPixelData, 0);
context->readTexturePixels(fpTexture, 0, 0, DEV_W, DEV_H, desc.fConfig, readBuffer, 0);
for (int j = 0; j < FP_CONTROL_ARRAY_SIZE; ++j) {
REPORTER_ASSERT(reporter, readBuffer[j] == controlPixelData[j]);
}
}
}
}
#endif