making my changes work on android

This commit is contained in:
Anna 2019-07-29 10:43:20 -07:00
commit 0cc8c1f434
10 changed files with 142 additions and 143 deletions

View file

@ -104,35 +104,34 @@ void Instance::enumerateNics() {
}
}
}
json Instance::getCPU(int index) {
assert(index <(int) _cpus.size());
assert(index < (int)_cpus.size());
if (index < 0 || (int) _cpus.size() <= index)
if (index < 0 || (int)_cpus.size() <= index)
return json();
return _cpus.at(index);
}
json Instance::getGPU(int index) {
assert(index <(int) _gpus.size());
assert(index < (int)_gpus.size());
if (index < 0 || (int) _gpus.size() <= index)
if (index < 0 || (int)_gpus.size() <= index)
return json();
return _gpus.at(index);
}
json Instance::getDisplay(int index) {
assert(index <(int) _displays.size());
if (index < 0 || (int) _displays.size() <= index)
assert(index < (int)_displays.size());
if (index < 0 || (int)_displays.size() <= index)
return json();
return _displays.at(index);
}
Instance::~Instance() {
if (_cpus.size() > 0) {
_cpus.clear();

View file

@ -60,7 +60,8 @@ void BloomThreshold::run(const render::RenderContextPointer& renderContext, cons
auto colorTexture = gpu::TexturePointer(gpu::Texture::createRenderBuffer(inputBuffer->getTexelFormat(), bufferSize.x, bufferSize.y,
gpu::Texture::SINGLE_MIP, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT, gpu::Sampler::WRAP_CLAMP)));
_outputBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("BloomThreshold"));
//_outputBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("BloomThreshold"));
_outputBuffer = args->_blitFramebuffer;
_outputBuffer->setRenderBuffer(0, colorTexture);
_parameters.edit()._deltaUV = { 1.0f / bufferSize.x, 1.0f / bufferSize.y };

View file

@ -29,6 +29,9 @@
#include "TextureCache.h"
#include "FramebufferCache.h"
#include <iostream>
#include <sstream>
namespace ru {
using render_utils::slot::texture::Texture;
using render_utils::slot::buffer::Buffer;

View file

@ -95,7 +95,7 @@ RenderDeferredTask::RenderDeferredTask()
void RenderDeferredTask::configure(const Config& config) {
// Propagate resolution scale to sub jobs who need it
auto preparePrimaryBufferConfig = config.getConfig<PreparePrimaryFramebuffer>("PreparePrimaryBuffer");
auto preparePrimaryBufferConfig = config.getConfig<PreparePrimaryFramebuffer>("PreparePrimaryBufferDeferred");
assert(preparePrimaryBufferConfig);
preparePrimaryBufferConfig->setResolutionScale(config.resolutionScale);
}
@ -145,7 +145,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
const auto jitter = task.addJob<JitterSample>("JitterCam");
// GPU jobs: Start preparing the primary, deferred and lighting buffer
const auto scaledPrimaryFramebuffer = task.addJob<PreparePrimaryFramebuffer>("PreparePrimaryBuffer");
const auto scaledPrimaryFramebuffer = task.addJob<PreparePrimaryFramebuffer>("PreparePrimaryBufferDeferred");
// Prepare deferred, generate the shared Deferred Frame Transform. Only valid with the scaled frame buffer
const auto deferredFrameTransform = task.addJob<GenerateDeferredFrameTransform>("DeferredFrameTransform", jitter);
@ -238,24 +238,20 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
task.addJob<BloomEffect>("Bloom", bloomInputs);
// Lighting Buffer ready for tone mapping
//TODO re-enable last 3 steps
//const auto toneMappingInputs = ToneMappingDeferred::Input(lightingFramebuffer, scaledPrimaryFramebuffer).asVarying();
//const auto toneMappedBuffer = task.addJob<ToneMappingDeferred>("ToneMapping", toneMappingInputs);
const auto toneMappingInputs = lightingFramebuffer;
const auto toneMappedBuffer = task.addJob<ToneMapAndResample>("ToneMapAndResample", toneMappingInputs);
// Debugging task is happening in the "over" layer after tone mapping and just before HUD
{ // Debug the bounds of the rendered items, still look at the zbuffer
const auto extraDebugBuffers = RenderDeferredTaskDebug::ExtraBuffers(linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, ambientOcclusionUniforms, scatteringResource, velocityBuffer);
const auto debugInputs = RenderDeferredTaskDebug::Input(fetchedItems, shadowTaskOutputs, lightingStageInputs, lightClusters, prepareDeferredOutputs, extraDebugBuffers,
deferredFrameTransform, jitter, lightingModel).asVarying();
deferredFrameTransform, jitter, lightingModel).asVarying();
task.addJob<RenderDeferredTaskDebug>("DebugRenderDeferredTask", debugInputs);
}
// Upscale to finale resolution
//const auto primaryFramebuffer = task.addJob<render::UpsampleToBlitFramebuffer>("PrimaryBufferUpscale", toneMappedBuffer);
// HUD Layer
//const auto renderHUDLayerInputs = RenderHUDLayerTask::Input(primaryFramebuffer, lightingModel, hudOpaque, hudTransparent, hazeFrame).asVarying();
//task.addJob<RenderHUDLayerTask>("RenderHUDLayer", renderHUDLayerInputs);
const auto renderHUDLayerInputs = RenderHUDLayerTask::Input(toneMappedBuffer, lightingModel, hudOpaque, hudTransparent, hazeFrame).asVarying();
task.addJob<RenderHUDLayerTask>("RenderHUDLayer", renderHUDLayerInputs);
}
RenderDeferredTaskDebug::RenderDeferredTaskDebug() {
@ -415,7 +411,6 @@ void RenderDeferredTaskDebug::build(JobModel& task, const render::Varying& input
const auto debugZoneInputs = DebugZoneLighting::Inputs(deferredFrameTransform, lightFrame, backgroundFrame).asVarying();
task.addJob<DebugZoneLighting>("DrawZoneStack", debugZoneInputs);
}

View file

@ -19,8 +19,6 @@
#include <gpu/Texture.h>
#include <graphics/ShaderConstants.h>
#include <render/ShapePipeline.h>
//#include <render/ResampleTask.h>
//#include <ToneMapAndResampleTask.h>
#include <render/FilterTask.h>
@ -29,7 +27,6 @@
#include "StencilMaskPass.h"
#include "ZoneRenderer.h"
#include "FadeEffect.h"
//#include "ToneMappingEffect.h"
#include "ToneMapAndResampleTask.h"
#include "BackgroundStage.h"
#include "FramebufferCache.h"
@ -53,7 +50,7 @@ extern void initForwardPipelines(ShapePlumber& plumber);
void RenderForwardTask::configure(const Config& config) {
// Propagate resolution scale to sub jobs who need it
auto preparePrimaryBufferConfig = config.getConfig<PreparePrimaryFramebufferMSAA>("PreparePrimaryBuffer");
auto preparePrimaryBufferConfig = config.getConfig<PreparePrimaryFramebufferMSAA>("PreparePrimaryBufferForward");
assert(preparePrimaryBufferConfig);
preparePrimaryBufferConfig->setResolutionScale(config.resolutionScale);
}
@ -101,7 +98,7 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend
// GPU jobs: Start preparing the main framebuffer
const auto scaledPrimaryFramebuffer = task.addJob<PreparePrimaryFramebufferMSAA>("PreparePrimaryBuffer");
const auto scaledPrimaryFramebuffer = task.addJob<PreparePrimaryFramebufferMSAA>("PreparePrimaryBufferForward");
// Prepare deferred, generate the shared Deferred Frame Transform. Only valid with the scaled frame buffer
const auto deferredFrameTransform = task.addJob<GenerateDeferredFrameTransform>("DeferredFrameTransform");
@ -149,7 +146,7 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend
const auto resolveInputs = ResolveFramebuffer::Inputs(scaledPrimaryFramebuffer, static_cast<gpu::FramebufferPointer>(nullptr)).asVarying();
const auto resolvedFramebuffer = task.addJob<ResolveFramebuffer>("Resolve", resolveInputs);
const auto toneMappedBuffer = resolvedFramebuffer;
//const auto toneMappedBuffer = resolvedFramebuffer;
#else
const auto newResolvedFramebuffer = task.addJob<NewFramebuffer>("MakeResolvingFramebuffer");
@ -168,7 +165,7 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend
const auto primaryFramebuffer = task.addJob<ToneMapAndResample>("ToneMapAndResample", resolvedFramebuffer);
// HUD Layer
const auto renderHUDLayerInputs = RenderHUDLayerTask::Input(primaryFramebuffer, lightingModel, hudOpaque, hudTransparent, hazeFrame).asVarying();
const auto renderHUDLayerInputs = RenderHUDLayerTask::Input(toneMappedBuffer, lightingModel, hudOpaque, hudTransparent, hazeFrame).asVarying();
task.addJob<RenderHUDLayerTask>("RenderHUDLayer", renderHUDLayerInputs);
}

View file

@ -50,11 +50,13 @@ public:
const float SCALE_RANGE_MIN = 0.1f;
const float SCALE_RANGE_MAX = 2.0f;
resolutionScale = std::max(SCALE_RANGE_MIN, std::min(SCALE_RANGE_MAX, scale));
//emit dirty();
}
int getNumSamples() const { return numSamples; }
void setNumSamples(int num) {
numSamples = std::max(1, std::min(32, num));
emit dirty();
}
signals:

View file

@ -1,15 +1,14 @@
//
// ResampleTask.cpp
// render/src/render
// ToneMapAndResampleTask.cpp
// libraries/render-utils/src
//
// Various to Resample or downsample textures into framebuffers.
//
// Created by Olivier Prat on 10/09/17.
// Copyright 2017 High Fidelity, Inc.
// Created by Anna Brewer on 7/3/19.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "ToneMapAndResampleTask.h"
#include <gpu/Context.h>
@ -23,11 +22,26 @@ using namespace render;
using namespace shader::gpu::program;
using namespace shader::render_utils::program;
gpu::PipelinePointer ToneMapAndResample::_pipeline;
gpu::PipelinePointer ToneMapAndResample::_mirrorPipeline;
ToneMapAndResample::ToneMapAndResample() {
Parameters parameters;
_parametersBuffer = gpu::BufferView(std::make_shared<gpu::Buffer>(sizeof(Parameters), (const gpu::Byte*) &parameters));
}
void ToneMapAndResample::init(RenderArgs* args) {
// shared_ptr to gpu::State
gpu::StatePointer blitState = gpu::StatePointer(new gpu::State());
blitState->setDepthTest(gpu::State::DepthTest(false, false));
blitState->setColorWriteMask(true, true, true, true);
_pipeline = gpu::PipelinePointer(gpu::Pipeline::create(gpu::Shader::createProgram(toneMapping), blitState));
_mirrorPipeline = gpu::PipelinePointer(gpu::Pipeline::create(gpu::Shader::createProgram(toneMapping_mirrored), blitState));
}
void ToneMapAndResample::setExposure(float exposure) {
auto& params = _parametersBuffer.get<Parameters>();
if (params._exposure != exposure) {
@ -48,12 +62,10 @@ void ToneMapAndResample::configure(const Config& config) {
setToneCurve((ToneCurve)config.curve);
}
gpu::PipelinePointer ToneMapAndResample::_pipeline;
gpu::PipelinePointer ToneMapAndResample::_mirrorPipeline;
void ToneMapAndResample::run(const RenderContextPointer& renderContext, const Input& input, gpu::FramebufferPointer& resampledFrameBuffer) {
assert(renderContext->args);
assert(renderContext->args->hasViewFrustum());
RenderArgs* args = renderContext->args;
auto sourceFramebuffer = input;
@ -61,47 +73,40 @@ void ToneMapAndResample::run(const RenderContextPointer& renderContext, const In
resampledFrameBuffer = args->_blitFramebuffer;
/*
if (!lightingBuffer || !blitFramebuffer) {
return;
}*/
}
if (resampledFrameBuffer != sourceFramebuffer) {
if (!_pipeline) {
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
state->setDepthTest(gpu::State::DepthTest(false, false));
state->setColorWriteMask(true, true, true, true);
_pipeline = gpu::Pipeline::create(gpu::Shader::createProgram(toneMapping), state);
_mirrorPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(toneMapping_mirrored), state);
init(args);
}
const auto bufferSize = resampledFrameBuffer->getSize();
auto srcBufferSize = glm::ivec2(lightingBuffer->getDimensions());
const auto srcBufferSize = glm::ivec2(lightingBuffer->getDimensions());
glm::ivec4 viewport{ 0, 0, bufferSize.x, bufferSize.y };
glm::ivec4 destViewport{ 0, 0, bufferSize.x, bufferSize.y };
gpu::doInBatch("Resample::run", args->_context, [&](gpu::Batch& batch) {
batch.enableStereo(false);
batch.setFramebuffer(resampledFrameBuffer);
batch.setViewportTransform(viewport);
batch.setViewportTransform(destViewport);
batch.setProjectionTransform(glm::mat4());
batch.resetViewTransform();
batch.setPipeline(args->_renderMode == RenderArgs::MIRROR_RENDER_MODE ? _mirrorPipeline : _pipeline);
// viewport = args->_viewport ??
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(srcBufferSize, args->_viewport));
batch.setUniformBuffer(render_utils::slot::buffer::ToneMappingParams, _parametersBuffer);
batch.setResourceTexture(render_utils::slot::texture::ToneMappingColor, lightingBuffer);
//batch.setResourceTexture(0, sourceFramebuffer->getRenderBuffer(0));
batch.draw(gpu::TRIANGLE_STRIP, 4);
});
// Set full final viewport
args->_viewport = viewport;
output = blitFramebuffer;
}
}

View file

@ -1,105 +1,102 @@
//
// ResampleTask.h
// render/src/render
// ToneMapAndResample.h
// libraries/render-utils/src
//
// Various to upsample or downsample textures into framebuffers.
//
// Created by Olivier Prat on 10/09/17.
// Copyright 2017 High Fidelity, Inc.
// Created by Anna Brewer on 7/3/19.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_render_ToneMapAndResampleTask_h
#define hifi_render_ToneMapAndResampleTask_h
#include "render/Engine.h"
#ifndef hifi_ToneMapAndResample_h
#define hifi_ToneMapAndResample_h
#include <DependencyManager.h>
#include <NumericalConstants.h>
#include <gpu/Resource.h>
#include <gpu/Pipeline.h>
#include <render/Forward.h>
#include <render/DrawTask.h>
//namespace render {
enum class ToneCurve {
// Different tone curve available
None,
Gamma22,
Reinhard,
Filmic,
};
enum class ToneCurve {
// Different tone curve available
None,
Gamma22,
Reinhard,
Filmic,
};
class ToneMappingConfig : public render::Job::Config {
Q_OBJECT
class ToneMappingConfig : public render::Job::Config {
Q_OBJECT
Q_PROPERTY(float exposure MEMBER exposure WRITE setExposure);
Q_PROPERTY(int curve MEMBER curve WRITE setCurve);
Q_PROPERTY(int curve MEMBER curve WRITE setCurve);
public:
ToneMappingConfig() : render::Job::Config(true) {}
void setExposure(float newExposure) { exposure = newExposure; emit dirty(); }
void setCurve(int newCurve) { curve = std::max((int)ToneCurve::None, std::min((int)ToneCurve::Filmic, newCurve)); emit dirty(); }
float exposure{ 0.0f };
int curve{ (int)ToneCurve::Gamma22 };
signals:
void dirty();
};
class ToneMapAndResample {
public:
ToneMapAndResample();
virtual ~ToneMapAndResample() {}
void render(RenderArgs* args, const gpu::TexturePointer& lightingBuffer, gpu::FramebufferPointer& destinationBuffer);
void setExposure(float exposure);
float getExposure() const { return _parametersBuffer.get<Parameters>()._exposure; }
void setToneCurve(ToneCurve curve);
ToneCurve getToneCurve() const { return (ToneCurve)_parametersBuffer.get<Parameters>()._toneCurve; }
// Inputs: lightingFramebuffer, destinationFramebuffer
using Input = gpu::FramebufferPointer;
using Output = gpu::FramebufferPointer;
using Config = ToneMappingConfig;
using JobModel = render::Job::ModelIO<ToneMapAndResample, Input, Output, Config>;
void configure(const Config& config);
void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
protected:
static gpu::PipelinePointer _pipeline;
static gpu::PipelinePointer _mirrorPipeline;
gpu::FramebufferPointer _destinationFrameBuffer;
float _factor{ 2.0f };
gpu::FramebufferPointer getResampledFrameBuffer(const gpu::FramebufferPointer& sourceFramebuffer);
private:
gpu::PipelinePointer _blitLightBuffer;
// Class describing the uniform buffer with all the parameters common to the tone mapping shaders
class Parameters {
public:
ToneMappingConfig() : render::Job::Config(true) {}
float _exposure = 0.0f;
float _twoPowExposure = 1.0f;
glm::vec2 spareA;
int _toneCurve = (int)ToneCurve::Gamma22;
glm::vec3 spareB;
void setExposure(float newExposure) { exposure = newExposure; emit dirty(); }
void setCurve(int newCurve) { curve = std::max((int)ToneCurve::None, std::min((int)ToneCurve::Filmic, newCurve)); emit dirty(); }
float exposure{ 0.0f };
int curve{ (int)ToneCurve::Gamma22 };
signals:
void dirty();
Parameters() {}
};
typedef gpu::BufferView UniformBufferView;
gpu::BufferView _parametersBuffer;
class ToneMapAndResample{
public:
ToneMapAndResample();
virtual ~ToneMapAndResample() {}
void init(RenderArgs* args);
};
void setExposure(float exposure);
float getExposure() const { return _parametersBuffer.get<Parameters>()._exposure; }
void setToneCurve(ToneCurve curve);
ToneCurve getToneCurve() const { return (ToneCurve)_parametersBuffer.get<Parameters>()._toneCurve; }
// Inputs: lightingFramebuffer, destinationFramebuffer
using Input = gpu::FramebufferPointer;
using Output = gpu::FramebufferPointer;
using Config = ToneMappingConfig;
//using JobModel = render::Job::ModelIO<ToneMapAndResample, Input, Output, Config>;
using JobModel = render::Job::ModelIO<ToneMapAndResample, Input, gpu::FramebufferPointer, Config>;
void configure(const Config& config);
void run(const render::RenderContextPointer& renderContext, const Input& input, gpu::FramebufferPointer& resampledFrameBuffer);
protected:
static gpu::PipelinePointer _pipeline;
static gpu::PipelinePointer _mirrorPipeline;
gpu::FramebufferPointer _destinationFrameBuffer;
float _factor{ 2.0f };
gpu::FramebufferPointer getResampledFrameBuffer(const gpu::FramebufferPointer& sourceFramebuffer);
private:
gpu::PipelinePointer _blitLightBuffer;
// Class describing the uniform buffer with all the parameters common to the tone mapping shaders
class Parameters {
public:
float _exposure = 0.0f;
float _twoPowExposure = 1.0f;
glm::vec2 spareA;
int _toneCurve = (int)ToneCurve::Gamma22;
glm::vec3 spareB;
Parameters() {}
};
typedef gpu::BufferView UniformBufferView;
gpu::BufferView _parametersBuffer;
void init(RenderArgs* args);
};
//}
#endif // hifi_render_ResampleTask_h
#endif // hifi_ToneMapAndResample_h

View file

@ -43,11 +43,11 @@ layout(location=0) in vec2 varTexCoord0;
layout(location=0) out vec4 outFragColor;
void main(void) {
<@if HIFI_USE_MIRRORED@>
vec4 fragColorRaw = texture(colorMap, vec2(1.0 - varTexCoord0.x, varTexCoord0.y));
<@else@>
vec4 fragColorRaw = texture(colorMap, varTexCoord0);
<@endif@>
<@if HIFI_USE_MIRRORED@>
vec4 fragColorRaw = texture(colorMap, vec2(1.0 - varTexCoord0.x, varTexCoord0.y);
<@else@>
vec4 fragColorRaw = texture(colorMap, varTexCoord0);
<@endif@>
vec3 fragColor = fragColorRaw.xyz;
vec3 srcColor = fragColor * getTwoPowExposure();

View file

@ -45,7 +45,7 @@ Rectangle {
anchors.right: parent.right
spacing: 5
Repeater {
model: [ "MSAA:PrepareFramebuffer:numSamples:4:1"
model: [ "MSAA:PreparePrimaryBufferForward:numSamples:4:1"
]
ConfigSlider {
label: qsTr(modelData.split(":")[0])