summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/windows/d3dhlsl.h
blob: 7d508ddb2a114a82bc90cf1edc5c00fc4b6e2f60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
//============================================================
//
//  drawd3d.c - Win32 Direct3D HLSL-specific header
//
//============================================================
//
//  Copyright Aaron Giles
//  All rights reserved.
//
//  Redistribution and use in source and binary forms, with or
//  without modification, are permitted provided that the
//  following conditions are met:
//
//    * Redistributions of source code must retain the above
//      copyright notice, this list of conditions and the
//      following disclaimer.
//    * Redistributions in binary form must reproduce the
//      above copyright notice, this list of conditions and
//      the following disclaimer in the documentation and/or
//      other materials provided with the distribution.
//    * Neither the name 'MAME' nor the names of its
//      contributors may be used to endorse or promote
//      products derived from this software without specific
//      prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND
//  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
//  EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
//  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
//  DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
//  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
//  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
//  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//============================================================

#ifndef __WIN_D3DHLSL__
#define __WIN_D3DHLSL__

#include "aviio.h"

//============================================================
//  CONSTANTS
//============================================================

#define HLSL_VECTOR			(0)

//============================================================
//  TYPE DEFINITIONS
//============================================================

class d3d_render_target;
class d3d_cache_target;
struct d3d_info;

/* hlsl_options is the information about runtime-mutable Direct3D HLSL options */
/* in the future this will be moved into an OSD/emu shared buffer */
struct hlsl_options
{
	bool                    params_dirty;
	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                   curvature;
	float                   pincushion;
	float                   scanline_alpha;
	float                   scanline_scale;
	float                   scanline_height;
	float                   scanline_bright_scale;
	float                   scanline_bright_offset;
	float                   scanline_offset;
	float                   defocus[4];
	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;

    // NTSC
	bool                    yiq_enable;
	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;

    // Vectors
    float                   vector_time_scale;
    float                   vector_time_period;
    float                   vector_length_scale;
    float                   vector_length_ratio;
};

class hlsl_info
{
public:
	// construction/destruction
	hlsl_info();
	~hlsl_info();

	void init(d3d_base *d3dintf, win_window_info *window);

	bool enabled() { return master_enable; }
	void toggle();

	bool vector_enabled() { return master_enable && vector_enable && (bool)HLSL_VECTOR; }
	d3d_render_target* get_vector_target();
	void create_vector_target(render_primitive *prim);

	void begin_frame();
	void end_frame();

	void begin_draw();
	void end_draw();

	void init_effect_info(d3d_poly_info *poly);
	void render_quad(d3d_poly_info *poly, int vertnum);

	bool register_texture(d3d_texture_info *texture);
	bool register_prescaled_texture(d3d_texture_info *texture);
	bool add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, bool bloom = false);
	bool add_cache_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index);

	void window_save();
	void window_record();
	bool recording() { return avi_output_file != NULL; }

	void avi_update_snap(d3d_surface *surface);
	void render_snapshot(d3d_surface *surface);
	void record_texture();
    void init_fsfx_quad(void *vertbuf);

	void                    set_texture(d3d_texture_info *texture);
	d3d_render_target *     find_render_target(d3d_texture_info *info);
	void                    remove_render_target(d3d_texture_info *texture);
	void                    remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
	void                    remove_render_target(d3d_render_target *rt);

	int create_resources(bool reset);
	void delete_resources(bool reset);

	// slider-related functions
	slider_state *init_slider_list();

private:
	void					blit(d3d_surface *dst, d3d_texture *src, d3d_surface *new_dst,
								 D3DPRIMITIVETYPE prim_type, UINT32 prim_index, UINT32 prim_count,
                                 int dstw, int dsth);
    void                    blit(d3d_surface *dst, d3d_texture *src, d3d_surface *new_dst,
                                 D3DPRIMITIVETYPE prim_type, UINT32 prim_index, UINT32 prim_count);
	void                    enumerate_screens();

	void                    end_avi_recording();
	void                    begin_avi_recording(const char *name);

	bool                    register_texture(d3d_texture_info *texture, int width, int height, int xscale, int yscale);

	d3d_render_target*      find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
	d3d_cache_target *      find_cache_target(UINT32 screen_index, int width, int height);
	void                    remove_cache_target(d3d_cache_target *cache);

	d3d_base *              d3dintf;                    // D3D interface
	win_window_info *       window;                     // D3D window info

	bool                    master_enable;              // overall enable flag
	bool                    vector_enable;              // vector post-processing enable flag
	bool                    paused;                     // whether or not rendering is currently paused
	int                     num_screens;                // number of emulated physical screens
	int                     curr_screen;                // current screen for render target operations
	int                     curr_frame;                 // current frame (0/1) of a screen for render target operations
	int                     lastidx;                    // index of the last-encountered target
	bool                    write_ini;                  // enable external ini saving
	bool                    read_ini;                   // enable external ini loading
	int                     prescale_force_x;           // prescale force x
	int                     prescale_force_y;           // prescale force y
	int                     prescale_size_x;            // prescale size x
	int                     prescale_size_y;            // prescale size y
	int                     preset;                     // preset, if relevant
	bitmap_argb32           shadow_bitmap;              // shadow mask bitmap for post-processing shader
	d3d_texture_info *      shadow_texture;             // shadow mask texture for post-processing shader
	hlsl_options *          options;                    // current uniform state
	D3DPRIMITIVETYPE		vecbuf_type;
	UINT32					vecbuf_index;
	UINT32					vecbuf_count;

	avi_file *              avi_output_file;            // AVI file
	bitmap_rgb32            avi_snap;                   // AVI snapshot
	int                     avi_frame;                  // AVI frame
	attotime                avi_frame_period;           // AVI frame period
	attotime                avi_next_frame_time;        // AVI next frame time
	d3d_surface *           avi_copy_surface;           // AVI destination surface in system memory
	d3d_texture *           avi_copy_texture;           // AVI destination texture in system memory
	d3d_surface *           avi_final_target;           // AVI upscaled surface
	d3d_texture *           avi_final_texture;          // AVI upscaled texture

    d3d_surface *           black_surface;              // black dummy surface
    d3d_texture *           black_texture;              // black dummy texture

	bool                    render_snap;                // whether or not to take HLSL post-render snapshot
	bool                    snap_rendered;              // whether we just rendered our HLSL post-render shot or not
	d3d_surface *           snap_copy_target;           // snapshot destination surface in system memory
	d3d_texture *           snap_copy_texture;          // snapshot destination surface in system memory
	d3d_surface *           snap_target;                // snapshot upscaled surface
	d3d_texture *           snap_texture;               // snapshot upscaled texture
	int                     snap_width;                 // snapshot width
	int                     snap_height;                // snapshot height
	bool                    lines_pending;              // whether or not we have lines to flush on the next quad

	bool					initialized;				// whether or not we're initialize

	// HLSL effects
	d3d_surface *           backbuffer;                 // pointer to our device's backbuffer
	d3d_effect *            curr_effect;                // pointer to the currently active effect object
	d3d_effect *            effect;                     // pointer to the primary-effect object
	d3d_effect *            prescale_effect;            // pointer to the prescale-effect object
	d3d_effect *            post_effect;                // pointer to the post-effect object
	d3d_effect *            pincushion_effect;          // pointer to the pincushion-effect object
	d3d_effect *            focus_effect;               // pointer to the focus-effect object
	d3d_effect *            phosphor_effect;            // pointer to the phosphor-effect object
	d3d_effect *            deconverge_effect;          // pointer to the deconvergence-effect object
	d3d_effect *            color_effect;               // pointer to the color-effect object
	d3d_effect *            yiq_encode_effect;          // pointer to the YIQ encoder effect object
	d3d_effect *            yiq_decode_effect;          // pointer to the YIQ decoder effect object
#if HLSL_VECTOR
    d3d_effect *            bloom_effect;               // pointer to the bloom composite effect
    d3d_effect *            downsample_effect;          // pointer to the bloom downsample effect
	d3d_effect *            vector_effect;              // pointer to the vector-effect object
#endif
	d3d_vertex *            fsfx_vertices;              // pointer to our full-screen-quad object

public:
	d3d_render_target *     targethead;
	d3d_cache_target *      cachehead;
};

#endif