Previous 199869 Revisions Next

r19975 Monday 31st December, 2012 at 21:29:02 UTC by Ryan Holtz
- 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]
[hlsl]vector.fx*
[src/emu]render.c render.h
[src/emu/video]vector.c
[src/osd/windows]d3dhlsl.c d3dhlsl.h drawd3d.c drawd3d.h

trunk/hlsl/vector.fx
r0r19975
1//-----------------------------------------------------------------------------
2// Effect File Variables
3//-----------------------------------------------------------------------------
4
5texture Diffuse;
6
7sampler DiffuseSampler = sampler_state
8{
9   Texture   = <Diffuse>;
10   MipFilter = LINEAR;
11   MinFilter = LINEAR;
12   MagFilter = LINEAR;
13   AddressU = CLAMP;
14   AddressV = CLAMP;
15   AddressW = CLAMP;
16};
17
18//-----------------------------------------------------------------------------
19// Vertex Definitions
20//-----------------------------------------------------------------------------
21
22struct VS_OUTPUT
23{
24   float4 Position : POSITION;
25   float4 Color : COLOR0;
26   float2 TexCoord : TEXCOORD0;
27};
28
29struct VS_INPUT
30{
31   float3 Position : POSITION;
32   float4 Color : COLOR0;
33   float2 TexCoord : TEXCOORD0;
34};
35
36struct PS_INPUT
37{
38   float4 Color : COLOR0;
39   float2 TexCoord : TEXCOORD0;
40};
41
42//-----------------------------------------------------------------------------
43// Simple Vertex Shader
44//-----------------------------------------------------------------------------
45
46uniform float TargetWidth;
47uniform float TargetHeight;
48
49VS_OUTPUT vs_main(VS_INPUT Input)
50{
51   VS_OUTPUT Output = (VS_OUTPUT)0;
52   
53   Output.Position = float4(Input.Position.xyz, 1.0f);
54   Output.Position.x /= TargetWidth;
55   Output.Position.y /= TargetHeight;
56   Output.Position.y = 1.0f - Output.Position.y;
57   Output.Position.x -= 0.5f;
58   Output.Position.y -= 0.5f;
59   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
60   Output.Color = float4(0.0f, 0.0f, Input.Color.z, 1.0f);
61   Output.TexCoord = Input.Position.xy / float2(TargetWidth, TargetHeight);
62
63   return Output;
64}
65
66//-----------------------------------------------------------------------------
67// Simple Pixel Shader
68//-----------------------------------------------------------------------------
69
70float4 ps_main(PS_INPUT Input) : COLOR
71{
72   float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
73   return BaseTexel * Input.Color;
74}
75
76//-----------------------------------------------------------------------------
77// Simple Effect
78//-----------------------------------------------------------------------------
79
80technique TestTechnique
81{
82   pass Pass0
83   {
84      Lighting = FALSE;
85
86      //Sampler[0] = <DiffuseSampler>;
87
88      VertexShader = compile vs_2_0 vs_main();
89      PixelShader  = compile ps_2_0 ps_main();
90   }
91}
trunk/src/osd/windows/d3dhlsl.h
r19974r19975
4545#include "aviio.h"
4646
4747//============================================================
48//  CONSTANTS
49//============================================================
50
51#define HLSL_VECTOR         (0)
52
53//============================================================
4854//  TYPE DEFINITIONS
4955//============================================================
5056
r19974r19975
111117
112118   bool enabled() { return master_enable; }
113119
120   bool vector_enabled() { return vector_enable && (bool)HLSL_VECTOR; }
121   d3d_render_target* get_vector_target(d3d_info *d3d);
122   void create_vector_target(d3d_info *d3d, render_primitive *prim);
123
114124   void begin();
115125   void init_effect_info(d3d_poly_info *poly);
116126   void render_quad(d3d_poly_info *poly, int vertnum);
r19974r19975
159169   win_window_info *       window;                  // D3D window info
160170
161171   bool               master_enable;            // overall enable flag
172   bool               vector_enable;             // vector post-processing enable flag
162173   bool               paused;                  // whether or not rendering is currently paused
163174   int                  num_screens;            // number of emulated physical screens
164175   int                  curr_screen;            // current screen for render target operations
r19974r19975
193204   d3d_texture *           snap_texture;            // snapshot upscaled texture
194205   int                  snap_width;               // snapshot width
195206   int                  snap_height;            // snapshot height
207   bool               lines_pending;            // whether or not we have lines to flush on the next quad
196208
197209   // HLSL effects
198210   d3d_surface *         backbuffer;               // pointer to our device's backbuffer
199211   d3d_effect *         curr_effect;            // pointer to the currently active effect object
200   d3d_effect *         effect;                  // pointer to the current primary-effect object
201   d3d_effect *         prescale_effect;         // pointer to the current prescale-effect object
202   d3d_effect *         post_effect;            // pointer to the current post-effect object
203   d3d_effect *         pincushion_effect;         // pointer to the current pincushion-effect object
204   d3d_effect *         focus_effect;            // pointer to the current focus-effect object
205   d3d_effect *         phosphor_effect;         // pointer to the current phosphor-effect object
206   d3d_effect *         deconverge_effect;         // pointer to the current deconvergence-effect object
207   d3d_effect *         color_effect;            // pointer to the current color-effect object
208   d3d_effect *         yiq_encode_effect;         // pointer to the current YIQ encoder effect object
209   d3d_effect *         yiq_decode_effect;         // pointer to the current YIQ decoder effect object
212   d3d_effect *         effect;                  // pointer to the primary-effect object
213   d3d_effect *         prescale_effect;         // pointer to the prescale-effect object
214   d3d_effect *         post_effect;            // pointer to the post-effect object
215   d3d_effect *         pincushion_effect;         // pointer to the pincushion-effect object
216   d3d_effect *         focus_effect;            // pointer to the focus-effect object
217   d3d_effect *         phosphor_effect;         // pointer to the phosphor-effect object
218   d3d_effect *         deconverge_effect;         // pointer to the deconvergence-effect object
219   d3d_effect *         color_effect;            // pointer to the color-effect object
220   d3d_effect *         yiq_encode_effect;         // pointer to the YIQ encoder effect object
221   d3d_effect *         yiq_decode_effect;         // pointer to the YIQ decoder effect object
222#if HLSL_VECTOR
223   d3d_effect *         vector_effect;            // pointer to the vector-effect object
224#endif
210225   d3d_vertex *         fsfx_vertices;            // pointer to our full-screen-quad object
211226
212227public:
trunk/src/osd/windows/drawd3d.c
r19974r19975
584584   // first update any textures
585585   window->primlist->acquire_lock();
586586   for (prim = window->primlist->first(); prim != NULL; prim = prim->next())
587   {
587588      if (prim->texture.base != NULL)
589      {
588590         texture_update(d3d, prim);
591      }
592      else if(d3d->hlsl->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags))
593      {
594         if (!d3d->hlsl->get_vector_target(d3d))
595         {
596            d3d->hlsl->create_vector_target(d3d, prim);
597         }
598      }
599   }
589600
590601   // begin the scene
591602mtlog_add("drawd3d_window_draw: begin_scene");
r19974r19975
18461857            {
18471858               if (d3d->hlsl->enabled() && !d3d->hlsl->register_prescaled_texture(texture))
18481859               {
1849                  printf("hlsl issue 2\n");
18501860                  goto error;
18511861               }
18521862               break;
r19974r19975
25902600}
25912601
25922602
2593
25942603//============================================================
25952604//  texture_update
25962605//============================================================
trunk/src/osd/windows/d3dhlsl.c
r19974r19975
191191hlsl_info::hlsl_info()
192192{
193193   master_enable = false;
194   vector_enable = true;
194195   prescale_size_x = 1;
195196   prescale_size_y = 1;
196197   prescale_force_x = 0;
r19974r19975
10621063   g_slider_list = init_slider_list();
10631064
10641065   const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir();
1066
1067   // Replace all this garbage with a proper data-driven system
10651068   char primary_name_cstr[1024];
1066   char post_name_cstr[1024];
1067   char prescale_name_cstr[1024];
1068   char pincushion_name_cstr[1024];
1069   char phosphor_name_cstr[1024];
1070   char focus_name_cstr[1024];
1071   char deconverge_name_cstr[1024];
1072   char color_name_cstr[1024];
1073   char yiq_encode_name_cstr[1024];
1074   char yiq_decode_name_cstr[1024];
1075
10761069   sprintf(primary_name_cstr, "%s\\primary.fx", fx_dir);
10771070   TCHAR *primary_name = tstring_from_utf8(primary_name_cstr);
10781071
1072   char post_name_cstr[1024];
10791073   sprintf(post_name_cstr, "%s\\post.fx", fx_dir);
10801074   TCHAR *post_name = tstring_from_utf8(post_name_cstr);
10811075
1076   char prescale_name_cstr[1024];
10821077   sprintf(prescale_name_cstr, "%s\\prescale.fx", fx_dir);
10831078   TCHAR *prescale_name = tstring_from_utf8(prescale_name_cstr);
10841079
1080   char pincushion_name_cstr[1024];
10851081   sprintf(pincushion_name_cstr, "%s\\pincushion.fx", fx_dir);
10861082   TCHAR *pincushion_name = tstring_from_utf8(pincushion_name_cstr);
10871083
1084   char phosphor_name_cstr[1024];
10881085   sprintf(phosphor_name_cstr, "%s\\phosphor.fx", fx_dir);
10891086   TCHAR *phosphor_name = tstring_from_utf8(phosphor_name_cstr);
10901087
1088   char focus_name_cstr[1024];
10911089   sprintf(focus_name_cstr, "%s\\focus.fx", fx_dir);
10921090   TCHAR *focus_name = tstring_from_utf8(focus_name_cstr);
10931091
1092   char deconverge_name_cstr[1024];
10941093   sprintf(deconverge_name_cstr, "%s\\deconverge.fx", fx_dir);
10951094   TCHAR *deconverge_name = tstring_from_utf8(deconverge_name_cstr);
10961095
1096   char color_name_cstr[1024];
10971097   sprintf(color_name_cstr, "%s\\color.fx", fx_dir);
10981098   TCHAR *color_name = tstring_from_utf8(color_name_cstr);
10991099
1100   char yiq_encode_name_cstr[1024];
11001101   sprintf(yiq_encode_name_cstr, "%s\\yiq_encode.fx", fx_dir);
11011102   TCHAR *yiq_encode_name = tstring_from_utf8(yiq_encode_name_cstr);
11021103
1104   char yiq_decode_name_cstr[1024];
11031105   sprintf(yiq_decode_name_cstr, "%s\\yiq_decode.fx", fx_dir);
11041106   TCHAR *yiq_decode_name = tstring_from_utf8(yiq_decode_name_cstr);
11051107
r19974r19975
11831185      return 1;
11841186   }
11851187
1188   // create the vector shader
1189#if HLSL_VECTOR
1190   char vector_cstr[1024];
1191   sprintf(vector_cstr, "%s\\vector.fx", fx_dir);
1192   TCHAR *vector_name = tstring_from_utf8(vector_cstr);
1193
1194   result = (*d3dintf->device.create_effect)(d3d->device, vector_name, &vector_effect);
1195   if(result != D3D_OK)
1196   {
1197      mame_printf_verbose("Direct3D: Unable to load vector.fx\n");
1198      return 1;
1199   }
1200   if (vector_name)
1201      osd_free(vector_name);
1202#endif
1203
11861204   if (primary_name)
11871205      osd_free(primary_name);
11881206   if (post_name)
r19974r19975
13671385   UINT num_passes = 0;
13681386   d3d_info *d3d = (d3d_info *)window->drawdata;
13691387
1388#if HLSL_VECTOR
1389   if(PRIMFLAG_GET_VECTOR(poly->flags) && vector_enable)
1390   {
1391      lines_pending = true;
1392   }
1393   else if (PRIMFLAG_GET_VECTORBUF(poly->flags) && vector_enable)
1394   {
1395   }
1396#endif
1397
13701398   if(PRIMFLAG_GET_SCREENTEX(d3d->last_texture_flags) && poly->texture != NULL)
13711399   {
13721400      d3d_render_target *rt = find_render_target(poly->texture);
r19974r19975
17821810
17831811      options->params_dirty = false;
17841812   }
1813#if HLSL_VECTOR
1814   else if(PRIMFLAG_GET_VECTOR(poly->flags) && vector_enable)
1815   {
1816   }
1817#endif
17851818   else
17861819   {
17871820      (*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f);
r19974r19975
18631896   return true;
18641897}
18651898
1899d3d_render_target* hlsl_info::get_vector_target(d3d_info *d3d)
1900{
1901#if HLSL_VECTOR
1902   if (!vector_enable)
1903   {
1904      return false;
1905   }
1906
1907   return find_render_target(d3d->width, d3d->height, 0, 0);
1908#endif
1909   return NULL;
1910}
1911
1912void hlsl_info::create_vector_target(d3d_info *d3d, render_primitive *prim)
1913{
1914#if HLSL_VECTOR
1915   if (!add_render_target(d3d, NULL, d3d->width, d3d->height, 1, 1))
1916   {
1917      vector_enable = false;
1918   }
1919#endif
1920}
1921
18661922//============================================================
18671923//  hlsl_info::add_render_target - register a render target
18681924//============================================================
18691925
18701926bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale)
18711927{
1872   if (find_render_target(info))
1928   UINT32 screen_index = 0;
1929   UINT32 page_index = 0;
1930   if (info != NULL)
18731931   {
1874      remove_render_target(info);
1932      if (find_render_target(info))
1933      {
1934         remove_render_target(info);
1935      }
1936
1937      UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
1938      screen_index = screen_index_data >> 1;
1939      page_index = screen_index_data & 1;
18751940   }
18761941
1877   UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
1878   UINT32 screen_index = screen_index_data >> 1;
1879   UINT32 page_index = screen_index_data & 1;
1880
18811942   d3d_render_target* target = (d3d_render_target*)global_alloc_clear(d3d_render_target);
18821943
18831944   if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
r19974r19975
18861947      return false;
18871948   }
18881949
1889   target->info = info;
1950   if (info != NULL)
1951   {
1952      target->width = info->texinfo.width;
1953      target->height = info->texinfo.height;
1954   }
1955   else
1956   {
1957      target->width = d3d->width;
1958      target->height = d3d->height;
1959   }
18901960
1891   target->width = info->texinfo.width;
1892   target->height = info->texinfo.height;
1893
18941961   target->screen_index = screen_index;
18951962   target->page_index = page_index;
18961963
1897   d3d_cache_target* cache = find_cache_target(target->screen_index, info->texinfo.width, info->texinfo.height);
1964   d3d_cache_target* cache = find_cache_target(target->screen_index, target->width, target->height);
18981965   if (cache == NULL)
18991966   {
19001967      if (!add_cache_target(d3d, info, width, height, xprescale, yprescale, target->screen_index))
trunk/src/osd/windows/drawd3d.h
r19974r19975
5353#define VERTEX_BASE_FORMAT   (D3DFVF_DIFFUSE | D3DFVF_TEX1)
5454#define VERTEX_BUFFER_SIZE   (2048*4+4)
5555
56
57
5856//============================================================
5957//  TYPE DEFINITIONS
6058//============================================================
r19974r19975
109107   d3d_surface *target[5];
110108   d3d_texture *texture[5];
111109
112   d3d_texture_info *info;
113
114110   d3d_render_target *next;
115111   d3d_render_target *prev;
116112};
trunk/src/emu/render.c
r19974r19975
17621762
17631763            // set the line type
17641764            prim->type = render_primitive::LINE;
1765            prim->flags |= PRIMFLAG_TYPE_LINE;
17651766
17661767            // scale the width by the minimum of X/Y scale factors
17671768            prim->width = curitem->width() * MIN(container_xform.xscale, container_xform.yscale);
r19974r19975
17741775         case CONTAINER_ITEM_QUAD:
17751776            // set the quad type
17761777            prim->type = render_primitive::QUAD;
1778            prim->flags |= PRIMFLAG_TYPE_QUAD;
17771779
17781780            // normalize the bounds
17791781            normalize_bounds(prim->bounds);
trunk/src/emu/render.h
r19974r19975
134134const int PRIMFLAG_TEXSHADE_SHIFT = 15;
135135const UINT32 PRIMFLAG_TEXSHADE_MASK = 3 << PRIMFLAG_TEXSHADE_SHIFT;
136136
137const int PRIMFLAG_VECTOR_SHIFT = 17;
138const UINT32 PRIMFLAG_VECTOR_MASK = 1 << PRIMFLAG_VECTOR_SHIFT;
137139
140const int PRIMFLAG_VECTORBUF_SHIFT = 18;
141const UINT32 PRIMFLAG_VECTORBUF_MASK = 1 << PRIMFLAG_VECTORBUF_SHIFT;
142
143const int PRIMFLAG_TYPE_SHIFT = 19;
144const UINT32 PRIMFLAG_TYPE_MASK = 3 << PRIMFLAG_TYPE_SHIFT;
145const UINT32 PRIMFLAG_TYPE_LINE = 0 << PRIMFLAG_TYPE_SHIFT;
146const UINT32 PRIMFLAG_TYPE_QUAD = 1 << PRIMFLAG_TYPE_SHIFT;
147
138148//**************************************************************************
139149//  MACROS
140150//**************************************************************************
r19974r19975
160170#define PRIMFLAG_TEXSHADE(x)      ((x) << PRIMFLAG_TEXSHADE_SHIFT)
161171#define PRIMFLAG_GET_TEXSHADE(x)   (((x) & PRIMFLAG_TEXSHADE_MASK) >> PRIMFLAG_TEXSHADE_SHIFT)
162172
173#define PRIMFLAG_VECTOR(x)         ((x) << PRIMFLAG_VECTOR_SHIFT)
174#define PRIMFLAG_GET_VECTOR(x)      (((x) & PRIMFLAG_VECTOR_MASK) >> PRIMFLAG_VECTOR_SHIFT)
163175
176#define PRIMFLAG_VECTORBUF(x)      ((x) << PRIMFLAG_VECTORBUF_SHIFT)
177#define PRIMFLAG_GET_VECTORBUF(x)   (((x) & PRIMFLAG_VECTORBUF_MASK) >> PRIMFLAG_VECTORBUF_SHIFT)
164178
179
165180//**************************************************************************
166181//  TYPE DEFINITIONS
167182//**************************************************************************
trunk/src/emu/video/vector.c
r19974r19975
255255
256256SCREEN_UPDATE_RGB32( vector )
257257{
258   UINT32 flags = PRIMFLAG_ANTIALIAS(screen.machine().options().antialias() ? 1 : 0) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD);
258   UINT32 flags = PRIMFLAG_ANTIALIAS(screen.machine().options().antialias() ? 1 : 0) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD) | PRIMFLAG_VECTOR(1);
259259   const rectangle &visarea = screen.visible_area();
260260   float xscale = 1.0f / (65536 * visarea.width());
261261   float yscale = 1.0f / (65536 * visarea.height());
r19974r19975
269269   curpoint = vector_list;
270270
271271   screen.container().empty();
272   screen.container().add_rect(0.0f, 0.0f, 1.0f, 1.0f, MAKE_ARGB(0xff,0x00,0x00,0x00), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
272   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));
273273
274274   clip.x0 = clip.y0 = 0.0f;
275275   clip.x1 = clip.y1 = 1.0f;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team