Make blit_texture a generic function used by both Cg and HLSL

renderchains
This commit is contained in:
twinaphex 2018-05-14 19:11:45 +02:00
parent c1d949b017
commit 111aeb46b3
3 changed files with 76 additions and 72 deletions

View File

@ -32,7 +32,6 @@
#include <string/stdstring.h>
#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++;

View File

@ -22,6 +22,7 @@
#include <d3d9.h>
#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(&params);
}
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);

View File

@ -19,9 +19,21 @@
#include <stdint.h>
#include <retro_common_api.h>
#include <retro_inline.h>
#include <boolean.h>
#include <d3d9.h>
#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