diff options
Diffstat (limited to 'src/osd/modules')
29 files changed, 352 insertions, 95 deletions
diff --git a/src/osd/modules/debugger/win/consolewininfo.cpp b/src/osd/modules/debugger/win/consolewininfo.cpp index a9811f5fc93..88367c09fc9 100644 --- a/src/osd/modules/debugger/win/consolewininfo.cpp +++ b/src/osd/modules/debugger/win/consolewininfo.cpp @@ -199,7 +199,7 @@ void consolewin_info::update_menu() if (img.device().type() == CASSETTE) { - cassette_state const state = cassette_state(downcast<cassette_image_device *>(&img.device())->get_state() & CASSETTE_MASK_UISTATE); + cassette_state const state = downcast<cassette_image_device *>(&img.device())->get_state() & CASSETTE_MASK_UISTATE; AppendMenu(devicesubmenu, MF_SEPARATOR, 0, nullptr); AppendMenu(devicesubmenu, flags_for_exists | ((state == CASSETTE_STOPPED) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_STOPPAUSE, TEXT("Pause/Stop")); AppendMenu(devicesubmenu, flags_for_exists | ((state == CASSETTE_PLAY) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_PLAY, TEXT("Play")); @@ -208,9 +208,9 @@ void consolewin_info::update_menu() AppendMenu(devicesubmenu, flags_for_exists, new_item + DEVOPTION_CASSETTE_FASTFORWARD, TEXT("Fast Forward")); AppendMenu(devicesubmenu, MF_SEPARATOR, 0, nullptr); // Motor state can be overriden by the driver - cassette_state const motor_state = cassette_state(downcast<cassette_image_device *>(&img.device())->get_state() & CASSETTE_MASK_MOTOR); + cassette_state const motor_state = downcast<cassette_image_device *>(&img.device())->get_state() & CASSETTE_MASK_MOTOR; AppendMenu(devicesubmenu, flags_for_exists | ((motor_state == CASSETTE_MOTOR_ENABLED) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_MOTOR, TEXT("Motor")); - cassette_state const speaker_state = cassette_state(downcast<cassette_image_device *>(&img.device())->get_state() & CASSETTE_MASK_SPEAKER); + cassette_state const speaker_state = downcast<cassette_image_device *>(&img.device())->get_state() & CASSETTE_MASK_SPEAKER; AppendMenu(devicesubmenu, flags_for_exists | ((speaker_state == CASSETTE_SPEAKER_ENABLED) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_SOUND, TEXT("Audio while Loading")); } } diff --git a/src/osd/modules/file/posixptty.cpp b/src/osd/modules/file/posixptty.cpp index 6e468cf172f..a590dc682e2 100644 --- a/src/osd/modules/file/posixptty.cpp +++ b/src/osd/modules/file/posixptty.cpp @@ -109,6 +109,9 @@ bool posix_check_ptty_path(std::string const &path) osd_file::error posix_open_ptty(std::uint32_t openflags, osd_file::ptr &file, std::uint64_t &filesize, std::string &name) { +#if defined(__ANDROID__) + return osd_file::error::FAILURE; +#else // defined(__ANDROID__) #if (defined(sun) || defined(__sun)) && (defined(__SVR4) || defined(__svr4__)) int access = O_NOCTTY; if (openflags & OPEN_FLAG_WRITE) @@ -145,9 +148,6 @@ osd_file::error posix_open_ptty(std::uint32_t openflags, osd_file::ptr &file, st ::close(masterfd); return errno_to_file_error(err); } -#elif defined(__ANDROID__) - int masterfd = -1, slavefd = -1; - char slavepath[PATH_MAX]; #else struct termios tios; std::memset(&tios, 0, sizeof(tios)); @@ -188,4 +188,5 @@ osd_file::error posix_open_ptty(std::uint32_t openflags, osd_file::ptr &file, st ::close(masterfd); return osd_file::error::OUT_OF_MEMORY; } +#endif // defined(__ANDROID__) } diff --git a/src/osd/modules/input/input_x11.cpp b/src/osd/modules/input/input_x11.cpp index 07ade15c764..6b66220e32a 100644 --- a/src/osd/modules/input/input_x11.cpp +++ b/src/osd/modules/input/input_x11.cpp @@ -312,6 +312,9 @@ public: std::lock_guard<std::mutex> scope_lock(m_lock); XEvent xevent; + // If X11 has become invalid for some reason, XPending will crash. Assert instead. + assert(m_display != nullptr); + //Get XInput events while (XPending(m_display) != 0) { @@ -443,6 +446,17 @@ public: { } + virtual bool probe() override + { + // If there is no X server, X11 lightguns cannot be supported + if (XOpenDisplay(nullptr) == nullptr) + { + return false; + } + + return true; + } + void input_init(running_machine &machine) override { int index; @@ -454,6 +468,9 @@ public: x11_event_manager::instance().initialize(); m_display = x11_event_manager::instance().display(); + // If the X server has become invalid, a crash can occur + assert(m_display != nullptr); + // Loop through all 8 possible devices for (index = 0; index < 8; index++) { @@ -573,10 +590,9 @@ private: if (m_lightgun_map.initialized) { snprintf(tempname, ARRAY_LENGTH(tempname), "NC%d", index); - devicelist()->create_device<x11_lightgun_device>(machine, tempname, tempname, *this); - } - - return nullptr; + return devicelist()->create_device<x11_lightgun_device>(machine, tempname, tempname, *this); + } else + return nullptr; } return devicelist()->create_device<x11_lightgun_device>(machine, m_lightgun_map.map[index].name.c_str(), m_lightgun_map.map[index].name.c_str(), *this); diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp index 178fb4594cb..2b0e7a3d780 100644 --- a/src/osd/modules/lib/osdlib_unix.cpp +++ b/src/osd/modules/lib/osdlib_unix.cpp @@ -90,13 +90,13 @@ void osd_free_executable(void *ptr, size_t size) void osd_break_into_debugger(const char *message) { - #ifdef MAME_DEBUG +#ifdef MAME_DEBUG printf("MAME exception: %s\n", message); printf("Attempting to fall into debugger\n"); kill(getpid(), SIGTRAP); - #else +#else printf("Ignoring MAME exception: %s\n", message); - #endif +#endif } #ifdef SDLMAME_ANDROID diff --git a/src/osd/modules/render/bgfx/chain.cpp b/src/osd/modules/render/bgfx/chain.cpp index c7691973854..25dccf87eed 100644 --- a/src/osd/modules/render/bgfx/chain.cpp +++ b/src/osd/modules/render/bgfx/chain.cpp @@ -13,11 +13,14 @@ #include "slider.h" #include "parameter.h" #include "entryuniform.h" +#include "valueuniform.h" #include "texturemanager.h" #include "targetmanager.h" +#include "chainmanager.h" #include "target.h" #include "vertex.h" #include "screen.h" +#include "clear.h" #include "modules/osdwindow.h" #include "chain.h" @@ -33,6 +36,7 @@ bgfx_chain::bgfx_chain(std::string name, std::string author, bool transform, tar , m_target_list(target_list) , m_current_time(0) , m_screen_index(screen_index) + , m_has_converter(false) { for (bgfx_target* target : m_target_list) { @@ -138,3 +142,31 @@ uint32_t bgfx_chain::applicable_passes() return applicable_passes; } + +void bgfx_chain::prepend_converter(bgfx_effect *effect, chain_manager &chains) +{ + clear_state *clear = new clear_state(BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL, 0, 1.0f, 0); + std::vector<bgfx_suppressor*> suppressors; + + std::vector<bgfx_input_pair*> inputs; + std::vector<std::string> available_textures; + inputs.push_back(new bgfx_input_pair(0, "s_tex", "source", available_textures, "", chains, m_screen_index)); + inputs.push_back(new bgfx_input_pair(1, "s_pal", "palette", available_textures, "", chains, m_screen_index)); + + std::vector<bgfx_entry_uniform*> uniforms; + float value = 1.0f; + float values[4] = { 1.0f, 1.0f, 0.0f, 0.0f }; + uniforms.push_back(new bgfx_value_uniform(new bgfx_uniform("s_tex", bgfx::UniformType::Sampler), &value, 1)); + uniforms.push_back(new bgfx_value_uniform(new bgfx_uniform("s_pal", bgfx::UniformType::Sampler), &value, 1)); + uniforms.push_back(new bgfx_value_uniform(new bgfx_uniform("u_tex_size0", bgfx::UniformType::Vec4), values, 4)); + uniforms.push_back(new bgfx_value_uniform(new bgfx_uniform("u_tex_size1", bgfx::UniformType::Vec4), values, 4)); + uniforms.push_back(new bgfx_value_uniform(new bgfx_uniform("u_inv_tex_size0", bgfx::UniformType::Vec4), values, 4)); + uniforms.push_back(new bgfx_value_uniform(new bgfx_uniform("u_inv_tex_size1", bgfx::UniformType::Vec4), values, 4)); + + m_entries.insert(m_entries.begin(), new bgfx_chain_entry("XXconvert", effect, clear, suppressors, inputs, uniforms, m_targets, "screen")); + m_has_converter = true; + + const uint32_t screen_width = chains.targets().width(TARGET_STYLE_GUEST, m_screen_index); + const uint32_t screen_height = chains.targets().height(TARGET_STYLE_GUEST, m_screen_index); + m_targets.create_target("screen", bgfx::TextureFormat::RGBA8, screen_width, screen_height, TARGET_STYLE_GUEST, true, false, 1, m_screen_index); +} diff --git a/src/osd/modules/render/bgfx/chain.h b/src/osd/modules/render/bgfx/chain.h index 157f92173cf..cb5668d3368 100644 --- a/src/osd/modules/render/bgfx/chain.h +++ b/src/osd/modules/render/bgfx/chain.h @@ -38,7 +38,10 @@ public: std::vector<bgfx_slider*>& sliders() { return m_sliders; } std::vector<bgfx_chain_entry*>& entries() { return m_entries; } uint32_t applicable_passes(); - bool transform() { return m_transform; } + bool transform() const { return m_transform; } + bool has_converter() const { return m_has_converter; } + + void prepend_converter(bgfx_effect *effect, chain_manager &chains); private: std::string m_name; @@ -53,6 +56,7 @@ private: std::map<std::string, bgfx_target*> m_target_map; int64_t m_current_time; uint32_t m_screen_index; + bool m_has_converter; }; #endif // __DRAWBGFX_CHAIN__ diff --git a/src/osd/modules/render/bgfx/chainentry.h b/src/osd/modules/render/bgfx/chainentry.h index 64130c5c93e..e143def6c56 100644 --- a/src/osd/modules/render/bgfx/chainentry.h +++ b/src/osd/modules/render/bgfx/chainentry.h @@ -11,8 +11,8 @@ #pragma once -#ifndef __DRAWBGFX_CHAIN_ENTRY__ -#define __DRAWBGFX_CHAIN_ENTRY__ +#ifndef DRAWBGFX_CHAIN_ENTRY +#define DRAWBGFX_CHAIN_ENTRY #include <bgfx/bgfx.h> diff --git a/src/osd/modules/render/bgfx/chainentryreader.cpp b/src/osd/modules/render/bgfx/chainentryreader.cpp index bff221ec40c..d48b214f83d 100644 --- a/src/osd/modules/render/bgfx/chainentryreader.cpp +++ b/src/osd/modules/render/bgfx/chainentryreader.cpp @@ -84,7 +84,7 @@ bgfx_chain_entry* chain_entry_reader::read_from_value(const Value& value, std::s texture_name = chains.options().value(option.c_str()); } - if (texture_name != "" && texture_name != "screen") + if (texture_name != "" && texture_name != "screen" && texture_name != "palette") { if (selection == "") { diff --git a/src/osd/modules/render/bgfx/chainmanager.cpp b/src/osd/modules/render/bgfx/chainmanager.cpp index 62df9be9613..eb22cb1d253 100644 --- a/src/osd/modules/render/bgfx/chainmanager.cpp +++ b/src/osd/modules/render/bgfx/chainmanager.cpp @@ -49,6 +49,7 @@ chain_manager::chain_manager(running_machine& machine, osd_options& options, tex { refresh_available_chains(); parse_chain_selections(options.bgfx_screen_chains()); + init_texture_converters(); } chain_manager::~chain_manager() @@ -56,6 +57,15 @@ chain_manager::~chain_manager() destroy_chains(); } +void chain_manager::init_texture_converters() +{ + m_converters.push_back(nullptr); + m_converters.push_back(m_effects.effect("misc/texconv_palette16")); + m_converters.push_back(m_effects.effect("misc/texconv_rgb32")); + m_converters.push_back(nullptr); + m_converters.push_back(m_effects.effect("misc/texconv_yuy16")); +} + void chain_manager::refresh_available_chains() { m_available_chains.clear(); @@ -288,17 +298,73 @@ bgfx_chain* chain_manager::screen_chain(uint32_t screen) } } -void chain_manager::process_screen_quad(uint32_t view, uint32_t screen, render_primitive* prim, osd_window &window) +void chain_manager::process_screen_quad(uint32_t view, uint32_t screen, render_primitive* prim, osd_window& window) { - uint16_t tex_width(prim->texture.width); - uint16_t tex_height(prim->texture.height); + uint16_t tex_width(prim->texture.width); + uint16_t tex_height(prim->texture.height); + + bgfx_texture* texture = screen < m_screen_textures.size() ? m_screen_textures[screen] : nullptr; + bgfx_texture* palette = screen < m_screen_palettes.size() ? m_screen_palettes[screen] : nullptr; + + const uint32_t src_format = (prim->flags & PRIMFLAG_TEXFORMAT_MASK) >> PRIMFLAG_TEXFORMAT_SHIFT; + const bool needs_conversion = m_converters[src_format] != nullptr; + std::string screen_index = std::to_string(screen); + std::string source_name = "source" + screen_index; + std::string screen_name = "screen" + screen_index; + std::string palette_name = "palette" + screen_index; + std::string full_name = needs_conversion ? source_name : screen_name; + if (texture && (texture->width() != tex_width || texture->height() != tex_height)) + { + m_textures.add_provider(full_name, nullptr); + delete texture; + texture = nullptr; + + if (palette) + { + m_textures.add_provider(palette_name, nullptr); + delete palette; + palette = nullptr; + } + } - const bgfx::Memory* mem = bgfx_util::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::TextureFormat::Enum dst_format = bgfx::TextureFormat::RGBA8; + uint16_t pitch = tex_width; + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, prim->flags & PRIMFLAG_TEXFORMAT_MASK, + tex_width, tex_height, prim->texture.rowpixels, prim->texture.palette, prim->texture.base, &pitch); - std::string full_name = "screen" + std::to_string(screen); - bgfx_texture *texture = new bgfx_texture(full_name, bgfx::TextureFormat::RGBA8, tex_width, tex_height, mem, BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP | BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT); - m_textures.add_provider(full_name, texture); + if (texture == nullptr) + { + bgfx_texture *texture = new bgfx_texture(full_name, dst_format, tex_width, tex_height, mem, BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP | BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT, pitch); + m_textures.add_provider(full_name, texture); + + if (prim->texture.palette) + { + uint16_t palette_width = (uint16_t)std::min(prim->texture.palette_length, 256U); + uint16_t palette_height = (uint16_t)std::max(prim->texture.palette_length / 256, 1U); + const bgfx::Memory *palmem = bgfx::copy(prim->texture.palette, palette_width * palette_height * 4); + palette = new bgfx_texture(palette_name, bgfx::TextureFormat::BGRA8, palette_width, palette_height, palmem, BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP | BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT, palette_width); + m_textures.add_provider(palette_name, palette); + } + + if (screen >= m_screen_textures.size()) + { + m_screen_textures.push_back(texture); + if (palette) + { + m_screen_palettes.push_back(palette); + } + } + } + else + { + texture->update(mem, pitch); + + if (prim->texture.palette) + { + const bgfx::Memory *palmem = bgfx::copy(prim->texture.palette, palette->width() * palette->height() * 4); + palette->update(palmem); + } + } const bool any_targets_rebuilt = m_targets.update_target_sizes(screen, tex_width, tex_height, TARGET_STYLE_GUEST); if (any_targets_rebuilt) @@ -313,11 +379,12 @@ void chain_manager::process_screen_quad(uint32_t view, uint32_t screen, render_p } bgfx_chain* chain = screen_chain(screen); + if (needs_conversion && !chain->has_converter()) + { + chain->prepend_converter(m_converters[src_format], *this); + } chain->process(prim, view, screen, m_textures, window, bgfx_util::get_blend_state(PRIMFLAG_GET_BLENDMODE(prim->flags))); view += chain->applicable_passes(); - - m_textures.add_provider(full_name, nullptr); - delete texture; } std::vector<render_primitive*> chain_manager::count_screens(render_primitive* prim) diff --git a/src/osd/modules/render/bgfx/chainmanager.h b/src/osd/modules/render/bgfx/chainmanager.h index 4c76a02ee25..e03622d28f2 100644 --- a/src/osd/modules/render/bgfx/chainmanager.h +++ b/src/osd/modules/render/bgfx/chainmanager.h @@ -77,6 +77,8 @@ private: void destroy_chains(); void reload_chains(); + void init_texture_converters(); + void refresh_available_chains(); void destroy_unloaded_chains(); void find_available_chains(std::string root, std::string path); @@ -106,6 +108,9 @@ private: std::vector<ui::menu_item> m_selection_sliders; std::vector<std::unique_ptr<slider_state>> m_core_sliders; std::vector<int32_t> m_current_chain; + std::vector<bgfx_texture*> m_screen_textures; + std::vector<bgfx_texture*> m_screen_palettes; + std::vector<bgfx_effect*> m_converters; static const uint32_t CHAIN_NONE; }; diff --git a/src/osd/modules/render/bgfx/effect.cpp b/src/osd/modules/render/bgfx/effect.cpp index da5207f114b..9359faeb494 100644 --- a/src/osd/modules/render/bgfx/effect.cpp +++ b/src/osd/modules/render/bgfx/effect.cpp @@ -52,11 +52,5 @@ void bgfx_effect::submit(int view, uint64_t blend) bgfx_uniform* bgfx_effect::uniform(std::string name) { std::map<std::string, bgfx_uniform*>::iterator iter = m_uniforms.find(name); - - if (iter != m_uniforms.end()) - { - return iter->second; - } - - return nullptr; + return iter != m_uniforms.end() ? iter->second : nullptr; } diff --git a/src/osd/modules/render/bgfx/entryuniform.h b/src/osd/modules/render/bgfx/entryuniform.h index 4ba30250e6e..9c1462f360f 100644 --- a/src/osd/modules/render/bgfx/entryuniform.h +++ b/src/osd/modules/render/bgfx/entryuniform.h @@ -11,8 +11,8 @@ #pragma once -#ifndef __DRAWBGFX_ENTRY_UNIFORM__ -#define __DRAWBGFX_ENTRY_UNIFORM__ +#ifndef DRAWBGFX_ENTRY_UNIFORM +#define DRAWBGFX_ENTRY_UNIFORM #include <bgfx/bgfx.h> diff --git a/src/osd/modules/render/bgfx/inputpair.cpp b/src/osd/modules/render/bgfx/inputpair.cpp index 98d0594e27a..8d4441ccffe 100644 --- a/src/osd/modules/render/bgfx/inputpair.cpp +++ b/src/osd/modules/render/bgfx/inputpair.cpp @@ -50,13 +50,23 @@ void bgfx_input_pair::bind(bgfx_effect *effect, const int32_t screen) const std::string name = m_texture + std::to_string(screen); bgfx_texture_handle_provider* provider = chains().textures().provider(name); - bgfx_uniform *tex_size = effect->uniform("u_tex_size" + std::to_string(m_index)); - if (tex_size != nullptr) + if (!provider) + return; + + bgfx_uniform *tex_size = effect->uniform("u_tex_size" + std::to_string(m_index)); + if (tex_size && provider) { float values[2] = { float(provider->width()), float(provider->height()) }; tex_size->set(values, sizeof(float) * 2); } + bgfx_uniform *inv_tex_size = effect->uniform("u_inv_tex_size" + std::to_string(m_index)); + if (inv_tex_size && provider) + { + float values[2] = { 1.0f / float(provider->width()), 1.0f / float(provider->height()) }; + inv_tex_size->set(values, sizeof(float) * 2); + } + bgfx::setTexture(m_index, effect->uniform(m_sampler)->handle(), chains().textures().handle(name)); } diff --git a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_chroma.sc b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_chroma.sc index 51bb14676d3..c0d8ba07ac7 100644 --- a/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_chroma.sc +++ b/src/osd/modules/render/bgfx/shaders/chains/hlsl/fs_chroma.sc @@ -22,11 +22,20 @@ void main() vec4 cin = texture2D(s_tex, v_texcoord0); vec4 cout = vec4(0.0, 0.0, 0.0, cin.a); mat3 xy = mat3(u_chroma_a.xyz, u_chroma_b.xyz, u_chroma_c.xyz); + +#ifdef TRANSPOSED_XYZ_TO_sRGB const mat3 XYZ_TO_sRGB = mat3( 3.2406, -0.9689, 0.0557, -1.5372, 1.8758, -0.2040, -0.4986, 0.0415, 1.0570 ); +#else + const mat3 XYZ_TO_sRGB = mat3( + 3.2406, -1.5372, -0.4986, + -0.9689, 1.8758, 0.0415, + 0.0557, -0.2040, 1.0570 + ); +#endif for (int i = 0; i < 3; ++i) { float Y = u_y_gain[i] * cin[i]; diff --git a/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_palette16.sc b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_palette16.sc new file mode 100644 index 00000000000..82236d954a3 --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_palette16.sc @@ -0,0 +1,19 @@ +$input v_color0, v_texcoord0 + +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz + +#include "common.sh" + +// Samplers +SAMPLER2D(s_tex, 0); +SAMPLER2D(s_pal, 1); + +uniform vec4 u_inv_tex_size1; + +void main() +{ + vec2 palette_uv = texture2D(s_tex, v_texcoord0).rg; + palette_uv.xy = (palette_uv.xy * vec2(256.0, 256.0)) * u_inv_tex_size1.xy; + gl_FragColor = vec4(texture2D(s_pal, palette_uv).rgb, 1.0) * v_color0; +} diff --git a/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_rgb32.sc b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_rgb32.sc new file mode 100644 index 00000000000..4292e6cddc6 --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_rgb32.sc @@ -0,0 +1,14 @@ +$input v_color0, v_texcoord0 + +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz + +#include "common.sh" + +// Samplers +SAMPLER2D(s_tex, 0); + +void main() +{ + gl_FragColor = vec4(texture2D(s_tex, v_texcoord0).rgb, 1.0) * v_color0; +} diff --git a/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_yuy16.sc b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_yuy16.sc new file mode 100644 index 00000000000..7f91cbc2db0 --- /dev/null +++ b/src/osd/modules/render/bgfx/shaders/chains/misc/fs_blit_yuy16.sc @@ -0,0 +1,37 @@ +$input v_color0, v_texcoord0 + +// license:BSD-3-Clause +// copyright-holders:Ryan Holtz + +#include "common.sh" + +// Samplers +SAMPLER2D(s_tex, 0); + +vec4 u_tex_size0; +vec4 u_inv_tex_size0; + +vec3 ycc_to_rgb(float y, float cb, float cr) +{ + float r = saturate(y + 1.40200 * (cr - 0.5)); + float g = saturate(y - 0.34414 * (cb - 0.5) - 0.71414 * (cr - 0.5)); + float b = saturate(y + 1.77200 * (cb - 0.5)); + return vec3(r, g, b); +} + +void main() +{ + vec2 size_minus_one = u_tex_size0.xy - vec2(1.0, 1.0); + vec2 original_uv = round(v_texcoord0.xy * size_minus_one); + float mod_val = mod(original_uv.x, 2.0); + vec2 rounded_uv = round(vec2(original_uv.x - mod_val, original_uv.y)); + vec2 next_uv = rounded_uv + vec2(1.0, 0.0); + vec2 srcpix0 = texture2D(s_tex, rounded_uv / size_minus_one).rg; + vec2 srcpix1 = texture2D(s_tex, next_uv / size_minus_one).rg; + float cr = srcpix1.r; + float cb = srcpix0.r; + if (mod_val < 1.0) + gl_FragColor = vec4(ycc_to_rgb(srcpix0.g, cb, cr), 1.0) * v_color0; + else + gl_FragColor = vec4(ycc_to_rgb(srcpix1.g, cb, cr), 1.0) * v_color0; +} diff --git a/src/osd/modules/render/bgfx/shaders/makefile b/src/osd/modules/render/bgfx/shaders/makefile index 1ca45471b9b..c998f2564d9 100644 --- a/src/osd/modules/render/bgfx/shaders/makefile +++ b/src/osd/modules/render/bgfx/shaders/makefile @@ -12,25 +12,28 @@ SUBDIRS := $(patsubst .,,$(patsubst ./,,$(shell find . -type d))) rebuild: main $(SUBDIRS) endif +.NOTPARALLEL: $(SUBDIRS): @echo $@ ifeq ($(OS),windows) - @make -s --no-print-directory TARGET=0 SHADERS_DIR=$@/ clean all - @make -s --no-print-directory TARGET=1 SHADERS_DIR=$@/ clean all + $(SILENT) $(MAKE) --no-print-directory TARGET=0 SHADERS_DIR=$@/ clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=1 SHADERS_DIR=$@/ clean all SILENT="$(SILENT)" endif - @make -s --no-print-directory TARGET=2 SHADERS_DIR=$@/ clean all - @make -s --no-print-directory TARGET=3 SHADERS_DIR=$@/ clean all - @make -s --no-print-directory TARGET=4 SHADERS_DIR=$@/ clean all - @make -s --no-print-directory TARGET=5 SHADERS_DIR=$@/ clean all + $(SILENT) $(MAKE) --no-print-directory TARGET=2 SHADERS_DIR=$@/ clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=3 SHADERS_DIR=$@/ clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=4 SHADERS_DIR=$@/ clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=5 SHADERS_DIR=$@/ clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=7 SHADERS_DIR=$@/ clean all SILENT="$(SILENT)" main: ifeq ($(OS),windows) - @make -s --no-print-directory TARGET=0 clean all - @make -s --no-print-directory TARGET=1 clean all + $(SILENT) $(MAKE) --no-print-directory TARGET=0 clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=1 clean all SILENT="$(SILENT)" endif - @make -s --no-print-directory TARGET=2 clean all - @make -s --no-print-directory TARGET=3 clean all - @make -s --no-print-directory TARGET=4 clean all - @make -s --no-print-directory TARGET=5 clean all + $(SILENT) $(MAKE) --no-print-directory TARGET=2 clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=3 clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=4 clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=5 clean all SILENT="$(SILENT)" + $(SILENT) $(MAKE) --no-print-directory TARGET=7 clean all SILENT="$(SILENT)" .PHONY: main rebuild $(SUBDIRS) diff --git a/src/osd/modules/render/bgfx/shaders/shader.mk b/src/osd/modules/render/bgfx/shaders/shader.mk index e7db3cdc242..b9cf2f47cef 100644 --- a/src/osd/modules/render/bgfx/shaders/shader.mk +++ b/src/osd/modules/render/bgfx/shaders/shader.mk @@ -43,24 +43,24 @@ SHADER_PATH=shaders/dx11/$(SHADERS_DIR) else ifeq ($(TARGET), 2) VS_FLAGS=--platform nacl -FS_FLAGS=--platform nacl +FS_FLAGS=--platform nacl --define TRANSPOSED_XYZ_TO_sRGB SHADER_PATH=shaders/essl/$(SHADERS_DIR) else ifeq ($(TARGET), 3) VS_FLAGS=--platform android -FS_FLAGS=--platform android +FS_FLAGS=--platform android --define TRANSPOSED_XYZ_TO_sRGB CS_FLAGS=--platform android SHADER_PATH=shaders/essl/$(SHADERS_DIR) else ifeq ($(TARGET), 4) VS_FLAGS=--platform linux -p 120 -FS_FLAGS=--platform linux -p 120 +FS_FLAGS=--platform linux -p 120 --define TRANSPOSED_XYZ_TO_sRGB CS_FLAGS=--platform linux -p 430 SHADER_PATH=shaders/glsl/$(SHADERS_DIR) else ifeq ($(TARGET), 5) VS_FLAGS=--platform osx -p metal -FS_FLAGS=--platform osx -p metal +FS_FLAGS=--platform osx -p metal --define TRANSPOSED_XYZ_TO_sRGB CS_FLAGS=--platform osx -p metal SHADER_PATH=shaders/metal/$(SHADERS_DIR) else diff --git a/src/osd/modules/render/bgfx/suppressorreader.cpp b/src/osd/modules/render/bgfx/suppressorreader.cpp index 77a109a264b..024a99e20f8 100644 --- a/src/osd/modules/render/bgfx/suppressorreader.cpp +++ b/src/osd/modules/render/bgfx/suppressorreader.cpp @@ -77,6 +77,7 @@ bgfx_suppressor* suppressor_reader::read_from_value(const Value& value, std::str bool suppressor_reader::validate_parameters(const Value& value, std::string prefix) { + if (!READER_CHECK(value["type"].IsString(), (prefix + "Value 'type' must be a string\n").c_str())) return false; if (!READER_CHECK(value.HasMember("name"), (prefix + "Must have string value 'name'\n").c_str())) return false; if (!READER_CHECK(value["name"].IsString(), (prefix + "Value 'name' must be a string\n").c_str())) return false; if (!READER_CHECK(value.HasMember("value"), (prefix + "Must have numeric or array value 'value'\n").c_str())) return false; diff --git a/src/osd/modules/render/bgfx/texture.cpp b/src/osd/modules/render/bgfx/texture.cpp index ecbf51121ab..7b6747e0c54 100644 --- a/src/osd/modules/render/bgfx/texture.cpp +++ b/src/osd/modules/render/bgfx/texture.cpp @@ -32,7 +32,7 @@ bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, u } } -bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags) +bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags, uint16_t pitch) : m_name(name) , m_format(format) , m_width(width) @@ -40,10 +40,16 @@ bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, u { bgfx::TextureInfo info; bgfx::calcTextureSize(info, width, height, 1, false, false, 1, format); - m_texture = bgfx::createTexture2D(width, height, false, 1, format, flags, data); + m_texture = bgfx::createTexture2D(width, height, false, 1, format, flags, nullptr); + bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, width, height, data, pitch); } bgfx_texture::~bgfx_texture() { bgfx::destroy(m_texture); } + +void bgfx_texture::update(const bgfx::Memory *data, uint16_t pitch) +{ + bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, m_width, m_height, data, pitch); +} diff --git a/src/osd/modules/render/bgfx/texture.h b/src/osd/modules/render/bgfx/texture.h index 7cb6d988150..1d5b1dd9f6d 100644 --- a/src/osd/modules/render/bgfx/texture.h +++ b/src/osd/modules/render/bgfx/texture.h @@ -21,7 +21,7 @@ class bgfx_texture : public bgfx_texture_handle_provider { public: bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, uint32_t flags, void* data); - bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags = BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP); + bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags = BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP, uint16_t pitch = UINT16_MAX); virtual ~bgfx_texture(); // Getters @@ -34,6 +34,8 @@ public: virtual bgfx::TextureHandle texture() const override { return m_texture; } virtual bool is_target() const override { return false; } + void update(const bgfx::Memory *data, uint16_t pitch = UINT16_MAX); + protected: std::string m_name; bgfx::TextureFormat::Enum m_format; diff --git a/src/osd/modules/render/bgfx/texturemanager.cpp b/src/osd/modules/render/bgfx/texturemanager.cpp index a5fbca97f35..e2614133205 100644 --- a/src/osd/modules/render/bgfx/texturemanager.cpp +++ b/src/osd/modules/render/bgfx/texturemanager.cpp @@ -116,8 +116,10 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form } else { - const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(format, width, height, rowpixels, palette, base); - bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)width, (uint16_t)height, mem); + bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::BGRA8; + uint16_t pitch = width; + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, width, height, rowpixels, palette, base, &pitch); + bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)width, (uint16_t)height, mem, pitch); return handle; } } @@ -142,8 +144,10 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form } else { - const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(format, width, height, rowpixels, palette, base); - bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)width, (uint16_t)height, mem); + bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::BGRA8; + uint16_t pitch = width; + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, width, height, rowpixels, palette, base, &pitch); + bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)width, (uint16_t)height, mem, pitch); return handle; } } @@ -151,9 +155,11 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form } } - const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(format, width, height, rowpixels, palette, base); - handle = bgfx::createTexture2D(width, height, false, 1, bgfx::TextureFormat::RGBA8, flags, nullptr); - bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)width, (uint16_t)height, mem); + bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::BGRA8; + uint16_t pitch = width; + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, width, height, rowpixels, palette, base, &pitch); + handle = bgfx::createTexture2D(width, height, false, 1, dst_format, flags, nullptr); + bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)width, (uint16_t)height, mem, pitch); m_mame_textures[key] = { handle, seqid, width, height }; return handle; diff --git a/src/osd/modules/render/bgfx/uniform.cpp b/src/osd/modules/render/bgfx/uniform.cpp index ef33c11f128..dc81475ad59 100644 --- a/src/osd/modules/render/bgfx/uniform.cpp +++ b/src/osd/modules/render/bgfx/uniform.cpp @@ -29,7 +29,7 @@ bgfx_uniform::~bgfx_uniform() void bgfx_uniform::upload() { - if (m_type != bgfx::UniformType::Int1) + if (m_type != bgfx::UniformType::Sampler) { bgfx::setUniform(m_handle, m_data); } @@ -42,7 +42,7 @@ bgfx_uniform* bgfx_uniform::set(float* value) bgfx_uniform* bgfx_uniform::set_int(int value) { - return set(&value, get_size_for_type(bgfx::UniformType::Int1)); + return set(&value, get_size_for_type(bgfx::UniformType::Sampler)); } bgfx_uniform* bgfx_uniform::set_mat3(float* value) @@ -69,7 +69,7 @@ size_t bgfx_uniform::get_size_for_type(bgfx::UniformType::Enum type) case bgfx::UniformType::Vec4: return sizeof(float) * 4; - case bgfx::UniformType::Int1: + case bgfx::UniformType::Sampler: return sizeof(int); case bgfx::UniformType::Mat3: diff --git a/src/osd/modules/render/bgfx/uniformreader.cpp b/src/osd/modules/render/bgfx/uniformreader.cpp index 3e3cb5db318..c97ca484e48 100644 --- a/src/osd/modules/render/bgfx/uniformreader.cpp +++ b/src/osd/modules/render/bgfx/uniformreader.cpp @@ -11,7 +11,7 @@ #include "uniform.h" const uniform_reader::string_to_enum uniform_reader::TYPE_NAMES[uniform_reader::TYPE_COUNT] = { - { "int", bgfx::UniformType::Int1 }, + { "int", bgfx::UniformType::Sampler }, { "vec4", bgfx::UniformType::Vec4 }, { "mat3", bgfx::UniformType::Mat3 }, { "mat4", bgfx::UniformType::Mat4 } diff --git a/src/osd/modules/render/bgfx/vertex.h b/src/osd/modules/render/bgfx/vertex.h index 32b3c36064f..2036296a9d0 100644 --- a/src/osd/modules/render/bgfx/vertex.h +++ b/src/osd/modules/render/bgfx/vertex.h @@ -31,7 +31,7 @@ struct ScreenVertex .end(); } - static bgfx::VertexDecl ms_decl; + static bgfx::VertexLayout ms_decl; }; #endif // __DRAWBGFX_VERTEX__ diff --git a/src/osd/modules/render/bgfxutil.cpp b/src/osd/modules/render/bgfxutil.cpp index 5ba76cbd2a1..7114b6008d8 100644 --- a/src/osd/modules/render/bgfxutil.cpp +++ b/src/osd/modules/render/bgfxutil.cpp @@ -14,37 +14,57 @@ #include "render.h" -const bgfx::Memory* bgfx_util::mame_texture_data_to_bgfx_texture_data(uint32_t format, int width, int height, int rowpixels, const rgb_t *palette, void *base) +const bgfx::Memory* bgfx_util::mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t src_format, int width, int height, int rowpixels, const rgb_t *palette, void *base, uint16_t *out_pitch) { - const bgfx::Memory* mem = bgfx::alloc(width * height * 4); - uint32_t* data = reinterpret_cast<uint32_t*>(mem->data); + bgfx::TextureInfo info; + switch (src_format) + { + case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16): + case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16): + dst_format = bgfx::TextureFormat::RG8; + if (out_pitch) + *out_pitch = rowpixels * 2; + break; + case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32): + case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32): + dst_format = bgfx::TextureFormat::BGRA8; + if (out_pitch) + *out_pitch = rowpixels * 4; + break; + } + bgfx::calcTextureSize(info, rowpixels, height, 1, false, false, 1, dst_format); + return bgfx::copy(base, info.storageSize); + /*const bgfx::Memory* mem = bgfx::alloc(width * height * 4); + uint32_t* dst = reinterpret_cast<uint32_t*>(mem->data); uint16_t* src16 = reinterpret_cast<uint16_t*>(base); uint32_t* src32 = reinterpret_cast<uint32_t*>(base); for (int y = 0; y < height; y++) { - uint32_t* dst_line = data + y * width; - uint16_t* src_line16 = src16 + y * rowpixels; - uint32_t* src_line32 = src32 + y * rowpixels; switch (format) { - case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16): - copy_util::copyline_palette16(dst_line, src_line16, width, palette); - break; - case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16): - copy_util::copyline_yuy16_to_argb(dst_line, src_line16, width, palette, 1); - break; - case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32): - copy_util::copyline_argb32(dst_line, src_line32, width, palette); - break; - case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32): - copy_util::copyline_rgb32(dst_line, src_line32, width, palette); - break; - default: - break; + case PRIMFLAG_TEXFORMAT(TEXFORMAT_PALETTE16): + copy_util::copyline_palette16(dst, src16, width, palette); + src16 += rowpixels; + break; + case PRIMFLAG_TEXFORMAT(TEXFORMAT_YUY16): + copy_util::copyline_yuy16_to_argb(dst, src16, width, palette, 1); + src16 += rowpixels; + break; + case PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32): + copy_util::copyline_argb32(dst, src32, width, palette); + src32 += rowpixels; + break; + case PRIMFLAG_TEXFORMAT(TEXFORMAT_RGB32): + copy_util::copyline_rgb32(dst, src32, width, palette); + src32 += rowpixels; + break; + default: + break; } + dst += width; } - return mem; + return mem;*/ } uint64_t bgfx_util::get_blend_state(uint32_t blend) diff --git a/src/osd/modules/render/bgfxutil.h b/src/osd/modules/render/bgfxutil.h index c733987ef18..f1311858324 100644 --- a/src/osd/modules/render/bgfxutil.h +++ b/src/osd/modules/render/bgfxutil.h @@ -11,7 +11,7 @@ class bgfx_util { public: - static const bgfx::Memory* mame_texture_data_to_bgfx_texture_data(uint32_t format, int width, int height, int rowpixels, const rgb_t *palette, void *base); + static const bgfx::Memory* mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t format, int width, int height, int rowpixels, const rgb_t *palette, void *base, uint16_t *out_pitch = nullptr); static uint64_t get_blend_state(uint32_t blend); }; diff --git a/src/osd/modules/render/drawbgfx.cpp b/src/osd/modules/render/drawbgfx.cpp index 3c15bc3cf96..a7677905353 100644 --- a/src/osd/modules/render/drawbgfx.cpp +++ b/src/osd/modules/render/drawbgfx.cpp @@ -278,6 +278,11 @@ int renderer_bgfx::create() { init.type = bgfx::RendererType::Direct3D11; } +// Throws exception on exit +// else if (backend == "dx12" || backend == "d3d12") +// { +// init.type = bgfx::RendererType::Direct3D12; +// } else if (backend == "gles") { init.type = bgfx::RendererType::OpenGLES; @@ -286,6 +291,10 @@ int renderer_bgfx::create() { init.type = bgfx::RendererType::OpenGL; } + else if (backend == "vulkan") + { + init.type = bgfx::RendererType::Vulkan; + } else if (backend == "metal") { init.type = bgfx::RendererType::Metal; @@ -441,7 +450,7 @@ int renderer_bgfx::xy_to_render_target(int x, int y, int *xt, int *yt) // drawbgfx_window_draw //============================================================ -bgfx::VertexDecl ScreenVertex::ms_decl; +bgfx::VertexLayout ScreenVertex::ms_decl; void renderer_bgfx::put_packed_quad(render_primitive *prim, uint32_t hash, ScreenVertex* vertices) { @@ -1131,8 +1140,10 @@ void renderer_bgfx::process_atlas_packs(std::vector<std::vector<rectangle_packer continue; } m_hash_to_entry[rect.hash()] = rect; - const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(rect.format(), rect.width(), rect.height(), rect.rowpixels(), rect.palette(), rect.base()); - bgfx::updateTexture2D(m_texture_cache->texture(), 0, 0, rect.x(), rect.y(), rect.width(), rect.height(), mem); + bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::RGBA8; + uint16_t pitch = rect.width(); + const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, rect.format(), rect.width(), rect.height(), rect.rowpixels(), rect.palette(), rect.base(), &pitch); + bgfx::updateTexture2D(m_texture_cache->texture(), 0, 0, rect.x(), rect.y(), rect.width(), rect.height(), mem, pitch); } } } |