Split HLSL code into a separate file, d3dhlsl.c/.h. Also split drawd3d.c into a couple of headers. [Ryan Holtz, Bat Country Entertainment]

This commit is contained in:
Ryan Holtz 2011-06-02 06:22:09 +00:00
parent 6a52f841eb
commit 844296b795
8 changed files with 3024 additions and 2490 deletions

4
.gitattributes vendored
View File

@ -4798,10 +4798,14 @@ src/osd/sdl/window.c svneol=native#text/plain
src/osd/sdl/window.h svneol=native#text/plain
src/osd/windows/d3d8intf.c svneol=native#text/plain
src/osd/windows/d3d9intf.c svneol=native#text/plain
src/osd/windows/d3dcomm.h svneol=native#text/plain
src/osd/windows/d3dhlsl.c svneol=native#text/plain
src/osd/windows/d3dhlsl.h svneol=native#text/plain
src/osd/windows/d3dintf.h svneol=native#text/plain
src/osd/windows/debugwin.c svneol=native#text/plain
src/osd/windows/debugwin.h svneol=native#text/plain
src/osd/windows/drawd3d.c svneol=native#text/plain
src/osd/windows/drawd3d.h svneol=native#text/plain
src/osd/windows/drawdd.c svneol=native#text/plain
src/osd/windows/drawgdi.c svneol=native#text/plain
src/osd/windows/drawnone.c svneol=native#text/plain

View File

@ -122,7 +122,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
float4 CoordX = Input.Coord0.x + Input.Coord0.z * n4 * 0.25f;
float4 CoordY = Input.Coord0.y;
float2 TexCoord = float2(CoordX.r, CoordY.r);
float4 C = tex2D(CompositeSampler, TexCoord) * CRange + MinC;
float4 C = tex2D(CompositeSampler, TexCoord + float2(0.125f, 0.0f) / RawDims) * CRange + MinC;
float4 WT = W * (CoordX * WidthRatio + AValue * CoordY * 2.0f * (RawHeight / HeightRatio) + BValue) + OValue;
float4 SincYIn = PI2 * Fc_y * n4;

113
src/osd/windows/d3dcomm.h Normal file
View File

@ -0,0 +1,113 @@
//============================================================
//
// d3dcomm.h - Common Win32 Direct3D structures
//
//============================================================
//
// 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_D3DCOMM__
#define __WIN_D3DCOMM__
//============================================================
// CONSTANTS
//============================================================
//============================================================
// TYPE DEFINITIONS
//============================================================
/* d3d_texture_info holds information about a texture */
typedef struct _d3d_texture_info d3d_texture_info;
struct _d3d_texture_info
{
d3d_texture_info * next; // next texture in the list
d3d_texture_info * prev; // prev texture in the list
UINT32 hash; // hash value for the texture
UINT32 flags; // rendering flags
render_texinfo texinfo; // copy of the texture info
float ustart, ustop; // beginning/ending U coordinates
float vstart, vstop; // beginning/ending V coordinates
int rawwidth, rawheight; // raw width/height of the texture
int type; // what type of texture are we?
int xborderpix; // number of border pixels in X
int yborderpix; // number of border pixels in Y
int xprescale; // what is our X prescale factor?
int yprescale; // what is our Y prescale factor?
int cur_frame; // what is our current frame?
d3d_texture * d3dtex; // Direct3D texture pointer
d3d_surface * d3dsurface; // Direct3D offscreen plain surface pointer
d3d_texture * d3dfinaltex; // Direct3D final (post-scaled) texture
int target_index; // Direct3D target index
};
/* d3d_poly_info holds information about a single polygon/d3d primitive */
typedef struct _d3d_poly_info d3d_poly_info;
struct _d3d_poly_info
{
D3DPRIMITIVETYPE type; // type of primitive
UINT32 count; // total number of primitives
UINT32 numverts; // total number of vertices
UINT32 flags; // rendering flags
DWORD modmode; // texture modulation mode
d3d_texture_info * texture; // pointer to texture info
};
/* d3d_vertex describes a single vertex */
typedef struct _d3d_vertex d3d_vertex;
struct _d3d_vertex
{
float x, y, z; // X,Y,Z coordinates
float rhw; // RHW when no HLSL, padding when HLSL
D3DCOLOR color; // diffuse color
float u0, v0; // texture stage 0 coordinates
};
/* line_aa_step is used for drawing antialiased lines */
typedef struct _line_aa_step line_aa_step;
struct _line_aa_step
{
float xoffs, yoffs; // X/Y deltas
float weight; // weight contribution
};
#endif

2481
src/osd/windows/d3dhlsl.c Normal file

File diff suppressed because it is too large Load Diff

221
src/osd/windows/d3dhlsl.h Normal file
View File

@ -0,0 +1,221 @@
//============================================================
//
// 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"
//============================================================
// TYPE DEFINITIONS
//============================================================
/* hlsl_options is the information about runtime-mutable Direct3D HLSL options */
/* in the future this will be moved into an OSD/emu shared buffer */
typedef struct _hlsl_options hlsl_options;
struct _hlsl_options
{
float shadow_mask_alpha;
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_x;
float defocus_y;
float red_converge_x;
float red_converge_y;
float green_converge_x;
float green_converge_y;
float blue_converge_x;
float blue_converge_y;
float red_radial_converge_x;
float red_radial_converge_y;
float green_radial_converge_x;
float green_radial_converge_y;
float blue_radial_converge_x;
float blue_radial_converge_y;
float red_from_red;
float red_from_green;
float red_from_blue;
float green_from_red;
float green_from_green;
float green_from_blue;
float blue_from_red;
float blue_from_green;
float blue_from_blue;
float red_offset;
float green_offset;
float blue_offset;
float red_scale;
float green_scale;
float blue_scale;
float red_power;
float green_power;
float blue_power;
float red_floor;
float green_floor;
float blue_floor;
float red_phosphor_life;
float green_phosphor_life;
float blue_phosphor_life;
float saturation;
};
class hlsl_info
{
public:
// construction/destruction
hlsl_info();
~hlsl_info();
void init(d3d *d3dintf, win_window_info *window);
void init_fsfx_quad(void *vertbuf);
bool enabled() { return master_enable; }
void begin();
void init_effect_info(d3d_poly_info *poly);
void render_quad(d3d_poly_info *poly, int vertnum);
void end();
int register_texture(d3d_texture_info *texture);
int register_prescaled_texture(d3d_texture_info *texture, int scwidth, int scheight);
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 frame_complete();
void set_texture(d3d_texture_info *texture);
int create_resources();
void delete_resources();
// slider-related functions
slider_state *init_slider_list();
private:
void end_avi_recording();
void begin_avi_recording(const char *name);
bool screen_encountered[9]; // whether a given screen was encountered this frame
d3d * d3dintf; // D3D interface
win_window_info * window; // D3D window info
bool master_enable; // overall enable flag
bool yiq_enable; // YIQ-convolution flag
int prescale_size; // prescale size
int preset; // preset, if relevant
bitmap_t * shadow_bitmap; // shadow mask bitmap for post-processing shader
d3d_texture_info * shadow_texture; // shadow mask texture for post-processing shader
int registered_targets; // number of registered HLSL targets (i.e., screens)
hlsl_options * options; // current uniform state
avi_file * avi_output_file; // AVI file
bitmap_t * 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
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
// 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 current primary-effect object
d3d_effect * prescale_effect; // pointer to the current prescale-effect object
d3d_effect * post_effect; // pointer to the current post-effect object
d3d_effect * pincushion_effect; // pointer to the current pincushion-effect object
d3d_effect * focus_effect; // pointer to the current focus-effect object
d3d_effect * phosphor_effect; // pointer to the current phosphor-effect object
d3d_effect * deconverge_effect; // pointer to the current deconvergence-effect object
d3d_effect * color_effect; // pointer to the current color-effect object
d3d_effect * yiq_encode_effect; // pointer to the current YIQ encoder effect object
d3d_effect * yiq_decode_effect; // pointer to the current YIQ decoder effect object
d3d_vertex * fsfx_vertices; // pointer to our full-screen-quad object
// render targets
int target_use_count[9]; // Whether or not a target has been used yet
d3d_texture_info * target_in_use[9]; // Target texture that is currently in use
d3d_surface * last_target[9]; // Render target surface pointer for each screen's previous frame
d3d_texture * last_texture[9]; // Render target texture pointer for each screen's previous frame
d3d_surface * prescaletarget0[9]; // Render target surface pointer (prescale, if necessary)
d3d_surface * target0[9]; // Render target surface pointer (pass 0, if necessary)
d3d_surface * target1[9]; // Render target surface pointer (pass 1, if necessary)
d3d_surface * target2[9]; // Render target surface pointer (pass 2, if necessary)
d3d_surface * target3[9]; // Render target surface pointer (pass 3, if necessary)
d3d_surface * target4[9]; // Render target surface pointer (pass 4, if necessary)
d3d_surface * smalltarget0[9]; // Render target surface pointer (small pass 0, if necessary)
d3d_texture * prescaletexture0[9]; // Render target surface pointer (prescale, if necessary)
d3d_texture * texture0[9]; // Render target texture pointer (pass 0, if necessary)
d3d_texture * texture1[9]; // Render target texture pointer (pass 1, if necessary)
d3d_texture * texture2[9]; // Render target texture pointer (pass 2, if necessary)
d3d_texture * texture3[9]; // Render target texture pointer (pass 3, if necessary)
d3d_texture * texture4[9]; // Render target texture pointer (pass 4, if necessary)
d3d_texture * smalltexture0[9]; // Render target texture pointer (small pass 0, if necessary)
};
#endif

File diff suppressed because it is too large Load Diff

127
src/osd/windows/drawd3d.h Normal file
View File

@ -0,0 +1,127 @@
//============================================================
//
// drawd3d.h - Win32 Direct3D 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_DRAWD3D__
#define __WIN_DRAWD3D__
#include "d3dhlsl.h"
//============================================================
// CONSTANTS
//============================================================
#define VERTEX_BASE_FORMAT (D3DFVF_DIFFUSE | D3DFVF_TEX1)
#define VERTEX_BUFFER_SIZE (2048*4+4)
//============================================================
// TYPE DEFINITIONS
//============================================================
/* d3d_info is the information about Direct3D for the current screen */
typedef struct _d3d_info d3d_info;
struct _d3d_info
{
int adapter; // ordinal adapter number
int width, height; // current width, height
int refresh; // current refresh rate
int create_error_count; // number of consecutive create errors
win_window_info * window; // current window info
d3d_device * device; // pointer to the Direct3DDevice object
int gamma_supported; // is full screen gamma supported?
d3d_present_parameters presentation; // set of presentation parameters
D3DDISPLAYMODE origmode; // original display mode for the adapter
D3DFORMAT pixformat; // pixel format we are using
d3d_vertex_buffer * vertexbuf; // pointer to the vertex buffer object
d3d_vertex * lockedbuf; // pointer to the locked vertex buffer
int numverts; // number of accumulated vertices
d3d_poly_info poly[VERTEX_BUFFER_SIZE/3]; // array to hold polygons as they are created
int numpolys; // number of accumulated polygons
d3d_texture_info * texlist; // list of active textures
int dynamic_supported; // are dynamic textures supported?
int stretch_supported; // is StretchRect with point filtering supported?
int mod2x_supported; // is D3DTOP_MODULATE2X supported?
int mod4x_supported; // is D3DTOP_MODULATE4X supported?
D3DFORMAT screen_format; // format to use for screen textures
D3DFORMAT yuv_format; // format to use for YUV textures
DWORD texture_caps; // textureCaps field
DWORD texture_max_aspect; // texture maximum aspect ratio
DWORD texture_max_width; // texture maximum width
DWORD texture_max_height; // texture maximum height
d3d_texture_info * last_texture; // previous texture
UINT32 last_texture_flags; // previous texture flags
int last_blendenable; // previous blendmode
int last_blendop; // previous blendmode
int last_blendsrc; // previous blendmode
int last_blenddst; // previous blendmode
int last_filter; // previous texture filter
int last_wrap; // previous wrap state
DWORD last_modmode; // previous texture modulation
bitmap_t * vector_bitmap; // experimental: bitmap for vectors
d3d_texture_info * vector_texture; // experimental: texture for vectors
bitmap_t * default_bitmap; // experimental: default bitmap
d3d_texture_info * default_texture; // experimental: default texture
void * hlsl_buf; // HLSL vertex data
hlsl_info * hlsl; // HLSL interface
};
//============================================================
// PROTOTYPES
//============================================================
d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource, UINT32 flags);
#endif

View File

@ -286,6 +286,7 @@ OSDCOREOBJS = \
OSDOBJS = \
$(WINOBJ)/d3d9intf.o \
$(WINOBJ)/drawd3d.o \
$(WINOBJ)/d3dhlsl.o \
$(WINOBJ)/drawdd.o \
$(WINOBJ)/drawgdi.o \
$(WINOBJ)/drawnone.o \