From e32ceb8f3041299ae3811cef8e1b1c95825fe396 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 16 Jan 2018 00:08:10 +0100 Subject: [PATCH] Rewrite d3d_texture_blit --- gfx/common/d3d_common.c | 29 +++++++++---------- gfx/drivers_renderchain/d3d8_renderchain.c | 9 ++++-- gfx/drivers_renderchain/d3d9_cg_renderchain.c | 15 ++++++++-- .../d3d9_hlsl_renderchain.c | 9 ++++-- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/gfx/common/d3d_common.c b/gfx/common/d3d_common.c index 27713e0ee3..c6d521285c 100644 --- a/gfx/common/d3d_common.c +++ b/gfx/common/d3d_common.c @@ -1206,27 +1206,24 @@ bool d3d_set_vertex_shader_constantf(LPDIRECT3DDEVICE dev, } void d3d_texture_blit(unsigned pixel_size, - LPDIRECT3DTEXTURE tex, D3DLOCKED_RECT *lr, const void *frame, + LPDIRECT3DTEXTURE tex, + D3DLOCKED_RECT *lr, const void *frame, unsigned width, unsigned height, unsigned pitch) { - if (d3d_lock_rectangle(tex, 0, lr, NULL, 0, 0)) - { #if defined(_XBOX360) - D3DSURFACE_DESC desc; - d3d_texture_get_level_desc(tex, 0, &desc); - XGCopySurface(lr->pBits, lr->Pitch, width, height, desc.Format, NULL, - frame, pitch, desc.Format, NULL, 0, 0); + D3DSURFACE_DESC desc; + d3d_texture_get_level_desc(tex, 0, &desc); + XGCopySurface(lr->pBits, lr->Pitch, width, height, desc.Format, NULL, + frame, pitch, desc.Format, NULL, 0, 0); #else - unsigned y; - for (y = 0; y < height; y++) - { - const uint8_t *in = (const uint8_t*)frame + y * pitch; - uint8_t *out = (uint8_t*)lr->pBits + y * lr->Pitch; - memcpy(out, in, width * pixel_size); - } -#endif - d3d_unlock_rectangle(tex); + unsigned y; + for (y = 0; y < height; y++) + { + const uint8_t *in = (const uint8_t*)frame + y * pitch; + uint8_t *out = (uint8_t*)lr->pBits + y * lr->Pitch; + memcpy(out, in, width * pixel_size); } +#endif } bool d3d_get_render_state(void *data, D3DRENDERSTATETYPE state, DWORD *value) diff --git a/gfx/drivers_renderchain/d3d8_renderchain.c b/gfx/drivers_renderchain/d3d8_renderchain.c index 73e57a334c..86ed9811dc 100644 --- a/gfx/drivers_renderchain/d3d8_renderchain.c +++ b/gfx/drivers_renderchain/d3d8_renderchain.c @@ -189,8 +189,13 @@ static void d3d8_renderchain_blit_to_texture(void *data, const void *frame, /* Set the texture to NULL so D3D doesn't complain about it being in use... */ d3d_set_texture(d3dr, 0, NULL); - d3d_texture_blit(chain->pixel_size, chain->tex, - &d3dlr, frame, width, height, pitch); + + if (d3d_lock_rectangle(chain->tex, 0, &d3dlr, NULL, 0, 0)) + { + d3d_texture_blit(chain->pixel_size, chain->tex, + &d3dlr, frame, width, height, pitch); + d3d_unlock_rectangle(chain->tex); + } } static void d3d8_renderchain_deinit(void *data) diff --git a/gfx/drivers_renderchain/d3d9_cg_renderchain.c b/gfx/drivers_renderchain/d3d9_cg_renderchain.c index b494722154..1132b996dc 100644 --- a/gfx/drivers_renderchain/d3d9_cg_renderchain.c +++ b/gfx/drivers_renderchain/d3d9_cg_renderchain.c @@ -74,6 +74,7 @@ struct CGVertex struct Pass { struct LinkInfo info; + D3DPOOL pool; LPDIRECT3DTEXTURE tex; LPDIRECT3DVERTEXBUFFER vertex_buf; CGprogram vPrg, fPrg; @@ -939,6 +940,7 @@ static bool d3d9_cg_renderchain_set_pass_size( pass->info.tex_w = width; pass->info.tex_h = height; + pass->pool = D3DPOOL_DEFAULT; pass->tex = d3d_texture_new(chain->dev, NULL, width, height, 1, D3DUSAGE_RENDERTARGET, @@ -1078,6 +1080,7 @@ static bool d3d9_cg_renderchain_add_pass( pass.last_width = 0; pass.last_height = 0; pass.attrib_map = unsigned_vector_list_new(); + pass.pool = D3DPOOL_DEFAULT; d3d9_cg_load_program(chain, &pass.fPrg, &pass.vPrg, info->pass->source.path, true); @@ -1339,7 +1342,9 @@ static void cg_d3d9_renderchain_blit_to_texture( D3DLOCKED_RECT d3dlr; struct Pass *first = (struct Pass*)&chain->passes->data[0]; - if (first->last_width != width || first->last_height != height) + if ( + (first->last_width != width || first->last_height != height) + ) { d3d_lock_rectangle(first->tex, 0, &d3dlr, NULL, first->info.tex_h, D3DLOCK_NOSYSLOCK); @@ -1347,8 +1352,12 @@ static void cg_d3d9_renderchain_blit_to_texture( NULL, first->info.tex_h, D3DLOCK_NOSYSLOCK); } - d3d_texture_blit(chain->pixel_size, first->tex, - &d3dlr, frame, width, height, pitch); + if (d3d_lock_rectangle(first->tex, 0, &d3dlr, NULL, 0, 0)) + { + d3d_texture_blit(chain->pixel_size, first->tex, + &d3dlr, frame, width, height, pitch); + d3d_unlock_rectangle(first->tex); + } } static void cg_d3d9_renderchain_unbind_all(cg_renderchain_t *chain) diff --git a/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c b/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c index bea9cc8b5c..7ed56a2e73 100644 --- a/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c +++ b/gfx/drivers_renderchain/d3d9_hlsl_renderchain.c @@ -233,8 +233,13 @@ static void hlsl_d3d9_renderchain_blit_to_texture( /* Set the texture to NULL so D3D doesn't complain about it being in use... */ d3d_set_texture(d3dr, 0, NULL); - d3d_texture_blit(chain->pixel_size, chain->tex, - &d3dlr, frame, width, height, pitch); + + if (d3d_lock_rectangle(chain->tex, 0, &d3dlr, NULL, 0, 0)) + { + d3d_texture_blit(chain->pixel_size, chain->tex, + &d3dlr, frame, width, height, pitch); + d3d_unlock_rectangle(chain->tex); + } } static void hlsl_d3d9_renderchain_deinit(void *data)