rebase and shader fixes

This commit is contained in:
Brad Davis 2019-06-29 17:18:01 -07:00 committed by Karol Suprynowicz
parent 1906b636fe
commit b7efed9461
12 changed files with 31 additions and 166 deletions

View file

@ -21,14 +21,14 @@
<@include CullFace.slh@>
// the albedo texture
TEXTURE(0, sampler2D, originalTexture);
TEXTURE(0, sampler2D, _texture);
<@if not HIFI_USE_FORWARD@>
layout(location=0) in vec3 _normalWS;
INPUT(0, vec3, _normalWS);
<@endif@>
layout(location=1) in vec2 _texCoord;
layout(location=2) in vec4 _color;
layout(location=3) in float _distanceFromCenter;
INPUT(1, vec2, _texCoord);
INPUT(2, vec4, _color);
INPUT(3, float, _distanceFromCenter);
void main(void) {
vec4 texel = texture(_texture, _texCoord);

View file

@ -11,6 +11,7 @@
//
<@include gpu/ShaderConstants.h@>
INPUT(GPU_ATTR_POSITION, vec4, inPosition);
INPUT(GPU_ATTR_NORMAL, vec4, inNormal);
INPUT(GPU_ATTR_COLOR, vec4, inColor);

View file

@ -255,6 +255,9 @@ void GLTextureTransferEngineDefault::updateMemoryPressure() {
pressure = (float)totalVariableMemoryAllocation / (float)allowedMemoryAllocation;
}
PROFILE_COUNTER_IF_CHANGED(render_gpu_gl, "textureMemTarget", size_t, idealMemoryAllocation);
PROFILE_COUNTER_IF_CHANGED(render_gpu_gl, "textureMemActual", size_t, totalVariableMemoryAllocation);
// If we're oversubscribed we need to demote textures IMMEDIATELY
if (pressure > OVERSUBSCRIBED_PRESSURE_VALUE && canDemote) {
auto overPressure = pressure - OVERSUBSCRIBED_PRESSURE_VALUE;
@ -275,6 +278,8 @@ void GLTextureTransferEngineDefault::updateMemoryPressure() {
}
}
PROFILE_COUNTER(render_gpu_gl, "textureTransfer", { { "state", static_cast<int>(_memoryPressureState) } });
// If we've changed state then we have to populate the appropriate structure with the work to be done
if (newState != _memoryPressureState) {
_memoryPressureState = newState;
@ -415,6 +420,7 @@ void GLTextureTransferEngineDefault::populateActiveBufferQueue() {
}
bool GLTextureTransferEngineDefault::processActiveBufferQueue() {
PROFILE_RANGE(render_gpu_gl, __FUNCTION__);
ActiveTransferQueue activeBufferQueue;
{
Lock lock(_bufferMutex);

View file

@ -37,6 +37,7 @@ class VKBackend : public Backend, public std::enable_shared_from_this<VKBackend>
public:
VKBackend();
~VKBackend();
void syncProgram(const gpu::ShaderPointer& program) override {}
void syncCache() override {}
void recycle() const override {}
void setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool reset = false) override {}

View file

@ -30,152 +30,6 @@ class QImage;
namespace gpu {
//
// GL Backend pointer storage mechanism
// One of the following three defines must be defined.
// GPU_POINTER_STORAGE_SHARED
// The platonic ideal, use references to smart pointers.
// However, this produces artifacts because there are too many places in the code right now that
// create temporary values (undesirable smart pointer duplications) and then those temp variables
// get passed on and have their reference taken, and then invalidated
// GPU_POINTER_STORAGE_REF
// Raw pointer manipulation. Seems more dangerous than the reference wrappers,
// but in practice, the danger of grabbing a reference to a temporary variable
// is causing issues
// GPU_POINTER_STORAGE_RAW
#if defined(USE_GLES)
#define GPU_POINTER_STORAGE_SHARED
#else
#define GPU_POINTER_STORAGE_RAW
#endif
#if defined(GPU_POINTER_STORAGE_SHARED)
template <typename T>
static inline bool compare(const std::shared_ptr<T>& a, const std::shared_ptr<T>& b) {
return a == b;
}
template <typename T>
static inline T* acquire(const std::shared_ptr<T>& pointer) {
return pointer.get();
}
template <typename T>
static inline void reset(std::shared_ptr<T>& pointer) {
return pointer.reset();
}
template <typename T>
static inline bool valid(const std::shared_ptr<T>& pointer) {
return pointer.operator bool();
}
template <typename T>
static inline void assign(std::shared_ptr<T>& pointer, const std::shared_ptr<T>& source) {
pointer = source;
}
using BufferReference = BufferPointer;
using TextureReference = TexturePointer;
using FramebufferReference = FramebufferPointer;
using FormatReference = Stream::FormatPointer;
using PipelineReference = PipelinePointer;
#define GPU_REFERENCE_INIT_VALUE nullptr
#elif defined(GPU_POINTER_STORAGE_REF)
template <typename T>
class PointerReferenceWrapper : public std::reference_wrapper<const std::shared_ptr<T>> {
using Parent = std::reference_wrapper<const std::shared_ptr<T>>;
public:
using Pointer = std::shared_ptr<T>;
PointerReferenceWrapper() : Parent(EMPTY()) {}
PointerReferenceWrapper(const Pointer& pointer) : Parent(pointer) {}
void clear() { *this = EMPTY(); }
private:
static const Pointer& EMPTY() {
static const Pointer EMPTY_VALUE;
return EMPTY_VALUE;
};
};
template <typename T>
static bool compare(const PointerReferenceWrapper<T>& reference, const std::shared_ptr<T>& pointer) {
return reference.get() == pointer;
}
template <typename T>
static inline T* acquire(const PointerReferenceWrapper<T>& reference) {
return reference.get().get();
}
template <typename T>
static void assign(PointerReferenceWrapper<T>& reference, const std::shared_ptr<T>& pointer) {
reference = pointer;
}
template <typename T>
static bool valid(const PointerReferenceWrapper<T>& reference) {
return reference.get().operator bool();
}
template <typename T>
static inline void reset(PointerReferenceWrapper<T>& reference) {
return reference.clear();
}
using BufferReference = PointerReferenceWrapper<Buffer>;
using TextureReference = PointerReferenceWrapper<Texture>;
using FramebufferReference = PointerReferenceWrapper<Framebuffer>;
using FormatReference = PointerReferenceWrapper<Stream::Format>;
using PipelineReference = PointerReferenceWrapper<Pipeline>;
#define GPU_REFERENCE_INIT_VALUE
#elif defined(GPU_POINTER_STORAGE_RAW)
template <typename T>
static bool compare(const T* const& rawPointer, const std::shared_ptr<T>& pointer) {
return rawPointer == pointer.get();
}
template <typename T>
static inline T* acquire(T* const& rawPointer) {
return rawPointer;
}
template <typename T>
static inline bool valid(const T* const& rawPointer) {
return rawPointer;
}
template <typename T>
static inline void reset(T*& rawPointer) {
rawPointer = nullptr;
}
template <typename T>
static inline void assign(T*& rawPointer, const std::shared_ptr<T>& pointer) {
rawPointer = pointer.get();
}
using BufferReference = Buffer*;
using TextureReference = Texture*;
using FramebufferReference = Framebuffer*;
using FormatReference = Stream::Format*;
using PipelineReference = Pipeline*;
#define GPU_REFERENCE_INIT_VALUE nullptr
#endif
struct ContextStats {
public:
uint32_t _ISNumFormatChanges { 0 };
@ -204,7 +58,6 @@ public:
virtual void shutdown() {}
virtual const std::string& getVersion() const = 0;
virtual void setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool reset = false) = 0;
virtual uint32_t getTextureID(const TexturePointer& texture) = 0;
void setStereoState(const StereoState& stereo) { _stereo = stereo; }

View file

@ -191,16 +191,10 @@ constexpr const char* COMMAND_NAMES[] = {
"startNamedCall",
"stopNamedCall",
"glUniform1i",
"glUniform1f",
"glUniform2f",
"glUniform3f",
"glUniform4f",
"glUniform3fv",
"glUniform4fv",
"glUniform4iv",
"glUniformMatrix3fv",
"glUniformMatrix4fv",
"pushProfileRange",
"popProfileRange",

View file

@ -249,7 +249,7 @@ float fetchScatteringMap(vec2 uv) {
<$declareMaterialTexMapArrayBuffer()$>
TEXTURE(GRAPHICS_TEXTURE_MATERIAL_EMISSIVE_LIGHTMAP, sampler2D, emissiveMap);
vec3 fetchLightmapMap(vec2 uv) {
vec3 fetchLightMap(vec2 uv) {
vec2 lightmapParams = getTexMapArray()._lightmapParams.xy;
return (vec3(lightmapParams.x) + lightmapParams.y * texture(emissiveMap, uv).rgb);
}

View file

@ -29,16 +29,12 @@ UNIFORM_BUFFER(0, gridBuffer) {
Grid grid;
};
Grid getGrid() { return grid; }
INPUT(GPU_ATTR_TEXCOORD0, vec2, varTexCoord0);
INPUT(GPU_ATTR_COLOR, vec4, varColor);
// unused, but needed for shader interface matching
INPUT(GPU_ATTR_POSITION, vec3, varPosition);
INPUT(GPU_ATTR_NORMAL, vec3, varNormal);
INPUT(GPU_ATTR_TEXCOORD0, vec2, varTexCoord0);
INPUT(GPU_ATTR_COLOR, vec4, varColor);
OUTPUT(0, vec4, outFragColor);
void main(void) {
float gridLine = mix(paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge),

View file

@ -11,6 +11,7 @@
//
<@include gpu/ShaderConstants.h@>
<@include gpu/Color.slh@>
INPUT(GPU_ATTR_POSITION, vec4, inPosition);
INPUT(GPU_ATTR_TEXCOORD0, vec4, inTexCoord0);

View file

@ -90,7 +90,7 @@ const vk::DispatchLoaderDynamic& getInstanceDispatcher(const vk::Instance& insta
static vk::DispatchLoaderDynamic dispatcher;
static std::once_flag once;
if (instance) {
std::call_once(once, [&] { dispatcher.init(instance); });
std::call_once(once, [&] { dispatcher.init(instance, &vkGetInstanceProcAddr); });
}
return dispatcher;
}

View file

@ -8,6 +8,7 @@
#include "PlayerWindow.h"
#include <QtCore/QTimer>
#include <QtCore/QByteArray>
#include <QtCore/QBuffer>
#include <QtGui/QResizeEvent>
@ -106,7 +107,18 @@ void PlayerWindow::resizeEvent(QResizeEvent* ev) {
_renderThread.resize(ev->size());
}
static const QString DEFAULT_TRACING_RULES =
"trace.*=true\n" \
"*.detail=false\n";
void PlayerWindow::loadFrame(const QString& path) {
DependencyManager::get<tracing::Tracer>()->startTracing();
QLoggingCategory::setFilterRules(DEFAULT_TRACING_RULES);
QTimer::singleShot(8000, [] {
DependencyManager::get<tracing::Tracer>()->stopTracing();
DependencyManager::get<tracing::Tracer>()->serialize("D:/frames/trace-{DATE}_{TIME}.json.gz");
});
auto frame = gpu::readFrame(path.toStdString(), _renderThread._externalTexture);
if (frame) {
_renderThread.submitFrame(frame);

View file

@ -118,6 +118,7 @@ extern vk::CommandBuffer currentCommandBuffer;
#endif
void RenderThread::renderFrame(gpu::FramePointer& frame) {
PROFILE_RANGE(render_gpu_gl, __FUNCTION__);
++_presentCount;
#ifdef USE_GL
_context.makeCurrent();