Misc code cleanups for Direct3D code

Removed unused methods, unused function parameters, redundant casts, doubly linked lists made into singly linked lists, etc.
This commit is contained in:
Giuseppe Gorgoglione 2016-06-30 21:26:36 +02:00
parent 1f0dc8903f
commit 05ae871334
6 changed files with 240 additions and 464 deletions

View File

@ -126,20 +126,13 @@ public:
void set_data(const render_texinfo *texsource, UINT32 flags); void set_data(const render_texinfo *texsource, UINT32 flags);
texture_info * get_next() const { return m_next; } texture_info * get_next() const { return m_next; }
texture_info * get_prev() const { return m_prev; }
UINT32 get_hash() const { return m_hash; } UINT32 get_hash() const { return m_hash; }
void set_next(texture_info *next) { m_next = next; }
void set_prev(texture_info *prev) { m_prev = prev; }
bool paused() const { return m_cur_frame == m_prev_frame; }
void advance_frame() { m_prev_frame = m_cur_frame; }
void increment_frame_count() { m_cur_frame++; } void increment_frame_count() { m_cur_frame++; }
void mask_frame_count(int mask) { m_cur_frame %= mask; } void mask_frame_count(int mask) { m_cur_frame %= mask; }
int get_cur_frame() const { return m_cur_frame; } int get_cur_frame() const { return m_cur_frame; }
int get_prev_frame() const { return m_prev_frame; }
IDirect3DTexture9 * get_tex() const { return m_d3dtex; } IDirect3DTexture9 * get_tex() const { return m_d3dtex; }
IDirect3DSurface9 * get_surface() const { return m_d3dsurface; } IDirect3DSurface9 * get_surface() const { return m_d3dsurface; }
@ -159,7 +152,6 @@ private:
renderer_d3d9 * m_renderer; // renderer pointer renderer_d3d9 * m_renderer; // renderer pointer
texture_info * m_next; // next texture in the list texture_info * m_next; // next texture in the list
texture_info * m_prev; // prev texture in the list
UINT32 m_hash; // hash value for the texture UINT32 m_hash; // hash value for the texture
UINT32 m_flags; // rendering flags UINT32 m_flags; // rendering flags
@ -171,7 +163,6 @@ private:
int m_xborderpix, m_yborderpix; // number of border pixels on X/Y int m_xborderpix, m_yborderpix; // number of border pixels on X/Y
int m_xprescale, m_yprescale; // X/Y prescale factor int m_xprescale, m_yprescale; // X/Y prescale factor
int m_cur_frame; // what is our current frame? int m_cur_frame; // what is our current frame?
int m_prev_frame; // what was our last frame? (used to determine pause state)
IDirect3DTexture9 * m_d3dtex; // Direct3D texture pointer IDirect3DTexture9 * m_d3dtex; // Direct3D texture pointer
IDirect3DSurface9 * m_d3dsurface; // Direct3D offscreen plain surface pointer IDirect3DSurface9 * m_d3dsurface; // Direct3D offscreen plain surface pointer
IDirect3DTexture9 * m_d3dfinaltex; // Direct3D final (post-scaled) texture IDirect3DTexture9 * m_d3dfinaltex; // Direct3D final (post-scaled) texture
@ -181,46 +172,42 @@ private:
class poly_info class poly_info
{ {
public: public:
poly_info() { }
void init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts, void init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
UINT32 flags, texture_info *texture, UINT32 modmode, UINT32 flags, texture_info *texture, UINT32 modmode,
float prim_width, float prim_height); float prim_width, float prim_height)
void init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts, {
UINT32 flags, texture_info *texture, UINT32 modmode, m_type = type;
float line_time, float line_length, m_count = count;
float prim_width, float prim_height); m_numverts = numverts;
m_flags = flags;
m_texture = texture;
m_modmode = modmode;
m_prim_width = prim_width;
m_prim_height = prim_height;
}
// TODO: Remove needless 'get_' prefix D3DPRIMITIVETYPE type() const { return m_type; }
D3DPRIMITIVETYPE get_type() const { return m_type; } UINT32 count() const { return m_count; }
UINT32 get_count() const { return m_count; } UINT32 numverts() const { return m_numverts; }
UINT32 get_vertcount() const { return m_numverts; } UINT32 flags() const { return m_flags; }
UINT32 get_flags() const { return m_flags; }
texture_info * get_texture() const { return m_texture; } texture_info * texture() const { return m_texture; }
DWORD get_modmode() const { return m_modmode; } DWORD modmode() const { return m_modmode; }
float get_line_time() const { return m_line_time; } float prim_width() const { return m_prim_width; }
float get_line_length() const { return m_line_length; } float prim_height() const { return m_prim_height; }
float get_prim_width() const { return m_prim_width; }
float get_prim_height() const { return m_prim_height; }
private: private:
D3DPRIMITIVETYPE m_type; // type of primitive
UINT32 m_count; // total number of primitives
UINT32 m_numverts; // total number of vertices
UINT32 m_flags; // rendering flags
D3DPRIMITIVETYPE m_type; // type of primitive texture_info * m_texture; // pointer to texture info
UINT32 m_count; // total number of primitives DWORD m_modmode; // texture modulation mode
UINT32 m_numverts; // total number of vertices
UINT32 m_flags; // rendering flags
texture_info * m_texture; // pointer to texture info float m_prim_width; // used by quads
DWORD m_modmode; // texture modulation mode float m_prim_height; // used by quads
float m_line_time; // used by vectors
float m_line_length; // used by vectors
float m_prim_width; // used by quads
float m_prim_height; // used by quads
}; };
/* vertex describes a single vertex */ /* vertex describes a single vertex */
@ -234,27 +221,20 @@ struct vertex
}; };
/* line_aa_step is used for drawing antialiased lines */ /* cache_target is a simple linked list containing only a renderable target and texture, used for phosphor effects */
struct line_aa_step
{
float xoffs, yoffs; // X/Y deltas
float weight; // weight contribution
};
/* cache_target is a simple linked list containing only a rednerable target and texture, used for phosphor effects */
class cache_target class cache_target
{ {
public: public:
// construction/destruction // construction/destruction
cache_target(): last_target(nullptr), last_texture(nullptr), target_width(0), target_height(0), width(0), height(0), screen_index(0), next(nullptr), prev(nullptr) cache_target(): target(nullptr), texture(nullptr), target_width(0), target_height(0), width(0), height(0), screen_index(0), next(nullptr), prev(nullptr)
{ } { }
~cache_target(); ~cache_target();
bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_width, int source_height, int target_width, int target_height); bool init(renderer_d3d9 *d3d, int source_width, int source_height, int target_width, int target_height, int screen_index);
IDirect3DSurface9 *last_target; IDirect3DSurface9 *target;
IDirect3DTexture9 *last_texture; IDirect3DTexture9 *texture;
int target_width; int target_width;
int target_height; int target_height;
@ -268,7 +248,7 @@ public:
cache_target *prev; cache_target *prev;
}; };
/* render_target is the information about a Direct3D render target chain */ /* d3d_render_target is the information about a Direct3D render target chain */
class d3d_render_target class d3d_render_target
{ {
public: public:
@ -278,7 +258,7 @@ public:
~d3d_render_target(); ~d3d_render_target();
bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_width, int source_height, int target_width, int target_height); bool init(renderer_d3d9 *d3d, int source_width, int source_height, int target_width, int target_height, int screen_index, int page_index);
int next_index(int index) { return ++index > 1 ? 0 : index; } int next_index(int index) { return ++index > 1 ? 0 : index; }
// real target dimension // real target dimension

View File

@ -43,12 +43,12 @@ static void get_vector(const char *data, int count, float *out, bool report_erro
//============================================================ //============================================================
shaders::shaders() : shaders::shaders() :
d3dintf(nullptr), machine(nullptr), d3d(nullptr), post_fx_enable(false), oversampling_enable(false), paused(true), num_screens(0), curr_screen(0), d3dintf(nullptr), machine(nullptr), d3d(nullptr), post_fx_enable(false), oversampling_enable(false), num_screens(0), curr_screen(0),
shadow_texture(nullptr), options(nullptr), avi_output_file(nullptr), avi_frame(0), avi_copy_surface(nullptr), avi_copy_texture(nullptr), avi_final_target(nullptr), avi_final_texture(nullptr), shadow_texture(nullptr), options(nullptr), avi_output_file(nullptr), avi_frame(0), avi_copy_surface(nullptr), avi_copy_texture(nullptr), avi_final_target(nullptr), avi_final_texture(nullptr),
black_surface(nullptr), black_texture(nullptr), render_snap(false), snap_rendered(false), snap_copy_target(nullptr), snap_copy_texture(nullptr), snap_target(nullptr), snap_texture(nullptr), black_surface(nullptr), black_texture(nullptr), render_snap(false), snap_rendered(false), snap_copy_target(nullptr), snap_copy_texture(nullptr), snap_target(nullptr), snap_texture(nullptr),
snap_width(0), snap_height(0), lines_pending(false), initialized(false), backbuffer(nullptr), curr_effect(nullptr), default_effect(nullptr), prescale_effect(nullptr), post_effect(nullptr), snap_width(0), snap_height(0), initialized(false), backbuffer(nullptr), curr_effect(nullptr), default_effect(nullptr), prescale_effect(nullptr), post_effect(nullptr),
distortion_effect(nullptr), focus_effect(nullptr), phosphor_effect(nullptr), deconverge_effect(nullptr), color_effect(nullptr), ntsc_effect(nullptr), bloom_effect(nullptr), distortion_effect(nullptr), focus_effect(nullptr), phosphor_effect(nullptr), deconverge_effect(nullptr), color_effect(nullptr), ntsc_effect(nullptr), bloom_effect(nullptr),
downsample_effect(nullptr), vector_effect(nullptr), fsfx_vertices(nullptr), curr_texture(nullptr), curr_render_target(nullptr), curr_poly(nullptr), targethead(nullptr), cachehead(nullptr) downsample_effect(nullptr), vector_effect(nullptr), curr_texture(nullptr), curr_render_target(nullptr), curr_poly(nullptr), targethead(nullptr), cachehead(nullptr)
{ {
} }
@ -102,7 +102,7 @@ void shaders::window_save()
HRESULT result = d3d->get_device()->CreateTexture(snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture, nullptr); HRESULT result = d3d->get_device()->CreateTexture(snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture, nullptr);
if (FAILED(result)) if (FAILED(result))
{ {
osd_printf_verbose("Direct3D: Unable to init system-memory target for HLSL snapshot (%08x), bailing\n", (UINT32)result); osd_printf_verbose("Direct3D: Unable to init system-memory target for HLSL snapshot (%08lX), bailing\n", result);
return; return;
} }
snap_copy_texture->GetSurfaceLevel(0, &snap_copy_target); snap_copy_texture->GetSurfaceLevel(0, &snap_copy_target);
@ -110,7 +110,7 @@ void shaders::window_save()
result = d3d->get_device()->CreateTexture(snap_width, snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &snap_texture, nullptr); result = d3d->get_device()->CreateTexture(snap_width, snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &snap_texture, nullptr);
if (FAILED(result)) if (FAILED(result))
{ {
osd_printf_verbose("Direct3D: Unable to init video-memory target for HLSL snapshot (%08x), bailing\n", (UINT32)result); osd_printf_verbose("Direct3D: Unable to init video-memory target for HLSL snapshot (%08lX), bailing\n", result);
return; return;
} }
snap_texture->GetSurfaceLevel(0, &snap_target); snap_texture->GetSurfaceLevel(0, &snap_target);
@ -159,9 +159,9 @@ void shaders::avi_update_snap(IDirect3DSurface9 *surface)
D3DLOCKED_RECT rect; D3DLOCKED_RECT rect;
// if we don't have a bitmap, or if it's not the right size, allocate a new one // if we don't have a bitmap, or if it's not the right size, allocate a new one
if (!avi_snap.valid() || (int)snap_width != avi_snap.width() || (int)snap_height != avi_snap.height()) if (!avi_snap.valid() || snap_width != avi_snap.width() || snap_height != avi_snap.height())
{ {
avi_snap.allocate((int)snap_width, (int)snap_height); avi_snap.allocate(snap_width, snap_height);
} }
// copy the texture // copy the texture
@ -179,7 +179,7 @@ void shaders::avi_update_snap(IDirect3DSurface9 *surface)
} }
// loop over Y // loop over Y
for (int srcy = 0; srcy < (int)snap_height; srcy++) for (int srcy = 0; srcy < snap_height; srcy++)
{ {
DWORD *src = (DWORD *)((BYTE *)rect.pBits + srcy * rect.Pitch); DWORD *src = (DWORD *)((BYTE *)rect.pBits + srcy * rect.Pitch);
UINT32 *dst = &avi_snap.pix32(srcy); UINT32 *dst = &avi_snap.pix32(srcy);
@ -344,7 +344,7 @@ void shaders::record_texture()
//============================================================ //============================================================
// shaders::end_hlsl_avi_recording // shaders::end_avi_recording
//============================================================ //============================================================
void shaders::end_avi_recording() void shaders::end_avi_recording()
@ -403,27 +403,24 @@ void shaders::begin_avi_recording(const char *name)
// create a new temporary movie file // create a new temporary movie file
osd_file::error filerr; osd_file::error filerr;
std::string fullpath; std::string fullpath;
emu_file tempfile(machine->options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
if (name != nullptr)
{ {
emu_file tempfile(machine->options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); filerr = tempfile.open(name);
if (name != nullptr) }
{ else
filerr = tempfile.open(name); {
} filerr = machine->video().open_next(tempfile, "avi");
else }
{
filerr = machine->video().open_next(tempfile, "avi");
}
// compute the frame time // compute the frame time
{ avi_frame_period = attotime::from_seconds(1000) / info.video_timescale;
avi_frame_period = attotime::from_seconds(1000) / info.video_timescale;
}
// if we succeeded, make a copy of the name and create the real file over top // if we succeeded, make a copy of the name and create the real file over top
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
{ {
fullpath = tempfile.fullpath(); fullpath = tempfile.fullpath();
}
} }
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
@ -439,31 +436,30 @@ void shaders::begin_avi_recording(const char *name)
//============================================================ //============================================================
// remove_cache_target - remove an active cache target when // remove_cache_target - remove an active cache target
// refcount hits zero
//============================================================ //============================================================
void shaders::remove_cache_target(cache_target *cache) void shaders::remove_cache_target(cache_target *cache)
{ {
if (cache != nullptr) if (cache == nullptr)
return;
if (cache == cachehead)
{ {
if (cache == cachehead) cachehead = cachehead->next;
{
cachehead = cachehead->next;
}
if (cache->prev != nullptr)
{
cache->prev->next = cache->next;
}
if (cache->next != nullptr)
{
cache->next->prev = cache->prev;
}
global_free(cache);
} }
if (cache->prev != nullptr)
{
cache->prev->next = cache->next;
}
if (cache->next != nullptr)
{
cache->next->prev = cache->prev;
}
global_free(cache);
} }
@ -478,48 +474,40 @@ void shaders::remove_render_target(texture_info *texture)
void shaders::remove_render_target(int source_width, int source_height, UINT32 screen_index, UINT32 page_index) void shaders::remove_render_target(int source_width, int source_height, UINT32 screen_index, UINT32 page_index)
{ {
d3d_render_target *target = find_render_target(source_width, source_height, screen_index, page_index); remove_render_target(find_render_target(source_width, source_height, screen_index, page_index));
if (target != nullptr)
{
remove_render_target(target);
}
} }
void shaders::remove_render_target(d3d_render_target *rt) void shaders::remove_render_target(d3d_render_target *rt)
{ {
if (rt != nullptr) if (rt == nullptr)
return;
if (rt == targethead)
{ {
if (rt == targethead) targethead = targethead->next;
{
targethead = targethead->next;
}
if (rt->prev != nullptr)
{
rt->prev->next = rt->next;
}
if (rt->next != nullptr)
{
rt->next->prev = rt->prev;
}
cache_target *cache = find_cache_target(rt->screen_index, rt->width, rt->height);
if (cache != nullptr)
{
remove_cache_target(cache);
}
int screen_index = rt->screen_index;
int other_page = 1 - rt->page_index;
int width = rt->width;
int height = rt->height;
global_free(rt);
// Remove other double-buffered page (if it exists)
remove_render_target(width, height, screen_index, other_page);
} }
if (rt->prev != nullptr)
{
rt->prev->next = rt->next;
}
if (rt->next != nullptr)
{
rt->next->prev = rt->prev;
}
remove_cache_target(find_cache_target(rt->screen_index, rt->width, rt->height));
int screen_index = rt->screen_index;
int other_page = 1 - rt->page_index;
int width = rt->width;
int height = rt->height;
global_free(rt);
// Remove other double-buffered page (if it exists)
remove_render_target(width, height, screen_index, other_page);
} }
@ -534,12 +522,6 @@ void shaders::set_texture(texture_info *texture)
return; return;
} }
if (texture != nullptr)
{
paused = texture->paused();
texture->advance_frame();
}
// set initial texture to use // set initial texture to use
texture_info *default_texture = d3d->get_default_texture(); texture_info *default_texture = d3d->get_default_texture();
default_effect->set_texture("Diffuse", (texture == nullptr) ? default_texture->get_finaltex() : texture->get_finaltex()); default_effect->set_texture("Diffuse", (texture == nullptr) ? default_texture->get_finaltex() : texture->get_finaltex());
@ -704,76 +686,72 @@ bool shaders::init(d3d_base *d3dintf, running_machine *machine, renderer_d3d9 *r
//============================================================ //============================================================
// shaders::init_fsfx_quad // shaders::init_fsfx_quad
//
// Called always at the start of each frame so that the two
// triangles used for the post-processing effects are always
// at the beginning of the vertex buffer
//============================================================ //============================================================
void shaders::init_fsfx_quad(void *vertbuf) void shaders::init_fsfx_quad()
{ {
// Called at the start of each frame by the D3D code in order to reserve two triangles
// that are guaranteed to be at a fixed position so as to simply use D3DPT_TRIANGLELIST, 0, 2
// instead of having to do bookkeeping about a specific screen quad
if (!enabled()) if (!enabled())
{
return; return;
}
// get a pointer to the vertex buffer vertex *vertbuf = d3d->mesh_alloc(6);
fsfx_vertices = (vertex *)vertbuf; if (vertbuf == nullptr)
if (fsfx_vertices == nullptr)
{
return; return;
}
// fill in the vertexes clockwise // fill in the vertexes clockwise
fsfx_vertices[0].x = 0.0f; vertbuf[0].x = 0.0f;
fsfx_vertices[0].y = 0.0f; vertbuf[0].y = 0.0f;
fsfx_vertices[1].x = d3d->get_width(); vertbuf[1].x = d3d->get_width();
fsfx_vertices[1].y = 0.0f; vertbuf[1].y = 0.0f;
fsfx_vertices[2].x = 0.0f; vertbuf[2].x = 0.0f;
fsfx_vertices[2].y = d3d->get_height(); vertbuf[2].y = d3d->get_height();
fsfx_vertices[3].x = d3d->get_width(); vertbuf[3].x = d3d->get_width();
fsfx_vertices[3].y = 0.0f; vertbuf[3].y = 0.0f;
fsfx_vertices[4].x = 0.0f; vertbuf[4].x = 0.0f;
fsfx_vertices[4].y = d3d->get_height(); vertbuf[4].y = d3d->get_height();
fsfx_vertices[5].x = d3d->get_width(); vertbuf[5].x = d3d->get_width();
fsfx_vertices[5].y = d3d->get_height(); vertbuf[5].y = d3d->get_height();
fsfx_vertices[0].u0 = 0.0f; vertbuf[0].u0 = 0.0f;
fsfx_vertices[0].v0 = 0.0f; vertbuf[0].v0 = 0.0f;
fsfx_vertices[1].u0 = 1.0f; vertbuf[1].u0 = 1.0f;
fsfx_vertices[1].v0 = 0.0f; vertbuf[1].v0 = 0.0f;
fsfx_vertices[2].u0 = 0.0f; vertbuf[2].u0 = 0.0f;
fsfx_vertices[2].v0 = 1.0f; vertbuf[2].v0 = 1.0f;
fsfx_vertices[3].u0 = 1.0f; vertbuf[3].u0 = 1.0f;
fsfx_vertices[3].v0 = 0.0f; vertbuf[3].v0 = 0.0f;
fsfx_vertices[4].u0 = 0.0f; vertbuf[4].u0 = 0.0f;
fsfx_vertices[4].v0 = 1.0f; vertbuf[4].v0 = 1.0f;
fsfx_vertices[5].u0 = 1.0f; vertbuf[5].u0 = 1.0f;
fsfx_vertices[5].v0 = 1.0f; vertbuf[5].v0 = 1.0f;
fsfx_vertices[0].u1 = 0.0f; vertbuf[0].u1 = 0.0f;
fsfx_vertices[0].v1 = 0.0f; vertbuf[0].v1 = 0.0f;
fsfx_vertices[1].u1 = 0.0f; vertbuf[1].u1 = 0.0f;
fsfx_vertices[1].v1 = 0.0f; vertbuf[1].v1 = 0.0f;
fsfx_vertices[2].u1 = 0.0f; vertbuf[2].u1 = 0.0f;
fsfx_vertices[2].v1 = 0.0f; vertbuf[2].v1 = 0.0f;
fsfx_vertices[3].u1 = 0.0f; vertbuf[3].u1 = 0.0f;
fsfx_vertices[3].v1 = 0.0f; vertbuf[3].v1 = 0.0f;
fsfx_vertices[4].u1 = 0.0f; vertbuf[4].u1 = 0.0f;
fsfx_vertices[4].v1 = 0.0f; vertbuf[4].v1 = 0.0f;
fsfx_vertices[5].u1 = 0.0f; vertbuf[5].u1 = 0.0f;
fsfx_vertices[5].v1 = 0.0f; vertbuf[5].v1 = 0.0f;
// set the color, Z parameters to standard values // set the color, Z parameters to standard values
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
fsfx_vertices[i].z = 0.0f; vertbuf[i].z = 0.0f;
fsfx_vertices[i].rhw = 1.0f; vertbuf[i].rhw = 1.0f;
fsfx_vertices[i].color = D3DCOLOR_ARGB(255, 255, 255, 255); vertbuf[i].color = D3DCOLOR_ARGB(255, 255, 255, 255);
} }
} }
@ -804,7 +782,7 @@ int shaders::create_resources()
result = d3d->get_device()->CreateTexture(4, 4, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &black_texture, nullptr); result = d3d->get_device()->CreateTexture(4, 4, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &black_texture, nullptr);
if (FAILED(result)) if (FAILED(result))
{ {
osd_printf_verbose("Direct3D: Unable to init video-memory target for black texture (%08x)\n", (UINT32)result); osd_printf_verbose("Direct3D: Unable to init video-memory target for black texture (%08lX)\n", result);
return 1; return 1;
} }
black_texture->GetSurfaceLevel(0, &black_surface); black_texture->GetSurfaceLevel(0, &black_surface);
@ -818,18 +796,18 @@ int shaders::create_resources()
if (FAILED(result)) if (FAILED(result))
osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result); osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result);
result = d3d->get_device()->CreateTexture((int)snap_width, (int)snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &avi_copy_texture, nullptr); result = d3d->get_device()->CreateTexture(snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &avi_copy_texture, nullptr);
if (FAILED(result)) if (FAILED(result))
{ {
osd_printf_verbose("Direct3D: Unable to init system-memory target for HLSL AVI dumping (%08x)\n", (UINT32)result); osd_printf_verbose("Direct3D: Unable to init system-memory target for HLSL AVI dumping (%08lX)\n", result);
return 1; return 1;
} }
avi_copy_texture->GetSurfaceLevel(0, &avi_copy_surface); avi_copy_texture->GetSurfaceLevel(0, &avi_copy_surface);
result = d3d->get_device()->CreateTexture((int)snap_width, (int)snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &avi_final_texture, nullptr); result = d3d->get_device()->CreateTexture(snap_width, snap_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &avi_final_texture, nullptr);
if (FAILED(result)) if (FAILED(result))
{ {
osd_printf_verbose("Direct3D: Unable to init video-memory target for HLSL AVI dumping (%08x)\n", (UINT32)result); osd_printf_verbose("Direct3D: Unable to init video-memory target for HLSL AVI dumping (%08lX)\n", result);
return 1; return 1;
} }
avi_final_texture->GetSurfaceLevel(0, &avi_final_target); avi_final_texture->GetSurfaceLevel(0, &avi_final_target);
@ -1076,23 +1054,6 @@ void shaders::end_frame()
{ {
render_snapshot(snap_target); render_snapshot(snap_target);
} }
if (!lines_pending)
{
return;
}
lines_pending = false;
}
//============================================================
// shaders::init_effect_info
//============================================================
void shaders::init_effect_info(poly_info *poly)
{
// nothing to do
} }
@ -1144,7 +1105,7 @@ d3d_render_target* shaders::find_render_target(int source_width, int source_heig
// shaders::find_cache_target // shaders::find_cache_target
//============================================================ //============================================================
cache_target* shaders::find_cache_target(UINT32 screen_index, int width, int height) cache_target *shaders::find_cache_target(UINT32 screen_index, int width, int height)
{ {
cache_target *curr = cachehead; cache_target *curr = cachehead;
while (curr != nullptr && ( while (curr != nullptr && (
@ -1310,7 +1271,7 @@ int shaders::phosphor_pass(d3d_render_target *rt, cache_target *ct, int source_i
curr_effect = phosphor_effect; curr_effect = phosphor_effect;
curr_effect->update_uniforms(); curr_effect->update_uniforms();
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
curr_effect->set_texture("LastPass", ct->last_texture); curr_effect->set_texture("LastPass", ct->texture);
curr_effect->set_bool("Passthrough", false); curr_effect->set_bool("Passthrough", false);
next_index = rt->next_index(next_index); next_index = rt->next_index(next_index);
@ -1323,7 +1284,7 @@ int shaders::phosphor_pass(d3d_render_target *rt, cache_target *ct, int source_i
curr_effect->set_bool("Passthrough", true); curr_effect->set_bool("Passthrough", true);
// Avoid changing targets due to page flipping // Avoid changing targets due to page flipping
blit(ct->last_target, true, D3DPT_TRIANGLELIST, 0, 2); blit(ct->target, true, D3DPT_TRIANGLELIST, 0, 2);
return next_index; return next_index;
} }
@ -1483,7 +1444,7 @@ int shaders::vector_pass(d3d_render_target *rt, int source_index, poly_info *pol
curr_effect->set_float("LengthScale", options->vector_length_scale); curr_effect->set_float("LengthScale", options->vector_length_scale);
curr_effect->set_float("BeamSmooth", options->vector_beam_smooth); curr_effect->set_float("BeamSmooth", options->vector_beam_smooth);
blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); blit(rt->target_surface[next_index], true, poly->type(), vertnum, poly->count());
return next_index; return next_index;
} }
@ -1515,11 +1476,11 @@ int shaders::screen_pass(d3d_render_target *rt, int source_index, poly_info *pol
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
// we do not clear the backbuffer here because multiple screens might be rendered into // we do not clear the backbuffer here because multiple screens might be rendered into
blit(backbuffer, false, poly->get_type(), vertnum, poly->get_count()); blit(backbuffer, false, poly->type(), vertnum, poly->count());
if (avi_output_file != nullptr) if (avi_output_file != nullptr)
{ {
blit(avi_final_target, false, poly->get_type(), vertnum, poly->get_count()); blit(avi_final_target, false, poly->type(), vertnum, poly->count());
HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer); HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer);
if (FAILED(result)) if (FAILED(result))
@ -1530,7 +1491,7 @@ int shaders::screen_pass(d3d_render_target *rt, int source_index, poly_info *pol
if (render_snap) if (render_snap)
{ {
blit(snap_target, false, poly->get_type(), vertnum, poly->get_count()); blit(snap_target, false, poly->type(), vertnum, poly->count());
HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer); HRESULT result = d3d->get_device()->SetRenderTarget(0, backbuffer);
if (FAILED(result)) if (FAILED(result))
@ -1550,7 +1511,7 @@ void shaders::ui_pass(poly_info *poly, int vertnum)
curr_effect->update_uniforms(); curr_effect->update_uniforms();
curr_effect->set_technique("UiTechnique"); curr_effect->set_technique("UiTechnique");
blit(nullptr, false, poly->get_type(), vertnum, poly->get_count()); blit(nullptr, false, poly->type(), vertnum, poly->count());
} }
@ -1565,7 +1526,7 @@ void shaders::render_quad(poly_info *poly, int vertnum)
return; return;
} }
curr_texture = poly->get_texture(); curr_texture = poly->texture();
curr_poly = poly; curr_poly = poly;
auto win = d3d->assert_window(); auto win = d3d->assert_window();
@ -1617,12 +1578,10 @@ void shaders::render_quad(poly_info *poly, int vertnum)
curr_screen++; curr_screen++;
} }
else if (PRIMFLAG_GET_VECTOR(poly->get_flags())) else if (PRIMFLAG_GET_VECTOR(poly->flags()))
{ {
lines_pending = true; int source_width = int(poly->prim_width() + 0.5f);
int source_height = int(poly->prim_height() + 0.5f);
int source_width = int(poly->get_prim_width() + 0.5f);
int source_height = int(poly->get_prim_height() + 0.5f);
if (win->swap_xy()) if (win->swap_xy())
{ {
std::swap(source_width, source_height); std::swap(source_width, source_height);
@ -1646,12 +1605,12 @@ void shaders::render_quad(poly_info *poly, int vertnum)
osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result); osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result);
} }
} }
else if (PRIMFLAG_GET_VECTORBUF(poly->get_flags())) else if (PRIMFLAG_GET_VECTORBUF(poly->flags()))
{ {
curr_screen = curr_screen < num_screens ? curr_screen : 0; curr_screen = curr_screen < num_screens ? curr_screen : 0;
int source_width = int(poly->get_prim_width() + 0.5f); int source_width = int(poly->prim_width() + 0.5f);
int source_height = int(poly->get_prim_height() + 0.5f); int source_height = int(poly->prim_height() + 0.5f);
if (win->swap_xy()) if (win->swap_xy())
{ {
std::swap(source_width, source_height); std::swap(source_width, source_height);
@ -1698,8 +1657,6 @@ void shaders::render_quad(poly_info *poly, int vertnum)
osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result); osd_printf_verbose("Direct3D: Error %08lX during device SetRenderTarget call\n", result);
} }
lines_pending = false;
curr_screen++; curr_screen++;
} }
else else
@ -1738,13 +1695,12 @@ bool shaders::add_cache_target(renderer_d3d9* d3d, texture_info* texture, int so
{ {
cache_target* target = (cache_target*)global_alloc_clear<cache_target>(); cache_target* target = (cache_target*)global_alloc_clear<cache_target>();
if (!target->init(d3d, d3dintf, source_width, source_height, target_width, target_height)) if (!target->init(d3d, source_width, source_height, target_width, target_height, screen_index))
{ {
global_free(target); global_free(target);
return false; return false;
} }
target->screen_index = screen_index;
target->next = cachehead; target->next = cachehead;
target->prev = nullptr; target->prev = nullptr;
@ -1758,7 +1714,7 @@ bool shaders::add_cache_target(renderer_d3d9* d3d, texture_info* texture, int so
} }
//============================================================ //============================================================
// shaders::get_texture_target(render_primitive::prim, texture_info::texture) // shaders::get_texture_target
//============================================================ //============================================================
d3d_render_target* shaders::get_texture_target(render_primitive *prim, texture_info *texture) d3d_render_target* shaders::get_texture_target(render_primitive *prim, texture_info *texture)
@ -1900,14 +1856,12 @@ bool shaders::add_render_target(renderer_d3d9* d3d, render_primitive *prim, text
d3d_render_target* target = (d3d_render_target*)global_alloc_clear<d3d_render_target>(); d3d_render_target* target = (d3d_render_target*)global_alloc_clear<d3d_render_target>();
if (!target->init(d3d, d3dintf, source_width, source_height, target_width, target_height)) if (!target->init(d3d, source_width, source_height, target_width, target_height, screen_index, page_index))
{ {
global_free(target); global_free(target);
return false; return false;
} }
target->screen_index = screen_index;
target->page_index = page_index;
target->next = targethead; target->next = targethead;
target->prev = nullptr; target->prev = nullptr;
@ -2197,7 +2151,6 @@ INT32 slider::update(std::string *str, INT32 newval)
case SLIDER_INT_ENUM: case SLIDER_INT_ENUM:
{ {
INT32 *val_ptr = reinterpret_cast<INT32 *>(m_value); INT32 *val_ptr = reinterpret_cast<INT32 *>(m_value);
*m_dirty = true;
if (newval != SLIDER_NOCHANGE) if (newval != SLIDER_NOCHANGE)
{ {
*val_ptr = newval; *val_ptr = newval;
@ -2212,7 +2165,6 @@ INT32 slider::update(std::string *str, INT32 newval)
case SLIDER_INT: case SLIDER_INT:
{ {
int *val_ptr = reinterpret_cast<int *>(m_value); int *val_ptr = reinterpret_cast<int *>(m_value);
*m_dirty = true;
if (newval != SLIDER_NOCHANGE) if (newval != SLIDER_NOCHANGE)
{ {
*val_ptr = newval; *val_ptr = newval;
@ -2227,7 +2179,6 @@ INT32 slider::update(std::string *str, INT32 newval)
default: default:
{ {
float *val_ptr = reinterpret_cast<float *>(m_value); float *val_ptr = reinterpret_cast<float *>(m_value);
*m_dirty = true;
if (newval != SLIDER_NOCHANGE) if (newval != SLIDER_NOCHANGE)
{ {
*val_ptr = (float)newval * m_desc->scale; *val_ptr = (float)newval * m_desc->scale;
@ -2561,35 +2512,7 @@ uniform::uniform(effect *shader, const char *name, uniform_type type, int id)
m_type = type; m_type = type;
m_next = nullptr; m_next = nullptr;
m_handle = m_shader->get_parameter(nullptr, name); m_handle = m_shader->get_parameter(nullptr, name);
m_ival = 0;
m_bval = false;
memset(m_vec, 0, sizeof(float) * 4);
m_mval = nullptr;
m_texture = nullptr;
m_id = id; m_id = id;
switch (type)
{
case UT_BOOL:
case UT_INT:
case UT_FLOAT:
case UT_MATRIX:
case UT_SAMPLER:
m_count = 1;
break;
case UT_VEC2:
m_count = 2;
break;
case UT_VEC3:
m_count = 3;
break;
case UT_VEC4:
m_count = 4;
break;
default:
m_count = 1;
break;
}
} }
void uniform::set_next(uniform *next) void uniform::set_next(uniform *next)
@ -2663,8 +2586,8 @@ void uniform::update()
{ {
float quaddims[2] = { float quaddims[2] = {
// round // round
static_cast<float>(static_cast<int>(shadersys->curr_poly->get_prim_width() + 0.5f)), static_cast<float>(static_cast<int>(shadersys->curr_poly->prim_width() + 0.5f)),
static_cast<float>(static_cast<int>(shadersys->curr_poly->get_prim_height() + 0.5f)) }; static_cast<float>(static_cast<int>(shadersys->curr_poly->prim_height() + 0.5f)) };
m_shader->set_vector("QuadDims", 2, quaddims); m_shader->set_vector("QuadDims", 2, quaddims);
} }
break; break;
@ -2841,79 +2764,6 @@ void uniform::update()
} }
} }
void uniform::set(float x, float y, float z, float w)
{
m_vec[0] = x;
m_vec[1] = y;
m_vec[2] = z;
m_vec[3] = w;
}
void uniform::set(float x, float y, float z)
{
m_vec[0] = x;
m_vec[1] = y;
m_vec[2] = z;
}
void uniform::set(float x, float y)
{
m_vec[0] = x;
m_vec[1] = y;
}
void uniform::set(float x)
{
m_vec[0] = x;
}
void uniform::set(int x)
{
m_ival = x;
}
void uniform::set(bool x)
{
m_bval = x;
}
void uniform::set(D3DMATRIX *mat)
{
m_mval = mat;
}
void uniform::set(IDirect3DTexture9 *tex)
{
m_texture = tex;
}
void uniform::upload()
{
switch (m_type)
{
case UT_BOOL:
m_shader->set_bool(m_handle, m_bval);
break;
case UT_INT:
m_shader->set_int(m_handle, m_ival);
break;
case UT_FLOAT:
m_shader->set_float(m_handle, m_vec[0]);
break;
case UT_VEC2:
case UT_VEC3:
case UT_VEC4:
m_shader->set_vector(m_handle, m_count, m_vec);
break;
case UT_MATRIX:
m_shader->set_matrix(m_handle, m_mval);
break;
case UT_SAMPLER:
m_shader->set_texture(m_handle, m_texture);
break;
}
}
//============================================================ //============================================================
// effect functions // effect functions
@ -2926,7 +2776,6 @@ effect::effect(shaders *shadersys, IDirect3DDevice9 *dev, const char *name, cons
m_shaders = shadersys; m_shaders = shadersys;
m_uniform_head = nullptr; m_uniform_head = nullptr;
m_uniform_tail = nullptr; m_uniform_tail = nullptr;
m_effect = nullptr;
m_valid = false; m_valid = false;
char name_cstr[1024]; char name_cstr[1024];
@ -2939,11 +2788,11 @@ effect::effect(shaders *shadersys, IDirect3DDevice9 *dev, const char *name, cons
if (buffer_errors != nullptr) if (buffer_errors != nullptr)
{ {
LPVOID compile_errors = buffer_errors->GetBufferPointer(); LPVOID compile_errors = buffer_errors->GetBufferPointer();
printf("Unable to compile shader: %s\n", (const char*)compile_errors); fflush(stdout); osd_printf_verbose("Unable to compile shader: %s\n", (const char*)compile_errors);
} }
else else
{ {
printf("Shader %s is missing, corrupt or cannot be compiled.\n", (const char*)name); fflush(stdout); osd_printf_verbose("Shader %s is missing, corrupt or cannot be compiled.\n", (const char*)name);
} }
} }
else else
@ -3060,9 +2909,9 @@ void effect::set_bool(D3DXHANDLE param, bool value)
m_effect->SetBool(param, value); m_effect->SetBool(param, value);
} }
void effect::set_matrix(D3DXHANDLE param, D3DMATRIX *matrix) void effect::set_matrix(D3DXHANDLE param, D3DXMATRIX *matrix)
{ {
m_effect->SetMatrix(param, (D3DXMATRIX*)matrix); m_effect->SetMatrix(param, matrix);
} }
void effect::set_texture(D3DXHANDLE param, IDirect3DTexture9 *tex) void effect::set_texture(D3DXHANDLE param, IDirect3DTexture9 *tex)
@ -3074,8 +2923,3 @@ D3DXHANDLE effect::get_parameter(D3DXHANDLE param, const char *name)
{ {
return m_effect->GetParameterByName(param, name); return m_effect->GetParameterByName(param, name);
} }
ULONG effect::release()
{
return m_effect->Release();
}

View File

@ -77,7 +77,6 @@ public:
CU_FOCUS_SIZE, CU_FOCUS_SIZE,
CU_PHOSPHOR_LIFE, CU_PHOSPHOR_LIFE,
CU_PHOSPHOR_IGNORE,
CU_POST_VIGNETTING, CU_POST_VIGNETTING,
CU_POST_DISTORTION, CU_POST_DISTORTION,
@ -108,27 +107,11 @@ public:
void set_next(uniform *next); void set_next(uniform *next);
uniform * get_next() { return m_next; } uniform * get_next() { return m_next; }
void set(float x, float y, float z, float w);
void set(float x, float y, float z);
void set(float x, float y);
void set(float x);
void set(int x);
void set(bool x);
void set(D3DMATRIX *mat);
void set(IDirect3DTexture9 *tex);
void upload();
void update(); void update();
protected: protected:
uniform *m_next; uniform *m_next;
float m_vec[4];
int m_ival;
bool m_bval;
D3DMATRIX *m_mval;
IDirect3DTexture9 *m_texture;
int m_count;
uniform_type m_type; uniform_type m_type;
int m_id; int m_id;
@ -156,7 +139,7 @@ public:
void set_float(D3DXHANDLE param, float value); void set_float(D3DXHANDLE param, float value);
void set_int(D3DXHANDLE param, int value); void set_int(D3DXHANDLE param, int value);
void set_bool(D3DXHANDLE param, bool value); void set_bool(D3DXHANDLE param, bool value);
void set_matrix(D3DXHANDLE param, D3DMATRIX *matrix); void set_matrix(D3DXHANDLE param, D3DXMATRIX *matrix);
void set_texture(D3DXHANDLE param, IDirect3DTexture9 *tex); void set_texture(D3DXHANDLE param, IDirect3DTexture9 *tex);
void add_uniform(const char *name, uniform::uniform_type type, int id); void add_uniform(const char *name, uniform::uniform_type type, int id);
@ -164,8 +147,6 @@ public:
D3DXHANDLE get_parameter(D3DXHANDLE param, const char *name); D3DXHANDLE get_parameter(D3DXHANDLE param, const char *name);
ULONG release();
shaders* get_shaders() { return m_shaders; } shaders* get_shaders() { return m_shaders; }
bool is_valid() { return m_valid; } bool is_valid() { return m_valid; }
@ -281,14 +262,13 @@ struct slider_desc
class slider class slider
{ {
public: public:
slider(slider_desc *desc, void *value, bool *dirty) : m_desc(desc), m_value(value), m_dirty(dirty) { } slider(slider_desc *desc, void *value, bool *dirty) : m_desc(desc), m_value(value) { }
INT32 update(std::string *str, INT32 newval); INT32 update(std::string *str, INT32 newval);
private: private:
slider_desc * m_desc; slider_desc * m_desc;
void * m_value; void * m_value;
bool * m_dirty;
}; };
class shaders : public slider_changed_notifier class shaders : public slider_changed_notifier
@ -315,7 +295,6 @@ public:
void begin_draw(); void begin_draw();
void end_draw(); void end_draw();
void init_effect_info(poly_info *poly);
void render_quad(poly_info *poly, int vertnum); void render_quad(poly_info *poly, int vertnum);
bool register_texture(render_primitive *prim, texture_info *texture); bool register_texture(render_primitive *prim, texture_info *texture);
@ -330,7 +309,7 @@ public:
void avi_update_snap(IDirect3DSurface9 *surface); void avi_update_snap(IDirect3DSurface9 *surface);
void render_snapshot(IDirect3DSurface9 *surface); void render_snapshot(IDirect3DSurface9 *surface);
void record_texture(); void record_texture();
void init_fsfx_quad(void *vertbuf); void init_fsfx_quad();
void set_texture(texture_info *info); void set_texture(texture_info *info);
d3d_render_target * find_render_target(texture_info *texture); d3d_render_target * find_render_target(texture_info *texture);
@ -384,7 +363,6 @@ private:
bool post_fx_enable; // overall enable flag bool post_fx_enable; // overall enable flag
bool oversampling_enable; // oversampling enable flag bool oversampling_enable; // oversampling enable flag
bool paused; // whether or not rendering is currently paused
int num_screens; // number of emulated physical screens int num_screens; // number of emulated physical screens
int curr_screen; // current screen for render target operations int curr_screen; // current screen for render target operations
bitmap_argb32 shadow_bitmap; // shadow mask bitmap for post-processing shader bitmap_argb32 shadow_bitmap; // shadow mask bitmap for post-processing shader
@ -412,7 +390,6 @@ private:
IDirect3DTexture9 * snap_texture; // snapshot upscaled texture IDirect3DTexture9 * snap_texture; // snapshot upscaled texture
int snap_width; // snapshot width int snap_width; // snapshot width
int snap_height; // snapshot height int snap_height; // snapshot height
bool lines_pending; // whether or not we have lines to flush on the next quad
bool initialized; // whether or not we're initialized bool initialized; // whether or not we're initialized
@ -431,7 +408,6 @@ private:
effect * bloom_effect; // pointer to the bloom composite effect effect * bloom_effect; // pointer to the bloom composite effect
effect * downsample_effect; // pointer to the bloom downsample effect effect * downsample_effect; // pointer to the bloom downsample effect
effect * vector_effect; // pointer to the vector-effect object effect * vector_effect; // pointer to the vector-effect object
vertex * fsfx_vertices; // pointer to our full-screen-quad object
texture_info * curr_texture; texture_info * curr_texture;
d3d_render_target * curr_render_target; d3d_render_target * curr_render_target;

View File

@ -302,10 +302,30 @@ void renderer_d3d9::set_blendmode(int blendmode)
switch (blendmode) switch (blendmode)
{ {
default: default:
case BLENDMODE_NONE: blendenable = FALSE; blendop = D3DBLENDOP_ADD; blendsrc = D3DBLEND_SRCALPHA; blenddst = D3DBLEND_INVSRCALPHA; break; case BLENDMODE_NONE:
case BLENDMODE_ALPHA: blendenable = TRUE; blendop = D3DBLENDOP_ADD; blendsrc = D3DBLEND_SRCALPHA; blenddst = D3DBLEND_INVSRCALPHA; break; blendenable = FALSE;
case BLENDMODE_RGB_MULTIPLY: blendenable = TRUE; blendop = D3DBLENDOP_ADD; blendsrc = D3DBLEND_DESTCOLOR; blenddst = D3DBLEND_ZERO; break; blendop = D3DBLENDOP_ADD;
case BLENDMODE_ADD: blendenable = TRUE; blendop = D3DBLENDOP_ADD; blendsrc = D3DBLEND_SRCALPHA; blenddst = D3DBLEND_ONE; break; blendsrc = D3DBLEND_SRCALPHA;
blenddst = D3DBLEND_INVSRCALPHA;
break;
case BLENDMODE_ALPHA:
blendenable = TRUE;
blendop = D3DBLENDOP_ADD;
blendsrc = D3DBLEND_SRCALPHA;
blenddst = D3DBLEND_INVSRCALPHA;
break;
case BLENDMODE_RGB_MULTIPLY:
blendenable = TRUE;
blendop = D3DBLENDOP_ADD;
blendsrc = D3DBLEND_DESTCOLOR;
blenddst = D3DBLEND_ZERO;
break;
case BLENDMODE_ADD:
blendenable = TRUE;
blendop = D3DBLENDOP_ADD;
blendsrc = D3DBLEND_SRCALPHA;
blenddst = D3DBLEND_ONE;
break;
} }
// adjust the bits that changed // adjust the bits that changed
@ -522,7 +542,7 @@ renderer_d3d9::renderer_d3d9(std::shared_ptr<osd_window> window)
: osd_renderer(window, FLAG_NONE), m_adapter(0), m_width(0), m_height(0), m_refresh(0), m_create_error_count(0), m_device(nullptr), m_gamma_supported(0), m_pixformat(), : osd_renderer(window, FLAG_NONE), m_adapter(0), m_width(0), m_height(0), m_refresh(0), m_create_error_count(0), m_device(nullptr), m_gamma_supported(0), m_pixformat(),
m_vertexbuf(nullptr), m_lockedbuf(nullptr), m_numverts(0), m_vectorbatch(nullptr), m_batchindex(0), m_numpolys(0), m_toggle(false), m_vertexbuf(nullptr), m_lockedbuf(nullptr), m_numverts(0), m_vectorbatch(nullptr), m_batchindex(0), m_numpolys(0), m_toggle(false),
m_screen_format(), m_last_texture(nullptr), m_last_texture_flags(0), m_last_blendenable(0), m_last_blendop(0), m_last_blendsrc(0), m_last_blenddst(0), m_last_filter(0), m_screen_format(), m_last_texture(nullptr), m_last_texture_flags(0), m_last_blendenable(0), m_last_blendop(0), m_last_blendsrc(0), m_last_blenddst(0), m_last_filter(0),
m_last_wrap(), m_last_modmode(0), m_hlsl_buf(nullptr), m_shaders(nullptr), m_texture_manager(nullptr) m_last_wrap(), m_last_modmode(0), m_shaders(nullptr), m_texture_manager(nullptr)
{ {
} }
@ -609,16 +629,9 @@ void d3d_texture_manager::update_textures()
texture_info *texture = find_texinfo(&prim.texture, prim.flags); texture_info *texture = find_texinfo(&prim.texture, prim.flags);
if (texture == nullptr) if (texture == nullptr)
{ {
if (m_renderer->get_shaders()->enabled()) int prescale = m_renderer->get_shaders()->enabled() ? 1 : win->prescale();
{
// if there isn't one, create a new texture without prescale texture = global_alloc(texture_info(this, &prim.texture, prescale, prim.flags));
texture = global_alloc(texture_info(this, &prim.texture, 1, prim.flags));
}
else
{
// if there isn't one, create a new texture
texture = global_alloc(texture_info(this, &prim.texture, win->prescale(), prim.flags));
}
} }
else else
{ {
@ -677,13 +690,8 @@ void renderer_d3d9::begin_frame()
if (FAILED(result)) if (FAILED(result))
osd_printf_verbose("Direct3D: Error %08lX during device BeginScene call\n", result); osd_printf_verbose("Direct3D: Error %08lX during device BeginScene call\n", result);
m_lockedbuf = nullptr; if (m_shaders->enabled())
m_shaders->init_fsfx_quad();
if(m_shaders->enabled())
{
m_hlsl_buf = (void*)mesh_alloc(6);
m_shaders->init_fsfx_quad(m_hlsl_buf);
}
} }
void renderer_d3d9::process_primitives() void renderer_d3d9::process_primitives()
@ -1519,7 +1527,7 @@ void renderer_d3d9::batch_vectors(int vector_count)
} }
// now add a polygon entry // now add a polygon entry
m_poly[m_numpolys].init(D3DPT_TRIANGLELIST, triangle_count, vertex_count, cached_flags, nullptr, D3DTOP_MODULATE, 0.0f, 1.0f, quad_width, quad_height); m_poly[m_numpolys].init(D3DPT_TRIANGLELIST, triangle_count, vertex_count, cached_flags, nullptr, D3DTOP_MODULATE, quad_width, quad_height);
m_numpolys++; m_numpolys++;
} }
@ -1686,7 +1694,7 @@ void renderer_d3d9::draw_line(const render_primitive &prim)
} }
// now add a polygon entry // now add a polygon entry
m_poly[m_numpolys].init(D3DPT_TRIANGLESTRIP, 2, 4, prim.flags, nullptr, D3DTOP_MODULATE, 0.0f, 1.0f, 0.0f, 0.0f); m_poly[m_numpolys].init(D3DPT_TRIANGLESTRIP, 2, 4, prim.flags, nullptr, D3DTOP_MODULATE, 0.0f, 0.0f);
m_numpolys++; m_numpolys++;
} }
@ -1760,30 +1768,6 @@ void renderer_d3d9::draw_quad(const render_primitive &prim)
m_numpolys++; m_numpolys++;
} }
void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
UINT32 flags, texture_info *texture, UINT32 modmode,
float line_time, float line_length,
float prim_width, float prim_height)
{
init(type, count, numverts, flags, texture, modmode, prim_width, prim_height);
m_line_time = line_time;
m_line_length = line_length;
}
void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
UINT32 flags, texture_info *texture, UINT32 modmode,
float prim_width, float prim_height)
{
m_type = type;
m_count = count;
m_numverts = numverts;
m_flags = flags;
m_texture = texture;
m_modmode = modmode;
m_prim_width = prim_width;
m_prim_height = prim_height;
}
//============================================================ //============================================================
// primitive_alloc // primitive_alloc
@ -1798,11 +1782,8 @@ vertex *renderer_d3d9::mesh_alloc(int numverts)
{ {
primitive_flush_pending(); primitive_flush_pending();
if(m_shaders->enabled()) if (m_shaders->enabled())
{ m_shaders->init_fsfx_quad();
m_hlsl_buf = (void*)mesh_alloc(6);
m_shaders->init_fsfx_quad(m_hlsl_buf);
}
} }
// if we don't have a lock, grab it now // if we don't have a lock, grab it now
@ -1820,6 +1801,7 @@ vertex *renderer_d3d9::mesh_alloc(int numverts)
m_numverts += numverts; m_numverts += numverts;
return &m_lockedbuf[oldverts]; return &m_lockedbuf[oldverts];
} }
return nullptr; return nullptr;
} }
@ -1857,8 +1839,8 @@ void renderer_d3d9::primitive_flush_pending()
// now do the polys // now do the polys
for (int polynum = 0; polynum < m_numpolys; polynum++) for (int polynum = 0; polynum < m_numpolys; polynum++)
{ {
UINT32 flags = m_poly[polynum].get_flags(); UINT32 flags = m_poly[polynum].flags();
texture_info *texture = m_poly[polynum].get_texture(); texture_info *texture = m_poly[polynum].texture();
int newfilter; int newfilter;
// set the texture if different // set the texture if different
@ -1872,21 +1854,19 @@ void renderer_d3d9::primitive_flush_pending()
newfilter = video_config.filter; newfilter = video_config.filter;
set_filter(newfilter); set_filter(newfilter);
set_wrap(PRIMFLAG_GET_TEXWRAP(flags) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP); set_wrap(PRIMFLAG_GET_TEXWRAP(flags) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
set_modmode(m_poly[polynum].get_modmode()); set_modmode(m_poly[polynum].modmode());
m_shaders->init_effect_info(&m_poly[polynum]);
} }
// set the blendmode if different // set the blendmode if different
set_blendmode(PRIMFLAG_GET_BLENDMODE(flags)); set_blendmode(PRIMFLAG_GET_BLENDMODE(flags));
if (vertnum + m_poly[polynum].get_vertcount() > m_numverts) if (vertnum + m_poly[polynum].numverts() > m_numverts)
{ {
osd_printf_error("Error: vertnum (%d) plus poly vertex count (%d) > %d\n", vertnum, m_poly[polynum].get_vertcount(), m_numverts); osd_printf_error("Error: vertnum (%d) plus poly vertex count (%d) > %d\n", vertnum, m_poly[polynum].numverts(), m_numverts);
fflush(stdout); fflush(stdout);
} }
assert(vertnum + m_poly[polynum].get_vertcount() <= m_numverts); assert(vertnum + m_poly[polynum].numverts() <= m_numverts);
if(m_shaders->enabled() && d3dintf->post_fx_available) if(m_shaders->enabled() && d3dintf->post_fx_available)
{ {
@ -1895,12 +1875,12 @@ void renderer_d3d9::primitive_flush_pending()
else else
{ {
// add the primitives // add the primitives
result = m_device->DrawPrimitive(m_poly[polynum].get_type(), vertnum, m_poly[polynum].get_count()); result = m_device->DrawPrimitive(m_poly[polynum].type(), vertnum, m_poly[polynum].count());
if (FAILED(result)) if (FAILED(result))
osd_printf_verbose("Direct3D: Error %08lX during device draw_primitive call\n", result); osd_printf_verbose("Direct3D: Error %08lX during device draw_primitive call\n", result);
} }
vertnum += m_poly[polynum].get_vertcount(); vertnum += m_poly[polynum].numverts();
} }
m_shaders->end_draw(); m_shaders->end_draw();
@ -2126,9 +2106,6 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t
set_data(texsource, flags); set_data(texsource, flags);
// add us to the texture list // add us to the texture list
if(m_texture_manager->get_texlist() != nullptr)
m_texture_manager->get_texlist()->m_prev = this;
m_prev = nullptr;
m_next = m_texture_manager->get_texlist(); m_next = m_texture_manager->get_texlist();
m_texture_manager->set_texlist(this); m_texture_manager->set_texlist(this);
return; return;
@ -2746,12 +2723,12 @@ void texture_info::prescale()
osd_printf_verbose("Direct3D: Error %08lX during device SetTexture call\n", result); osd_printf_verbose("Direct3D: Error %08lX during device SetTexture call\n", result);
// lock the vertex buffer // lock the vertex buffer
result = m_renderer->get_vertex_buffer()->Lock(0, 0, m_renderer->get_locked_buffer_ptr(), D3DLOCK_DISCARD); vertex *lockedbuf;
result = m_renderer->get_vertex_buffer()->Lock(0, 0, (VOID **)&lockedbuf, D3DLOCK_DISCARD);
if (FAILED(result)) if (FAILED(result))
osd_printf_verbose("Direct3D: Error %08lX during vertex buffer lock call\n", result); osd_printf_verbose("Direct3D: Error %08lX during vertex buffer lock call\n", result);
// configure the X/Y coordinates on the target surface // configure the X/Y coordinates on the target surface
vertex *lockedbuf = m_renderer->get_locked_buffer();
lockedbuf[0].x = -0.5f; lockedbuf[0].x = -0.5f;
lockedbuf[0].y = -0.5f; lockedbuf[0].y = -0.5f;
lockedbuf[1].x = (float)((m_texinfo.width + 2 * m_xborderpix) * m_xprescale) - 0.5f; lockedbuf[1].x = (float)((m_texinfo.width + 2 * m_xborderpix) * m_xprescale) - 0.5f;
@ -2783,7 +2760,6 @@ void texture_info::prescale()
result = m_renderer->get_vertex_buffer()->Unlock(); result = m_renderer->get_vertex_buffer()->Unlock();
if (FAILED(result)) if (FAILED(result))
osd_printf_verbose("Direct3D: Error %08lX during vertex buffer unlock call\n", result); osd_printf_verbose("Direct3D: Error %08lX during vertex buffer unlock call\n", result);
m_renderer->set_locked_buffer(nullptr);
// set the stream and draw the triangle strip // set the stream and draw the triangle strip
result = m_renderer->get_device()->SetStreamSource(0, m_renderer->get_vertex_buffer(), 0, sizeof(vertex)); result = m_renderer->get_device()->SetStreamSource(0, m_renderer->get_vertex_buffer(), 0, sizeof(vertex));
@ -2817,11 +2793,11 @@ void texture_info::prescale()
cache_target::~cache_target() cache_target::~cache_target()
{ {
if (last_texture != nullptr) if (texture != nullptr)
last_texture->Release(); texture->Release();
if (last_target != nullptr) if (target != nullptr)
last_target->Release(); target->Release();
} }
@ -2829,18 +2805,19 @@ cache_target::~cache_target()
// cache_target::init - initializes a target cache // cache_target::init - initializes a target cache
//============================================================ //============================================================
bool cache_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_width, int source_height, int target_width, int target_height) bool cache_target::init(renderer_d3d9 *d3d, int source_width, int source_height, int target_width, int target_height, int screen_index)
{ {
this->width = source_width; this->width = source_width;
this->height = source_height; this->height = source_height;
this->target_width = target_width; this->target_width = target_width;
this->target_height = target_height; this->target_height = target_height;
this->screen_index = screen_index;
HRESULT result = d3d->get_device()->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &last_texture, nullptr); HRESULT result = d3d->get_device()->CreateTexture(target_width, target_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, nullptr);
if (FAILED(result)) if (FAILED(result))
return false; return false;
last_texture->GetSurfaceLevel(0, &last_target); texture->GetSurfaceLevel(0, &target);
return true; return true;
} }
@ -2882,7 +2859,7 @@ d3d_render_target::~d3d_render_target()
// d3d_render_target::init - initializes a render target // d3d_render_target::init - initializes a render target
//============================================================ //============================================================
bool d3d_render_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_width, int source_height, int target_width, int target_height) bool d3d_render_target::init(renderer_d3d9 *d3d, int source_width, int source_height, int target_width, int target_height, int screen_index, int page_index)
{ {
HRESULT result; HRESULT result;
@ -2892,6 +2869,9 @@ bool d3d_render_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_w
this->target_width = target_width; this->target_width = target_width;
this->target_height = target_height; this->target_height = target_height;
this->screen_index = screen_index;
this->page_index = page_index;
for (int index = 0; index < 2; index++) for (int index = 0; index < 2; index++)
{ {
result = d3d->get_device()->CreateTexture(source_width, source_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &source_texture[index], nullptr); result = d3d->get_device()->CreateTexture(source_width, source_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &source_texture[index], nullptr);

View File

@ -118,9 +118,6 @@ public:
D3DPRESENT_PARAMETERS * get_presentation() { return &m_presentation; } D3DPRESENT_PARAMETERS * get_presentation() { return &m_presentation; }
IDirect3DVertexBuffer9 *get_vertex_buffer() const { return m_vertexbuf; } IDirect3DVertexBuffer9 *get_vertex_buffer() const { return m_vertexbuf; }
vertex * get_locked_buffer() const { return m_lockedbuf; }
VOID ** get_locked_buffer_ptr()const { return (VOID **)&m_lockedbuf; }
void set_locked_buffer(vertex *lockedbuf) { m_lockedbuf = lockedbuf; }
void set_toggle(bool toggle) { m_toggle = toggle; } void set_toggle(bool toggle) { m_toggle = toggle; }
@ -172,7 +169,6 @@ private:
UINT32 m_last_wrap; // previous wrap state UINT32 m_last_wrap; // previous wrap state
int m_last_modmode; // previous texture modulation int m_last_modmode; // previous texture modulation
void * m_hlsl_buf; // HLSL vertex data
shaders * m_shaders; // HLSL interface shaders * m_shaders; // HLSL interface
d3d_texture_manager * m_texture_manager; // texture manager d3d_texture_manager * m_texture_manager; // texture manager

0
src/osd/modules/sound/xaudio2_sound.cpp Executable file → Normal file
View File