Merge pull request #9606 from samcake/blue

More intrumentation, Pixel Format clean up and minor improvments in texture transfers
This commit is contained in:
samcake 2017-02-09 11:18:09 -08:00 committed by GitHub
commit 850be620f9
9 changed files with 80 additions and 49 deletions

View file

@ -116,7 +116,7 @@ void CauterizedModel::updateClusterMatrices() {
for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j);
auto jointMatrix = _rig->getJointTransform(cluster.jointIndex);
#if GLM_ARCH & GLM_ARCH_SSE2
#if (GLM_ARCH & GLM_ARCH_SSE2) && !(defined Q_OS_MACOS)
glm::mat4 out, inverseBindMatrix = cluster.inverseBindMatrix;
glm_mat4_mul((glm_vec4*)&jointMatrix, (glm_vec4*)&inverseBindMatrix, (glm_vec4*)&out);
state.clusterMatrices[j] = out;
@ -155,7 +155,7 @@ void CauterizedModel::updateClusterMatrices() {
if (_cauterizeBoneSet.find(cluster.jointIndex) != _cauterizeBoneSet.end()) {
jointMatrix = cauterizeMatrix;
}
#if GLM_ARCH & GLM_ARCH_SSE2
#if (GLM_ARCH & GLM_ARCH_SSE2) && !(defined Q_OS_MACOS)
glm::mat4 out, inverseBindMatrix = cluster.inverseBindMatrix;
glm_mat4_mul((glm_vec4*)&jointMatrix, (glm_vec4*)&inverseBindMatrix, (glm_vec4*)&out);
state.clusterMatrices[j] = out;

View file

@ -62,6 +62,7 @@ template<class T> QVariant readBinaryArray(QDataStream& in, int& position) {
position += sizeof(T) * arrayLength;
in.readRawData(arrayData.data(), arrayData.size());
}
if (arrayData.size() > 0) {
memcpy(&values[0], arrayData.constData(), arrayData.size());
}

View file

@ -328,12 +328,12 @@ void GLBackend::render(const Batch& batch) {
void GLBackend::syncCache() {
PROFILE_RANGE(render_gpu_gl_detail, __FUNCTION__);
syncTransformStateCache();
syncPipelineStateCache();
syncInputStateCache();
syncOutputStateCache();
glEnable(GL_LINE_SMOOTH);
}
#ifdef GPU_STEREO_DRAWCALL_DOUBLED

View file

@ -1,4 +1,4 @@
//
//
// GLBackendPipeline.cpp
// libraries/gpu/src/gpu
//

View file

@ -28,11 +28,8 @@ void GLBackend::resetPipelineState(State::Signature nextSignature) {
}
}
}
}
void GLBackend::syncPipelineStateCache() {
State::Data state;
// force a few states regardless
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
// Point size is always on
@ -43,6 +40,25 @@ void GLBackend::syncPipelineStateCache() {
// Default line width accross the board
glLineWidth(1.0f);
glEnable(GL_LINE_SMOOTH);
}
void GLBackend::syncPipelineStateCache() {
State::Data state;
// force a few states regardless
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
// Point size is always on
// FIXME CORE
//glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glEnable(GL_PROGRAM_POINT_SIZE_EXT);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
// Default line width accross the board
glLineWidth(1.0f);
glEnable(GL_LINE_SMOOTH);
getCurrentGLState(state);
State::Signature signature = State::evalSignature(state);

View file

@ -151,6 +151,7 @@ bool GLTextureTransferHelper::process() {
#endif
return true;
}
PROFILE_COUNTER_IF_CHANGED(render_gpu_gl, "transferringTextures", int, (int) _transferringTextures.size())
static auto lastReport = usecTimestampNow();
auto now = usecTimestampNow();

View file

@ -297,6 +297,7 @@ void GL45Texture::startTransfer() {
}
bool GL45Texture::continueTransfer() {
PROFILE_RANGE(render_gpu_gl, "continueTransfer")
size_t maxFace = GL_TEXTURE_CUBE_MAP == _target ? CUBE_NUM_FACES : 1;
for (uint8_t face = 0; face < maxFace; ++face) {
for (uint16_t mipLevel = _minMip; mipLevel <= _maxMip; ++mipLevel) {
@ -306,6 +307,8 @@ bool GL45Texture::continueTransfer() {
_sparseInfo.allocatedPages += _sparseInfo.getPageCount(size);
}
if (_gpuObject.isStoredMipFaceAvailable(mipLevel, face)) {
PROFILE_RANGE_EX(render_gpu_gl, "texSubImage", 0x0000ffff, (size.x * size.y * maxFace / 1024));
auto mip = _gpuObject.accessStoredMipFace(mipLevel, face);
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(_gpuObject.getTexelFormat(), mip->getFormat());
if (GL_TEXTURE_2D == _target) {
@ -379,6 +382,8 @@ void GL45Texture::stripToMip(uint16_t newMinMip) {
return;
}
PROFILE_RANGE(render_gpu_gl, "GL45Texture::stripToMip");
auto mipLevels = usedMipLevels();
{
Lock lock(texturesByMipCountsMutex);
@ -420,29 +425,35 @@ void GL45Texture::stripToMip(uint16_t newMinMip) {
auto newLevels = usedMipLevels();
// Create and setup the new texture (allocate)
glCreateTextures(_target, 1, &const_cast<GLuint&>(_id));
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, 0);
glTextureParameteri(_id, GL_TEXTURE_MAX_LEVEL, _maxMip - _minMip);
Vec3u newDimensions = _gpuObject.evalMipDimensions(_mipOffset);
glTextureStorage2D(_id, newLevels, _internalFormat, newDimensions.x, newDimensions.y);
{
Vec3u newDimensions = _gpuObject.evalMipDimensions(_mipOffset);
PROFILE_RANGE_EX(render_gpu_gl, "Re-Allocate", 0xff0000ff, (newDimensions.x * newDimensions.y));
glCreateTextures(_target, 1, &const_cast<GLuint&>(_id));
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, 0);
glTextureParameteri(_id, GL_TEXTURE_MAX_LEVEL, _maxMip - _minMip);
glTextureStorage2D(_id, newLevels, _internalFormat, newDimensions.x, newDimensions.y);
}
// Copy the contents of the old texture to the new
GLuint fbo { 0 };
glCreateFramebuffers(1, &fbo);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
for (uint16 targetMip = _minMip; targetMip <= _maxMip; ++targetMip) {
uint16 sourceMip = targetMip + mipDelta;
Vec3u mipDimensions = _gpuObject.evalMipDimensions(targetMip + _mipOffset);
for (GLenum target : getFaceTargets(_target)) {
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, oldId, sourceMip);
(void)CHECK_GL_ERROR();
glCopyTextureSubImage2D(_id, targetMip, 0, 0, 0, 0, mipDimensions.x, mipDimensions.y);
(void)CHECK_GL_ERROR();
{
PROFILE_RANGE(render_gpu_gl, "Blit");
// Preferred path only available in 4.3
for (uint16 targetMip = _minMip; targetMip <= _maxMip; ++targetMip) {
uint16 sourceMip = targetMip + mipDelta;
Vec3u mipDimensions = _gpuObject.evalMipDimensions(targetMip + _mipOffset);
for (GLenum target : getFaceTargets(_target)) {
glCopyImageSubData(
oldId, target, sourceMip, 0, 0, 0,
_id, target, targetMip, 0, 0, 0,
mipDimensions.x, mipDimensions.y, 1
);
(void)CHECK_GL_ERROR();
}
}
glDeleteTextures(1, &oldId);
}
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &fbo);
glDeleteTextures(1, &oldId);
}
// Re-sync the sampler to force access to the new mip level

View file

@ -17,7 +17,6 @@
#include <Profile.h>
#include "ModelLogging.h"
using namespace model;
using namespace gpu;
@ -142,8 +141,9 @@ const QImage TextureUsage::process2DImageColor(const QImage& srcImage, bool& val
validAlpha = (numOpaques != NUM_PIXELS);
}
if (!validAlpha && image.format() != QImage::Format_RGB888) {
image = image.convertToFormat(QImage::Format_RGB888);
// Force all the color images to be rgba32bits
if (image.format() != QImage::Format_ARGB32) {
image = image.convertToFormat(QImage::Format_ARGB32);
}
return image;
@ -200,7 +200,7 @@ const QImage& image, bool isLinear, bool doCompress) {
}
}
#define CPU_MIPMAPS 0
#define CPU_MIPMAPS 1
void generateMips(gpu::Texture* texture, QImage& image, gpu::Element formatMip) {
#if CPU_MIPMAPS
@ -286,15 +286,16 @@ gpu::Texture* TextureUsage::createNormalTextureFromNormalImage(const QImage& src
PROFILE_RANGE(resource_parse, "createNormalTextureFromNormalImage");
QImage image = processSourceImage(srcImage, false);
if (image.format() != QImage::Format_RGB888) {
image = image.convertToFormat(QImage::Format_RGB888);
// Make sure the normal map source image is RGBA32
if (image.format() != QImage::Format_RGBA8888) {
image = image.convertToFormat(QImage::Format_RGBA8888);
}
gpu::Texture* theTexture = nullptr;
if ((image.width() > 0) && (image.height() > 0)) {
gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB);
gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB);
gpu::Element formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA);
gpu::Element formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA);
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
theTexture->setSource(srcImageName);
@ -330,7 +331,8 @@ gpu::Texture* TextureUsage::createNormalTextureFromBumpImage(const QImage& srcIm
const double pStrength = 2.0;
int width = image.width();
int height = image.height();
QImage result(width, height, QImage::Format_RGB888);
// THe end result image for normal map is RGBA32 even though the A is not used
QImage result(width, height, QImage::Format_RGBA8888);
for (int i = 0; i < width; i++) {
const int iNextClamped = clampPixelCoordinate(i + 1, width - 1);
@ -378,8 +380,8 @@ gpu::Texture* TextureUsage::createNormalTextureFromBumpImage(const QImage& srcIm
gpu::Texture* theTexture = nullptr;
if ((image.width() > 0) && (image.height() > 0)) {
gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB);
gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::NUINT8, gpu::RGB);
gpu::Element formatGPU = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA);
gpu::Element formatMip = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA);
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
theTexture->setSource(srcImageName);
@ -398,8 +400,8 @@ gpu::Texture* TextureUsage::createRoughnessTextureFromImage(const QImage& srcIma
image = image.convertToFormat(QImage::Format_RGB888);
}
} else {
if (image.format() != QImage::Format_ARGB32) {
image = image.convertToFormat(QImage::Format_ARGB32);
if (image.format() != QImage::Format_RGBA8888) {
image = image.convertToFormat(QImage::Format_RGBA8888);
}
}
@ -433,8 +435,8 @@ gpu::Texture* TextureUsage::createRoughnessTextureFromGlossImage(const QImage& s
image = image.convertToFormat(QImage::Format_RGB888);
}
} else {
if (image.format() != QImage::Format_ARGB32) {
image = image.convertToFormat(QImage::Format_ARGB32);
if (image.format() != QImage::Format_RGBA8888) {
image = image.convertToFormat(QImage::Format_RGBA8888);
}
}
@ -472,8 +474,8 @@ gpu::Texture* TextureUsage::createMetallicTextureFromImage(const QImage& srcImag
image = image.convertToFormat(QImage::Format_RGB888);
}
} else {
if (image.format() != QImage::Format_ARGB32) {
image = image.convertToFormat(QImage::Format_ARGB32);
if (image.format() != QImage::Format_RGBA8888) {
image = image.convertToFormat(QImage::Format_RGBA8888);
}
}
@ -762,8 +764,8 @@ gpu::Texture* TextureUsage::processCubeTextureColorFromImage(const QImage& srcIm
gpu::Texture* theTexture = nullptr;
if ((srcImage.width() > 0) && (srcImage.height() > 0)) {
QImage image = processSourceImage(srcImage, true);
if (image.format() != QImage::Format_RGB888) {
image = image.convertToFormat(QImage::Format_RGB888);
if (image.format() != QImage::Format_ARGB32) {
image = image.convertToFormat(QImage::Format_ARGB32);
}
gpu::Element formatGPU;

View file

@ -1178,7 +1178,7 @@ void Model::updateClusterMatrices() {
for (int j = 0; j < mesh.clusters.size(); j++) {
const FBXCluster& cluster = mesh.clusters.at(j);
auto jointMatrix = _rig->getJointTransform(cluster.jointIndex);
#if GLM_ARCH & GLM_ARCH_SSE2
#if (GLM_ARCH & GLM_ARCH_SSE2) && !(defined Q_OS_MACOS)
glm::mat4 out, inverseBindMatrix = cluster.inverseBindMatrix;
glm_mat4_mul((glm_vec4*)&jointMatrix, (glm_vec4*)&inverseBindMatrix, (glm_vec4*)&out);
state.clusterMatrices[j] = out;