mirror of
https://github.com/holub/mame
synced 2025-06-05 12:26:35 +03:00
-bgfx: Corrected a data overrun in the d3d12 backend from allocating only enough texture data for width*height, not rowpixels*height. [Ryan Holtz]
This commit is contained in:
parent
9b482402df
commit
9cc98f0b62
@ -172,46 +172,84 @@ function osdmodulesbuild()
|
||||
MAME_DIR .. "src/osd/modules/render/bgfxutil.h",
|
||||
MAME_DIR .. "src/osd/modules/render/binpacker.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/blendreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/blendreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chain.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chain.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainentry.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainentry.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainentryreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainentryreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainmanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainmanager.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/chainreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/clear.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/clear.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/clearreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/clearreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/cullreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/cullreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/depthreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/depthreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/effect.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/effect.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/effectmanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/effectmanager.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/effectreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/effectreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/entryuniformreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/entryuniformreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/inputpair.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/inputpair.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/frameparameter.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/frameparameter.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/timeparameter.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/timeparameter.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramuniform.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramuniform.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramuniformreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/paramuniformreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/shadermanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/shadermanager.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slider.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slider.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/sliderreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/sliderreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slideruniform.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slideruniform.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slideruniformreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/slideruniformreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/statereader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/statereader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/suppressor.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/suppressor.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/suppressorreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/suppressorreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/target.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/target.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/targetreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/targetreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/targetmanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/targetmanager.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/texture.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/texture.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/texturehandleprovider.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/texturemanager.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/texturemanager.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/uniform.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/uniform.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/uniformreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/uniformreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/valueuniform.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/valueuniform.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/valueuniformreader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/valueuniformreader.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/view.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/view.h",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/writereader.cpp",
|
||||
MAME_DIR .. "src/osd/modules/render/bgfx/writereader.h",
|
||||
}
|
||||
includedirs {
|
||||
MAME_DIR .. "3rdparty/bgfx/examples/common",
|
||||
|
@ -125,7 +125,7 @@ void bgfx_chain::process(chain_manager::screen_prim &prim, int view, int screen,
|
||||
|
||||
for (bgfx_parameter* param : m_params)
|
||||
{
|
||||
param->tick(frameTimeInSeconds* toMs);
|
||||
param->tick(frameTimeInSeconds * toMs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ bgfx_chain_entry::~bgfx_chain_entry()
|
||||
|
||||
void bgfx_chain_entry::submit(int view, chain_manager::screen_prim &prim, texture_manager& textures, uint16_t screen_count, uint16_t screen_width, uint16_t screen_height, float screen_scale_x, float screen_scale_y, float screen_offset_x, float screen_offset_y, uint32_t rotation_type, bool swap_xy, uint64_t blend, int32_t screen)
|
||||
{
|
||||
if (!setup_view(view, screen_width, screen_height, screen))
|
||||
if (!setup_view(textures, view, screen_width, screen_height, screen))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -250,7 +250,7 @@ void bgfx_chain_entry::setup_auto_uniforms(chain_manager::screen_prim &prim, tex
|
||||
setup_screenindex_uniform(screen);
|
||||
}
|
||||
|
||||
bool bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t screen_height, int32_t screen) const
|
||||
bool bgfx_chain_entry::setup_view(texture_manager &textures, int view, uint16_t screen_width, uint16_t screen_height, int32_t screen) const
|
||||
{
|
||||
bgfx::FrameBufferHandle handle = BGFX_INVALID_HANDLE;
|
||||
uint16_t width = screen_width;
|
||||
@ -272,8 +272,11 @@ bool bgfx_chain_entry::setup_view(int view, uint16_t screen_width, uint16_t scre
|
||||
|
||||
const bgfx::Caps* caps = bgfx::getCaps();
|
||||
|
||||
std::string name = m_inputs[0]->texture() + std::to_string(screen);
|
||||
const float right_ratio = (float)textures.provider(name)->width() / textures.provider(name)->rowpixels();
|
||||
|
||||
float projMat[16];
|
||||
bx::mtxOrtho(projMat, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth);
|
||||
bx::mtxOrtho(projMat, 0.0f, right_ratio, 1.0f, 0.0f, 0.0f, 100.0f, 0.0f, caps->homogeneousDepth);
|
||||
bgfx::setViewTransform(view, nullptr, projMat);
|
||||
|
||||
m_clear->bind(view);
|
||||
|
@ -58,7 +58,7 @@ private:
|
||||
void setup_quaddims_uniform(chain_manager::screen_prim &prim) const;
|
||||
void setup_screenindex_uniform(int32_t screen) const;
|
||||
|
||||
bool setup_view(int view, uint16_t screen_width, uint16_t screen_height, int32_t screen) const;
|
||||
bool setup_view(texture_manager& textures, int view, uint16_t screen_width, uint16_t screen_height, int32_t screen) const;
|
||||
void put_screen_buffer(uint16_t screen_width, uint16_t screen_height, uint32_t screen_tint, bgfx::TransientVertexBuffer* buffer) const;
|
||||
|
||||
std::string m_name;
|
||||
|
@ -465,13 +465,13 @@ uint32_t chain_manager::update_screen_textures(uint32_t view, render_primitive *
|
||||
}
|
||||
|
||||
bgfx::TextureFormat::Enum dst_format = bgfx::TextureFormat::RGBA8;
|
||||
uint16_t pitch = tex_width;
|
||||
uint16_t pitch = prim.m_rowpixels;
|
||||
const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, prim.m_flags & PRIMFLAG_TEXFORMAT_MASK,
|
||||
tex_width, tex_height, prim.m_rowpixels, prim.m_prim->texture.palette, prim.m_prim->texture.base, &pitch);
|
||||
prim.m_rowpixels, tex_height, prim.m_prim->texture.palette, prim.m_prim->texture.base, &pitch);
|
||||
|
||||
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);
|
||||
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, prim.m_rowpixels);
|
||||
m_textures.add_provider(full_name, texture);
|
||||
|
||||
if (prim.m_prim->texture.palette)
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
// bgfx_texture_handle_provider
|
||||
virtual uint16_t width() const override { return m_width; }
|
||||
virtual uint16_t height() const override { return m_height; }
|
||||
virtual uint16_t rowpixels() const override { return m_width; }
|
||||
virtual bgfx::TextureHandle texture() const override;
|
||||
virtual bool is_target() const override { return true; }
|
||||
|
||||
|
@ -32,16 +32,17 @@ 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, uint16_t pitch)
|
||||
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, uint16_t rowpixels)
|
||||
: m_name(name)
|
||||
, m_format(format)
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
, m_rowpixels(rowpixels ? rowpixels : width)
|
||||
{
|
||||
bgfx::TextureInfo info;
|
||||
bgfx::calcTextureSize(info, width, height, 1, false, false, 1, format);
|
||||
m_texture = bgfx::createTexture2D(width, height, false, 1, format, flags, nullptr);
|
||||
bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, width, height, data, pitch);
|
||||
bgfx::calcTextureSize(info, m_rowpixels, height, 1, false, false, 1, format);
|
||||
m_texture = bgfx::createTexture2D(m_rowpixels, height, false, 1, format, flags, nullptr);
|
||||
bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, m_rowpixels, height, data, pitch);
|
||||
}
|
||||
|
||||
bgfx_texture::~bgfx_texture()
|
||||
|
@ -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, uint16_t pitch = UINT16_MAX);
|
||||
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, uint16_t rowpixels = 0);
|
||||
virtual ~bgfx_texture();
|
||||
|
||||
// Getters
|
||||
@ -31,6 +31,7 @@ public:
|
||||
// bgfx_texture_handle_provider
|
||||
virtual uint16_t width() const override { return m_width; }
|
||||
virtual uint16_t height() const override { return m_height; }
|
||||
virtual uint16_t rowpixels() const override { return m_rowpixels; }
|
||||
virtual bgfx::TextureHandle texture() const override { return m_texture; }
|
||||
virtual bool is_target() const override { return false; }
|
||||
|
||||
@ -41,6 +42,7 @@ protected:
|
||||
bgfx::TextureFormat::Enum m_format;
|
||||
uint16_t m_width;
|
||||
uint16_t m_height;
|
||||
uint16_t m_rowpixels;
|
||||
bgfx::TextureHandle m_texture;
|
||||
};
|
||||
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
virtual bool is_target() const = 0;
|
||||
virtual uint16_t width() const = 0;
|
||||
virtual uint16_t height() const = 0;
|
||||
virtual uint16_t rowpixels() const = 0;
|
||||
};
|
||||
|
||||
#endif // __DRAWBGFX_TEXTURE_HANDLE_PROVIDER__
|
||||
|
@ -118,7 +118,7 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form
|
||||
{
|
||||
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);
|
||||
const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, palette, base, &pitch);
|
||||
bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)width, (uint16_t)height, mem, pitch);
|
||||
return handle;
|
||||
}
|
||||
@ -146,7 +146,7 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form
|
||||
{
|
||||
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);
|
||||
const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, palette, base, &pitch);
|
||||
bgfx::updateTexture2D(handle, 0, 0, 0, 0, (uint16_t)width, (uint16_t)height, mem, pitch);
|
||||
return handle;
|
||||
}
|
||||
@ -157,7 +157,7 @@ bgfx::TextureHandle texture_manager::create_or_update_mame_texture(uint32_t form
|
||||
|
||||
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);
|
||||
const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, format, rowpixels, height, 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);
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "render.h"
|
||||
|
||||
|
||||
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* bgfx_util::mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t src_format, int rowpixels, int height, const rgb_t *palette, void *base, uint16_t *out_pitch)
|
||||
{
|
||||
bgfx::TextureInfo info;
|
||||
switch (src_format)
|
||||
@ -38,7 +38,7 @@ const bgfx::Memory* bgfx_util::mame_texture_data_to_bgfx_texture_data(bgfx::Text
|
||||
|
||||
const bgfx::Memory* bgfx_util::mame_texture_data_to_argb32(uint32_t src_format, int width, int height, int rowpixels, const rgb_t *palette, void *base)
|
||||
{
|
||||
const bgfx::Memory* mem = bgfx::alloc(width * height * 4);
|
||||
const bgfx::Memory* mem = bgfx::alloc(rowpixels * height * 4);
|
||||
auto* dst = reinterpret_cast<uint32_t*>(mem->data);
|
||||
auto* src16 = reinterpret_cast<uint16_t*>(base);
|
||||
auto* src32 = reinterpret_cast<uint32_t*>(base);
|
||||
|
@ -11,7 +11,7 @@
|
||||
class bgfx_util
|
||||
{
|
||||
public:
|
||||
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 const bgfx::Memory* mame_texture_data_to_bgfx_texture_data(bgfx::TextureFormat::Enum &dst_format, uint32_t format, int width, int height, const rgb_t *palette, void *base, uint16_t *out_pitch = nullptr);
|
||||
static const bgfx::Memory* mame_texture_data_to_argb32(uint32_t src_format, int width, int height, int rowpixels, const rgb_t *palette, void *base);
|
||||
static uint64_t get_blend_state(uint32_t blend);
|
||||
};
|
||||
|
@ -1171,7 +1171,7 @@ void renderer_bgfx::process_atlas_packs(std::vector<std::vector<rectangle_packer
|
||||
m_hash_to_entry[rect.hash()] = rect;
|
||||
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);
|
||||
const bgfx::Memory* mem = bgfx_util::mame_texture_data_to_bgfx_texture_data(dst_format, rect.format(), rect.rowpixels(), rect.height(), rect.palette(), rect.base(), &pitch);
|
||||
bgfx::updateTexture2D(m_texture_cache->texture(), 0, 0, rect.x(), rect.y(), rect.width(), rect.height(), mem, pitch);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user