Previous 15994 Revisions Next

r11646 Tuesday 24th May, 2011 at 19:36:55 UTC by MooglyGuy
Fixed D3D crash on low-end GPUs, ported from MAME. [Ryan Holtz, Ashura-X]
[hlsl]color.fx deconverge.fx focus.fx phosphor.fx pincushion.fx post.fx primary.fx yiq_decode.fx yiq_encode.fx
[src/osd/windows]drawd3d.c

hlsl/primary.fx
r11645r11646
2424   float4 Position : POSITION;
2525   float4 Color : COLOR0;
2626   float2 TexCoord : TEXCOORD0;
27   float2 ExtraInfo : TEXCOORD1;
2827};
2928
3029struct VS_INPUT
r11645r11646
3231   float3 Position : POSITION;
3332   float4 Color : COLOR0;
3433   float2 TexCoord : TEXCOORD0;
35   float2 ExtraInfo : TEXCOORD1;
3634};
3735
3836struct PS_INPUT
3937{
4038   float4 Color : COLOR0;
4139   float2 TexCoord : TEXCOORD0;
42   float2 ExtraInfo : TEXCOORD1;
4340};
4441
4542//-----------------------------------------------------------------------------
r11645r11646
6461   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
6562   Output.Color = Input.Color;
6663   Output.TexCoord = lerp(Input.TexCoord, Input.Position.xy / float2(TargetWidth, TargetHeight), PostPass);
67   Output.ExtraInfo = Input.ExtraInfo;
6864
6965   return Output;
7066}
r11645r11646
7672float4 ps_main(PS_INPUT Input) : COLOR
7773{
7874   float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
79   return lerp(Input.Color, BaseTexel * Input.Color, Input.ExtraInfo.x);
75   return BaseTexel * Input.Color;
8076}
8177
8278//-----------------------------------------------------------------------------
hlsl/post.fx
r11645r11646
3737   float4 Position : POSITION;
3838   float4 Color : COLOR0;
3939   float2 TexCoord : TEXCOORD0;
40   float2 ExtraInfo : TEXCOORD1;
4140};
4241
4342struct VS_INPUT
r11645r11646
4544   float4 Position : POSITION;
4645   float4 Color : COLOR0;
4746   float2 TexCoord : TEXCOORD0;
48   float2 ExtraInfo : TEXCOORD1;
4947};
5048
5149struct PS_INPUT
5250{
5351   float4 Color : COLOR0;
5452   float2 TexCoord : TEXCOORD0;
55   float2 ExtraInfo : TEXCOORD1;
5653};
5754
5855//-----------------------------------------------------------------------------
r11645r11646
8178   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
8279   Output.Color = Input.Color;
8380   Output.TexCoord = Input.TexCoord + 0.5f / float2(RawWidth, RawHeight);
84   Output.ExtraInfo = Input.ExtraInfo;
8581
8682   //float Zoom = 1.0f;
8783   //Output.TexCoord /= Zoom;
r11645r11646
169165   float3 ShadowTexel = lerp(1.0f, tex2D(ShadowSampler, ShadowCoord), UseShadow);
170166   
171167   // -- Final Pixel --
172   float4 Output = lerp(Input.Color, float4(Scanned * lerp(1.0f, ShadowTexel * 1.25f, ShadowBrightness), BaseTexel.a) * Input.Color, Input.ExtraInfo.x);
168   float4 Output = float4(Scanned * lerp(1.0f, ShadowTexel * 1.25f, ShadowBrightness), BaseTexel.a) * Input.Color;
173169   
174170   return Output;
175171}
hlsl/yiq_decode.fx
r11645r11646
5151   float4 Position : POSITION;
5252   float4 Color : COLOR0;
5353   float2 TexCoord : TEXCOORD0;
54   float2 ExtraInfo : TEXCOORD1;
5554};
5655
5756struct PS_INPUT
hlsl/color.fx
r11645r11646
2424   float4 Position : POSITION;
2525   float4 Color : COLOR0;
2626   float2 TexCoord : TEXCOORD0;
27   float2 ExtraInfo : TEXCOORD1;
2827};
2928
3029struct VS_INPUT
r11645r11646
3231   float4 Position : POSITION;
3332   float4 Color : COLOR0;
3433   float2 TexCoord : TEXCOORD0;
35   float2 ExtraInfo : TEXCOORD1;
3634};
3735
3836struct PS_INPUT
3937{
4038   float4 Color : COLOR0;
4139   float2 TexCoord : TEXCOORD0;
42   float2 ExtraInfo : TEXCOORD1;
4340};
4441
4542//-----------------------------------------------------------------------------
r11645r11646
7067   Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
7168   Output.Color = Input.Color;
7269   Output.TexCoord = Input.TexCoord;
73   Output.ExtraInfo = Input.ExtraInfo;
7470
7571   return Output;
7672}
hlsl/focus.fx
r11645r11646
3838   float3 Position : POSITION;
3939   float4 Color : COLOR0;
4040   float2 TexCoord : TEXCOORD0;
41   float2 ExtraInfo : TEXCOORD1;
4241};
4342
4443struct PS_INPUT
hlsl/pincushion.fx
r11645r11646
2424   float4 Position : POSITION;
2525   float4 Color : COLOR0;
2626   float2 TexCoord : TEXCOORD0;
27   float2 ExtraInfo : TEXCOORD1;
2827   float2 RedCoord : TEXCOORD2;
2928   float2 GreenCoord : TEXCOORD3;
3029   float2 BlueCoord : TEXCOORD4;
r11645r11646
3534   float3 Position : POSITION;
3635   float4 Color : COLOR0;
3736   float2 TexCoord : TEXCOORD0;
38   float2 ExtraInfo : TEXCOORD1;
3937};
4038
4139struct PS_INPUT
4240{
4341   float4 Color : COLOR0;
4442   float2 TexCoord : TEXCOORD0;
45   float2 ExtraInfo : TEXCOORD1;
4643   float2 RedCoord : TEXCOORD2;
4744   float2 GreenCoord : TEXCOORD3;
4845   float2 BlueCoord : TEXCOORD4;
hlsl/yiq_encode.fx
r11645r11646
3434   float4 Position : POSITION;
3535   float4 Color : COLOR0;
3636   float2 TexCoord : TEXCOORD0;
37   float2 ExtraInfo : TEXCOORD1;
3837};
3938
4039struct PS_INPUT
hlsl/deconverge.fx
r11645r11646
3434   float4 Position : POSITION;
3535   float4 Color : COLOR0;
3636   float2 TexCoord : TEXCOORD0;
37   float2 ExtraInfo : TEXCOORD1;
3837};
3938
4039struct PS_INPUT
hlsl/phosphor.fx
r11645r11646
4545   float3 Position : POSITION;
4646   float4 Color : COLOR0;
4747   float2 TexCoord : TEXCOORD0;
48   float2 ExtraInfo : TEXCOORD1;
4948};
5049
5150struct PS_INPUT
src/osd/windows/drawd3d.c
r11645r11646
8787
8888#define ENABLE_BORDER_PIX   (1)
8989
90#define VERTEX_BASE_FORMAT   (D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEX2)
91#define VERTEX_BUFFER_SIZE   (2048*6+6)
90#define VERTEX_BASE_FORMAT   (D3DFVF_DIFFUSE | D3DFVF_TEX1)
91#define VERTEX_BUFFER_SIZE   (2048*4+4)
9292
9393enum
9494{
r11645r11646
167167   float               rhw;                  // RHW when no HLSL, padding when HLSL
168168   D3DCOLOR            color;                  // diffuse color
169169   float               u0, v0;                  // texture stage 0 coordinates
170   float               uv_stretch, pad;         // UV stretch (used by HLSL)
171170};
172171
173172
r11645r11646
799798   {
800799      d3d->last_texture = texture;
801800      d3d->last_texture_flags = (texture == NULL ? 0 : texture->flags);
802      result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? NULL : texture->d3dfinaltex);
801      result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
803802      if(d3d->hlsl_enable && d3d->effect != NULL)
804803      {
805         (*d3dintf->effect.set_texture)(d3d->effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex);
804         (*d3dintf->effect.set_texture)(d3d->effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
806805         if(d3d->yiq_enable)
807806         {
808            (*d3dintf->effect.set_texture)(d3d->yiq_encode_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex);
807            (*d3dintf->effect.set_texture)(d3d->yiq_encode_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
809808         }
810809         else
811810         {
812            (*d3dintf->effect.set_texture)(d3d->color_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex);
811            (*d3dintf->effect.set_texture)(d3d->color_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
813812         }
814         (*d3dintf->effect.set_texture)(d3d->pincushion_effect, "Diffuse", (texture == NULL) ? NULL : texture->d3dfinaltex);
813         (*d3dintf->effect.set_texture)(d3d->pincushion_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
815814      }
816815      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result);
817816   }
r11645r11646
11621161   }
11631162
11641163mtlog_add("drawd3d_window_draw: begin");
1165
11661164   result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
1167   if(result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
1165   if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
11681166
11691167   // first update any textures
11701168   window->primlist->acquire_lock();
r11645r11646
13091307
13101308   // create the D3D device
13111309   result = (*d3dintf->d3d.create_device)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, win_window_list->hwnd,
1312               D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device);
1310               D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device);
13131311   if (result != D3D_OK)
13141312   {
13151313      // if we got a "DEVICELOST" error, it may be transitory; count it and only fail if
r11645r11646
15071505   // allocate a vertex buffer to use
15081506   result = (*d3dintf->device.create_vertex_buffer)(d3d->device,
15091507            sizeof(d3d_vertex) * VERTEX_BUFFER_SIZE,
1510            D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
1508            D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY,
15111509            VERTEX_BASE_FORMAT | ((d3d->hlsl_enable && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW), D3DPOOL_DEFAULT, &d3d->vertexbuf);
15121510   if (result != D3D_OK)
15131511   {
r11645r11646
15521550   reset_render_states(d3d);
15531551
15541552   // clear the buffer
1555   result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 0, 0);
1553   result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
15561554   result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0);
15571555
15581556   // experimental: if we have a vector bitmap, create a texture for it
r11645r11646
15721570      d3d->vector_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
15731571   }
15741572
1575   // experimental: initialize some more things if we're using HLSL
1576   if(d3d->hlsl_enable && d3dintf->post_fx_available)
1573   // experimental: create a default bitmap for our shader
1574   if (d3d->default_bitmap != NULL)
15771575   {
1578      // experimental: create a default bitmap for our shader
1579      if (d3d->default_bitmap != NULL)
1580      {
1581         render_texinfo texture;
1576      render_texinfo texture;
15821577
1583         // fake in the basic data so it looks like it came from render.c
1584         texture.base = d3d->default_bitmap->base;
1585         texture.rowpixels = d3d->default_bitmap->rowpixels;
1586         texture.width = d3d->default_bitmap->width;
1587         texture.height = d3d->default_bitmap->height;
1588         texture.palette = NULL;
1589         texture.seqid = 0;
1578      // fake in the basic data so it looks like it came from render.c
1579      texture.base = d3d->default_bitmap->base;
1580      texture.rowpixels = d3d->default_bitmap->rowpixels;
1581      texture.width = d3d->default_bitmap->width;
1582      texture.height = d3d->default_bitmap->height;
1583      texture.palette = NULL;
1584      texture.seqid = 0;
15901585
1591         // now create it
1592         d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
1593      }
1586      // now create it
1587      d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
1588   }
15941589
1590   // experimental: initialize some more things if we're using HLSL
1591   if(d3d->hlsl_enable && d3dintf->post_fx_available)
1592   {
15951593      windows_options &options = downcast<windows_options &>(d3d->window->machine().options());
15961594
15971595      // experimental: load a PNG to use for vector rendering; it is treated
r11645r11646
23522350
23532351         vertex[3].u0 = d3d->vector_texture->ustop;
23542352         vertex[3].v0 = d3d->vector_texture->vstop;
2355
2356         vertex[0].uv_stretch = 1.0f;
2357         vertex[1].uv_stretch = 1.0f;
2358         vertex[2].uv_stretch = 1.0f;
2359         vertex[3].uv_stretch = 1.0f;
23602353      }
23612354      else if(d3d->default_texture != NULL)
23622355      {
r11645r11646
23712364
23722365         vertex[3].u0 = d3d->default_texture->ustart;
23732366         vertex[3].v0 = d3d->default_texture->vstart;
2374
2375         vertex[0].uv_stretch = 0.0f;
2376         vertex[1].uv_stretch = 0.0f;
2377         vertex[2].uv_stretch = 0.0f;
2378         vertex[3].uv_stretch = 0.0f;
23792367      }
2380      else
2381      {
2382         vertex[0].uv_stretch = 0.0f;
2383         vertex[1].uv_stretch = 0.0f;
2384         vertex[2].uv_stretch = 0.0f;
2385         vertex[3].uv_stretch = 0.0f;
2386      }
23872368
23882369      // set the color, Z parameters to standard values
23892370      for (i = 0; i < 4; i++)
r11645r11646
24222403   texture = texture != NULL ? texture : d3d->default_texture;
24232404
24242405   // get a pointer to the vertex buffer
2425   vertex = primitive_alloc(d3d, 6);
2406   vertex = primitive_alloc(d3d, 4);
24262407   if (vertex == NULL)
24272408      return;
24282409
r11645r11646
24332414   vertex[1].y = prim->bounds.y0 - 0.5f;
24342415   vertex[2].x = prim->bounds.x0 - 0.5f;
24352416   vertex[2].y = prim->bounds.y1 - 0.5f;
2417   vertex[3].x = prim->bounds.x1 - 0.5f;
2418   vertex[3].y = prim->bounds.y1 - 0.5f;
24362419
2437   vertex[3].x = vertex[1].x;
2438   vertex[3].y = vertex[1].y;
2439   vertex[4].x = vertex[2].x;
2440   vertex[4].y = vertex[2].y;
2441   vertex[5].x = prim->bounds.x1 - 0.5f;
2442   vertex[5].y = prim->bounds.y1 - 0.5f;
2443
24442420   // set the texture coordinates
24452421   if(texture != NULL)
24462422   {
r11645r11646
24522428      vertex[1].v0 = texture->vstart + dv * prim->texcoords.tr.v;
24532429      vertex[2].u0 = texture->ustart + du * prim->texcoords.bl.u;
24542430      vertex[2].v0 = texture->vstart + dv * prim->texcoords.bl.v;
2455
2456      vertex[3].u0 = texture->ustart + du * prim->texcoords.tr.u;
2457      vertex[3].v0 = texture->vstart + dv * prim->texcoords.tr.v;
2458      vertex[4].u0 = texture->ustart + du * prim->texcoords.bl.u;
2459      vertex[4].v0 = texture->vstart + dv * prim->texcoords.bl.v;
2460      vertex[5].u0 = texture->ustart + du * prim->texcoords.br.u;
2461      vertex[5].v0 = texture->vstart + dv * prim->texcoords.br.v;
2462
2463      vertex[0].uv_stretch = 1.0f;
2464      vertex[1].uv_stretch = 1.0f;
2465      vertex[2].uv_stretch = 1.0f;
2466      vertex[3].uv_stretch = 1.0f;
2467      vertex[4].uv_stretch = 1.0f;
2468      vertex[5].uv_stretch = 1.0f;
2431      vertex[3].u0 = texture->ustart + du * prim->texcoords.br.u;
2432      vertex[3].v0 = texture->vstart + dv * prim->texcoords.br.v;
24692433   }
2470   else
2471   {
2472      vertex[0].uv_stretch = 1.0f;
2473      vertex[1].uv_stretch = 1.0f;
2474      vertex[2].uv_stretch = 1.0f;
2475      vertex[3].uv_stretch = 1.0f;
2476      vertex[4].uv_stretch = 1.0f;
2477      vertex[5].uv_stretch = 1.0f;
2478   }
24792434
24802435   // determine the color, allowing for over modulation
24812436   r = (INT32)(prim->color.r * 255.0f);
r11645r11646
25062461   color = D3DCOLOR_ARGB(a, r, g, b);
25072462
25082463   // set the color, Z parameters to standard values
2509   for (i = 0; i < 6; i++)
2464   for (i = 0; i < 4; i++)
25102465   {
25112466      vertex[i].z = 0.0f;
25122467      vertex[i].rhw = 1.0f;
r11645r11646
25152470
25162471   // now add a polygon entry
25172472   poly = &d3d->poly[d3d->numpolys++];
2518   poly->type = D3DPT_TRIANGLELIST;
2473   poly->type = D3DPT_TRIANGLESTRIP;
25192474   poly->count = 2;
2520   poly->numverts = 6;
2475   poly->numverts = 4;
25212476   poly->flags = prim->flags;
25222477   poly->modmode = modmode;
25232478   poly->texture = texture;
r11645r11646
25322487static void init_fsfx_quad(d3d_info *d3d)
25332488{
25342489   // get a pointer to the vertex buffer
2535   d3d->fsfx_vertices = primitive_alloc(d3d, 6);
2490   d3d->fsfx_vertices = primitive_alloc(d3d, 4);
25362491   if (d3d->fsfx_vertices == NULL)
25372492      return;
25382493
r11645r11646
25472502   d3d->fsfx_vertices[1].y = 0.0f;
25482503   d3d->fsfx_vertices[2].x = (d3d->width * (scale_bottom * 0.5f - 0.5f));
25492504   d3d->fsfx_vertices[2].y = d3d->height;
2550   d3d->fsfx_vertices[3].x = d3d->width - (d3d->width * (scale_top * 0.5f - 0.5f));
2551   d3d->fsfx_vertices[3].y = 0.0f;
2552   d3d->fsfx_vertices[4].x = (d3d->width * (scale_bottom * 0.5f - 0.5f));
2553   d3d->fsfx_vertices[4].y = d3d->height;
2554   d3d->fsfx_vertices[5].x = d3d->width - (d3d->width * (scale_bottom * 0.5f - 0.5f));
2555   d3d->fsfx_vertices[5].y = d3d->height;
2505   d3d->fsfx_vertices[3].x = d3d->width - (d3d->width * (scale_bottom * 0.5f - 0.5f));
2506   d3d->fsfx_vertices[3].y = d3d->height;
25562507
25572508   d3d->fsfx_vertices[0].u0 = 0.0f;
25582509   d3d->fsfx_vertices[0].v0 = 0.0f;
r11645r11646
25612512   d3d->fsfx_vertices[2].u0 = 0.0f;
25622513   d3d->fsfx_vertices[2].v0 = 1.0f;
25632514   d3d->fsfx_vertices[3].u0 = 1.0f;
2564   d3d->fsfx_vertices[3].v0 = 0.0f;
2565   d3d->fsfx_vertices[4].u0 = 0.0f;
2566   d3d->fsfx_vertices[4].v0 = 1.0f;
2567   d3d->fsfx_vertices[5].u0 = 1.0f;
2568   d3d->fsfx_vertices[5].v0 = 1.0f;
2515   d3d->fsfx_vertices[3].v0 = 1.0f;
25692516
25702517   // set the color, Z parameters to standard values
2571   for (int i = 0; i < 6; i++)
2518   for (int i = 0; i < 4; i++)
25722519   {
25732520      d3d->fsfx_vertices[i].z = 0.0f;
25742521      d3d->fsfx_vertices[i].rhw = 1.0f;
r11645r11646
26562603   {
26572604      result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer);
26582605      if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
2659      vertnum = 6;
2606      vertnum = 4;
26602607   }
26612608   else
26622609   {

Previous 15994 Revisions Next


© 1998-2018 The MESS Team