Previous 199869 Revisions Next

r20086 Saturday 5th January, 2013 at 19:02:01 UTC by Ryan Holtz
- d3dhlsl.c: Free HLSL resources on device reset. Fixes hang when alt-tabbing
            away from a fullscreen window and back. [MooglyGuy]
[src/osd/windows]d3dhlsl.c d3dhlsl.h drawd3d.c

trunk/src/osd/windows/drawd3d.c
r20085r20086
803803      d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
804804   }
805805
806   int ret = d3d->hlsl->create_resources();
806   int ret = d3d->hlsl->create_resources(false);
807807   if (ret != 0)
808808       return ret;
809809
r20085r20086
900900static void device_delete(d3d_info *d3d)
901901{
902902   // free our effects
903   d3d->hlsl->delete_resources();
903   d3d->hlsl->delete_resources(false);
904904
905905   // delete the HLSL interface
906906   global_free(d3d->hlsl);
r20085r20086
11441144
11451145      // free all existing resources and call reset on the device
11461146      device_delete_resources(d3d);
1147      d3d->hlsl->delete_resources(true);
11471148      result = (*d3dintf->device.reset)(d3d->device, &d3d->presentation);
11481149
11491150      // if it didn't work, punt to GDI
11501151      if (result != D3D_OK)
1152      {
1153         printf("Unable to reset, result %08x\n", (UINT32)result);
11511154         return 1;
1155      }
11521156
11531157      // try to create the resources again; if that didn't work, delete the whole thing
11541158      if (device_create_resources(d3d))
r20085r20086
11571161         device_delete(d3d);
11581162         return 1;
11591163      }
1164
1165      if (d3d->hlsl->create_resources(true))
1166      {
1167         mame_printf_verbose("Direct3D: failed to recreate HLSL resources for device; failing permanently\n");
1168         device_delete(d3d);
1169         return 1;
1170      }
11601171   }
11611172   return 0;
11621173}
trunk/src/osd/windows/d3dhlsl.c
r20085r20086
777777//  hlsl_info::create_resources
778778//============================================================
779779
780int hlsl_info::create_resources()
780int hlsl_info::create_resources(bool reset)
781781{
782782   if (!master_enable || !d3dintf->post_fx_available)
783783      return 0;
r20085r20086
802802
803803   windows_options &winoptions = downcast<windows_options &>(window->machine().options());
804804
805   options = (hlsl_options*)global_alloc_clear(hlsl_options);
805   if (!reset)
806   {
807      options = (hlsl_options*)global_alloc_clear(hlsl_options);
806808
807   options->params_dirty = true;
808   strcpy(options->shadow_mask_texture, downcast<windows_options &>(window->machine().options()).screen_shadow_mask_texture()); // unsafe
809      options->params_dirty = true;
810      strcpy(options->shadow_mask_texture, downcast<windows_options &>(window->machine().options()).screen_shadow_mask_texture()); // unsafe
809811
810   write_ini = downcast<windows_options &>(window->machine().options()).hlsl_write_ini();
811   read_ini = downcast<windows_options &>(window->machine().options()).hlsl_read_ini();
812      write_ini = downcast<windows_options &>(window->machine().options()).hlsl_write_ini();
813      read_ini = downcast<windows_options &>(window->machine().options()).hlsl_read_ini();
812814
813   if(read_ini)
814   {
815      emu_file ini_file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_READ | OPEN_FLAG_CREATE_PATHS);
816      file_error filerr = open_next((d3d_info*)window->drawdata, ini_file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0);
815      if(read_ini)
816      {
817         emu_file ini_file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_READ | OPEN_FLAG_CREATE_PATHS);
818         file_error filerr = open_next((d3d_info*)window->drawdata, ini_file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0);
817819
818      read_ini = false;
819      if (filerr == FILERR_NONE)
820      {
821         ini_file.seek(0, SEEK_END);
822         if (ini_file.tell() >= 1000)
820         read_ini = false;
821         if (filerr == FILERR_NONE)
823822         {
824            read_ini = true;
825            ini_file.seek(0, SEEK_SET);
823            ini_file.seek(0, SEEK_END);
824            if (ini_file.tell() >= 1000)
825            {
826               read_ini = true;
827               ini_file.seek(0, SEEK_SET);
826828
827            int en = 0;
828            char buf[1024];
829            ini_file.gets(buf, 1024);
830            sscanf(buf, "hlsl_enable %d\n", &en);
831            master_enable = en == 1;
829               int en = 0;
830               char buf[1024];
831               ini_file.gets(buf, 1024);
832               sscanf(buf, "hlsl_enable %d\n", &en);
833               master_enable = en == 1;
832834
833            ini_file.gets(buf, 1024);
834            sscanf(buf, "hlsl_prescale_x %d\n", &prescale_force_x);
835               ini_file.gets(buf, 1024);
836               sscanf(buf, "hlsl_prescale_x %d\n", &prescale_force_x);
835837
836            ini_file.gets(buf, 1024);
837            sscanf(buf, "hlsl_prescale_y %d\n", &prescale_force_y);
838               ini_file.gets(buf, 1024);
839               sscanf(buf, "hlsl_prescale_y %d\n", &prescale_force_y);
838840
839            ini_file.gets(buf, 1024);
840            sscanf(buf, "hlsl_preset %d\n", &preset);
841               ini_file.gets(buf, 1024);
842               sscanf(buf, "hlsl_preset %d\n", &preset);
841843
842            ini_file.gets(buf, 1024);
843            sscanf(buf, "hlsl_snap_width %d\n", &snap_width);
844               ini_file.gets(buf, 1024);
845               sscanf(buf, "hlsl_snap_width %d\n", &snap_width);
844846
845            ini_file.gets(buf, 1024);
846            sscanf(buf, "hlsl_snap_height %d\n", &snap_height);
847               ini_file.gets(buf, 1024);
848               sscanf(buf, "hlsl_snap_height %d\n", &snap_height);
847849
848            ini_file.gets(buf, 1024);
849            sscanf(buf, "shadow_mask_alpha %f\n", &options->shadow_mask_alpha);
850               ini_file.gets(buf, 1024);
851               sscanf(buf, "shadow_mask_alpha %f\n", &options->shadow_mask_alpha);
850852
851            ini_file.gets(buf, 1024);
852            sscanf(buf, "shadow_mask_texture %s\n", options->shadow_mask_texture);
853               ini_file.gets(buf, 1024);
854               sscanf(buf, "shadow_mask_texture %s\n", options->shadow_mask_texture);
853855
854            ini_file.gets(buf, 1024);
855            sscanf(buf, "shadow_mask_x_count %d\n", &options->shadow_mask_count_x);
856               ini_file.gets(buf, 1024);
857               sscanf(buf, "shadow_mask_x_count %d\n", &options->shadow_mask_count_x);
856858
857            ini_file.gets(buf, 1024);
858            sscanf(buf, "shadow_mask_y_count %d\n", &options->shadow_mask_count_y);
859               ini_file.gets(buf, 1024);
860               sscanf(buf, "shadow_mask_y_count %d\n", &options->shadow_mask_count_y);
859861
860            ini_file.gets(buf, 1024);
861            sscanf(buf, "shadow_mask_usize %f\n", &options->shadow_mask_u_size);
862               ini_file.gets(buf, 1024);
863               sscanf(buf, "shadow_mask_usize %f\n", &options->shadow_mask_u_size);
862864
863            ini_file.gets(buf, 1024);
864            sscanf(buf, "shadow_mask_vsize %f\n", &options->shadow_mask_v_size);
865               ini_file.gets(buf, 1024);
866               sscanf(buf, "shadow_mask_vsize %f\n", &options->shadow_mask_v_size);
865867
866            ini_file.gets(buf, 1024);
867            sscanf(buf, "curvature %f\n", &options->curvature);
868               ini_file.gets(buf, 1024);
869               sscanf(buf, "curvature %f\n", &options->curvature);
868870
869            ini_file.gets(buf, 1024);
870            sscanf(buf, "pincushion %f\n", &options->pincushion);
871               ini_file.gets(buf, 1024);
872               sscanf(buf, "pincushion %f\n", &options->pincushion);
871873
872            ini_file.gets(buf, 1024);
873            sscanf(buf, "scanline_alpha %f\n", &options->scanline_alpha);
874               ini_file.gets(buf, 1024);
875               sscanf(buf, "scanline_alpha %f\n", &options->scanline_alpha);
874876
875            ini_file.gets(buf, 1024);
876            sscanf(buf, "scanline_size %f\n", &options->scanline_scale);
877               ini_file.gets(buf, 1024);
878               sscanf(buf, "scanline_size %f\n", &options->scanline_scale);
877879
878            ini_file.gets(buf, 1024);
879            sscanf(buf, "scanline_height %f\n", &options->scanline_height);
880               ini_file.gets(buf, 1024);
881               sscanf(buf, "scanline_height %f\n", &options->scanline_height);
880882
881            ini_file.gets(buf, 1024);
882            sscanf(buf, "scanline_bright_scale %f\n", &options->scanline_bright_scale);
883               ini_file.gets(buf, 1024);
884               sscanf(buf, "scanline_bright_scale %f\n", &options->scanline_bright_scale);
883885
884            ini_file.gets(buf, 1024);
885            sscanf(buf, "scanline_bright_offset %f\n", &options->scanline_bright_offset);
886               ini_file.gets(buf, 1024);
887               sscanf(buf, "scanline_bright_offset %f\n", &options->scanline_bright_offset);
886888
887            ini_file.gets(buf, 1024);
888            sscanf(buf, "scanline_jitter %f\n", &options->scanline_offset);
889               ini_file.gets(buf, 1024);
890               sscanf(buf, "scanline_jitter %f\n", &options->scanline_offset);
889891
890            ini_file.gets(buf, 1024);
891            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
892            sscanf(buf, "defocus %f %f\n", &options->defocus[0], &options->defocus[1]);
892               ini_file.gets(buf, 1024);
893               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
894               sscanf(buf, "defocus %f %f\n", &options->defocus[0], &options->defocus[1]);
893895
894            ini_file.gets(buf, 1024);
895            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
896            sscanf(buf, "converge_x %f %f %f\n", &options->converge_x[0], &options->converge_x[1], &options->converge_x[2]);
896               ini_file.gets(buf, 1024);
897               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
898               sscanf(buf, "converge_x %f %f %f\n", &options->converge_x[0], &options->converge_x[1], &options->converge_x[2]);
897899
898            ini_file.gets(buf, 1024);
899            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
900            sscanf(buf, "converge_y %f %f %f\n", &options->converge_y[0], &options->converge_y[1], &options->converge_y[2]);
900               ini_file.gets(buf, 1024);
901               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
902               sscanf(buf, "converge_y %f %f %f\n", &options->converge_y[0], &options->converge_y[1], &options->converge_y[2]);
901903
902            ini_file.gets(buf, 1024);
903            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
904            sscanf(buf, "radial_converge_x %f %f %f\n", &options->radial_converge_x[0], &options->radial_converge_x[1], &options->radial_converge_x[2]);
904               ini_file.gets(buf, 1024);
905               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
906               sscanf(buf, "radial_converge_x %f %f %f\n", &options->radial_converge_x[0], &options->radial_converge_x[1], &options->radial_converge_x[2]);
905907
906            ini_file.gets(buf, 1024);
907            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
908            sscanf(buf, "radial_converge_y %f %f %f\n", &options->radial_converge_y[0], &options->radial_converge_y[1], &options->radial_converge_y[2]);
908               ini_file.gets(buf, 1024);
909               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
910               sscanf(buf, "radial_converge_y %f %f %f\n", &options->radial_converge_y[0], &options->radial_converge_y[1], &options->radial_converge_y[2]);
909911
910            ini_file.gets(buf, 1024);
911            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
912            sscanf(buf, "red_ratio %f %f %f\n", &options->red_ratio[0], &options->red_ratio[1], &options->red_ratio[2]);
912               ini_file.gets(buf, 1024);
913               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
914               sscanf(buf, "red_ratio %f %f %f\n", &options->red_ratio[0], &options->red_ratio[1], &options->red_ratio[2]);
913915
914            ini_file.gets(buf, 1024);
915            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
916            sscanf(buf, "grn_ratio %f %f %f\n", &options->grn_ratio[0], &options->grn_ratio[1], &options->grn_ratio[2]);
916               ini_file.gets(buf, 1024);
917               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
918               sscanf(buf, "grn_ratio %f %f %f\n", &options->grn_ratio[0], &options->grn_ratio[1], &options->grn_ratio[2]);
917919
918            ini_file.gets(buf, 1024);
919            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
920            sscanf(buf, "blu_ratio %f %f %f\n", &options->blu_ratio[0], &options->blu_ratio[1], &options->blu_ratio[2]);
920               ini_file.gets(buf, 1024);
921               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
922               sscanf(buf, "blu_ratio %f %f %f\n", &options->blu_ratio[0], &options->blu_ratio[1], &options->blu_ratio[2]);
921923
922            ini_file.gets(buf, 1024);
923            sscanf(buf, "saturation %f\n", &options->saturation);
924               ini_file.gets(buf, 1024);
925               sscanf(buf, "saturation %f\n", &options->saturation);
924926
925            ini_file.gets(buf, 1024);
926            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
927            sscanf(buf, "offset %f %f %f\n", &options->offset[0], &options->offset[1], &options->offset[2]);
927               ini_file.gets(buf, 1024);
928               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
929               sscanf(buf, "offset %f %f %f\n", &options->offset[0], &options->offset[1], &options->offset[2]);
928930
929            ini_file.gets(buf, 1024);
930            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
931            sscanf(buf, "scale %f %f %f\n", &options->scale[0], &options->scale[1], &options->scale[2]);
931               ini_file.gets(buf, 1024);
932               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
933               sscanf(buf, "scale %f %f %f\n", &options->scale[0], &options->scale[1], &options->scale[2]);
932934
933            ini_file.gets(buf, 1024);
934            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
935            sscanf(buf, "power %f %f %f\n", &options->power[0], &options->power[1], &options->power[2]);
935               ini_file.gets(buf, 1024);
936               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
937               sscanf(buf, "power %f %f %f\n", &options->power[0], &options->power[1], &options->power[2]);
936938
937            ini_file.gets(buf, 1024);
938            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
939            sscanf(buf, "floor %f %f %f\n", &options->floor[0], &options->floor[1], &options->floor[2]);
939               ini_file.gets(buf, 1024);
940               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
941               sscanf(buf, "floor %f %f %f\n", &options->floor[0], &options->floor[1], &options->floor[2]);
940942
941            ini_file.gets(buf, 1024);
942            for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
943            sscanf(buf, "phosphor_life %f %f %f\n", &options->phosphor[0], &options->phosphor[1], &options->phosphor[2]);
943               ini_file.gets(buf, 1024);
944               for(int idx = 0; idx < strlen(buf); idx++) if(buf[idx] == ',') buf[idx] = ' ';
945               sscanf(buf, "phosphor_life %f %f %f\n", &options->phosphor[0], &options->phosphor[1], &options->phosphor[2]);
944946
945            ini_file.gets(buf, 1024);
946            sscanf(buf, "yiq_enable %d\n", &en);
947            options->yiq_enable = en == 1;
947               ini_file.gets(buf, 1024);
948               sscanf(buf, "yiq_enable %d\n", &en);
949               options->yiq_enable = en == 1;
948950
949            ini_file.gets(buf, 1024);
950            sscanf(buf, "yiq_cc %f\n", &options->yiq_cc);
951               ini_file.gets(buf, 1024);
952               sscanf(buf, "yiq_cc %f\n", &options->yiq_cc);
951953
952            ini_file.gets(buf, 1024);
953            sscanf(buf, "yiq_a %f\n", &options->yiq_a);
954               ini_file.gets(buf, 1024);
955               sscanf(buf, "yiq_a %f\n", &options->yiq_a);
954956
955            ini_file.gets(buf, 1024);
956            sscanf(buf, "yiq_b %f\n", &options->yiq_b);
957               ini_file.gets(buf, 1024);
958               sscanf(buf, "yiq_b %f\n", &options->yiq_b);
957959
958            ini_file.gets(buf, 1024);
959            sscanf(buf, "yiq_o %f\n", &options->yiq_o);
960               ini_file.gets(buf, 1024);
961               sscanf(buf, "yiq_o %f\n", &options->yiq_o);
960962
961            ini_file.gets(buf, 1024);
962            sscanf(buf, "yiq_p %f\n", &options->yiq_p);
963               ini_file.gets(buf, 1024);
964               sscanf(buf, "yiq_p %f\n", &options->yiq_p);
963965
964            ini_file.gets(buf, 1024);
965            sscanf(buf, "yiq_n %f\n", &options->yiq_n);
966               ini_file.gets(buf, 1024);
967               sscanf(buf, "yiq_n %f\n", &options->yiq_n);
966968
967            ini_file.gets(buf, 1024);
968            sscanf(buf, "yiq_y %f\n", &options->yiq_y);
969               ini_file.gets(buf, 1024);
970               sscanf(buf, "yiq_y %f\n", &options->yiq_y);
969971
970            ini_file.gets(buf, 1024);
971            sscanf(buf, "yiq_i %f\n", &options->yiq_i);
972               ini_file.gets(buf, 1024);
973               sscanf(buf, "yiq_i %f\n", &options->yiq_i);
972974
973            ini_file.gets(buf, 1024);
974            sscanf(buf, "yiq_q %f\n", &options->yiq_q);
975               ini_file.gets(buf, 1024);
976               sscanf(buf, "yiq_q %f\n", &options->yiq_q);
975977
976            ini_file.gets(buf, 1024);
977            sscanf(buf, "yiq_scan_time %f\n", &options->yiq_scan_time);
978               ini_file.gets(buf, 1024);
979               sscanf(buf, "yiq_scan_time %f\n", &options->yiq_scan_time);
978980
979            ini_file.gets(buf, 1024);
980            sscanf(buf, "yiq_phase_count %d\n", &options->yiq_phase_count);
981               ini_file.gets(buf, 1024);
982               sscanf(buf, "yiq_phase_count %d\n", &options->yiq_phase_count);
983            }
981984         }
982985      }
983986   }
r20085r20086
20552058//  hlsl_info::delete_resources
20562059//============================================================
20572060
2058void hlsl_info::delete_resources()
2061void hlsl_info::delete_resources(bool reset)
20592062{
20602063   if (!master_enable || !d3dintf->post_fx_available)
20612064      return;
20622065
2063   if(write_ini)
2066   if(write_ini && !reset)
20642067   {
20652068      emu_file file(downcast<windows_options &>(window->machine().options()).screen_post_fx_dir(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
20662069      file_error filerr = open_next((d3d_info*)window->drawdata, file, downcast<windows_options &>(window->machine().options()).hlsl_ini_name(), "ini", 0);
r20085r20086
21162119      file.printf("yiq_phase_count        %d\n", options->yiq_phase_count);
21172120   }
21182121
2122   while (targethead != NULL)
2123   {
2124      remove_render_target(targethead);
2125   }
2126
21192127   if (effect != NULL)
21202128   {
21212129      (*d3dintf->effect.release)(effect);
r20085r20086
21672175      yiq_decode_effect = NULL;
21682176   }
21692177
2170   for (int index = 0; index < 9; index++)
2171   {
2172   }
2173
21742178   if (avi_copy_texture != NULL)
21752179   {
21762180      (*d3dintf->texture.release)(avi_copy_texture);
trunk/src/osd/windows/d3dhlsl.h
r20085r20086
147147   void                remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
148148   void                remove_render_target(d3d_render_target *rt);
149149
150   int create_resources();
151   void delete_resources();
150   int create_resources(bool reset);
151   void delete_resources(bool reset);
152152
153153   // slider-related functions
154154   slider_state *init_slider_list();

Previous 199869 Revisions Next


© 1997-2024 The MAME Team