diff --git a/gfx/drivers_renderchain/d3d9_cg_renderchain.c b/gfx/drivers_renderchain/d3d9_cg_renderchain.c index bbe877e4e5..0e324d1c69 100644 --- a/gfx/drivers_renderchain/d3d9_cg_renderchain.c +++ b/gfx/drivers_renderchain/d3d9_cg_renderchain.c @@ -32,7 +32,6 @@ #include #include "../common/d3d_common.h" -#include "../common/d3d9_common.h" #include "../drivers/d3d_shaders/opaque.cg.d3d9.h" #include "../video_driver.h" @@ -57,13 +56,6 @@ cgD3D9SetUniform(cgp, &val); \ } while(0) -struct lut_info -{ - LPDIRECT3DTEXTURE9 tex; - char id[64]; - bool smooth; -}; - struct CGVertex { float x, y, z; @@ -1239,33 +1231,6 @@ static void cg_d3d9_renderchain_set_vertices( } } -static void cg_d3d9_renderchain_blit_to_texture( - cg_renderchain_t *chain, - const void *frame, - unsigned width, unsigned height, - unsigned pitch) -{ - D3DLOCKED_RECT d3dlr = {0, NULL}; - struct cg_pass *first = (struct cg_pass*)&chain->passes->data[0]; - - if ( - (first->last_width != width || first->last_height != height) - ) - { - d3d9_lock_rectangle(first->tex, 0, &d3dlr, - NULL, first->info.tex_h, D3DLOCK_NOSYSLOCK); - d3d9_lock_rectangle_clear(first->tex, 0, &d3dlr, - NULL, first->info.tex_h, D3DLOCK_NOSYSLOCK); - } - - if (d3d9_lock_rectangle(first->tex, 0, &d3dlr, NULL, 0, 0)) - { - d3d9_texture_blit(chain->pixel_size, first->tex, - &d3dlr, frame, width, height, pitch); - d3d9_unlock_rectangle(first->tex); - } -} - static void cg_d3d9_renderchain_unbind_all(cg_renderchain_t *chain) { unsigned i; @@ -1407,19 +1372,30 @@ static bool d3d9_cg_renderchain_render( struct cg_pass *last_pass = NULL; cg_renderchain_t *chain = d3d ? (cg_renderchain_t*)d3d->renderchain_data : NULL; + struct cg_pass *first_pass = NULL; + d3d9_cg_renderchain_start_render(chain); - current_width = width; - current_height = height; + current_width = width; + current_height = height; + + first_pass = (struct cg_pass*)&chain->passes->data[0]; d3d9_cg_renderchain_convert_geometry(chain, - &chain->passes->data[0].info, + &first_pass->info, &out_width, &out_height, current_width, current_height, chain->final_viewport); - cg_d3d9_renderchain_blit_to_texture(chain, - frame_data, width, height, pitch); + d3d9_renderchain_blit_to_texture(first_pass->tex, + frame_data, + first_pass->info.tex_w, + first_pass->info.tex_h, + width, + height, + first_pass->last_width, + first_pass->last_height, + pitch, chain->pixel_size); /* Grab back buffer. */ d3d9_device_get_render_target(chain->dev, 0, (void**)&back_buffer); @@ -1485,10 +1461,9 @@ static bool d3d9_cg_renderchain_render( chain->final_viewport->Width, chain->final_viewport->Height, rotation); - if (chain) - cg_d3d9_renderchain_render_pass(chain, last_pass, - tracker, - chain->passes->count); + cg_d3d9_renderchain_render_pass(chain, last_pass, + tracker, + chain->passes->count); chain->frame_count++; diff --git a/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c b/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c index c2b316139a..567bf6199d 100644 --- a/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c +++ b/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c @@ -22,6 +22,7 @@ #include +#include "d3d9_renderchain.h" #include "../../defines/d3d_defines.h" #include "../common/d3d_common.h" #include "../common/d3d9_common.h" @@ -59,6 +60,11 @@ typedef struct hlsl_d3d9_renderchain unsigned tex_h; LPDIRECT3DDEVICE9 dev; D3DVIEWPORT9 *final_viewport; + struct hlsl_pass_vector_list *passes; + struct unsigned_vector_list *bound_tex; + struct unsigned_vector_list *bound_vert; + struct lut_info_vector_list *luts; + LPDIRECT3DTEXTURE9 tex; LPDIRECT3DVERTEXBUFFER9 vertex_buf; LPDIRECT3DVERTEXDECLARATION9 vertex_decl; @@ -196,32 +202,6 @@ static void hlsl_d3d9_renderchain_set_vertices( video_shader_driver_set_parameters(¶ms); } -static void hlsl_d3d9_renderchain_blit_to_texture( - hlsl_d3d9_renderchain_t *chain, const void *frame, - unsigned width, unsigned height, unsigned pitch) -{ - D3DLOCKED_RECT d3dlr = { 0, NULL }; - - if (chain->last_width != width || chain->last_height != height) - { - d3d9_lock_rectangle(chain->tex, - 0, &d3dlr, NULL, chain->tex_h, D3DLOCK_NOSYSLOCK); - d3d9_lock_rectangle_clear(chain->tex, - 0, &d3dlr, NULL, chain->tex_h, D3DLOCK_NOSYSLOCK); - } - - /* Set the texture to NULL so D3D doesn't - * complain about it being in use... */ - d3d9_set_texture(chain->dev, 0, NULL); - - if (d3d9_lock_rectangle(chain->tex, 0, &d3dlr, NULL, 0, 0)) - { - d3d9_texture_blit(chain->pixel_size, chain->tex, - &d3dlr, frame, width, height, pitch); - d3d9_unlock_rectangle(chain->tex); - } -} - static void hlsl_d3d9_renderchain_free(void *data) { hlsl_d3d9_renderchain_t *chain = (hlsl_d3d9_renderchain_t*)data; @@ -318,8 +298,17 @@ static bool hlsl_d3d9_renderchain_render( video_driver_get_size(&width, &height); - hlsl_d3d9_renderchain_blit_to_texture(chain, - frame, frame_width, frame_height, pitch); + d3d9_renderchain_blit_to_texture(chain->tex, + frame, + chain->tex_w, + chain->tex_h, + frame_width, + frame_height, + chain->last_width, + chain->last_height, + pitch, + chain->pixel_size); + hlsl_d3d9_renderchain_set_vertices(d3d, chain, 1, frame_width, frame_height, chain->frame_count); diff --git a/gfx/drivers_renderchain/d3d9_renderchain.h b/gfx/drivers_renderchain/d3d9_renderchain.h index 46dd97c547..5359c4560a 100644 --- a/gfx/drivers_renderchain/d3d9_renderchain.h +++ b/gfx/drivers_renderchain/d3d9_renderchain.h @@ -19,9 +19,21 @@ #include #include +#include +#include + +#include +#include "../common/d3d9_common.h" RETRO_BEGIN_DECLS +struct lut_info +{ + LPDIRECT3DTEXTURE9 tex; + char id[64]; + bool smooth; +}; + #define VECTOR_LIST_TYPE unsigned #define VECTOR_LIST_NAME unsigned #include "../../libretro-common/lists/vector_list.c" @@ -34,6 +46,34 @@ RETRO_BEGIN_DECLS #undef VECTOR_LIST_TYPE #undef VECTOR_LIST_NAME +static INLINE void d3d9_renderchain_blit_to_texture( + LPDIRECT3DTEXTURE9 tex, + const void *frame, + unsigned tex_width, unsigned tex_height, + unsigned width, unsigned height, + unsigned last_width, unsigned last_height, + unsigned pitch, unsigned pixel_size) +{ + D3DLOCKED_RECT d3dlr = {0, NULL}; + + if ( + (last_width != width || last_height != height) + ) + { + d3d9_lock_rectangle(tex, 0, &d3dlr, + NULL, tex_height, D3DLOCK_NOSYSLOCK); + d3d9_lock_rectangle_clear(tex, 0, &d3dlr, + NULL, tex_height, D3DLOCK_NOSYSLOCK); + } + + if (d3d9_lock_rectangle(tex, 0, &d3dlr, NULL, 0, 0)) + { + d3d9_texture_blit(pixel_size, tex, + &d3dlr, frame, width, height, pitch); + d3d9_unlock_rectangle(tex); + } +} + RETRO_END_DECLS #endif