- render.c: Added new PRIMFLAG macros pertaining to vectors, to be used by the

OSD. [MooglyGuy]

- d3dhlsl.c: Began laying the groundwork for vector post-processing, disabled
            by default. [MooglyGuy]
This commit is contained in:
Ryan Holtz 2012-12-31 21:29:02 +00:00
parent 2be79ec4d3
commit 7e652d13c5
9 changed files with 235 additions and 39 deletions

1
.gitattributes vendored
View file

@ -240,6 +240,7 @@ hlsl/pincushion.fx svneol=native#text/plain
hlsl/post.fx svneol=native#text/plain
hlsl/prescale.fx svneol=native#text/plain
hlsl/primary.fx svneol=native#text/plain
hlsl/vector.fx svneol=native#text/plain
hlsl/yiq_decode.fx svneol=native#text/plain
hlsl/yiq_encode.fx svneol=native#text/plain
keymaps/km_be_LINUX.map svneol=native#text/plain

91
hlsl/vector.fx Normal file
View file

@ -0,0 +1,91 @@
//-----------------------------------------------------------------------------
// Effect File Variables
//-----------------------------------------------------------------------------
texture Diffuse;
sampler DiffuseSampler = sampler_state
{
Texture = <Diffuse>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
};
//-----------------------------------------------------------------------------
// Vertex Definitions
//-----------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
};
struct VS_INPUT
{
float3 Position : POSITION;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
};
struct PS_INPUT
{
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
};
//-----------------------------------------------------------------------------
// Simple Vertex Shader
//-----------------------------------------------------------------------------
uniform float TargetWidth;
uniform float TargetHeight;
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output = (VS_OUTPUT)0;
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.x /= TargetWidth;
Output.Position.y /= TargetHeight;
Output.Position.y = 1.0f - Output.Position.y;
Output.Position.x -= 0.5f;
Output.Position.y -= 0.5f;
Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
Output.Color = float4(0.0f, 0.0f, Input.Color.z, 1.0f);
Output.TexCoord = Input.Position.xy / float2(TargetWidth, TargetHeight);
return Output;
}
//-----------------------------------------------------------------------------
// Simple Pixel Shader
//-----------------------------------------------------------------------------
float4 ps_main(PS_INPUT Input) : COLOR
{
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
return BaseTexel * Input.Color;
}
//-----------------------------------------------------------------------------
// Simple Effect
//-----------------------------------------------------------------------------
technique TestTechnique
{
pass Pass0
{
Lighting = FALSE;
//Sampler[0] = <DiffuseSampler>;
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_main();
}
}

View file

@ -1762,6 +1762,7 @@ void render_target::add_container_primitives(render_primitive_list &list, const
// set the line type
prim->type = render_primitive::LINE;
prim->flags |= PRIMFLAG_TYPE_LINE;
// scale the width by the minimum of X/Y scale factors
prim->width = curitem->width() * MIN(container_xform.xscale, container_xform.yscale);
@ -1774,6 +1775,7 @@ void render_target::add_container_primitives(render_primitive_list &list, const
case CONTAINER_ITEM_QUAD:
// set the quad type
prim->type = render_primitive::QUAD;
prim->flags |= PRIMFLAG_TYPE_QUAD;
// normalize the bounds
normalize_bounds(prim->bounds);

View file

@ -134,6 +134,16 @@ const UINT32 PRIMFLAG_TEXWRAP_MASK = 1 << PRIMFLAG_TEXWRAP_SHIFT;
const int PRIMFLAG_TEXSHADE_SHIFT = 15;
const UINT32 PRIMFLAG_TEXSHADE_MASK = 3 << PRIMFLAG_TEXSHADE_SHIFT;
const int PRIMFLAG_VECTOR_SHIFT = 17;
const UINT32 PRIMFLAG_VECTOR_MASK = 1 << PRIMFLAG_VECTOR_SHIFT;
const int PRIMFLAG_VECTORBUF_SHIFT = 18;
const UINT32 PRIMFLAG_VECTORBUF_MASK = 1 << PRIMFLAG_VECTORBUF_SHIFT;
const int PRIMFLAG_TYPE_SHIFT = 19;
const UINT32 PRIMFLAG_TYPE_MASK = 3 << PRIMFLAG_TYPE_SHIFT;
const UINT32 PRIMFLAG_TYPE_LINE = 0 << PRIMFLAG_TYPE_SHIFT;
const UINT32 PRIMFLAG_TYPE_QUAD = 1 << PRIMFLAG_TYPE_SHIFT;
//**************************************************************************
// MACROS
@ -160,6 +170,11 @@ const UINT32 PRIMFLAG_TEXSHADE_MASK = 3 << PRIMFLAG_TEXSHADE_SHIFT;
#define PRIMFLAG_TEXSHADE(x) ((x) << PRIMFLAG_TEXSHADE_SHIFT)
#define PRIMFLAG_GET_TEXSHADE(x) (((x) & PRIMFLAG_TEXSHADE_MASK) >> PRIMFLAG_TEXSHADE_SHIFT)
#define PRIMFLAG_VECTOR(x) ((x) << PRIMFLAG_VECTOR_SHIFT)
#define PRIMFLAG_GET_VECTOR(x) (((x) & PRIMFLAG_VECTOR_MASK) >> PRIMFLAG_VECTOR_SHIFT)
#define PRIMFLAG_VECTORBUF(x) ((x) << PRIMFLAG_VECTORBUF_SHIFT)
#define PRIMFLAG_GET_VECTORBUF(x) (((x) & PRIMFLAG_VECTORBUF_MASK) >> PRIMFLAG_VECTORBUF_SHIFT)
//**************************************************************************

View file

@ -255,7 +255,7 @@ void vector_clear_list (void)
SCREEN_UPDATE_RGB32( vector )
{
UINT32 flags = PRIMFLAG_ANTIALIAS(screen.machine().options().antialias() ? 1 : 0) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD);
UINT32 flags = PRIMFLAG_ANTIALIAS(screen.machine().options().antialias() ? 1 : 0) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD) | PRIMFLAG_VECTOR(1);
const rectangle &visarea = screen.visible_area();
float xscale = 1.0f / (65536 * visarea.width());
float yscale = 1.0f / (65536 * visarea.height());
@ -269,7 +269,7 @@ SCREEN_UPDATE_RGB32( vector )
curpoint = vector_list;
screen.container().empty();
screen.container().add_rect(0.0f, 0.0f, 1.0f, 1.0f, MAKE_ARGB(0xff,0x00,0x00,0x00), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
screen.container().add_rect(0.0f, 0.0f, 1.0f, 1.0f, MAKE_ARGB(0xff,0x00,0x00,0x00), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_VECTORBUF(1));
clip.x0 = clip.y0 = 0.0f;
clip.x1 = clip.y1 = 1.0f;

View file

@ -191,6 +191,7 @@ static file_error open_next(d3d_info *d3d, emu_file &file, const char *templ, co
hlsl_info::hlsl_info()
{
master_enable = false;
vector_enable = true;
prescale_size_x = 1;
prescale_size_y = 1;
prescale_force_x = 0;
@ -1062,44 +1063,45 @@ int hlsl_info::create_resources()
g_slider_list = init_slider_list();
const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir();
char primary_name_cstr[1024];
char post_name_cstr[1024];
char prescale_name_cstr[1024];
char pincushion_name_cstr[1024];
char phosphor_name_cstr[1024];
char focus_name_cstr[1024];
char deconverge_name_cstr[1024];
char color_name_cstr[1024];
char yiq_encode_name_cstr[1024];
char yiq_decode_name_cstr[1024];
// Replace all this garbage with a proper data-driven system
char primary_name_cstr[1024];
sprintf(primary_name_cstr, "%s\\primary.fx", fx_dir);
TCHAR *primary_name = tstring_from_utf8(primary_name_cstr);
char post_name_cstr[1024];
sprintf(post_name_cstr, "%s\\post.fx", fx_dir);
TCHAR *post_name = tstring_from_utf8(post_name_cstr);
char prescale_name_cstr[1024];
sprintf(prescale_name_cstr, "%s\\prescale.fx", fx_dir);
TCHAR *prescale_name = tstring_from_utf8(prescale_name_cstr);
char pincushion_name_cstr[1024];
sprintf(pincushion_name_cstr, "%s\\pincushion.fx", fx_dir);
TCHAR *pincushion_name = tstring_from_utf8(pincushion_name_cstr);
char phosphor_name_cstr[1024];
sprintf(phosphor_name_cstr, "%s\\phosphor.fx", fx_dir);
TCHAR *phosphor_name = tstring_from_utf8(phosphor_name_cstr);
char focus_name_cstr[1024];
sprintf(focus_name_cstr, "%s\\focus.fx", fx_dir);
TCHAR *focus_name = tstring_from_utf8(focus_name_cstr);
char deconverge_name_cstr[1024];
sprintf(deconverge_name_cstr, "%s\\deconverge.fx", fx_dir);
TCHAR *deconverge_name = tstring_from_utf8(deconverge_name_cstr);
char color_name_cstr[1024];
sprintf(color_name_cstr, "%s\\color.fx", fx_dir);
TCHAR *color_name = tstring_from_utf8(color_name_cstr);
char yiq_encode_name_cstr[1024];
sprintf(yiq_encode_name_cstr, "%s\\yiq_encode.fx", fx_dir);
TCHAR *yiq_encode_name = tstring_from_utf8(yiq_encode_name_cstr);
char yiq_decode_name_cstr[1024];
sprintf(yiq_decode_name_cstr, "%s\\yiq_decode.fx", fx_dir);
TCHAR *yiq_decode_name = tstring_from_utf8(yiq_decode_name_cstr);
@ -1183,6 +1185,22 @@ int hlsl_info::create_resources()
return 1;
}
// create the vector shader
#if HLSL_VECTOR
char vector_cstr[1024];
sprintf(vector_cstr, "%s\\vector.fx", fx_dir);
TCHAR *vector_name = tstring_from_utf8(vector_cstr);
result = (*d3dintf->device.create_effect)(d3d->device, vector_name, &vector_effect);
if(result != D3D_OK)
{
mame_printf_verbose("Direct3D: Unable to load vector.fx\n");
return 1;
}
if (vector_name)
osd_free(vector_name);
#endif
if (primary_name)
osd_free(primary_name);
if (post_name)
@ -1367,6 +1385,16 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
UINT num_passes = 0;
d3d_info *d3d = (d3d_info *)window->drawdata;
#if HLSL_VECTOR
if(PRIMFLAG_GET_VECTOR(poly->flags) && vector_enable)
{
lines_pending = true;
}
else if (PRIMFLAG_GET_VECTORBUF(poly->flags) && vector_enable)
{
}
#endif
if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL)
{
d3d_render_target *rt = find_render_target(poly->texture);
@ -1782,6 +1810,11 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
options->params_dirty = false;
}
#if HLSL_VECTOR
else if(PRIMFLAG_GET_VECTOR(poly->flags) && vector_enable)
{
}
#endif
else
{
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f);
@ -1863,20 +1896,48 @@ bool hlsl_info::add_cache_target(d3d_info* d3d, d3d_texture_info* info, int widt
return true;
}
d3d_render_target* hlsl_info::get_vector_target(d3d_info *d3d)
{
#if HLSL_VECTOR
if (!vector_enable)
{
return false;
}
return find_render_target(d3d->width, d3d->height, 0, 0);
#endif
return NULL;
}
void hlsl_info::create_vector_target(d3d_info *d3d, render_primitive *prim)
{
#if HLSL_VECTOR
if (!add_render_target(d3d, NULL, d3d->width, d3d->height, 1, 1))
{
vector_enable = false;
}
#endif
}
//============================================================
// hlsl_info::add_render_target - register a render target
//============================================================
bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale)
{
if (find_render_target(info))
UINT32 screen_index = 0;
UINT32 page_index = 0;
if (info != NULL)
{
remove_render_target(info);
}
if (find_render_target(info))
{
remove_render_target(info);
}
UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
UINT32 screen_index = screen_index_data >> 1;
UINT32 page_index = screen_index_data & 1;
UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
screen_index = screen_index_data >> 1;
page_index = screen_index_data & 1;
}
d3d_render_target* target = (d3d_render_target*)global_alloc_clear(d3d_render_target);
@ -1886,15 +1947,21 @@ bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int wid
return false;
}
target->info = info;
target->width = info->texinfo.width;
target->height = info->texinfo.height;
if (info != NULL)
{
target->width = info->texinfo.width;
target->height = info->texinfo.height;
}
else
{
target->width = d3d->width;
target->height = d3d->height;
}
target->screen_index = screen_index;
target->page_index = page_index;
d3d_cache_target* cache = find_cache_target(target->screen_index, info->texinfo.width, info->texinfo.height);
d3d_cache_target* cache = find_cache_target(target->screen_index, target->width, target->height);
if (cache == NULL)
{
if (!add_cache_target(d3d, info, width, height, xprescale, yprescale, target->screen_index))

View file

@ -44,6 +44,12 @@
#include "aviio.h"
//============================================================
// CONSTANTS
//============================================================
#define HLSL_VECTOR (0)
//============================================================
// TYPE DEFINITIONS
//============================================================
@ -111,6 +117,10 @@ public:
bool enabled() { return master_enable; }
bool vector_enabled() { return vector_enable && (bool)HLSL_VECTOR; }
d3d_render_target* get_vector_target(d3d_info *d3d);
void create_vector_target(d3d_info *d3d, render_primitive *prim);
void begin();
void init_effect_info(d3d_poly_info *poly);
void render_quad(d3d_poly_info *poly, int vertnum);
@ -159,6 +169,7 @@ private:
win_window_info * window; // D3D window info
bool master_enable; // overall enable flag
bool vector_enable; // vector post-processing enable flag
bool paused; // whether or not rendering is currently paused
int num_screens; // number of emulated physical screens
int curr_screen; // current screen for render target operations
@ -193,20 +204,24 @@ private:
d3d_texture * snap_texture; // snapshot upscaled texture
int snap_width; // snapshot width
int snap_height; // snapshot height
bool lines_pending; // whether or not we have lines to flush on the next quad
// HLSL effects
d3d_surface * backbuffer; // pointer to our device's backbuffer
d3d_effect * curr_effect; // pointer to the currently active effect object
d3d_effect * effect; // pointer to the current primary-effect object
d3d_effect * prescale_effect; // pointer to the current prescale-effect object
d3d_effect * post_effect; // pointer to the current post-effect object
d3d_effect * pincushion_effect; // pointer to the current pincushion-effect object
d3d_effect * focus_effect; // pointer to the current focus-effect object
d3d_effect * phosphor_effect; // pointer to the current phosphor-effect object
d3d_effect * deconverge_effect; // pointer to the current deconvergence-effect object
d3d_effect * color_effect; // pointer to the current color-effect object
d3d_effect * yiq_encode_effect; // pointer to the current YIQ encoder effect object
d3d_effect * yiq_decode_effect; // pointer to the current YIQ decoder effect object
d3d_effect * effect; // pointer to the primary-effect object
d3d_effect * prescale_effect; // pointer to the prescale-effect object
d3d_effect * post_effect; // pointer to the post-effect object
d3d_effect * pincushion_effect; // pointer to the pincushion-effect object
d3d_effect * focus_effect; // pointer to the focus-effect object
d3d_effect * phosphor_effect; // pointer to the phosphor-effect object
d3d_effect * deconverge_effect; // pointer to the deconvergence-effect object
d3d_effect * color_effect; // pointer to the color-effect object
d3d_effect * yiq_encode_effect; // pointer to the YIQ encoder effect object
d3d_effect * yiq_decode_effect; // pointer to the YIQ decoder effect object
#if HLSL_VECTOR
d3d_effect * vector_effect; // pointer to the vector-effect object
#endif
d3d_vertex * fsfx_vertices; // pointer to our full-screen-quad object
public:

View file

@ -584,8 +584,19 @@ mtlog_add("drawd3d_window_draw: begin");
// first update any textures
window->primlist->acquire_lock();
for (prim = window->primlist->first(); prim != NULL; prim = prim->next())
{
if (prim->texture.base != NULL)
{
texture_update(d3d, prim);
}
else if(d3d->hlsl->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags))
{
if (!d3d->hlsl->get_vector_target(d3d))
{
d3d->hlsl->create_vector_target(d3d, prim);
}
}
}
// begin the scene
mtlog_add("drawd3d_window_draw: begin_scene");
@ -1846,7 +1857,6 @@ d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource,
{
if (d3d->hlsl->enabled() && !d3d->hlsl->register_prescaled_texture(texture))
{
printf("hlsl issue 2\n");
goto error;
}
break;
@ -2590,7 +2600,6 @@ static d3d_texture_info *texture_find(d3d_info *d3d, const render_primitive *pri
}
//============================================================
// texture_update
//============================================================

View file

@ -53,8 +53,6 @@
#define VERTEX_BASE_FORMAT (D3DFVF_DIFFUSE | D3DFVF_TEX1)
#define VERTEX_BUFFER_SIZE (2048*4+4)
//============================================================
// TYPE DEFINITIONS
//============================================================
@ -109,8 +107,6 @@ public:
d3d_surface *target[5];
d3d_texture *texture[5];
d3d_texture_info *info;
d3d_render_target *next;
d3d_render_target *prev;
};