From a20459a6a3722389f77d6e4671fda16898d4ae8a Mon Sep 17 00:00:00 2001 From: "therealmogminer@gmail.com" Date: Tue, 8 Mar 2016 23:55:54 +0100 Subject: [PATCH] Fix up numerous bgfx shader bugs, add auto-uniform u_texsize, nw --- bgfx/chains/test.json | 14 ++- bgfx/effects/tint.json | 7 +- shaders/dx11/fs_tint.bin | Bin 543 -> 551 bytes shaders/dx9/fs_tint.bin | Bin 420 -> 456 bytes shaders/gles/fs_tint.bin | Bin 375 -> 438 bytes shaders/glsl/fs_tint.bin | Bin 306 -> 371 bytes shaders/metal/fs_tint.bin | Bin 784 -> 835 bytes src/osd/modules/render/bgfx/chain.cpp | 70 +---------- src/osd/modules/render/bgfx/chainentry.cpp | 109 +++++++++++++++--- src/osd/modules/render/bgfx/chainentry.h | 7 +- src/osd/modules/render/bgfx/effect.h | 1 + src/osd/modules/render/bgfx/fs_tint.sc | 3 +- src/osd/modules/render/bgfx/inputpair.cpp | 15 ++- src/osd/modules/render/bgfx/slideruniform.cpp | 1 - src/osd/modules/render/bgfx/target.cpp | 4 +- src/osd/modules/render/bgfx/uniform.cpp | 3 +- src/osd/modules/render/bgfx/valueuniform.cpp | 1 - src/osd/modules/render/drawbgfx.cpp | 31 +++-- 18 files changed, 153 insertions(+), 113 deletions(-) diff --git a/bgfx/chains/test.json b/bgfx/chains/test.json index 34ddc00fc5c..4da0656d481 100644 --- a/bgfx/chains/test.json +++ b/bgfx/chains/test.json @@ -3,9 +3,9 @@ "sliders": [ { "type": "int_enum", "name": "adjustments", "text": "Enable Adjustments", "default": 0, "max": 1, "min": 0, "step": 1, "scale": 1.0, "format": "%s", "screen": "any", "strings": [ "On", "Off" ] }, { "type": "float", "name": "ratio_amount", "text": "Ratio Amount", "default": 0, "max": 100, "min": 0, "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "any" }, - { "type": "color", "name": "red_ratios", "text": "Color Matrix, Red from ", "default": [ 200, 0, 0 ], "max": [ 400, 400, 400 ], "min": [ -400, -400, -400 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" }, - { "type": "color", "name": "grn_ratios", "text": "Color Matrix, Green from ", "default": [ 0, 200, 0 ], "max": [ 400, 400, 400 ], "min": [ -400, -400, -400 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" }, - { "type": "color", "name": "blu_ratios", "text": "Color Matrix, Blue from ", "default": [ 0, 0, 200 ], "max": [ 400, 400, 400 ], "min": [ -400, -400, -400 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" }, + { "type": "color", "name": "red_ratios", "text": "Color Matrix, Red from ", "default": [ 200, 0, 0 ], "max": [ 400, 400, 400 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" }, + { "type": "color", "name": "grn_ratios", "text": "Color Matrix, Green from ", "default": [ 0, 200, 0 ], "max": [ 400, 400, 400 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" }, + { "type": "color", "name": "blu_ratios", "text": "Color Matrix, Blue from ", "default": [ 0, 0, 200 ], "max": [ 400, 400, 400 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.005, "format": "%2.3f", "screen": "any" }, { "type": "color", "name": "tint", "text": "Tint ", "default": [ 100, 100, 100 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "any" }, { "type": "color", "name": "phosphor", "text": "Phosphor Life, ", "default": [ 0, 0, 0 ], "max": [ 100, 100, 100 ], "min": [ 0, 0, 0 ], "step": 1, "scale": 0.01, "format": "%1.2f", "screen": "any" }, { "type": "vec2", "name": "shift", "text": "Frame Shift ", "default": [ 0, 0 ], "max": [ 25, 25 ], "min": [ -25, -25 ], "step": 1, "scale": 1.0, "format": "%2.f", "screen": "raster" } @@ -18,6 +18,10 @@ "mode": "native", "prescale": 1 }, + { "name": "native2", + "mode": "native", + "prescale": 1 + }, { "name": "previous", "mode": "native", "prescale": 1 @@ -53,7 +57,7 @@ "input": [ { "sampler": "s_tex", "texture": "native" } ], - "output": "native" + "output": "native2" }, { "effect": "phosphor", "name": "Phosphor Decay", @@ -66,7 +70,7 @@ { "uniform": "u_phosphor", "slider": "phosphor" } ], "input": [ - { "sampler": "s_tex", "texture": "native" }, + { "sampler": "s_tex", "texture": "native2" }, { "sampler": "s_prev", "texture": "previous" } ], "output": "native" diff --git a/bgfx/effects/tint.json b/bgfx/effects/tint.json index 19cd7687f15..7dfe9c8d709 100644 --- a/bgfx/effects/tint.json +++ b/bgfx/effects/tint.json @@ -17,8 +17,9 @@ "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 ] } + { "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 ] }, + { "name": "u_texsize", "type": "vec4", "values": [ 1.0, 1.0, 0.0, 0.0 ] } ] } \ No newline at end of file diff --git a/shaders/dx11/fs_tint.bin b/shaders/dx11/fs_tint.bin index f87cfb38dc54abc48cbfff712a9e556cd5629eb5..b18fd93ed9edc853536cdf15f81a23d9f95f24e8 100644 GIT binary patch delta 226 zcmbQwvYds}E!cyFvH8DeU*-w5>{zU;N|+4YHM<$+QR4<`ETmt+C59Dp20AdX~UU~%hH0J0bum?x_+y6b|J z88I+$8!-rgMco<{z%)o4#%2Ps1q2wFCigI^t5`5FaD0NP=7Z{jnhDYhG>vESe?|!z SCI=7~88q12fgH?WzyJUjIVa}; delta 237 zcmZ3^GM|OhE!cyFvH8a4}_C8-q#j0_Bn3@;d6BAlH6ZaK2>;su_%N!Cs4 zG!IUG2$W)YF)?PpBoC0~0OU9WaU=r+i(8)pkj22jG}(mFU6BdQX5cVl5CF5>1OymB zVr~rzU_RsI6^!aRKqmJmpbC(oF#RBDCI=t^0roJ41p@;+NG%As@gZoCUa*`3LJX`% N4q~ny$S({E3;@AFBgFs! diff --git a/shaders/dx9/fs_tint.bin b/shaders/dx9/fs_tint.bin index 31fe945173caa37be75d3d2a4d1884f5da89e801..ff099cbab0cbc22f2b19a84a795e23f437c3ac6e 100644 GIT binary patch delta 286 zcmYk0Jqp4=5QX3FMoFrmg^gap3#3sah^=U2WtBn@8zYE~0aIEe*jl6zJ3G%HUPH(U zJb>%lM8RPn!~5oE=d2#e8H|UP*uS1u>NI!GdKLzo)qES&g@izre!dLr0yMFJ()z7E z^d~*P1>i;*W-%F$6u2@iC`AcKgv=&l%B4)hZIZu50(r(e_*4Ysk)$U}{Nfb1V6gM7^6!5$_P5S{g>I%b*M9(O CTQ~Ip delta 271 zcmYj~Aq&D#6ot=wZ<7s#p;f!dWHdQJtfIlD27^TgPFQnbvFQ-Z3%30b{TqV6z-01y z?l5@aaPRpz_ujj?8hMCVG0^^cBzQcBs_&g0P8?$>Yr_9@iIYCIH)4KwX%1&Rum(^)d+HCrOu&hFSy7b pCRKRm)F~`|kOI#Xo-k;I(&v(unYmQM$=$!Ku+n?KUEZ>mU%senG-m(+ diff --git a/shaders/gles/fs_tint.bin b/shaders/gles/fs_tint.bin index 8268422519654ac83cfe6d55e0c9eb2b17834fd0..2e9ac7c950e2c29e96f76105da1a246f9e4b1ecb 100644 GIT binary patch delta 149 zcmey)w2hh5E!cyFvH8ItmEFP|rY9)0(T6i;DpO9GNUe delta 106 zcmdnS{GEx@E!cyFvH8u_U*kEU_rw zP(e#UqcpxGGp|HJTcIp9*+j!Y&p=1PK+hCJfLR8bnwmgmW%0@RIr&8fn$}#kTwDwQ DKQlC2@%Z9D*>^};*;}p@{0^Kff_+JY8dDl=qMlvLp=jcO>3@NE-nTD DEp#~_ delta 129 zcmey&w26t+E!cyFvH89S!%M0hJl`ej)H-nDTn~G3^c*Y T%HosrbMlJ}G_AR6xwser^zA0x diff --git a/shaders/metal/fs_tint.bin b/shaders/metal/fs_tint.bin index dab995e96118d080d688e7d9c5c9c035ff91a3a7..3168babec2cd367a51d50fec16328b61bd9c9698 100644 GIT binary patch delta 188 zcmbQhc9@OZE!cyFvH8 uv=uZm5_8f_G$D3s80Z=3C?E(!J)k0ME(L|6)RNMoJcxby)?Bq*Tnqr7y*usz delta 122 zcmX@iHi3=XE!cyFvH8(buffer.data); - - const uint32_t r = uint32_t(prim->color.r * 255); - const uint32_t g = uint32_t(prim->color.g * 255) << 8; - const uint32_t b = uint32_t(prim->color.b * 255) << 16; - const uint32_t a = uint32_t(prim->color.a * 255) << 24; - UINT32 rgba = r | g | b | a; - - vertex[0].m_x = prim->bounds.x0; - vertex[0].m_y = prim->bounds.y0; - vertex[0].m_z = 0; - vertex[0].m_rgba = rgba; - vertex[0].m_u = prim->texcoords.tl.u; - vertex[0].m_v = prim->texcoords.tl.v; - - vertex[1].m_x = prim->bounds.x1; - vertex[1].m_y = prim->bounds.y0; - vertex[1].m_z = 0; - vertex[1].m_rgba = rgba; - vertex[1].m_u = prim->texcoords.tr.u; - vertex[1].m_v = prim->texcoords.tr.v; - - vertex[2].m_x = prim->bounds.x1; - vertex[2].m_y = prim->bounds.y1; - vertex[2].m_z = 0; - vertex[2].m_rgba = rgba; - vertex[2].m_u = prim->texcoords.br.u; - vertex[2].m_v = prim->texcoords.br.v; - - vertex[3].m_x = prim->bounds.x1; - vertex[3].m_y = prim->bounds.y1; - vertex[3].m_z = 0; - vertex[3].m_rgba = rgba; - vertex[3].m_u = prim->texcoords.br.u; - vertex[3].m_v = prim->texcoords.br.v; - - vertex[4].m_x = prim->bounds.x0; - vertex[4].m_y = prim->bounds.y1; - vertex[4].m_z = 0; - vertex[4].m_rgba = rgba; - vertex[4].m_u = prim->texcoords.bl.u; - vertex[4].m_v = prim->texcoords.bl.v; - - vertex[5].m_x = prim->bounds.x0; - vertex[5].m_y = prim->bounds.y0; - vertex[5].m_z = 0; - vertex[5].m_rgba = rgba; - vertex[5].m_u = prim->texcoords.tl.u; - vertex[5].m_v = prim->texcoords.tl.v; - - bgfx::setVertexBuffer(&buffer); - - bgfx::setViewClear(view - , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH - , 0x000000ff - , 1.0f - , 0 - ); - - entry->submit(prim, view, textures, screen_width, screen_height, blend); + m_entries[index]->submit(prim, view, textures, screen_width, screen_height, blend); } } diff --git a/src/osd/modules/render/bgfx/chainentry.cpp b/src/osd/modules/render/bgfx/chainentry.cpp index d02754884d8..e51c5b04818 100644 --- a/src/osd/modules/render/bgfx/chainentry.cpp +++ b/src/osd/modules/render/bgfx/chainentry.cpp @@ -12,6 +12,7 @@ #include "emu.h" #include +#include #include "chainentry.h" @@ -20,6 +21,7 @@ #include "target.h" #include "entryuniform.h" #include "texturemanager.h" +#include "vertex.h" bgfx_chain_entry::bgfx_chain_entry(std::string name, bgfx_effect* effect, std::vector& inputs, std::vector uniforms, bgfx_target* output) : m_name(name) @@ -47,25 +49,102 @@ bgfx_chain_entry::~bgfx_chain_entry() void bgfx_chain_entry::submit(render_primitive* prim, int view, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint64_t blend) { - for (bgfx_input_pair input : m_inputs) - { - input.bind(m_effect, textures); - } - if (m_output != nullptr) - { - printf("Setting view to %s, %dx%d\n", m_output->name().c_str(), m_outptu->width, m_output->height()); - bgfx::setViewFrameBuffer(view, m_output->target()); - bgfx::setViewRect(view, 0, 0, m_output->width(), m_output->height()); - } - else - { - printf("Setting view to backbuffer, %dx%d\n", screen_width, screen_height); - bgfx::setViewFrameBuffer(view, BGFX_INVALID_HANDLE); - bgfx::setViewRect(view, 0, 0, screen_width, screen_height); + bgfx::setViewSeq(view, true); + + setup_view(view, screen_width, screen_height); + + for (bgfx_input_pair input : m_inputs) { + input.bind(m_effect, textures); } + + bgfx::TransientVertexBuffer buffer; + put_screen_buffer(prim, &buffer); + bgfx::setVertexBuffer(&buffer); + for (bgfx_entry_uniform* uniform : m_uniforms) { uniform->bind(); } + m_effect->submit(view, blend); } + +void bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t screen_height) +{ + bgfx::FrameBufferHandle handle = BGFX_INVALID_HANDLE; + uint16_t width = screen_width; + uint16_t height = screen_height; + if (m_output != nullptr) + { + handle = m_output->target(); + width = m_output->width(); + height = m_output->height(); + } + + bgfx::setViewFrameBuffer(view, handle); + bgfx::setViewRect(view, 0, 0, width, height); + + { + float viewMat[16]; + bx::mtxIdentity(viewMat); + + float projMat[16]; + bx::mtxOrtho(projMat, 0.0f, width, height, 0.0f, 0.0f, 100.0f); + bgfx::setViewTransform(view, viewMat, projMat); + } + + bgfx::setViewClear(view, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x000000ff, 1.0f, 0); +} + +void bgfx_chain_entry::put_screen_buffer(render_primitive* prim, bgfx::TransientVertexBuffer* buffer) +{ + if (bgfx::checkAvailTransientVertexBuffer(6, ScreenVertex::ms_decl)) { + bgfx::allocTransientVertexBuffer(buffer, 6, ScreenVertex::ms_decl); + } else { + return; + } + + ScreenVertex* vertex = reinterpret_cast(buffer->data); + + vertex[0].m_x = prim->bounds.x0; + vertex[0].m_y = prim->bounds.y0; + vertex[0].m_z = 0; + vertex[0].m_rgba = 0xffffffff; + vertex[0].m_u = prim->texcoords.tl.u; + vertex[0].m_v = prim->texcoords.tl.v; + + vertex[1].m_x = prim->bounds.x1; + vertex[1].m_y = prim->bounds.y0; + vertex[1].m_z = 0; + vertex[1].m_rgba = 0xffffffff; + vertex[1].m_u = prim->texcoords.tr.u; + vertex[1].m_v = prim->texcoords.tr.v; + + vertex[2].m_x = prim->bounds.x1; + vertex[2].m_y = prim->bounds.y1; + vertex[2].m_z = 0; + vertex[2].m_rgba = 0xffffffff; + vertex[2].m_u = prim->texcoords.br.u; + vertex[2].m_v = prim->texcoords.br.v; + + vertex[3].m_x = prim->bounds.x1; + vertex[3].m_y = prim->bounds.y1; + vertex[3].m_z = 0; + vertex[3].m_rgba = 0xffffffff; + vertex[3].m_u = prim->texcoords.br.u; + vertex[3].m_v = prim->texcoords.br.v; + + vertex[4].m_x = prim->bounds.x0; + vertex[4].m_y = prim->bounds.y1; + vertex[4].m_z = 0; + vertex[4].m_rgba = 0xffffffff; + vertex[4].m_u = prim->texcoords.bl.u; + vertex[4].m_v = prim->texcoords.bl.v; + + vertex[5].m_x = prim->bounds.x0; + vertex[5].m_y = prim->bounds.y0; + vertex[5].m_z = 0; + vertex[5].m_rgba = 0xffffffff; + vertex[5].m_u = prim->texcoords.tl.u; + vertex[5].m_v = prim->texcoords.tl.v; +} \ No newline at end of file diff --git a/src/osd/modules/render/bgfx/chainentry.h b/src/osd/modules/render/bgfx/chainentry.h index 33480d53f3f..a6ab71aae35 100644 --- a/src/osd/modules/render/bgfx/chainentry.h +++ b/src/osd/modules/render/bgfx/chainentry.h @@ -14,6 +14,8 @@ #ifndef __DRAWBGFX_CHAIN_ENTRY__ #define __DRAWBGFX_CHAIN_ENTRY__ +#include + #include #include @@ -31,12 +33,15 @@ public: bgfx_chain_entry(std::string name, bgfx_effect* effect, std::vector& inputs, std::vector uniforms, bgfx_target* output); ~bgfx_chain_entry(); - void submit(render_primitive* prim, int view, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint64_t blend = 0L); + void submit(render_primitive* prim, int view, texture_manager& textures, uint16_t screen_width, uint16_t screen_height, uint64_t blend); // Getters std::string name() const { return m_name; } private: + void setup_view(int view, uint16_t screen_width, uint16_t screen_height); + void put_screen_buffer(render_primitive* prim, bgfx::TransientVertexBuffer* buffer); + std::string m_name; bgfx_effect* m_effect; std::vector m_inputs; diff --git a/src/osd/modules/render/bgfx/effect.h b/src/osd/modules/render/bgfx/effect.h index f4af231dd6b..b44b6a8fb72 100644 --- a/src/osd/modules/render/bgfx/effect.h +++ b/src/osd/modules/render/bgfx/effect.h @@ -26,6 +26,7 @@ public: void submit(int view, uint64_t blend = 0L); bgfx_uniform* uniform(std::string name); + bool has_uniform(std::string name); private: uint64_t m_state; diff --git a/src/osd/modules/render/bgfx/fs_tint.sc b/src/osd/modules/render/bgfx/fs_tint.sc index b5892848b33..7bb433f9743 100644 --- a/src/osd/modules/render/bgfx/fs_tint.sc +++ b/src/osd/modules/render/bgfx/fs_tint.sc @@ -9,8 +9,9 @@ uniform vec4 u_tint; uniform vec4 u_shift; SAMPLER2D(s_tex, 0); +uniform vec4 u_texsize; void main() { - gl_FragColor = texture2D(s_tex, v_texcoord0 + u_shift.xy) * (u_tint + vec4(0.0, 0.5, 0.0, 0.0)) * v_color0; + gl_FragColor = texture2D(s_tex, v_texcoord0.xy + u_shift.xy * u_texsize.xy) * u_tint * v_color0 + vec4(0.0, 0.0, 0.0, 1.0); } diff --git a/src/osd/modules/render/bgfx/inputpair.cpp b/src/osd/modules/render/bgfx/inputpair.cpp index d73b957888e..1202dbcd72b 100644 --- a/src/osd/modules/render/bgfx/inputpair.cpp +++ b/src/osd/modules/render/bgfx/inputpair.cpp @@ -11,6 +11,7 @@ #include "inputpair.h" #include "texture.h" +#include "target.h" #include "effect.h" #include "uniform.h" #include "texturemanager.h" @@ -24,9 +25,13 @@ bgfx_input_pair::bgfx_input_pair(int index, std::string sampler, std::string tex void bgfx_input_pair::bind(bgfx_effect *effect, texture_manager& textures) { - printf("Binding texture %s to uniform %s\n", m_texture.c_str(), m_sampler.c_str()); - bgfx_uniform *uniform = effect->uniform(m_sampler); - bgfx::UniformHandle u_handle = uniform->handle(); - bgfx::TextureHandle t_handle = textures.texture(m_texture)->handle(); - bgfx::setTexture(m_index, u_handle, t_handle); + bgfx::setTexture(m_index, effect->uniform(m_sampler)->handle(), textures.texture(m_texture)->handle()); + bgfx_uniform *size_uniform = effect->uniform("u_texsize"); + if (size_uniform != nullptr) + { + float width = float(textures.texture(m_texture)->width()); + float height = float(textures.texture(m_texture)->height()); + float size[4] = { 1.0f / width, 1.0f / height, 0.0f, 0.0f }; + size_uniform->set(reinterpret_cast(size), sizeof(float) * 4); + } } diff --git a/src/osd/modules/render/bgfx/slideruniform.cpp b/src/osd/modules/render/bgfx/slideruniform.cpp index b79d5e1bb75..7a63b1e6901 100644 --- a/src/osd/modules/render/bgfx/slideruniform.cpp +++ b/src/osd/modules/render/bgfx/slideruniform.cpp @@ -29,6 +29,5 @@ void bgfx_slider_uniform::bind() { values[i] = m_sliders[i]->uniform_value(); } - printf("Setting slider uniform %s to %f, %f, %f, %f (%s)\n", m_uniform->name().c_str(), values[0], values[1], values[2], values[3], m_sliders[0]->name().c_str()); m_uniform->set(values, sizeof(float) * m_sliders.size()); } diff --git a/src/osd/modules/render/bgfx/target.cpp b/src/osd/modules/render/bgfx/target.cpp index dd2bc0de797..c47307d419c 100644 --- a/src/osd/modules/render/bgfx/target.cpp +++ b/src/osd/modules/render/bgfx/target.cpp @@ -9,14 +9,14 @@ #include "target.h" bgfx_target::bgfx_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter, uint32_t style) - : bgfx_texture(name, format, width, height, BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | (filter ? 0 : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT)), nullptr) + : bgfx_texture(name, format, width, height, BGFX_TEXTURE_RT | BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | (filter ? 0 : (BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT)), nullptr) , m_style(style) { m_target = bgfx::createFrameBuffer(1, &m_handle, false); } bgfx_target::bgfx_target(std::string name, uint32_t width, uint32_t height, uint32_t style, void *handle) - : bgfx_texture(name, bgfx::TextureFormat::RGBA8, width, height, BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT, nullptr) + : bgfx_texture(name, bgfx::TextureFormat::RGBA8, width, height, BGFX_TEXTURE_RT | BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP | BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT, nullptr) , m_style(style) { m_target = bgfx::createFrameBuffer(handle, width, height); diff --git a/src/osd/modules/render/bgfx/uniform.cpp b/src/osd/modules/render/bgfx/uniform.cpp index 687a306681e..a3e734f33dc 100644 --- a/src/osd/modules/render/bgfx/uniform.cpp +++ b/src/osd/modules/render/bgfx/uniform.cpp @@ -29,8 +29,7 @@ bgfx_uniform::~bgfx_uniform() void bgfx_uniform::upload() { - //if (m_type != bgfx::UniformType::Int1) // Avoid samplers; set separately! - bgfx::setUniform(m_handle, m_data); + bgfx::setUniform(m_handle, m_data); } bgfx_uniform* bgfx_uniform::set(float* value) diff --git a/src/osd/modules/render/bgfx/valueuniform.cpp b/src/osd/modules/render/bgfx/valueuniform.cpp index 96ea8ca465e..e920c45dc18 100644 --- a/src/osd/modules/render/bgfx/valueuniform.cpp +++ b/src/osd/modules/render/bgfx/valueuniform.cpp @@ -20,6 +20,5 @@ bgfx_value_uniform::bgfx_value_uniform(bgfx_uniform* uniform, float* values, con void bgfx_value_uniform::bind() { - printf("Setting value uniform %s to %f, %f, %f, %f (%s)\n", m_uniform->name().c_str(), m_values[0], m_values[1], m_values[2], m_values[3]); m_uniform->set(m_values, sizeof(float) * m_count); } diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp index d4ba07bbd60..91895d88a7c 100644 --- a/src/osd/modules/render/drawbgfx.cpp +++ b/src/osd/modules/render/drawbgfx.cpp @@ -61,7 +61,7 @@ const uint32_t renderer_bgfx::WHITE_HASH = 0x87654321; //============================================================ #define GIBBERISH (0) -#define USE_NEW_SHADERS (0) +#define USE_NEW_SHADERS (1) //============================================================ // INLINES @@ -139,7 +139,6 @@ 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) { @@ -162,8 +161,11 @@ 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 = m_chains->chain("test", window().machine()); +#if USE_NEW_SHADERS + m_chains = new chain_manager(*m_textures, *m_targets, *m_effects, m_width[window().m_index], m_height[window().m_index]); + m_screen_chain = m_chains->chain("test", window().machine()); m_sliders_dirty = true; +#endif 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); @@ -181,7 +183,9 @@ int renderer_bgfx::create() renderer_bgfx::~renderer_bgfx() { // Cleanup. - //delete m_chains; +#if USE_NEW_SHADERS + delete m_chains; +#endif delete m_effects; delete m_shaders; delete m_textures; @@ -307,13 +311,13 @@ void renderer_bgfx::render_screen_quad(int view, render_primitive* prim) texture_flags |= BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT; } - const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK, - prim->texture.width, prim->texture.height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base); - uint16_t tex_width(prim->texture.width); uint16_t tex_height(prim->texture.height); - bgfx_texture *texture = new bgfx_texture("screen", bgfx::TextureFormat::RGBA8, uint16_t(prim->texture.width), uint16_t(prim->texture.height), mem); + const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK, + tex_width, tex_height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base); + + bgfx_texture *texture = new bgfx_texture("screen", bgfx::TextureFormat::RGBA8, tex_width, tex_height, mem); m_textures->add_texture("screen", texture); m_targets->update_guest_targets(tex_width, tex_height); @@ -377,10 +381,13 @@ void renderer_bgfx::render_textured_quad(int view, render_primitive* prim, bgfx: texture_flags |= BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT | BGFX_TEXTURE_MIP_POINT; } - const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK, - prim->texture.width, prim->texture.height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base); + uint16_t tex_width(prim->texture.width); + uint16_t tex_height(prim->texture.height); - bgfx::TextureHandle texture = bgfx::createTexture2D(uint16_t(prim->texture.width), uint16_t(prim->texture.height), 1, bgfx::TextureFormat::RGBA8, texture_flags, mem); + const bgfx::Memory* mem = mame_texture_data_to_bgfx_texture_data(prim->flags & PRIMFLAG_TEXFORMAT_MASK, + tex_width, tex_height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base); + + bgfx::TextureHandle texture = bgfx::createTexture2D(tex_width, tex_height, 1, bgfx::TextureFormat::RGBA8, texture_flags, mem); bgfx_effect** effects = PRIMFLAG_GET_SCREENTEX(prim->flags) ? m_screen_effect : m_gui_effect; @@ -928,7 +935,7 @@ renderer_bgfx::buffer_status renderer_bgfx::buffer_primitives(int view, bool atl render_textured_quad(view, *prim, buffer); } #else - render_textured_quad(view, *prim, buffer); + render_textured_quad(*view, *prim, buffer); #endif return BUFFER_EMPTY; }