prepared gl improvements for merge

This commit is contained in:
itsmattkc
2020-02-14 02:35:10 +11:00
parent 6a47b05ab8
commit d66425c324
19 changed files with 11 additions and 1286 deletions
+2 -4
View File
@@ -37,14 +37,12 @@ if(UNIX AND NOT APPLE AND NOT DEFINED OpenGL_GL_PREFERENCE)
set(OpenGL_GL_PREFERENCE LEGACY)
endif()
find_package(OpenGL REQUIRED)
find_package(OpenColorIO REQUIRED)
find_package(OpenImageIO REQUIRED)
find_package(OpenShadingLanguage REQUIRED)
find_package(OpenEXR REQUIRED)
find_package(Qt5 5.6 REQUIRED
COMPONENTS
Core
+1 -4
View File
@@ -87,8 +87,6 @@ target_include_directories(
${FFMPEG_INCLUDE_DIRS}
${OCIO_INCLUDE_DIRS}
${OIIO_INCLUDE_DIRS}
${OSL_INCLUDE_DIRS}
${OPENEXR_INCLUDE_DIRS}
)
target_link_libraries(${OLIVE_TARGET}
@@ -99,6 +97,7 @@ target_link_libraries(${OLIVE_TARGET}
Qt5::Multimedia
Qt5::OpenGL
Qt5::Svg
OpenGL::GL
FFMPEG::avutil
FFMPEG::avcodec
FFMPEG::avformat
@@ -107,8 +106,6 @@ target_link_libraries(${OLIVE_TARGET}
FFMPEG::swresample
${OCIO_LIBRARIES}
${OIIO_LIBRARIES}
${OSL_LIBRARIES}
${OPENEXR_LIBRARIES}
)
set(OLIVE_TS_FILES
+1 -1
View File
@@ -90,7 +90,7 @@ void Config::SetDefaults()
// Online/offline settings
config_map_["OnlinePixelFormat"] = PixelFormat::PIX_FMT_RGBA32F;
config_map_["OfflinePixelFormat"] = PixelFormat::PIX_FMT_RGBA32F;
config_map_["OfflinePixelFormat"] = PixelFormat::PIX_FMT_RGBA16F;
config_map_["OnlineSampleFormat"] = SampleFormat::SAMPLE_FMT_FLT;
config_map_["OfflineSampleFormat"] = SampleFormat::SAMPLE_FMT_FLT;
config_map_["OnlineOCIOMethod"] = ColorManager::kOCIOAccurate;
-1
View File
@@ -16,7 +16,6 @@
add_subdirectory(audio)
add_subdirectory(opengl)
add_subdirectory(osl)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
+1 -1
View File
@@ -5,6 +5,6 @@
#include "render/colorprocessor.h"
#include "rendercache.h"
using ColorProcessorCache = ThreadSafeRenderCache<QString, ColorProcessorPtr>;
using ColorProcessorCache = RenderCache<QString, ColorProcessorPtr>;
#endif // COLORPROCESSORCACHE_H
@@ -2,7 +2,6 @@
#define OPENGLBACKEND_H
#include "../videorenderbackend.h"
#include "openglbackend.h"
#include "openglframebuffer.h"
#include "openglproxy.h"
#include "openglshader.h"
@@ -118,9 +118,6 @@ void OpenGLRenderFunctions::Blit(OpenGLShaderPtr pipeline, bool flipped, QMatrix
m_vbo.destroy();
m_vao.release();
m_vao.destroy();
// Make sure drawing is actually complete before this function returns
func->glFinish();
}
void OpenGLRenderFunctions::OCIOBlit(OpenGLShaderPtr pipeline,
-27
View File
@@ -1,27 +0,0 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
render/backend/osl/oslbackend.h
render/backend/osl/oslbackend.cpp
render/backend/osl/oslrenderer.h
render/backend/osl/oslrenderer.cpp
render/backend/osl/oslshadercache.h
render/backend/osl/oslworker.h
render/backend/osl/oslworker.cpp
PARENT_SCOPE
)
-102
View File
@@ -1,102 +0,0 @@
#include "oslbackend.h"
#include <OSL/oslcomp.h>
#include <QEventLoop>
#include <QThread>
#include "oslworker.h"
OSLBackend::OSLBackend(QObject *parent) :
VideoRenderBackend(parent),
shading_system_(nullptr),
renderer_(nullptr)
{
}
OSLBackend::~OSLBackend()
{
Close();
}
bool OSLBackend::InitInternal()
{
if (!VideoRenderBackend::InitInternal()) {
return false;
}
renderer_ = new OSL::SimpleRenderer();
shading_system_ = new OSL::ShadingSystem(renderer_);
// Initiate one thread per CPU core
for (int i=0;i<threads().size();i++) {
// Create one processor object for each thread
OSLWorker* processor = new OSLWorker(frame_cache(),
shading_system_,
&shader_cache_,
&color_cache_);
processor->SetParameters(params());
processors_.append(processor);
}
return true;
}
void OSLBackend::CloseInternal()
{
VideoRenderBackend::CloseInternal();
shader_cache_.Clear();
delete shading_system_;
shading_system_ = nullptr;
delete renderer_;
renderer_= nullptr;
}
bool OSLBackend::CompileInternal()
{
OSL::ShadingSystem* system = shading_system_;
OSL::OSLCompiler compiler;
QList<Node*> deps = viewer_node()->GetDependencies();
foreach (Node* n, deps) {
if (!shader_cache_.Has(n->id())) {
if (n->IsAccelerated()) {
std::string oso_buffer;
QString function_name = n->id().replace('.', '_');
if (!compiler.compile_buffer(n->AcceleratedCodeFragment().toStdString(),
oso_buffer,
std::vector<std::string>(),
"",
function_name.toStdString())) {
qWarning() << "Failed to compile" << n->id();
return false;
}
system->LoadMemoryCompiledShader(function_name.toStdString(), oso_buffer);
OSL::ShaderGroupRef ref = system->ShaderGroupBegin(n->id().toStdString());
system->Shader("shader", function_name.toStdString(), "layer1");
system->ShaderGroupEnd();
shader_cache_.Add(n->id(), ref);
} else {
// Insert null
shader_cache_.Add(n->id(), nullptr);
}
}
}
return true;
}
void OSLBackend::DecompileInternal()
{
}
-40
View File
@@ -1,40 +0,0 @@
#ifndef OSLBACKEND_H
#define OSLBACKEND_H
#include <OSL/oslexec.h>
#include "../videorenderbackend.h"
#include "oslrenderer.h"
#include "oslshadercache.h"
class OSLBackend : public VideoRenderBackend
{
Q_OBJECT
public:
OSLBackend(QObject* parent = nullptr);
virtual ~OSLBackend() override;
protected:
virtual bool InitInternal() override;
virtual void CloseInternal() override;
virtual bool CompileInternal() override;
virtual void DecompileInternal() override;
//virtual void ParamsChangedEvent() override;
private:
OSL::ShadingSystem* shading_system_;
OSL::SimpleRenderer* renderer_;
OSLShaderCache shader_cache_;
ColorProcessorCache color_cache_;
};
#endif // OSLBACKEND_H
-456
View File
@@ -1,456 +0,0 @@
/*
Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Sony Pictures Imageworks nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "oslrenderer.h"
using namespace OSL;
OSL_NAMESPACE_ENTER
static ustring u_camera("camera"), u_screen("screen");
static ustring u_NDC("NDC"), u_raster("raster");
static ustring u_perspective("perspective");
static ustring u_s("s"), u_t("t");
static TypeDesc TypeFloatArray2 (TypeDesc::FLOAT, 2);
static TypeDesc TypeFloatArray4 (TypeDesc::FLOAT, 4);
static TypeDesc TypeIntArray2 (TypeDesc::INT, 2);
SimpleRenderer::SimpleRenderer ()
{
Matrix44 M; M.makeIdentity();
camera_params (M, u_perspective, 90.0f,
0.1f, 1000.0f, 256, 256);
// Set up getters
m_attr_getters[ustring("osl:version")] = &SimpleRenderer::get_osl_version;
m_attr_getters[ustring("camera:resolution")] = &SimpleRenderer::get_camera_resolution;
m_attr_getters[ustring("camera:projection")] = &SimpleRenderer::get_camera_projection;
m_attr_getters[ustring("camera:pixelaspect")] = &SimpleRenderer::get_camera_pixelaspect;
m_attr_getters[ustring("camera:screen_window")] = &SimpleRenderer::get_camera_screen_window;
m_attr_getters[ustring("camera:fov")] = &SimpleRenderer::get_camera_fov;
m_attr_getters[ustring("camera:clip")] = &SimpleRenderer::get_camera_clip;
m_attr_getters[ustring("camera:clip_near")] = &SimpleRenderer::get_camera_clip_near;
m_attr_getters[ustring("camera:clip_far")] = &SimpleRenderer::get_camera_clip_far;
m_attr_getters[ustring("camera:shutter")] = &SimpleRenderer::get_camera_shutter;
m_attr_getters[ustring("camera:shutter_open")] = &SimpleRenderer::get_camera_shutter_open;
m_attr_getters[ustring("camera:shutter_close")] = &SimpleRenderer::get_camera_shutter_close;
}
int
SimpleRenderer::supports (string_view) const
{
return false;
}
void
SimpleRenderer::camera_params (const Matrix44 &world_to_camera,
ustring projection, float hfov,
float hither, float yon,
int xres, int yres)
{
m_world_to_camera = world_to_camera;
m_projection = projection;
m_fov = hfov;
m_pixelaspect = 1.0f; // hard-coded
m_hither = hither;
m_yon = yon;
m_shutter[0] = 0.0f; m_shutter[1] = 1.0f; // hard-coded
float frame_aspect = float(xres)/float(yres) * m_pixelaspect;
m_screen_window[0] = -frame_aspect;
m_screen_window[1] = -1.0f;
m_screen_window[2] = frame_aspect;
m_screen_window[3] = 1.0f;
m_xres = xres;
m_yres = yres;
}
bool
SimpleRenderer::get_matrix (ShaderGlobals *, Matrix44 &result,
TransformationPtr xform,
float)
{
// SimpleRenderer doesn't understand motion blur and transformations
// are just simple 4x4 matrices.
result = *reinterpret_cast<const Matrix44*>(xform);
return true;
}
bool
SimpleRenderer::get_matrix (ShaderGlobals *, Matrix44 &result,
ustring from, float)
{
TransformMap::const_iterator found = m_named_xforms.find (from);
if (found != m_named_xforms.end()) {
result = *(found->second);
return true;
} else {
return false;
}
}
bool
SimpleRenderer::get_matrix (ShaderGlobals *, Matrix44 &result,
TransformationPtr xform)
{
// SimpleRenderer doesn't understand motion blur and transformations
// are just simple 4x4 matrices.
result = *reinterpret_cast<const Matrix44*>(xform);
return true;
}
bool
SimpleRenderer::get_matrix (ShaderGlobals *, Matrix44 &result,
ustring from)
{
// SimpleRenderer doesn't understand motion blur, so we never fail
// on account of time-varying transformations.
TransformMap::const_iterator found = m_named_xforms.find (from);
if (found != m_named_xforms.end()) {
result = *(found->second);
return true;
} else {
return false;
}
}
bool
SimpleRenderer::get_inverse_matrix (ShaderGlobals *, Matrix44 &result,
ustring to, float)
{
if (to == u_camera || to == u_screen || to == u_NDC || to == u_raster) {
Matrix44 M = m_world_to_camera;
if (to == u_screen || to == u_NDC || to == u_raster) {
float depthrange = (double)m_yon-(double)m_hither;
if (m_projection == u_perspective) {
float tanhalffov = tanf (0.5f * m_fov * M_PI/180.0);
Matrix44 camera_to_screen (1/tanhalffov, 0, 0, 0,
0, 1/tanhalffov, 0, 0,
0, 0, m_yon/depthrange, 1,
0, 0, -m_yon*m_hither/depthrange, 0);
M = M * camera_to_screen;
} else {
Matrix44 camera_to_screen (1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1/depthrange, 0,
0, 0, -m_hither/depthrange, 1);
M = M * camera_to_screen;
}
if (to == u_NDC || to == u_raster) {
float screenleft = -1.0, screenwidth = 2.0;
float screenbottom = -1.0, screenheight = 2.0;
Matrix44 screen_to_ndc (1/screenwidth, 0, 0, 0,
0, 1/screenheight, 0, 0,
0, 0, 1, 0,
-screenleft/screenwidth, -screenbottom/screenheight, 0, 1);
M = M * screen_to_ndc;
if (to == u_raster) {
Matrix44 ndc_to_raster (m_xres, 0, 0, 0,
0, m_yres, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
M = M * ndc_to_raster;
}
}
}
result = M;
return true;
}
TransformMap::const_iterator found = m_named_xforms.find (to);
if (found != m_named_xforms.end()) {
result = *(found->second);
result.invert();
return true;
} else {
return false;
}
}
void
SimpleRenderer::name_transform (const char *name, const OSL::Matrix44 &xform)
{
std::shared_ptr<Transformation> M (new OSL::Matrix44 (xform));
m_named_xforms[ustring(name)] = M;
}
bool
SimpleRenderer::get_array_attribute (ShaderGlobals *sg, bool derivatives, ustring object,
TypeDesc type, ustring name,
int index, void *val)
{
AttrGetterMap::const_iterator g = m_attr_getters.find (name);
if (g != m_attr_getters.end()) {
AttrGetter getter = g->second;
return (this->*(getter)) (sg, derivatives, object, type, name, val);
}
// If no named attribute was found, allow userdata to bind to the
// attribute request.
if (object.empty() && index == -1)
return get_userdata (derivatives, name, type, sg, val);
return false;
}
bool
SimpleRenderer::get_attribute (ShaderGlobals *sg, bool derivatives, ustring object,
TypeDesc type, ustring name, void *val)
{
return get_array_attribute (sg, derivatives, object,
type, name, -1, val);
}
bool
SimpleRenderer::get_userdata (bool derivatives, ustring name, TypeDesc type,
ShaderGlobals *sg, void *val)
{
// Just to illustrate how this works, respect s and t userdata, filled
// in with the uv coordinates. In a real renderer, it would probably
// look up something specific to the primitive, rather than have hard-
// coded names.
if (name == u_s && type == TypeDesc::TypeFloat) {
((float *)val)[0] = sg->u;
if (derivatives) {
((float *)val)[1] = sg->dudx;
((float *)val)[2] = sg->dudy;
}
return true;
}
if (name == u_t && type == TypeDesc::TypeFloat) {
((float *)val)[0] = sg->v;
if (derivatives) {
((float *)val)[1] = sg->dvdx;
((float *)val)[2] = sg->dvdy;
}
return true;
}
return false;
}
bool
SimpleRenderer::get_osl_version (ShaderGlobals *, bool, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeDesc::TypeInt) {
((int *)val)[0] = OSL_VERSION;
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_resolution (ShaderGlobals *, bool, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeIntArray2) {
((int *)val)[0] = m_xres;
((int *)val)[1] = m_yres;
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_projection (ShaderGlobals *, bool, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeDesc::TypeString) {
((ustring *)val)[0] = m_projection;
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_fov (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
// N.B. in a real rederer, this may be time-dependent
if (type == TypeDesc::TypeFloat) {
((float *)val)[0] = m_fov;
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_pixelaspect (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeDesc::TypeFloat) {
((float *)val)[0] = m_pixelaspect;
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_clip (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeFloatArray2) {
((float *)val)[0] = m_hither;
((float *)val)[1] = m_yon;
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_clip_near (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeDesc::TypeFloat) {
((float *)val)[0] = m_hither;
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_clip_far (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeDesc::TypeFloat) {
((float *)val)[0] = m_yon;
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_shutter (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeFloatArray2) {
((float *)val)[0] = m_shutter[0];
((float *)val)[1] = m_shutter[1];
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_shutter_open (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeDesc::TypeFloat) {
((float *)val)[0] = m_shutter[0];
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_shutter_close (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
if (type == TypeDesc::TypeFloat) {
((float *)val)[0] = m_shutter[1];
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
bool
SimpleRenderer::get_camera_screen_window (ShaderGlobals *, bool derivs, ustring,
TypeDesc type, ustring, void *val)
{
// N.B. in a real rederer, this may be time-dependent
if (type == TypeFloatArray4) {
((float *)val)[0] = m_screen_window[0];
((float *)val)[1] = m_screen_window[1];
((float *)val)[2] = m_screen_window[2];
((float *)val)[3] = m_screen_window[3];
if (derivs)
memset ((char *)val+type.size(), 0, 2*type.size());
return true;
}
return false;
}
OSL_NAMESPACE_EXIT
-129
View File
@@ -1,129 +0,0 @@
/*
Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Sony Pictures Imageworks nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <map>
#include <memory>
#include <unordered_map>
#include <OpenImageIO/ustring.h>
#include <OSL/oslexec.h>
OSL_NAMESPACE_ENTER
class SimpleRenderer : public RendererServices
{
public:
// Just use 4x4 matrix for transformations
typedef Matrix44 Transformation;
SimpleRenderer ();
~SimpleRenderer () { }
virtual int supports (string_view feature) const;
virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result,
TransformationPtr xform,
float time);
virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result,
ustring from, float time);
virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result,
TransformationPtr xform);
virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result,
ustring from);
virtual bool get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
ustring to, float time);
void name_transform (const char *name, const Transformation &xform);
virtual bool get_array_attribute (ShaderGlobals *sg, bool derivatives,
ustring object, TypeDesc type, ustring name,
int index, void *val );
virtual bool get_attribute (ShaderGlobals *sg, bool derivatives, ustring object,
TypeDesc type, ustring name, void *val);
virtual bool get_userdata (bool derivatives, ustring name, TypeDesc type,
ShaderGlobals *sg, void *val);
// Super simple camera and display parameters. Many options not
// available, no motion blur, etc.
void camera_params (const Matrix44 &world_to_camera, ustring projection,
float hfov, float hither, float yon,
int xres, int yres);
private:
// Camera parameters
Matrix44 m_world_to_camera;
ustring m_projection;
float m_fov, m_pixelaspect, m_hither, m_yon;
float m_shutter[2];
float m_screen_window[4];
int m_xres, m_yres;
// Named transforms
typedef std::map <ustring, std::shared_ptr<Transformation> > TransformMap;
TransformMap m_named_xforms;
// Attribute and userdata retrieval -- for fast dispatch, use a hash
// table to map attribute names to functions that retrieve them. We
// imagine this to be fairly quick, but for a performance-critical
// renderer, we would encourage benchmarking various methods and
// alternate data structures.
typedef bool (SimpleRenderer::*AttrGetter)(ShaderGlobals *sg, bool derivs,
ustring object, TypeDesc type,
ustring name, void *val);
typedef std::unordered_map<ustring, AttrGetter, ustringHash> AttrGetterMap;
AttrGetterMap m_attr_getters;
// Attribute getters
bool get_osl_version (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_resolution (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_projection (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_fov (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_pixelaspect (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_clip (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_clip_near (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_clip_far (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_shutter (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_shutter_open (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_shutter_close (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_screen_window (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
};
OSL_NAMESPACE_EXIT
-11
View File
@@ -1,11 +0,0 @@
#ifndef OSLSHADERMAP_H
#define OSLSHADERMAP_H
#include <OSL/oslexec.h>
#include <QString>
#include "../rendercache.h"
using OSLShaderCache = ThreadSafeRenderCache<QString, OSL::ShaderGroupRef>;
#endif // OSLSHADERMAP_H
-353
View File
@@ -1,353 +0,0 @@
#include "oslworker.h"
#include <OpenImageIO/imagebuf.h>
#include <QMatrix4x4>
#include <QVector2D>
#include <QVector3D>
#include <QVector4D>
#include "common/clamp.h"
#include "common/define.h"
#include "core.h"
#include "node/block/transition/transition.h"
#include "node/node.h"
#include "render/colormanager.h"
#include "render/pixelservice.h"
OSLWorker::OSLWorker(VideoRenderFrameCache* frame_cache,
OSL::ShadingSystem* shading_system,
OSLShaderCache* shader_cache,
ColorProcessorCache* color_cache,
QObject* parent) :
VideoRenderWorker(frame_cache, parent),
shading_system_(shading_system),
shader_cache_(shader_cache),
color_cache_(color_cache)
{
}
void OSLWorker::FrameToValue(StreamPtr stream, FramePtr frame, NodeValueTable *table)
{
// Ensure stream is video or image type
if (stream->type() != Stream::kVideo && stream->type() != Stream::kImage) {
return;
}
ImageStreamPtr video_stream = std::static_pointer_cast<ImageStream>(stream);
// Set up OCIO context
ColorProcessorPtr color_processor = color_cache_->Get(video_stream->colorspace());
if (!color_processor) {
// FIXME: We match with the colorspace string, but this won't change if the user sets a new config with a colorspace with the same string
color_processor = ColorProcessor::Create(video_stream->footage()->project()->color_manager()->GetConfig(),
video_stream->colorspace(),
OCIO::ROLE_SCENE_LINEAR);
color_cache_->Add(video_stream->colorspace(), color_processor);
}
// Convert frame to float for OCIO
if (frame->format() != PixelFormat::PIX_FMT_RGBA32F) {
frame = PixelService::ConvertPixelFormat(frame, PixelFormat::PIX_FMT_RGBA32F);
}
// If alpha is associated, disassociate for the color transform
if (video_stream->premultiplied_alpha()) {
ColorManager::DisassociateAlpha(frame);
}
// Perform color transform
color_processor->ConvertFrame(frame);
// Associate alpha
if (video_stream->premultiplied_alpha()) {
ColorManager::ReassociateAlpha(frame);
} else {
ColorManager::AssociateAlpha(frame);
}
OIIOImageBufRef buf = std::make_shared<OIIO::ImageBuf>(OIIO::ImageSpec(frame->width(), frame->height(), kRGBAChannels, OIIO::TypeDesc::FLOAT));
memcpy(buf->localpixels(), frame->data(), frame->allocated_size());
table->Push(NodeParam::kTexture, QVariant::fromValue(buf));
}
void OSLWorker::RunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable *output_params)
{
if (!node->IsAccelerated()) {
return;
}
OSL::ShaderGroupRef group = shader_cache_->Get(node->id());
if (!group) {
return;
}
int input_texture_count = 0;
OIIOImageBufRef iteration_buf = nullptr;
int iteration_id = -1;
foreach (NodeParam* param, node->parameters()) {
if (param->type() == NodeParam::kInput) {
// This variable is used in the shader, let's set it to our value
NodeInput* input = static_cast<NodeInput*>(param);
// Get value from database at this input
const NodeValueTable& input_data = input_params[input];
QVariant value = node->InputValueFromTable(input, input_data);
switch (input->data_type()) {
case NodeInput::kInt:
{
int val = value.toInt();
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc::INT, &val);
break;
}
case NodeInput::kFloat:
{
double val = value.toDouble();
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc::DOUBLE, &val);
break;
}
case NodeInput::kVec2:
{
QVector2D val = value.value<QVector2D>();
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc(OIIO::TypeDesc::FLOAT, OIIO::TypeDesc::VEC2), &val);
break;
}
case NodeInput::kVec3:
{
QVector3D val = value.value<QVector3D>();
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc(OIIO::TypeDesc::FLOAT, OIIO::TypeDesc::VEC3), &val);
break;
}
case NodeInput::kVec4:
{
QVector4D val = value.value<QVector4D>();
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc(OIIO::TypeDesc::FLOAT, OIIO::TypeDesc::VEC4), &val);
break;
}
case NodeInput::kMatrix:
{
QMatrix4x4 val = value.value<QMatrix4x4>();
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc(OIIO::TypeDesc::FLOAT, OIIO::TypeDesc::MATRIX44), &val);
break;
}
case NodeInput::kColor:
{
QVector4D val = value.value<QVector4D>();
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc(OIIO::TypeDesc::FLOAT, OIIO::TypeDesc::VEC4, OIIO::TypeDesc::COLOR), &val);
break;
}
case NodeInput::kBoolean:
{
bool val = value.toBool();
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc::CHAR, &val);
break;
}
case NodeInput::kFootage:
case NodeInput::kTexture:
case NodeInput::kBuffer:
{
OIIOImageBufRef buf = value.value<OIIOImageBufRef>();
if (buf) {
QString tex_fn = ImageBufToTexture(*buf.get(), input_texture_count);
if (!tex_fn.isEmpty()) {
QByteArray tex_fn_bytes = tex_fn.toUtf8();
const char* tex_fn_c_str = tex_fn_bytes.constData();
if (!shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc::STRING, &tex_fn_c_str)) {
qDebug() << "Failed to set string parameter";
}
}
} else {
shading_system_->ReParameter(*group.get(), "layer1", param->id().toStdString(), OIIO::TypeDesc::STRING, nullptr);
}
if (node->AcceleratedCodeIterativeInput() == input) {
iteration_buf = buf;
iteration_id = input_texture_count;
}
/*
// Set enable flag if shader wants it
int enable_param_location = shader->uniformLocation(QStringLiteral("%1_enabled").arg(input->id()));
if (enable_param_location > -1) {
shader->setUniformValue(enable_param_location,
tex_id > 0);
}
if (tex_id > 0) {
// Set texture resolution if shader wants it
int res_param_location = shader->uniformLocation(QStringLiteral("%1_resolution").arg(input->id()));
if (res_param_location > -1) {
shader->setUniformValue(res_param_location,
static_cast<GLfloat>(texture->texture()->width()),
static_cast<GLfloat>(texture->texture()->height()));
}
}
OpenGLRenderFunctions::PrepareToDraw(functions_);
*/
input_texture_count++;
break;
}
case NodeInput::kSamples:
case NodeInput::kText:
case NodeInput::kRational:
case NodeInput::kFont:
case NodeInput::kFile:
case NodeInput::kDecimal:
case NodeInput::kWholeNumber:
case NodeInput::kNumber:
case NodeInput::kString:
case NodeInput::kVector:
case NodeInput::kNone:
case NodeInput::kAny:
break;
}
}
}
// Provide some standard args
{
QVector2D resolution(static_cast<float>(video_params().width()), static_cast<float>(video_params().height()));
shading_system_->ReParameter(*group.get(),
"layer1",
"ove_resolution",
OIIO::TypeDesc(OIIO::TypeDesc::FLOAT, OIIO::TypeDesc::VEC2),
&resolution);
}
if (node->IsBlock() && static_cast<const Block*>(node)->type() == Block::kTransition) {
const TransitionBlock* transition_node = static_cast<const TransitionBlock*>(node);
// Provides total transition progress from 0.0 (start) - 1.0 (end)
double p = transition_node->GetTotalProgress(range.in());
shading_system_->ReParameter(*group.get(),
"layer1",
"ove_tprog_all",
OIIO::TypeDesc::DOUBLE,
&p);
// Provides progress of out section from 1.0 (start) - 0.0 (end)
p = transition_node->GetOutProgress(range.in());
shading_system_->ReParameter(*group.get(),
"layer1",
"ove_tprog_out",
OIIO::TypeDesc::DOUBLE,
&p);
// Provides progress of in section from 0.0 (start) - 1.0 (end)
p = transition_node->GetInProgress(range.in());
shading_system_->ReParameter(*group.get(),
"layer1",
"ove_tprog_in",
OIIO::TypeDesc::DOUBLE,
&p);
}
OIIOImageBufRef dest_buf = nullptr;
// Some nodes use multiple iterations for optimization
for (int iteration=0;iteration<node->AcceleratedCodeIterations();iteration++) {
// Set iteration number
shading_system_->ReParameter(*group.get(),
"layer1",
"ove_iteration",
OIIO::TypeDesc::INT,
&iteration);
if (iteration > 0) {
// Convert destination buffer into texture
QString s = ImageBufToTexture(*dest_buf.get(), iteration_id);
QByteArray s_bytes = s.toUtf8();
const char* s_c_str = s_bytes.constData();
// Set texture as iterative input
shading_system_->ReParameter(*group.get(), "layer1", node->AcceleratedCodeIterativeInput()->id().toStdString(), OIIO::TypeDesc::STRING, &s_c_str);
// Swap destination buffer and iteration buffer
std::swap(iteration_buf, dest_buf);
}
// Ensure dest_buf exists
if (!dest_buf) {
dest_buf = std::make_shared<OIIO::ImageBuf>(OIIO::ImageSpec(video_params().width(),
video_params().height(),
kRGBAChannels,
PixelService::GetPixelFormatInfo(video_params().format()).oiio_desc));
}
static OSL::ustring outputs[] = {OSL::ustring("Cout")};
OIIO::ImageBufAlgo::parallel_image_options popt;
#if OPENIMAGEIO_VERSION > 10902
popt.minitems = 4096;
popt.splitdir = OIIO::Split_Tile;
popt.recursive = true;
#endif
shade_image(*shading_system_,
*group.get(),
nullptr,
*dest_buf.get(),
outputs,
OSL::ShadePixelCenters,
OIIO::ROI(),
popt);
}
output_params->Push(NodeParam::kTexture, QVariant::fromValue(dest_buf));
}
void OSLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer)
{
OIIOImageBufRef frame = tex_in.value<OIIOImageBufRef>();
memcpy(buffer.data(), frame->localpixels(), static_cast<size_t>(buffer.size()));
}
QString OSLWorker::ImageBufToTexture(const OpenImageIO_v2_1::ImageBuf &buf, int tex_no)
{
OIIO::ImageSpec config;
config.attribute("maketx:filtername", "lanczos3");
QString tex_fn = QStringLiteral("C:/Users/Matt/Desktop/temp-%1-%2.tx").arg(QString::number(reinterpret_cast<quintptr>(this)), QString::number(tex_no));
stringstream s;
if (!OIIO::ImageBufAlgo::make_texture(OIIO::ImageBufAlgo::MakeTextureMode::MakeTxTexture,
buf,
tex_fn.toStdString(),
config,
&s)) {
qCritical() << "Failed to make_texture:" << s.str().c_str();
return QString();
}
return tex_fn;
}
-41
View File
@@ -1,41 +0,0 @@
#ifndef OSLWORKER_H
#define OSLWORKER_H
#include <OpenImageIO/imagebufalgo.h>
#include <OSL/oslexec.h>
#include "../videorenderworker.h"
#include "oslshadercache.h"
class OSLWorker : public VideoRenderWorker
{
Q_OBJECT
public:
OSLWorker(VideoRenderFrameCache* frame_cache,
OSL::ShadingSystem* shading_system,
OSLShaderCache* shader_cache,
ColorProcessorCache* color_cache,
QObject* parent = nullptr);
protected:
virtual void FrameToValue(StreamPtr stream, FramePtr frame, NodeValueTable* table) override;
virtual void RunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable* output_params) override;
virtual void TextureToBuffer(const QVariant& texture, QByteArray& buffer) override;
private:
QString ImageBufToTexture(const OIIO::ImageBuf& buffer, int tex_no);
OSL::ShadingSystem* shading_system_;
OSLShaderCache* shader_cache_;
ColorProcessorCache* color_cache_;
};
using OIIOImageBufRef = std::shared_ptr<OIIO::ImageBuf>;
Q_DECLARE_METATYPE(OIIOImageBufRef)
#endif // OSLWORKER_H
+2 -10
View File
@@ -1,16 +1,8 @@
shader videoinput(string footage_in = "" [[ int lockgeom=0 ]],
float s = u [[ int lockgeom=0 ]],
float t = v [[ int lockgeom=0 ]],
output color Cout = 0)
{
Cout = texture (footage_in, s, t);
}
/*#version 110
#version 110
varying vec2 ove_texcoord;
uniform sampler2D footage_in;
void main(void) {
gl_FragColor = texture2D(footage_in, ove_texcoord);
}*/
}
+2 -2
View File
@@ -82,7 +82,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
SetScale(48.0);
// Start background renderers
video_renderer_ = new OSLBackend(this);
video_renderer_ = new OpenGLBackend(this);
connect(video_renderer_, &VideoRenderBackend::CachedFrameReady, this, &ViewerWidget::RendererCachedFrame);
connect(video_renderer_, &VideoRenderBackend::CachedTimeReady, this, &ViewerWidget::RendererCachedTime);
connect(video_renderer_, &VideoRenderBackend::CachedTimeReady, ruler(), &TimeRuler::CacheTimeReady);
@@ -225,7 +225,7 @@ void ViewerWidget::UpdateTextureFromNode(const rational& time)
if (!GetConnectedNode()) {
SetTexture(nullptr);
} else {
//SetTexture(video_renderer_->GetCachedFrameAsTexture(time));
SetTexture(video_renderer_->GetCachedFrameAsTexture(time));
}
}
+2 -2
View File
@@ -30,7 +30,7 @@
#include "common/rational.h"
#include "node/output/viewer/viewer.h"
#include "render/backend/osl/oslbackend.h"
#include "render/backend/opengl/openglbackend.h"
#include "render/backend/opengl/opengltexture.h"
#include "render/backend/audio/audiobackend.h"
#include "viewerglwidget.h"
@@ -124,7 +124,7 @@ protected:
virtual void resizeEvent(QResizeEvent *event) override;
OSLBackend* video_renderer_;
OpenGLBackend* video_renderer_;
AudioBackend* audio_renderer_;
private:
-98
View File
@@ -1,98 +0,0 @@
# - Find OpenShadingLanguage library
# Find the native OpenShadingLanguage includes and library
# This module defines
# OSL_INCLUDE_DIRS, where to find OSL headers, Set when
# OSL_INCLUDE_DIR is found.
# OSL_LIBRARIES, libraries to link against to use OSL.
# OSL_ROOT_DIR, the base directory to search for OSL.
# This can also be an environment variable.
# OSL_COMPILER, full path to OSL script compiler.
# OSL_FOUND, if false, do not try to use OSL.
# OSL_LIBRARY_VERSION_MAJOR, OSL_LIBRARY_VERSION_MINOR, the major
# and minor versions of OSL library if found.
#
#=============================================================================
# Copyright 2014 Blender Foundation.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# If OSL_ROOT_DIR was defined in the environment, use it.
IF(NOT OSL_ROOT_DIR AND NOT $ENV{OSL_ROOT_DIR} STREQUAL "")
SET(OSL_ROOT_DIR $ENV{OSL_ROOT_DIR})
ENDIF()
SET(_osl_FIND_COMPONENTS
oslcomp
oslexec
oslquery
)
SET(_osl_SEARCH_DIRS
${OSL_ROOT_DIR}
/usr/local
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt/lib/osl
)
FIND_PATH(OSL_INCLUDE_DIR
NAMES
OSL/oslversion.h
HINTS
${_osl_SEARCH_DIRS}
PATH_SUFFIXES
include
)
SET(_osl_LIBRARIES)
FOREACH(COMPONENT ${_osl_FIND_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
FIND_LIBRARY(OSL_${UPPERCOMPONENT}_LIBRARY
NAMES
${COMPONENT}
HINTS
${_osl_SEARCH_DIRS}
PATH_SUFFIXES
lib64 lib
)
LIST(APPEND _osl_LIBRARIES "${OSL_${UPPERCOMPONENT}_LIBRARY}")
ENDFOREACH()
FIND_PROGRAM(OSL_COMPILER oslc
HINTS ${_osl_SEARCH_DIRS}
PATH_SUFFIXES bin)
# handle the QUIETLY and REQUIRED arguments and set OSL_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OSL DEFAULT_MSG _osl_LIBRARIES OSL_INCLUDE_DIR OSL_COMPILER)
IF(OSL_FOUND)
SET(OSL_LIBRARIES ${_osl_LIBRARIES})
SET(OSL_INCLUDE_DIRS ${OSL_INCLUDE_DIR})
FILE(STRINGS "${OSL_INCLUDE_DIR}/OSL/oslversion.h" OSL_LIBRARY_VERSION_MAJOR
REGEX "^[ \t]*#define[ \t]+OSL_LIBRARY_VERSION_MAJOR[ \t]+[0-9]+.*$")
FILE(STRINGS "${OSL_INCLUDE_DIR}/OSL/oslversion.h" OSL_LIBRARY_VERSION_MINOR
REGEX "^[ \t]*#define[ \t]+OSL_LIBRARY_VERSION_MINOR[ \t]+[0-9]+.*$")
STRING(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_MAJOR[ \t]+([.0-9]+).*"
"\\1" OSL_LIBRARY_VERSION_MAJOR ${OSL_LIBRARY_VERSION_MAJOR})
STRING(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_MINOR[ \t]+([.0-9]+).*"
"\\1" OSL_LIBRARY_VERSION_MINOR ${OSL_LIBRARY_VERSION_MINOR})
ENDIF(OSL_FOUND)
MARK_AS_ADVANCED(
OSL_INCLUDE_DIR
)
FOREACH(COMPONENT ${_osl_FIND_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
MARK_AS_ADVANCED(OSL_${UPPERCOMPONENT}_LIBRARY)
ENDFOREACH()