Fix up a few things in chain JSON loading, nw

This commit is contained in:
therealmogminer@gmail.com 2016-02-25 03:22:14 +01:00
parent cedd799978
commit cdee786a5d
63 changed files with 395 additions and 20 deletions

View File

@ -1,5 +1,5 @@
{ "name": "Test Shader Chain"
"author": "Ryan Holtz"
{ "name": "Test Shader Chain",
"author": "Ryan Holtz",
"sliders": [
{ "type": "bool", "name": "adjustments", "text": "Enable Adjustments", "default": false },
{ "type": "float", "name": "ratio_amount", "text": "Ratio Amount", "default": 0, "max": 1, "min": 0 },
@ -7,25 +7,25 @@
{ "type": "color", "name": "red_ratios", "text": "Red Amount", "default": [ 1, 0, 0 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
{ "type": "color", "name": "grn_ratios", "text": "Green Amount", "default": [ 0, 1, 0 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
{ "type": "color", "name": "blu_ratios", "text": "Blue Amount", "default": [ 0, 0, 1 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
{ "type": "color", "name": "tint": "text": "Tint", "default": [ 1, 1, 1 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] }
{ "type": "color", "name": "phosphor", "text": "Phosphor Amount", "default": [ 0, 0, 0 ], "max": [ 1, 1, 1 ], "min": [ 0, 0 ,0 ] },
{ "type": "color", "name": "tint", "text": "Tint", "default": [ 1, 1, 1 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
{ "type": "color", "name": "phosphor", "text": "Phosphor Amount", "default": [ 0, 0, 0 ], "max": [ 1, 1, 1 ], "min": [ 0, 0, 0 ] },
{ "type": "vec2", "name": "shift", "text": "Frame Shift", "default": [ 0, 0 ], "max": [ 25, 25 ], "min": [ -25, -25 ] }
]
],
"parameters": [
{ "name": "alternating", "type": "frame_mask", "period": 2 }
]
],
"targets": [
{ "name": "native",
"screen": true,
"screen": true
},
{ "name": "previous",
"screen": true,
"prescale": true
}
]
],
"passes": [
{ "effect": "ratios",
"name": "Matrix Pass"
"name": "Matrix Pass",
"disable_conditions": [
{ "type": "slider", "name": "adjustments", "value": false },
{ "type": "slider", "name": "ratio_amount", "value": 0 }
@ -42,7 +42,7 @@
"output": "native"
},
{ "effect": "tint",
"name": "Tint Pass"
"name": "Tint Pass",
"disable_conditions": [
{ "type": "slider", "name": "adjustments", "value": false }
],
@ -55,14 +55,14 @@
],
"output": "native"
},
{ "effect": "phosphor"
{ "effect": "phosphor",
"name": "Phosphor Decay",
"disable_conditions": [
{ "type": "slider", "name": "adjustments", "value": false },
{ "type": "slider", "name": "phosphor", "value": [ 0, 0, 0 ] }
],
"uniforms": [
{ "name": "u_passthrough", "value": [ 0.0f ] },
{ "name": "u_passthrough", "value": [ 0 ] },
{ "name": "u_phosphor", "slider": "phosphor" }
],
"input": [
@ -71,14 +71,14 @@
],
"output": "native"
},
{ "effect": "phosphor"
{ "effect": "phosphor",
"name": "Phosphor Store",
"disable_conditions": [
{ "type": "slider", "name": "adjustments", "value": false },
{ "type": "slider", "name": "phosphor", "value": [ 0, 0, 0 ] }
],
"uniforms": [
{ "name": "u_passthrough", "value": [ 1.0f ] },
{ "name": "u_passthrough", "value": [ 1 ] },
{ "name": "u_phosphor", "slider": "phosphor" }
],
"input": [
@ -87,7 +87,7 @@
],
"output": "previous"
},
{ "effect": "blit"
{ "effect": "blit",
"name": "Final Blit",
"input": [
{ "sampler": "s_tex", "texture": "native" }

22
bgfx/effects/blit.json Normal file
View File

@ -0,0 +1,22 @@
{
"blend": {
"equation": "add",
"srcColor": "srcAlpha",
"dstColor": "1-srcAlpha",
"srcAlpha": "srcAlpha",
"dstAlpha": "1-srcAlpha"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_blit",
"fragment": "fs_blit",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] }
]
}

View File

@ -0,0 +1,25 @@
{
"blend": {
"equation": "add",
"srcColor": "srcAlpha",
"dstColor": "1-srcAlpha",
"srcAlpha": "srcAlpha",
"dstAlpha": "1-srcAlpha"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_phosphor",
"fragment": "fs_phosphor",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
{ "name": "s_prev", "type": "int", "values": [ 1.0 ] },
{ "name": "u_passthrough", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] },
{ "name": "u_phosphor", "type": "vec4", "values": [ 0.7, 0.7, 0.7, 0.0 ] }
]
}

26
bgfx/effects/ratios.json Normal file
View File

@ -0,0 +1,26 @@
{
"blend": {
"equation": "add",
"srcColor": "srcAlpha",
"dstColor": "1-srcAlpha",
"srcAlpha": "srcAlpha",
"dstAlpha": "1-srcAlpha"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_ratios",
"fragment": "fs_ratios",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
{ "name": "u_red_ratios", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 1.0 ] },
{ "name": "u_grn_ratios", "type": "vec4", "values": [ 0.0, 1.0, 0.0, 1.0 ] },
{ "name": "u_blu_ratios", "type": "vec4", "values": [ 0.0, 0.0, 1.0, 1.0 ] },
{ "name": "u_ratio_amount", "type": "vec4", "values": [ 1.0, 0.0, 0.0, 0.0 ] }
]
}

24
bgfx/effects/tint.json Normal file
View File

@ -0,0 +1,24 @@
{
"blend": {
"equation": "add",
"srcColor": "srcAlpha",
"dstColor": "1-srcAlpha",
"srcAlpha": "srcAlpha",
"dstAlpha": "1-srcAlpha"
},
"depth": {
"function": "always"
},
"cull": { "mode": "none" },
"write": {
"rgb": "true",
"alpha": "true"
},
"vertex": "vs_tint",
"fragment": "fs_tint",
"uniforms": [
{ "name": "s_tex", "type": "int", "values": [ 1.0 ] },
{ "name": "u_tint", "type": "vec4", "values": [ 1.0, 1.0, 1.0, 1.0 ] },
{ "name": "u_shift", "type": "vec4", "values": [ 0.1, 0.1, 0.0, 0.0 ] }
]
}

BIN
shaders/dx11/fs_blit.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
shaders/dx11/fs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/dx11/fs_tint.bin Normal file

Binary file not shown.

BIN
shaders/dx11/vs_blit.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
shaders/dx11/vs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/dx11/vs_tint.bin Normal file

Binary file not shown.

BIN
shaders/dx9/fs_blit.bin Normal file

Binary file not shown.

BIN
shaders/dx9/fs_phosphor.bin Normal file

Binary file not shown.

BIN
shaders/dx9/fs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/dx9/fs_tint.bin Normal file

Binary file not shown.

BIN
shaders/dx9/vs_blit.bin Normal file

Binary file not shown.

BIN
shaders/dx9/vs_phosphor.bin Normal file

Binary file not shown.

BIN
shaders/dx9/vs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/dx9/vs_tint.bin Normal file

Binary file not shown.

BIN
shaders/gles/fs_blit.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
shaders/gles/fs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/gles/fs_tint.bin Normal file

Binary file not shown.

BIN
shaders/gles/vs_blit.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
shaders/gles/vs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/gles/vs_tint.bin Normal file

Binary file not shown.

BIN
shaders/glsl/fs_blit.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
shaders/glsl/fs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/glsl/fs_tint.bin Normal file

Binary file not shown.

BIN
shaders/glsl/vs_blit.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
shaders/glsl/vs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/glsl/vs_tint.bin Normal file

Binary file not shown.

BIN
shaders/metal/fs_blit.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
shaders/metal/fs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/metal/fs_tint.bin Normal file

Binary file not shown.

BIN
shaders/metal/vs_blit.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
shaders/metal/vs_ratios.bin Normal file

Binary file not shown.

BIN
shaders/metal/vs_tint.bin Normal file

Binary file not shown.

View File

@ -23,6 +23,18 @@ bgfx_chain::bgfx_chain(std::string name, std::string author, std::vector<bgfx_sl
bgfx_chain::~bgfx_chain()
{
for (bgfx_slider* slider : m_sliders)
{
delete slider;
}
for (bgfx_parameter* param : m_params)
{
delete param;
}
for (bgfx_chain_entry* entry : m_entries)
{
delete entry;
}
}
void bgfx_chain::submit(render_primitive* prim, int view)

View File

@ -0,0 +1,66 @@
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
//============================================================
//
// chainmanager.cpp - BGFX shader chain manager
//
// Maintains a string-to-entry lookup of BGFX shader effect
// chains, defined by chain.h and read by chainreader.h
//
//============================================================
#include "emu.h"
#include <rapidjson/document.h>
#include <bgfx/bgfxplatform.h>
#include <bgfx/bgfx.h>
#include <bx/readerwriter.h>
#include "chainmanager.h"
#include "chainreader.h"
#include "chain.h"
using namespace rapidjson;
chain_manager::~chain_manager()
{
for (std::pair<std::string, bgfx_chain*> chain : m_chains)
{
delete chain.second;
}
m_chains.clear();
}
bgfx_chain* chain_manager::chain(std::string name)
{
std::map<std::string, bgfx_chain*>::iterator iter = m_chains.find(name);
if (iter != m_chains.end())
{
return iter->second;
}
return load_chain(name);
}
bgfx_chain* chain_manager::load_chain(std::string name) {
std::string path = "bgfx/chains/" + name + ".json";
bx::CrtFileReader reader;
bx::open(&reader, path.c_str());
int32_t size = (uint32_t)bx::getSize(&reader);
char* data = new char[size + 1];
bx::read(&reader, reinterpret_cast<void*>(data), size);
bx::close(&reader);
data[size] = 0;
Document document;
document.Parse<0>(data);
bgfx_chain* chain = chain_reader::read_from_value(document, m_textures, m_targets, m_effects, m_width, m_height);
m_chains[name] = chain;
return chain;
}

View File

@ -0,0 +1,54 @@
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
//============================================================
//
// chainmanager.h - BGFX shader chain manager
//
// Maintains a string-to-entry lookup of BGFX shader
// effect chains, defined by chain.h and read by chainreader.h
//
//============================================================
#pragma once
#ifndef __DRAWBGFX_CHAIN_MANAGER__
#define __DRAWBGFX_CHAIN_MANAGER__
#include <map>
#include <string>
#include <bgfx/bgfx.h>
#include "texturemanager.h"
#include "targetmanager.h"
#include "effectmanager.h"
class bgfx_chain;
class chain_manager {
public:
chain_manager(texture_manager& textures, target_manager& targets, effect_manager& effects, uint32_t width, uint32_t height)
: m_textures(textures)
, m_targets(targets)
, m_effects(effects)
, m_width(width)
, m_height(height)
{
}
~chain_manager();
// Getters
bgfx_chain* chain(std::string name);
private:
bgfx_chain* load_chain(std::string name);
texture_manager& m_textures;
target_manager& m_targets;
effect_manager& m_effects;
uint32_t m_width;
uint32_t m_height;
std::map<std::string, bgfx_chain*> m_chains;
};
#endif // __DRAWBGFX_CHAIN_MANAGER__

View File

@ -25,6 +25,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, texture_manager& t
std::string name = value["name"].GetString();
std::string author = value["author"].GetString();
// Parse sliders
std::vector<bgfx_slider*> sliders;
if (value.HasMember("sliders"))
{
@ -35,6 +36,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, texture_manager& t
}
}
// Parse parameters
std::vector<bgfx_parameter*> parameters;
if (value.HasMember("parameters"))
{
@ -45,6 +47,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, texture_manager& t
}
}
// Parse chain entries
std::vector<bgfx_chain_entry*> entries;
if (value.HasMember("passes"))
{
@ -55,6 +58,7 @@ bgfx_chain* chain_reader::read_from_value(const Value& value, texture_manager& t
}
}
// Create targets
if (value.HasMember("targets"))
{
const Value& target_array = value["targets"];

View File

@ -0,0 +1,13 @@
$input v_color0, v_texcoord0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
SAMPLER2D(s_tex, 0);
void main()
{
gl_FragColor = texture2D(s_tex, v_texcoord0) * v_color0;
}

View File

@ -0,0 +1,20 @@
$input v_color0, v_texcoord0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
uniform vec4 u_passthrough;
uniform vec4 u_phosphor;
SAMPLER2D(s_tex, 0);
SAMPLER2D(s_prev, 1);
void main()
{
vec4 curr = texture2D(s_tex, v_texcoord0);
vec4 prev = texture2D(s_prev, v_texcoord0);
vec4 phosphored = vec4(max(curr.r, prev.r * u_phosphor.r), max(curr.g, prev.g * u_phosphor.g), max(curr.b, prev.b * u_phosphor.b), curr.a);
gl_FragColor = mix(phosphored, curr, u_passthrough.x) * v_color0;
}

View File

@ -0,0 +1,23 @@
$input v_color0, v_texcoord0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
uniform vec4 u_ratio_amount;
uniform vec4 u_red_ratios;
uniform vec4 u_grn_ratios;
uniform vec4 u_blu_ratios;
SAMPLER2D(s_tex, 0);
void main()
{
vec4 texel = texture2D(s_tex, v_texcoord0);
float red = dot(texel.rgb, u_red_ratios.rgb);
float grn = dot(texel.rgb, u_grn_ratios.rgb);
float blu = dot(texel.rgb, u_blu_ratios.rgb);
vec3 mixed = mix(texel.rgb, vec3(red, grn, blu), u_ratio_amount.x);
gl_FragColor = vec4(mixed, texel.a) * v_color0;
}

View File

@ -0,0 +1,16 @@
$input v_color0, v_texcoord0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
uniform vec4 u_tint;
uniform vec4 u_shift;
SAMPLER2D(s_tex, 0);
void main()
{
gl_FragColor = texture2D(s_tex, v_texcoord0 + u_shift.xy) * u_tint * v_color0;
}

View File

@ -22,6 +22,7 @@ public:
// Getters
bgfx::FrameBufferHandle target() const { return m_target; }
virtual bool is_target() const override { return true; }
private:
bgfx::FrameBufferHandle m_target;

View File

@ -25,7 +25,6 @@ target_manager::~target_manager()
bgfx_target* target_manager::create_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter)
{
printf("Creating %s\n", name.c_str());
bgfx_target* target = new bgfx_target(name, format, width, height, filter);
m_targets[name] = target;
@ -35,7 +34,6 @@ bgfx_target* target_manager::create_target(std::string name, bgfx::TextureFormat
bgfx_target* target_manager::create_target(std::string name, void *handle, uint32_t width, uint32_t height)
{
printf("Creating %s\n", name.c_str());
bgfx_target* target = new bgfx_target(name, handle, width, height);
m_targets[name] = target;

View File

@ -27,6 +27,7 @@ public:
uint32_t width() const { return m_width; }
uint32_t height() const { return m_height; }
bgfx::TextureHandle handle() const { return m_handle; }
virtual bool is_target() const { return false; }
protected:
std::string m_name;

View File

@ -18,7 +18,10 @@ texture_manager::~texture_manager()
{
for (std::pair<std::string, bgfx_texture*> texture : m_textures)
{
delete texture.second;
if (!(texture.second)->is_target())
{
delete texture.second;
}
}
m_textures.clear();
}

View File

@ -0,0 +1,14 @@
$input a_position, a_texcoord0, a_color0
$output v_texcoord0, v_color0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
void main()
{
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
v_texcoord0 = a_texcoord0;
v_color0 = a_color0;
}

View File

@ -0,0 +1,14 @@
$input a_position, a_texcoord0, a_color0
$output v_texcoord0, v_color0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
void main()
{
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
v_texcoord0 = a_texcoord0;
v_color0 = a_color0;
}

View File

@ -0,0 +1,14 @@
$input a_position, a_texcoord0, a_color0
$output v_texcoord0, v_color0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
void main()
{
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
v_texcoord0 = a_texcoord0;
v_color0 = a_color0;
}

View File

@ -0,0 +1,14 @@
$input a_position, a_texcoord0, a_color0
$output v_texcoord0, v_color0
// license:BSD-3-Clause
// copyright-holders:Dario Manesku
#include "../../../../../3rdparty/bgfx/examples/common/common.sh"
void main()
{
gl_Position = mul(u_viewProj, vec4(a_position.xy, 0.0, 1.0));
v_texcoord0 = a_texcoord0;
v_color0 = a_color0;
}

View File

@ -35,9 +35,11 @@
#include "bgfx/targetmanager.h"
#include "bgfx/shadermanager.h"
#include "bgfx/effectmanager.h"
#include "bgfx/chainmanager.h"
#include "bgfx/effect.h"
#include "bgfx/texture.h"
#include "bgfx/target.h"
#include "bgfx/chain.h"
//============================================================
// DEBUGGING
@ -129,6 +131,7 @@ int renderer_bgfx::create()
m_targets = new target_manager(*m_textures);
m_shaders = new shader_manager();
m_effects = new effect_manager(*m_shaders);
m_chains = new chain_manager(*m_textures, *m_targets, *m_effects, m_width[window().m_index], m_height[window().m_index]);
if (window().m_index != 0)
{
@ -151,6 +154,8 @@ int renderer_bgfx::create()
m_screen_effect[2] = m_effects->effect("screen_multiply");
m_screen_effect[3] = m_effects->effect("screen_add");
//m_screen_chain[0] = m_chains->chain("test");
uint32_t flags = BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT;
m_texture_cache = m_textures->create_texture("#cache", bgfx::TextureFormat::RGBA8, CACHE_SIZE, CACHE_SIZE, nullptr, flags);
@ -167,10 +172,11 @@ int renderer_bgfx::create()
renderer_bgfx::~renderer_bgfx()
{
// Cleanup.
delete m_targets;
delete m_textures;
delete m_chains;
delete m_effects;
delete m_shaders;
delete m_textures;
delete m_targets;
}
void renderer_bgfx::exit()

View File

@ -14,9 +14,11 @@ class texture_manager;
class target_manager;
class shader_manager;
class effect_manager;
class chain_manager;
class bgfx_texture;
class bgfx_effect;
class bgfx_target;
class bgfx_chain;
/* sdl_info is the information about SDL for the current screen */
class renderer_bgfx : public osd_renderer
@ -107,8 +109,11 @@ private:
target_manager* m_targets;
shader_manager* m_shaders;
effect_manager* m_effects;
chain_manager* m_chains;
bgfx_effect* m_gui_effect[4];
bgfx_effect* m_screen_effect[4];
//bgfx_chain* m_screen_chain[4];
std::map<UINT32, rectangle_packer::packed_rectangle> m_hash_to_entry;
std::vector<rectangle_packer::packable_rectangle> m_texinfo;