Previous 199869 Revisions Next

r19930 Saturday 29th December, 2012 at 20:11:06 UTC by Ryan Holtz
(nw) Fixes HLSL bugs with Rocket Knight Adventures
[src/osd/windows]d3dhlsl.c d3dhlsl.h drawd3d.c drawd3d.h winmain.c

trunk/src/osd/windows/d3dhlsl.c
r19929r19930
193193   master_enable = false;
194194   prescale_size_x = 1;
195195   prescale_size_y = 1;
196   prescale_force_x = 0;
197   prescale_force_y = 0;
196   prescale_force_x = 1;
197   prescale_force_y = 1;
198198   preset = -1;
199199   shadow_texture = NULL;
200200   options = NULL;
r19929r19930
571571
572572
573573//============================================================
574//  remove_render_target - remove an active cache target when
574//  remove_cache_target - remove an active cache target when
575575//  refcount hits zero
576576//============================================================
577577
r19929r19930
581581   {
582582      if (cache == cachehead)
583583      {
584         cachehead= cachehead->next;
584         cachehead = cachehead->next;
585585      }
586586
587587      if (cache->prev != NULL)
r19929r19930
605605
606606void hlsl_info::remove_render_target(d3d_texture_info *texture)
607607{
608   d3d_render_target *rt = find_render_target(texture);
608   remove_render_target(find_render_target(texture));
609}
609610
611void hlsl_info::remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
612{
613   d3d_render_target *target = find_render_target(width, height, screen_index, page_index);
614   if (target != NULL)
615   {
616      remove_render_target(target);
617   }
618}
619
620void hlsl_info::remove_render_target(d3d_render_target *rt)
621{
610622   if (rt != NULL)
611623   {
612624      if (rt == targethead)
r19929r19930
624636         rt->next->prev = rt->prev;
625637      }
626638
627      d3d_cache_target *cache = find_cache_target(rt->screen_index);
639      d3d_cache_target *cache = find_cache_target(rt->screen_index, rt->width, rt->height);
628640      if (cache != NULL)
629641      {
630         cache->ref_count--;
631         if (cache->ref_count == 0)
632         {
633            remove_cache_target(cache);
634         }
642         remove_cache_target(cache);
635643      }
644
645      int screen_index = rt->screen_index;
646      int other_page = 1 - rt->page_index;
647      int width = rt->width;
648      int height = rt->height;
649
636650      global_free(rt);
651
652      // Remove other double-buffered page (if it exists)
653      remove_render_target(width, height, screen_index, other_page);
637654   }
638655}
639656
r19929r19930
9861003      shadow_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
9871004   }
9881005
1006   prescale_force_x = 1;
1007   prescale_force_y = 1;
1008
9891009   if(!read_ini)
9901010   {
9911011      prescale_force_x = winoptions.d3d_hlsl_prescale_x();
r19929r19930
10381058      options->yiq_scan_time = winoptions.screen_yiq_scan_time();
10391059      options->yiq_phase_count = winoptions.screen_yiq_phase_count();
10401060   }
1061   if (!prescale_force_x)
1062   {
1063      prescale_force_x = 1;
1064   }
1065   if (!prescale_force_y)
1066   {
1067      prescale_force_y = 1;
1068   }
10411069   g_slider_list = init_slider_list();
10421070
10431071   const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir();
r19929r19930
12871315{
12881316   d3d_render_target *curr = targethead;
12891317
1290   while (curr != NULL && curr->info != info)
1318   UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
1319   UINT32 screen_index = screen_index_data >> 1;
1320   UINT32 page_index = screen_index_data & 1;
1321
1322   while (curr != NULL && (curr->screen_index != screen_index || curr->page_index != page_index || curr->width != info->texinfo.width || curr->height != info->texinfo.height))
12911323   {
12921324      curr = curr->next;
12931325   }
r19929r19930
12971329
12981330
12991331//============================================================
1332//  hlsl_info::find_render_target
1333//============================================================
1334
1335d3d_render_target* hlsl_info::find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
1336{
1337   d3d_render_target *curr = targethead;
1338
1339   while (curr != NULL && (curr->width != width || curr->height != height || curr->screen_index != screen_index || curr->page_index != page_index))
1340   {
1341      curr = curr->next;
1342   }
1343
1344   return curr;
1345}
1346
1347
1348//============================================================
13001349//  hlsl_info::find_cache_target
13011350//============================================================
13021351
1303d3d_cache_target* hlsl_info::find_cache_target(int screen_index)
1352d3d_cache_target* hlsl_info::find_cache_target(UINT32 screen_index, int width, int height)
13041353{
13051354   d3d_cache_target *curr = cachehead;
13061355
1307   while (curr != NULL && curr->screen_index != screen_index)
1356   while (curr != NULL && (curr->screen_index != screen_index || curr->width != width || curr->height != height))
13081357   {
13091358      curr = curr->next;
13101359   }
r19929r19930
13321381      {
13331382         return;
13341383      }
1335      d3d_cache_target *ct = find_cache_target(rt->screen_index);
1384      d3d_cache_target *ct = find_cache_target(rt->screen_index, poly->texture->texinfo.width, poly->texture->texinfo.height);
13361385
13371386      if(options->yiq_enable)
13381387      {
r19929r19930
17821831
17831832
17841833//============================================================
1785//  hlsl_info::register_texture
1834//  hlsl_info::register_prescaled_texture
17861835//============================================================
17871836
1788int hlsl_info::register_prescaled_texture(d3d_texture_info *texture, int scwidth, int scheight)
1837bool hlsl_info::register_prescaled_texture(d3d_texture_info *texture)
17891838{
1790   if (!master_enable || !d3dintf->post_fx_available)
1791      return 0;
1792
1793   d3d_info *d3d = (d3d_info *)window->drawdata;
1794
1795   // Find the nearest prescale factor that is over our screen size
1796   int hlsl_prescale_x = prescale_force_x ? prescale_force_x : 1;
1797   if(!prescale_force_x)
1798   {
1799      while(scwidth * hlsl_prescale_x < d3d->width) hlsl_prescale_x++;
1800      prescale_size_x = hlsl_prescale_x;
1801   }
1802
1803   int hlsl_prescale_y = prescale_force_y ? prescale_force_y : 1;
1804   if(!prescale_force_y)
1805   {
1806      while(scheight * hlsl_prescale_y < d3d->height) hlsl_prescale_y++;
1807      prescale_size_y = hlsl_prescale_y;
1808   }
1809
1810   if (!add_render_target(d3d, texture, scwidth, scheight, hlsl_prescale_x, hlsl_prescale_y))
1811      return 1;
1812
1813   options->params_dirty = true;
1814
1815   enumerate_screens();
1816
1817   return 0;
1839   return register_texture(texture, texture->rawwidth, texture->rawheight, texture->xprescale, texture->yprescale);
18181840}
18191841
18201842
18211843//============================================================
18221844//  hlsl_info::add_cache_target - register a cache target
18231845//============================================================
1824bool hlsl_info::add_cache_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int prescale_x, int prescale_y, int screen_index)
1846bool hlsl_info::add_cache_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index)
18251847{
18261848   d3d_cache_target* target = (d3d_cache_target*)global_alloc_clear(d3d_cache_target);
18271849
1828   if (!target->init(d3d, d3dintf, width, height, prescale_x, prescale_y))
1850   if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
18291851   {
18301852      global_free(target);
18311853      return false;
18321854   }
18331855
1856   target->width = info->texinfo.width;
1857   target->height = info->texinfo.height;
1858
18341859   target->next = cachehead;
18351860   target->prev = NULL;
18361861
18371862   target->screen_index = screen_index;
1838   target->ref_count = 1;
18391863
18401864   if (cachehead != NULL)
18411865   {
r19929r19930
18501874//  hlsl_info::add_render_target - register a render target
18511875//============================================================
18521876
1853bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int prescale_x, int prescale_y)
1877bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale)
18541878{
1879   if (find_render_target(info))
1880   {
1881      remove_render_target(info);
1882   }
1883
1884   UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
1885   UINT32 screen_index = screen_index_data >> 1;
1886   UINT32 page_index = screen_index_data & 1;
1887
18551888   d3d_render_target* target = (d3d_render_target*)global_alloc_clear(d3d_render_target);
18561889
1857   if (!target->init(d3d, d3dintf, width, height, prescale_x, prescale_y))
1890   if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale))
18581891   {
18591892      global_free(target);
18601893      return false;
r19929r19930
18621895
18631896   target->info = info;
18641897
1865   UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
1866   target->screen_index = screen_index_data >> 1;
1867   target->page_index = screen_index_data & 1;
1898   target->width = info->texinfo.width;
1899   target->height = info->texinfo.height;
18681900
1869   d3d_cache_target* cache = find_cache_target(target->screen_index);
1901   target->screen_index = screen_index;
1902   target->page_index = page_index;
1903
1904   d3d_cache_target* cache = find_cache_target(target->screen_index, info->texinfo.width, info->texinfo.height);
18701905   if (cache == NULL)
18711906   {
1872      if (!add_cache_target(d3d, info, width, height, prescale_x, prescale_y, target->screen_index))
1907      if (!add_cache_target(d3d, info, width, height, xprescale * prescale_force_x, yprescale * prescale_force_y, target->screen_index))
18731908      {
18741909         global_free(target);
18751910         return false;
18761911      }
18771912   }
1878   else
1879   {
1880      cache->ref_count++;
1881   }
18821913
18831914   target->next = targethead;
18841915   target->prev = NULL;
r19929r19930
19011932   num_screens = iter.count();
19021933}
19031934
1935
19041936//============================================================
19051937//  hlsl_info::register_texture
19061938//============================================================
19071939
1908int hlsl_info::register_texture(d3d_texture_info *texture)
1940bool hlsl_info::register_texture(d3d_texture_info *texture)
19091941{
1910   enumerate_screens();
1942   return register_texture(texture, texture->rawwidth, texture->rawheight, 1, 1);
1943}
19111944
1945
1946//============================================================
1947//  hlsl_info::register_texture(d3d_texture_info, int, int, int, int)
1948//============================================================
1949
1950bool hlsl_info::register_texture(d3d_texture_info *texture, int width, int height, int xscale, int yscale)
1951{
19121952   if (!master_enable || !d3dintf->post_fx_available)
19131953      return 0;
19141954
1955   enumerate_screens();
1956
19151957   d3d_info *d3d = (d3d_info *)window->drawdata;
19161958
19171959   // Find the nearest prescale factor that is over our screen size
1918   int hlsl_prescale_x = prescale_force_x ? prescale_force_x : 1;
1919   if(!prescale_force_x)
1920   {
1921      while(texture->rawwidth * hlsl_prescale_x < d3d->width) hlsl_prescale_x++;
1922      prescale_size_x = hlsl_prescale_x;
1923   }
1960   int hlsl_prescale_x = prescale_force_x;
1961   int hlsl_prescale_y = prescale_force_y;
19241962
1925   int hlsl_prescale_y = prescale_force_y ? prescale_force_y : 1;
1926   if(!prescale_force_y)
1927   {
1928      while(texture->rawheight * hlsl_prescale_y < d3d->height) hlsl_prescale_y++;
1929      prescale_size_y = hlsl_prescale_y;
1930   }
1963   if (!add_render_target(d3d, texture, width, height, xscale * hlsl_prescale_x, yscale * hlsl_prescale_y))
1964      return false;
19311965
1932   if (!add_render_target(d3d, texture, texture->rawwidth, texture->rawheight, hlsl_prescale_x, hlsl_prescale_y))
1933      return 1;
1934
19351966   options->params_dirty = true;
19361967
1937   return 0;
1968   return true;
19381969}
19391970
19401971//============================================================
trunk/src/osd/windows/drawd3d.h
r19929r19930
7474   d3d_surface *last_target;
7575   d3d_texture *last_texture;
7676
77   int width;
78   int height;
79
7780   int screen_index;
78   int ref_count;
7981
8082   d3d_cache_target *next;
8183   d3d_cache_target *prev;
r19929r19930
9395
9496   int target_width;
9597   int target_height;
98
99   int width;
100   int height;
101
96102   int screen_index;
97103   int page_index;
104
98105   d3d_surface *prescaletarget;
99106   d3d_texture *prescaletexture;
100107   d3d_surface *smalltarget;
trunk/src/osd/windows/d3dhlsl.h
r19929r19930
116116   void render_quad(d3d_poly_info *poly, int vertnum);
117117   void end();
118118
119   int register_texture(d3d_texture_info *texture);
120   int register_prescaled_texture(d3d_texture_info *texture, int scwidth, int scheight);
121   bool add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int prescale_x, int prescale_y);
122   bool add_cache_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int prescale_x, int prescale_y, int screen_index);
119   bool register_texture(d3d_texture_info *texture);
120   bool register_prescaled_texture(d3d_texture_info *texture);
121   bool add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale);
122   bool add_cache_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index);
123123
124124   void window_save();
125125   void window_record();
r19929r19930
131131
132132   void frame_complete();
133133
134   void set_texture(d3d_texture_info *texture);
135   void remove_render_target(d3d_texture_info *texture);
134   void                set_texture(d3d_texture_info *texture);
135   d3d_render_target *      find_render_target(d3d_texture_info *info);
136   void                remove_render_target(d3d_texture_info *texture);
137   void                remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
138   void                remove_render_target(d3d_render_target *rt);
136139
137140   int create_resources();
138141   void delete_resources();
r19929r19930
146149   void               end_avi_recording();
147150   void               begin_avi_recording(const char *name);
148151
149   d3d_render_target *      find_render_target(d3d_texture_info *info);
150   d3d_cache_target *      find_cache_target(int screen_index);
152   bool               register_texture(d3d_texture_info *texture, int width, int height, int xscale, int yscale);
153
154   d3d_render_target*       find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
155   d3d_cache_target *      find_cache_target(UINT32 screen_index, int width, int height);
151156   void               remove_cache_target(d3d_cache_target *cache);
152157
153158   d3d_base *              d3dintf;               // D3D interface
trunk/src/osd/windows/winmain.c
r19929r19930
338338   { WINOPTION_HLSL_INI_READ,                           "0",       OPTION_BOOLEAN,   "enable HLSL INI reading" },
339339   { WINOPTION_HLSL_INI_WRITE,                           "0",       OPTION_BOOLEAN,   "enable HLSL INI writing" },
340340   { WINOPTION_HLSL_INI_NAME,                           "%g",        OPTION_STRING,     "HLSL INI file name for this game" },
341   { WINOPTION_HLSL_PRESCALE_X,                          "0",         OPTION_INTEGER,    "HLSL pre-scale override factor for X (0 for auto)" },
342   { WINOPTION_HLSL_PRESCALE_Y,                          "0",         OPTION_INTEGER,    "HLSL pre-scale override factor for Y (0 for auto)" },
341   { WINOPTION_HLSL_PRESCALE_X,                          "2",         OPTION_INTEGER,    "HLSL pre-scale override factor for X" },
342   { WINOPTION_HLSL_PRESCALE_Y,                          "2",         OPTION_INTEGER,    "HLSL pre-scale override factor for Y" },
343343   { WINOPTION_HLSL_PRESET";(-1-3)",                           "-1",        OPTION_INTEGER,    "HLSL preset to use (0-3)" },
344344   { WINOPTION_HLSL_WRITE,                                NULL,        OPTION_STRING,     "enable HLSL AVI writing (huge disk bandwidth suggested)" },
345345   { WINOPTION_HLSL_SNAP_WIDTH,                           "2048",      OPTION_STRING,     "HLSL upscaled-snapshot width" },
trunk/src/osd/windows/drawd3d.c
r19929r19930
18011801               texture->d3dfinaltex = texture->d3dtex;
18021802               texture->type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
18031803
1804               int ret = d3d->hlsl->register_texture(texture);
1805               if (ret != 0)
1804               if (d3d->hlsl->enabled() && !d3d->hlsl->register_texture(texture))
18061805                  goto error;
18071806
18081807               break;
r19929r19930
18431842            result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &texture->d3dfinaltex);
18441843            if (result == D3D_OK)
18451844            {
1846               int ret = d3d->hlsl->register_prescaled_texture(texture, scwidth, scheight);
1847               if (ret != 0)
1845               if (d3d->hlsl->enabled() && !d3d->hlsl->register_prescaled_texture(texture))
1846               {
18481847                  goto error;
1849
1848               }
18501849               break;
18511850            }
18521851            (*d3dintf->texture.release)(texture->d3dtex);
r19929r19930
25222521   // find a match
25232522   for (texture = d3d->texlist; texture != NULL; texture = texture->next)
25242523   {
2524      UINT32 test_screen = (UINT32)texture->texinfo.osddata >> 1;
2525      UINT32 test_page = (UINT32)texture->texinfo.osddata & 1;
2526      UINT32 prim_screen = (UINT32)prim->texture.osddata >> 1;
2527      UINT32 prim_page = (UINT32)prim->texture.osddata & 1;
2528      if (test_screen != prim_screen || test_page != prim_page)
2529      {
2530         continue;
2531      }
2532
25252533      if (texture->hash == texhash &&
25262534         texture->texinfo.base == prim->texture.base &&
25272535         texture->texinfo.width == prim->texture.width &&
25282536         texture->texinfo.height == prim->texture.height &&
25292537         ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
25302538      {
2531         return texture;
2539         // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
2540         if (d3d->hlsl->enabled() && prim->texture.width != 0 && prim->texture.height != 0 && (prim->flags & PRIMFLAG_SCREENTEX_MASK) != 0)
2541         {
2542            if (d3d->hlsl->find_render_target(texture) != NULL)
2543            {
2544               return texture;
2545            }
2546         }
2547         else
2548         {
2549            return texture;
2550         }
25322551      }
25332552   }
25342553
25352554   // nothing found, check if we need to unregister something with hlsl
2536   if (d3d->hlsl != NULL)
2555   if (d3d->hlsl->enabled())
25372556   {
2557      if (prim->texture.width == 0 || prim->texture.height == 0)
2558      {
2559         return NULL;
2560      }
2561
2562      UINT32 prim_screen = (UINT32)prim->texture.osddata >> 1;
2563      UINT32 prim_page = (UINT32)prim->texture.osddata & 1;
2564
25382565      for (texture = d3d->texlist; texture != NULL; texture = texture->next)
25392566      {
2567         UINT32 test_screen = (UINT32)texture->texinfo.osddata >> 1;
2568         UINT32 test_page = (UINT32)texture->texinfo.osddata & 1;
2569         if (test_screen != prim_screen || test_page != prim_page)
2570         {
2571            continue;
2572         }
2573
25402574         // Clear our old texture reference
25412575         if (texture->hash == texhash &&
25422576             texture->texinfo.base == prim->texture.base &&

Previous 199869 Revisions Next


© 1997-2024 The MAME Team