diff options
Diffstat (limited to 'src/osd/modules/render/d3d/d3dhlsl.h')
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.h | 263 |
1 files changed, 145 insertions, 118 deletions
diff --git a/src/osd/modules/render/d3d/d3dhlsl.h b/src/osd/modules/render/d3d/d3dhlsl.h index 7f7dacc4538..6820f3dd316 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.h +++ b/src/osd/modules/render/d3d/d3dhlsl.h @@ -2,18 +2,23 @@ // copyright-holders:Aaron Giles //============================================================ // -// drawd3d.c - Win32 Direct3D HLSL-specific header +// drawd3d.h - Win32 Direct3D HLSL-specific header // //============================================================ #ifndef __WIN_D3DHLSL__ #define __WIN_D3DHLSL__ -#include <vector> #include "../frontend/mame/ui/menuitem.h" #include "../frontend/mame/ui/slider.h" #include "modules/lib/osdlib.h" +#include <wrl/client.h> + +#include <map> +#include <memory> +#include <vector> + //============================================================ // TYPE DEFINITIONS //============================================================ @@ -133,11 +138,8 @@ public: effect(shaders *shadersys, IDirect3DDevice9 *dev, const char *name, const char *path); ~effect(); - void begin(UINT *passes, DWORD flags); - void begin_pass(UINT pass); - + void begin(DWORD flags); void end(); - void end_pass(); void set_technique(const char *name); @@ -145,7 +147,6 @@ public: void set_float(D3DXHANDLE param, float value); void set_int(D3DXHANDLE param, int value); void set_bool(D3DXHANDLE param, bool value); - void set_matrix(D3DXHANDLE param, D3DXMATRIX *matrix); void set_texture(D3DXHANDLE param, IDirect3DTexture9 *tex); void add_uniform(const char *name, uniform::uniform_type type, int id); @@ -154,16 +155,26 @@ public: D3DXHANDLE get_parameter(D3DXHANDLE param, const char *name); shaders* get_shaders() { return m_shaders; } + uint32_t num_passes() { return m_num_passes; } bool is_valid() { return m_valid; } + bool is_active() { return m_active; } private: std::vector<std::unique_ptr<uniform>> m_uniform_list; ID3DXEffect *m_effect; shaders *m_shaders; + uint32_t m_num_passes; + + std::map<D3DXHANDLE, D3DXVECTOR4> m_vecs; + std::map<D3DXHANDLE, float> m_floats; + std::map<D3DXHANDLE, int> m_ints; + std::map<D3DXHANDLE, bool> m_bools; + std::map<D3DXHANDLE, void*> m_textures; bool m_valid; + bool m_active; }; class d3d_render_target; @@ -175,92 +186,92 @@ class movie_recorder; /* in the future this will be moved into an OSD/emu shared buffer */ struct hlsl_options { - bool params_init; - bool params_dirty; - int shadow_mask_tile_mode; - float shadow_mask_alpha; - char shadow_mask_texture[1024]; - int shadow_mask_count_x; - int shadow_mask_count_y; - float shadow_mask_u_size; - float shadow_mask_v_size; - float shadow_mask_u_offset; - float shadow_mask_v_offset; - float distortion; - float cubic_distortion; - float distort_corner; - float round_corner; - float smooth_border; - float reflection; - float vignetting; - float scanline_alpha; - float scanline_scale; - float scanline_height; - float scanline_variation; - float scanline_bright_scale; - float scanline_bright_offset; - float scanline_jitter; - float hum_bar_alpha; - float defocus[2]; - float converge_x[3]; - float converge_y[3]; - float radial_converge_x[3]; - float radial_converge_y[3]; - float red_ratio[3]; - float grn_ratio[3]; - float blu_ratio[3]; - float offset[3]; - float scale[3]; - float power[3]; - float floor[3]; - float phosphor[3]; - float saturation; - int chroma_mode; - float chroma_a[2]; - float chroma_b[2]; - float chroma_c[2]; - float chroma_conversion_gain[3]; - float chroma_y_gain[3]; + bool params_init = false; + bool params_dirty = false; + int shadow_mask_tile_mode = 0; + float shadow_mask_alpha = 0.0; + char shadow_mask_texture[1024]{ 0 }; + int shadow_mask_count_x = 0; + int shadow_mask_count_y = 0; + float shadow_mask_u_size = 0.0; + float shadow_mask_v_size = 0.0; + float shadow_mask_u_offset = 0.0; + float shadow_mask_v_offset = 0.0; + float distortion = 0.0; + float cubic_distortion = 0.0; + float distort_corner = 0.0; + float round_corner = 0.0; + float smooth_border = 0.0; + float reflection = 0.0; + float vignetting = 0.0; + float scanline_alpha = 0.0; + float scanline_scale = 0.0; + float scanline_height = 0.0; + float scanline_variation = 0.0; + float scanline_bright_scale = 0.0; + float scanline_bright_offset = 0.0; + float scanline_jitter = 0.0; + float hum_bar_alpha = 0.0; + float defocus[2]{ 0.0 }; + float converge_x[3]{ 0.0 }; + float converge_y[3]{ 0.0 }; + float radial_converge_x[3]{ 0.0 }; + float radial_converge_y[3]{ 0.0 }; + float red_ratio[3]{ 0.0 }; + float grn_ratio[3]{ 0.0 }; + float blu_ratio[3]{ 0.0 }; + float offset[3]{ 0.0 }; + float scale[3]{ 0.0 }; + float power[3]{ 0.0 }; + float floor[3]{ 0.0 }; + float phosphor[3]{ 0.0 }; + float saturation = 0.0; + int chroma_mode = 0; + float chroma_a[2]{ 0.0 }; + float chroma_b[2]{ 0.0 }; + float chroma_c[2]{ 0.0 }; + float chroma_conversion_gain[3]{ 0.0 }; + float chroma_y_gain[3]{ 0.0 }; // NTSC - int yiq_enable; - float yiq_jitter; - float yiq_cc; - float yiq_a; - float yiq_b; - float yiq_o; - float yiq_p; - float yiq_n; - float yiq_y; - float yiq_i; - float yiq_q; - float yiq_scan_time; - int yiq_phase_count; + int yiq_enable = 0; + float yiq_jitter = 0.0; + float yiq_cc = 0.0; + float yiq_a = 0.0; + float yiq_b = 0.0; + float yiq_o = 0.0; + float yiq_p = 0.0; + float yiq_n = 0.0; + float yiq_y = 0.0; + float yiq_i = 0.0; + float yiq_q = 0.0; + float yiq_scan_time = 0.0; + int yiq_phase_count = 0; // Vectors - float vector_beam_smooth; - float vector_length_scale; - float vector_length_ratio; + float vector_beam_smooth = 0.0; + float vector_length_scale = 0.0; + float vector_length_ratio = 0.0; // Bloom - int bloom_blend_mode; - float bloom_scale; - float bloom_overdrive[3]; - float bloom_level0_weight; - float bloom_level1_weight; - float bloom_level2_weight; - float bloom_level3_weight; - float bloom_level4_weight; - float bloom_level5_weight; - float bloom_level6_weight; - float bloom_level7_weight; - float bloom_level8_weight; + int bloom_blend_mode = 0; + float bloom_scale = 0.0; + float bloom_overdrive[3]{ 0.0 }; + float bloom_level0_weight = 0.0; + float bloom_level1_weight = 0.0; + float bloom_level2_weight = 0.0; + float bloom_level3_weight = 0.0; + float bloom_level4_weight = 0.0; + float bloom_level5_weight = 0.0; + float bloom_level6_weight = 0.0; + float bloom_level7_weight = 0.0; + float bloom_level8_weight = 0.0; // Final - char lut_texture[1024]; - int lut_enable; - char ui_lut_texture[1024]; - int ui_lut_enable; + char lut_texture[1024]{ 0 }; + int lut_enable = 0; + char ui_lut_texture[1024]{ 0 }; + int ui_lut_enable = 0; }; struct slider_desc @@ -290,7 +301,7 @@ private: void * m_value; }; -class shaders : public slider_changed_notifier +class shaders { friend class effect; friend class uniform; @@ -300,11 +311,14 @@ public: shaders(); ~shaders(); - bool init(d3d_base *d3dintf, running_machine *machine, renderer_d3d9 *renderer); + bool init(IDirect3D9 *d3dobj, running_machine *machine, renderer_d3d9 *renderer); - bool enabled() { return post_fx_enable && d3dintf->post_fx_available; } + bool enabled() { return post_fx_enable && d3d->post_fx_available(); } void toggle() { post_fx_enable = initialized && !post_fx_enable; } + void begin_frame(render_primitive_list *primlist); + void end_frame(); + void begin_draw(); void end_draw(); @@ -323,6 +337,7 @@ public: void init_fsfx_quad(); void set_texture(texture_info *info); + void set_filter(bool filter_screens); void remove_render_target(int source_width, int source_height, uint32_t screen_index); void remove_render_target(d3d_render_target *rt); @@ -330,15 +345,18 @@ public: void delete_resources(); // slider-related functions - virtual int32_t slider_changed(running_machine &machine, void *arg, int /*id*/, std::string *str, int32_t newval) override; - std::unique_ptr<slider_state> slider_alloc(int id, const char *title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, void *arg); + std::unique_ptr<slider_state> slider_alloc(std::string &&title, int32_t minval, int32_t defval, int32_t maxval, int32_t incval, slider *arg); void init_slider_list(); std::vector<ui::menu_item> get_slider_list() { return m_sliders; } void *get_slider_option(int id, int index = 0); private: + using IDirect3D9Ptr = Microsoft::WRL::ComPtr<IDirect3D9>; + using IDirect3DTexture9Ptr = Microsoft::WRL::ComPtr<IDirect3DTexture9>; + using IDirect3DSurface9Ptr = Microsoft::WRL::ComPtr<IDirect3DSurface9>; + + void set_curr_effect(effect *curr_effect); void blit(IDirect3DSurface9 *dst, bool clear_dst, D3DPRIMITIVETYPE prim_type, uint32_t prim_index, uint32_t prim_count); - void enumerate_screens(); void render_snapshot(IDirect3DSurface9 *surface); // Time since last call, only updates once per render of all screens @@ -365,7 +383,7 @@ private: int screen_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); void ui_pass(poly_info *poly, int vertnum); - d3d_base * d3dintf; // D3D interface + IDirect3D9Ptr d3dobj; // D3D interface running_machine * machine; renderer_d3d9 * d3d; // D3D renderer @@ -373,7 +391,10 @@ private: bool post_fx_enable; // overall enable flag bool oversampling_enable; // oversampling enable flag int num_screens; // number of emulated physical screens - int curr_screen; // current screen for render target operations + int num_targets; // number of emulated screen targets (can be different from above; cf. artwork and Laserdisc games) + int curr_target; // current target index for render target operations + int targets_per_screen[256]; // screen target count per screen device/container index; estimated maximum count for array size + int target_to_screen[256]; // lookup from target index to screen device/container index; estimated maximum count for array size double acc_t; // accumulated machine time double delta_t; // data for delta_time bitmap_argb32 shadow_bitmap; // shadow mask bitmap for post-processing shader @@ -384,53 +405,59 @@ private: texture_info * ui_lut_texture; hlsl_options * options; // current options - IDirect3DSurface9 * black_surface; // black dummy surface - IDirect3DTexture9 * black_texture; // black dummy texture + IDirect3DSurface9Ptr black_surface; // black dummy surface + IDirect3DTexture9Ptr black_texture; // black dummy texture bool recording_movie; // ongoing movie recording std::unique_ptr<movie_recorder> recorder; // HLSL post-render movie recorder bool render_snap; // whether or not to take HLSL post-render snapshot - IDirect3DSurface9 * snap_copy_target; // snapshot destination surface in system memory - IDirect3DTexture9 * snap_copy_texture; // snapshot destination surface in system memory - IDirect3DSurface9 * snap_target; // snapshot upscaled surface - IDirect3DTexture9 * snap_texture; // snapshot upscaled texture + IDirect3DSurface9Ptr snap_copy_target; // snapshot destination surface in system memory + IDirect3DTexture9Ptr snap_copy_texture; // snapshot destination surface in system memory + IDirect3DSurface9Ptr snap_target; // snapshot upscaled surface + IDirect3DTexture9Ptr snap_texture; // snapshot upscaled texture int snap_width; // snapshot width int snap_height; // snapshot height bool initialized; // whether or not we're initialized // HLSL effects - IDirect3DSurface9 * backbuffer; // pointer to our device's backbuffer + IDirect3DSurface9Ptr backbuffer; // pointer to our device's backbuffer effect * curr_effect; // pointer to the currently active effect object - effect * default_effect; // pointer to the primary-effect object - effect * prescale_effect; // pointer to the prescale-effect object - effect * post_effect; // pointer to the post-effect object - effect * distortion_effect; // pointer to the distortion-effect object - effect * scanline_effect; - effect * focus_effect; // pointer to the focus-effect object - effect * phosphor_effect; // pointer to the phosphor-effect object - effect * deconverge_effect; // pointer to the deconvergence-effect object - effect * color_effect; // pointer to the color-effect object - effect * ntsc_effect; // pointer to the NTSC effect object - effect * bloom_effect; // pointer to the bloom composite effect - effect * downsample_effect; // pointer to the bloom downsample effect - effect * vector_effect; // pointer to the vector-effect object - effect * chroma_effect; - + std::unique_ptr<effect> default_effect; // pointer to the primary-effect object + std::unique_ptr<effect> ui_effect; // pointer to the UI-element effect object + std::unique_ptr<effect> ui_wrap_effect; // pointer to the UI-element effect object with texture wrapping + std::unique_ptr<effect> vector_buffer_effect; // pointer to the vector-buffering effect object + std::unique_ptr<effect> prescale_effect; // pointer to the prescale-effect object + std::unique_ptr<effect> prescale_point_effect; // pointer to the prescale-effect object with point filtering + std::unique_ptr<effect> post_effect; // pointer to the post-effect object + std::unique_ptr<effect> distortion_effect; // pointer to the distortion-effect object + std::unique_ptr<effect> scanline_effect; + std::unique_ptr<effect> focus_effect; // pointer to the focus-effect object + std::unique_ptr<effect> phosphor_effect; // pointer to the phosphor-effect object + std::unique_ptr<effect> deconverge_effect; // pointer to the deconvergence-effect object + std::unique_ptr<effect> color_effect; // pointer to the color-effect object + std::unique_ptr<effect> ntsc_effect; // pointer to the NTSC effect object + std::unique_ptr<effect> bloom_effect; // pointer to the bloom composite effect + std::unique_ptr<effect> downsample_effect; // pointer to the bloom downsample effect + std::unique_ptr<effect> vector_effect; // pointer to the vector-effect object + std::unique_ptr<effect> chroma_effect; + + texture_info * diffuse_texture; + bool filter_screens; texture_info * curr_texture; d3d_render_target * curr_render_target; poly_info * curr_poly; std::vector<std::unique_ptr<d3d_render_target>> m_render_target_list; - std::vector<slider*> internal_sliders; + std::vector<std::unique_ptr<slider> > internal_sliders; std::vector<ui::menu_item> m_sliders; - std::vector<std::unique_ptr<slider_state>> m_core_sliders; + std::vector<std::unique_ptr<slider_state> > m_core_sliders; static slider_desc s_sliders[]; static hlsl_options last_options; // last used options - static char last_system_name[16]; // last used system + static char last_system_name[MAX_DRIVER_NAME_CHARS + 1]; // last used system osd::dynamic_module::ptr d3dx9_dll; d3dx_create_effect_from_file_fn d3dx_create_effect_from_file_ptr; |