(D3D) Pass 'Pass' and 'LinkInfo' by pointer instead of reference

This commit is contained in:
twinaphex 2014-09-13 17:33:58 +02:00
parent 0a85e95d0d
commit 0de251079a
3 changed files with 100 additions and 100 deletions

View File

@ -117,22 +117,22 @@ bool renderchain_set_pass_size(void *data, unsigned pass_index,
{
renderchain_t *chain = (renderchain_t*)data;
LPDIRECT3DDEVICE d3dr = chain->dev;
Pass &pass = chain->passes[pass_index];
if (width != pass.info.tex_w || height != pass.info.tex_h)
Pass *pass = (Pass*)&chain->passes[pass_index];
if (width != pass->info.tex_w || height != pass->info.tex_h)
{
pass.tex->Release();
pass.info.tex_w = width;
pass.info.tex_h = height;
pass->tex->Release();
pass->info.tex_w = width;
pass->info.tex_h = height;
if (FAILED(d3dr->CreateTexture(width, height, 1,
D3DUSAGE_RENDERTARGET,
chain->passes.back().info.pass->fbo.fp_fbo ?
D3DFMT_A32B32G32R32F : D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
&pass.tex, NULL)))
&pass->tex, NULL)))
return false;
d3d_set_texture(d3dr, 0, pass.tex);
d3d_set_texture(d3dr, 0, pass->tex);
d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER);
d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER);
d3d_set_texture(d3dr, 0, NULL);
@ -144,7 +144,7 @@ bool renderchain_set_pass_size(void *data, unsigned pass_index,
bool renderchain_add_pass(void *data, const LinkInfo *info)
{
renderchain_t *chain = (renderchain_t*)data;
LPDIRECT3DDEVICE d3dr = chain->dev;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
Pass pass;
pass.info = *info;
pass.last_width = 0;
@ -153,7 +153,7 @@ bool renderchain_add_pass(void *data, const LinkInfo *info)
renderchain_compile_shaders(chain, pass.fPrg,
pass.vPrg, info->pass->source.path);
if (!renderchain_init_shader_fvf(chain, pass))
if (!renderchain_init_shader_fvf(chain, &pass))
return false;
if (FAILED(D3DDevice_CreateVertexBuffers(d3dr, 4 * sizeof(Vertex),
@ -273,21 +273,21 @@ bool renderchain_render(void *chain_data, const void *data,
// In-between render target passes.
for (unsigned i = 0; i < chain->passes.size() - 1; i++)
{
Pass &from_pass = chain->passes[i];
Pass &to_pass = chain->passes[i + 1];
Pass *from_pass = (Pass*)&chain->passes[i];
Pass *to_pass = (Pass*)&chain->passes[i + 1];
LPDIRECT3DSURFACE target;
to_pass.tex->GetSurfaceLevel(0, &target);
to_pass->tex->GetSurfaceLevel(0, &target);
d3dr->SetRenderTarget(0, target);
renderchain_convert_geometry(chain, &from_pass.info,
renderchain_convert_geometry(chain, &from_pass->info,
out_width, out_height,
current_width, current_height, chain->final_viewport);
// Clear out whole FBO.
/* Clear out whole FBO. */
D3DVIEWPORT viewport = {0};
viewport.Width = to_pass.info.tex_w;
viewport.Height = to_pass.info.tex_h;
viewport.Width = to_pass->info.tex_w;
viewport.Height = to_pass->info.tex_h;
viewport.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
d3d_set_viewport(d3dr, &viewport);
@ -309,11 +309,11 @@ bool renderchain_render(void *chain_data, const void *data,
target->Release();
}
// Final pass
/* Final pass */
d3dr->SetRenderTarget(0, back_buffer);
Pass &last_pass = chain->passes.back();
Pass *last_pass = (Pass*)&chain->passes.back();
renderchain_convert_geometry(chain, &last_pass.info,
renderchain_convert_geometry(chain, &last_pass->info,
out_width, out_height,
current_width, current_height, chain->final_viewport);
renderchain_set_viewport(chain, chain->final_viewport);
@ -385,28 +385,28 @@ bool renderchain_create_first_pass(void *data, const LinkInfo *info,
renderchain_compile_shaders(chain, pass.fPrg,
pass.vPrg, info->pass->source.path);
if (!renderchain_init_shader_fvf(chain, pass))
if (!renderchain_init_shader_fvf(chain, &pass))
return false;
chain->passes.push_back(pass);
return true;
}
void renderchain_set_vertices(void *data, Pass &pass,
void renderchain_set_vertices(void *data, Pass *pass,
unsigned width, unsigned height,
unsigned out_width, unsigned out_height,
unsigned vp_width, unsigned vp_height,
unsigned rotation)
{
renderchain_t *chain = (renderchain_t*)data;
const LinkInfo &info = pass.info;
const LinkInfo *info = (const LinkInfo*)&pass->info;
if (pass.last_width != width || pass.last_height != height)
if (pass->last_width != width || pass->last_height != height)
{
pass.last_width = width;
pass.last_height = height;
pass->last_width = width;
pass->last_height = height;
float _u = static_cast<float>(width) / info.tex_w;
float _v = static_cast<float>(height) / info.tex_h;
float _u = static_cast<float>(width) / info->tex_w;
float _v = static_cast<float>(height) / info->tex_h;
Vertex vert[4];
for (unsigned i = 0; i < 4; i++)
{
@ -449,15 +449,15 @@ void renderchain_set_vertices(void *data, Pass &pass,
}
void *verts;
pass.vertex_buf->Lock(0, sizeof(vert), &verts, 0);
pass->vertex_buf->Lock(0, sizeof(vert), &verts, 0);
memcpy(verts, vert, sizeof(vert));
pass.vertex_buf->Unlock();
pass->vertex_buf->Unlock();
}
renderchain_set_mvp(chain, pass.vPrg, vp_width, vp_height, rotation);
renderchain_set_mvp(chain, pass->vPrg, vp_width, vp_height, rotation);
renderchain_set_shader_params(chain, pass,
width, height,
info.tex_w, info.tex_h,
info->tex_w, info->tex_h,
vp_width, vp_height);
}
@ -542,26 +542,26 @@ void renderchain_blit_to_texture(void *data, const void *frame,
&d3dlr, frame, width, height, pitch);
}
void renderchain_render_pass(void *data, Pass &pass, unsigned pass_index)
void renderchain_render_pass(void *data, Pass *pass, unsigned pass_index)
{
renderchain_t *chain = (renderchain_t*)data;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
renderchain_set_shaders(chain, pass.fPrg, pass.vPrg);
renderchain_set_shaders(chain, pass->fPrg, pass->vPrg);
d3d_set_texture(d3dr, 0, pass.tex);
d3d_set_texture(d3dr, 0, pass->tex);
d3d_set_sampler_minfilter(d3dr, 0,
translate_filter(pass.info.pass->filter));
translate_filter(pass->info.pass->filter));
d3d_set_sampler_magfilter(d3dr, 0,
translate_filter(pass.info.pass->filter));
translate_filter(pass->info.pass->filter));
#ifdef _XBOX1
d3d_set_vertex_shader(d3dr, D3DFVF_XYZ | D3DFVF_TEX1, NULL);
#else
d3dr->SetVertexDeclaration(pass.vertex_decl);
d3dr->SetVertexDeclaration(pass->vertex_decl);
#endif
for (unsigned i = 0; i < 4; i++)
d3d_set_stream_source(d3dr, i,
pass.vertex_buf, 0, sizeof(Vertex));
pass->vertex_buf, 0, sizeof(Vertex));
renderchain_bind_orig(chain, pass);
renderchain_bind_prev(chain, pass);

View File

@ -139,7 +139,7 @@ D3DTEXTUREFILTERTYPE renderchain_translate_filter(bool smooth);
bool renderchain_create_first_pass(void *data,
const LinkInfo *info, PixelFormat fmt);
void renderchain_set_vertices(void *data, Pass &pass,
void renderchain_set_vertices(void *data, Pass *pass,
unsigned width, unsigned height,
unsigned out_width, unsigned out_height,
unsigned vp_width, unsigned vp_height,
@ -160,7 +160,7 @@ void renderchain_blit_to_texture(void *data, const void *frame,
unsigned width, unsigned height,
unsigned pitch);
void renderchain_render_pass(void *data, Pass &pass, unsigned pass_index);
void renderchain_render_pass(void *data, Pass *pass, unsigned pass_index);
void renderchain_log_info(void *data, const LinkInfo *info);
@ -177,22 +177,22 @@ void renderchain_destroy_shader(void *data, int i);
void renderchain_set_shader_mvp(void *data, CGprogram &vPrg, D3DXMATRIX &tmp);
void renderchain_set_shader_params(void *data, Pass &pass,
void renderchain_set_shader_params(void *data, Pass *pass,
unsigned video_w, unsigned video_h,
unsigned tex_w, unsigned tex_h,
unsigned viewport_w, unsigned viewport_h);
void renderchain_bind_tracker(void *data, Pass &pass, unsigned pass_index);
void renderchain_bind_tracker(void *data, Pass *pass, unsigned pass_index);
bool renderchain_init_shader_fvf(void *data, Pass &pass);
bool renderchain_init_shader_fvf(void *data, Pass *pass);
void renderchain_bind_orig(void *data, Pass &pass);
void renderchain_bind_orig(void *data, Pass *pass);
void renderchain_bind_prev(void *data, Pass &pass);
void renderchain_bind_prev(void *data, Pass *pass);
void renderchain_bind_luts(void *data, Pass &pass);
void renderchain_bind_luts(void *data, Pass *pass);
void renderchain_bind_pass(void *data, Pass &pass, unsigned pass_index);
void renderchain_bind_pass(void *data, Pass *pass, unsigned pass_index);
#endif

View File

@ -177,7 +177,7 @@ void renderchain_set_shader_mvp(void *data, CGprogram &vPrg, D3DXMATRIX &tmp)
cgD3D9SetUniform(cgp, &val); \
} while(0)
void renderchain_set_shader_params(void *data, Pass &pass,
void renderchain_set_shader_params(void *data, Pass *pass,
unsigned video_w, unsigned video_h,
unsigned tex_w, unsigned tex_h,
unsigned viewport_w, unsigned viewport_h)
@ -191,22 +191,22 @@ void renderchain_set_shader_params(void *data, Pass &pass,
output_size.x = viewport_w;
output_size.y = viewport_h;
set_cg_param(pass.vPrg, "IN.video_size", video_size);
set_cg_param(pass.fPrg, "IN.video_size", video_size);
set_cg_param(pass.vPrg, "IN.texture_size", texture_size);
set_cg_param(pass.fPrg, "IN.texture_size", texture_size);
set_cg_param(pass.vPrg, "IN.output_size", output_size);
set_cg_param(pass.fPrg, "IN.output_size", output_size);
set_cg_param(pass->vPrg, "IN.video_size", video_size);
set_cg_param(pass->fPrg, "IN.video_size", video_size);
set_cg_param(pass->vPrg, "IN.texture_size", texture_size);
set_cg_param(pass->fPrg, "IN.texture_size", texture_size);
set_cg_param(pass->vPrg, "IN.output_size", output_size);
set_cg_param(pass->fPrg, "IN.output_size", output_size);
float frame_cnt = chain->frame_count;
if (pass.info.pass->frame_count_mod)
frame_cnt = chain->frame_count % pass.info.pass->frame_count_mod;
set_cg_param(pass.fPrg, "IN.frame_count", frame_cnt);
set_cg_param(pass.vPrg, "IN.frame_count", frame_cnt);
if (pass->info.pass->frame_count_mod)
frame_cnt = chain->frame_count % pass->info.pass->frame_count_mod;
set_cg_param(pass->fPrg, "IN.frame_count", frame_cnt);
set_cg_param(pass->vPrg, "IN.frame_count", frame_cnt);
}
void renderchain_bind_tracker(void *data, Pass &pass, unsigned pass_index)
void renderchain_bind_tracker(void *data, Pass *pass, unsigned pass_index)
{
renderchain_t *chain = (renderchain_t*)data;
if (!chain->tracker)
@ -218,9 +218,9 @@ void renderchain_bind_tracker(void *data, Pass &pass, unsigned pass_index)
for (unsigned i = 0; i < chain->uniform_cnt; i++)
{
set_cg_param(pass.fPrg, chain->uniform_info[i].id,
set_cg_param(pass->fPrg, chain->uniform_info[i].id,
chain->uniform_info[i].value);
set_cg_param(pass.vPrg, chain->uniform_info[i].id,
set_cg_param(pass->vPrg, chain->uniform_info[i].id,
chain->uniform_info[i].value);
}
}
@ -236,7 +236,7 @@ void renderchain_bind_tracker(void *data, Pass &pass, unsigned pass_index)
D3DDECLUSAGE_COLOR, (BYTE)(index) } \
bool renderchain_init_shader_fvf(void *data, Pass &pass)
bool renderchain_init_shader_fvf(void *data, Pass *pass)
{
renderchain_t *chain = (renderchain_t*)data;
static const D3DVERTEXELEMENT decl_end = D3DDECL_END();
@ -246,7 +246,7 @@ bool renderchain_init_shader_fvf(void *data, Pass &pass)
static const D3DVERTEXELEMENT color = DECL_FVF_COLOR(3, 7, 0);
D3DVERTEXELEMENT decl[MAXD3DDECLLENGTH] = {{0}};
if (cgD3D9GetVertexDeclaration(pass.vPrg, decl) == CG_FALSE)
if (cgD3D9GetVertexDeclaration(pass->vPrg, decl) == CG_FALSE)
return false;
unsigned count;
@ -270,9 +270,9 @@ bool renderchain_init_shader_fvf(void *data, Pass &pass)
bool texcoord1_taken = false;
bool stream_taken[4] = {false};
CGparameter param = find_param_from_semantic(pass.vPrg, "POSITION");
CGparameter param = find_param_from_semantic(pass->vPrg, "POSITION");
if (!param)
param = find_param_from_semantic(pass.vPrg, "POSITION0");
param = find_param_from_semantic(pass->vPrg, "POSITION0");
if (param)
{
stream_taken[0] = true;
@ -282,9 +282,9 @@ bool renderchain_init_shader_fvf(void *data, Pass &pass)
indices[index] = true;
}
param = find_param_from_semantic(pass.vPrg, "TEXCOORD");
param = find_param_from_semantic(pass->vPrg, "TEXCOORD");
if (!param)
param = find_param_from_semantic(pass.vPrg, "TEXCOORD0");
param = find_param_from_semantic(pass->vPrg, "TEXCOORD0");
if (param)
{
stream_taken[1] = true;
@ -295,7 +295,7 @@ bool renderchain_init_shader_fvf(void *data, Pass &pass)
indices[index] = true;
}
param = find_param_from_semantic(pass.vPrg, "TEXCOORD1");
param = find_param_from_semantic(pass->vPrg, "TEXCOORD1");
if (param)
{
stream_taken[2] = true;
@ -306,9 +306,9 @@ bool renderchain_init_shader_fvf(void *data, Pass &pass)
indices[index] = true;
}
param = find_param_from_semantic(pass.vPrg, "COLOR");
param = find_param_from_semantic(pass->vPrg, "COLOR");
if (!param)
param = find_param_from_semantic(pass.vPrg, "COLOR0");
param = find_param_from_semantic(pass->vPrg, "COLOR0");
if (param)
{
stream_taken[3] = true;
@ -334,10 +334,10 @@ bool renderchain_init_shader_fvf(void *data, Pass &pass)
for (unsigned i = 0; i < count; i++)
{
if (indices[i])
pass.attrib_map.push_back(0);
pass->attrib_map.push_back(0);
else
{
pass.attrib_map.push_back(index);
pass->attrib_map.push_back(index);
D3DVERTEXELEMENT elem = DECL_FVF_TEXCOORD(index, 3, tex_index);
decl[i] = elem;
@ -352,13 +352,13 @@ bool renderchain_init_shader_fvf(void *data, Pass &pass)
}
}
if (FAILED(chain->dev->CreateVertexDeclaration(decl, &pass.vertex_decl)))
if (FAILED(chain->dev->CreateVertexDeclaration(decl, &pass->vertex_decl)))
return false;
return true;
}
void renderchain_bind_orig(void *data, Pass &pass)
void renderchain_bind_orig(void *data, Pass *pass)
{
renderchain_t *chain = (renderchain_t*)data;
D3DXVECTOR2 video_size, texture_size;
@ -367,12 +367,12 @@ void renderchain_bind_orig(void *data, Pass &pass)
texture_size.x = chain->passes[0].info.tex_w;
texture_size.y = chain->passes[0].info.tex_h;
set_cg_param(pass.vPrg, "ORIG.video_size", video_size);
set_cg_param(pass.fPrg, "ORIG.video_size", video_size);
set_cg_param(pass.vPrg, "ORIG.texture_size", texture_size);
set_cg_param(pass.fPrg, "ORIG.texture_size", texture_size);
set_cg_param(pass->vPrg, "ORIG.video_size", video_size);
set_cg_param(pass->fPrg, "ORIG.video_size", video_size);
set_cg_param(pass->vPrg, "ORIG.texture_size", texture_size);
set_cg_param(pass->fPrg, "ORIG.texture_size", texture_size);
CGparameter param = cgGetNamedParameter(pass.fPrg, "ORIG.texture");
CGparameter param = cgGetNamedParameter(pass->fPrg, "ORIG.texture");
if (param)
{
unsigned index = cgGetParameterResourceIndex(param);
@ -386,16 +386,16 @@ void renderchain_bind_orig(void *data, Pass &pass)
chain->bound_tex.push_back(index);
}
param = cgGetNamedParameter(pass.vPrg, "ORIG.tex_coord");
param = cgGetNamedParameter(pass->vPrg, "ORIG.tex_coord");
if (param)
{
unsigned index = pass.attrib_map[cgGetParameterResourceIndex(param)];
unsigned index = pass->attrib_map[cgGetParameterResourceIndex(param)];
chain->dev->SetStreamSource(index, chain->passes[0].vertex_buf, 0, sizeof(Vertex));
chain->bound_vert.push_back(index);
}
}
void renderchain_bind_prev(void *data, Pass &pass)
void renderchain_bind_prev(void *data, Pass *pass)
{
renderchain_t *chain = (renderchain_t*)data;
static const char *prev_names[] = {
@ -425,12 +425,12 @@ void renderchain_bind_prev(void *data, Pass &pass)
video_size.x = chain->prev.last_width[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
video_size.y = chain->prev.last_height[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
set_cg_param(pass.vPrg, attr_input_size, video_size);
set_cg_param(pass.fPrg, attr_input_size, video_size);
set_cg_param(pass.vPrg, attr_tex_size, texture_size);
set_cg_param(pass.fPrg, attr_tex_size, texture_size);
set_cg_param(pass->vPrg, attr_input_size, video_size);
set_cg_param(pass->fPrg, attr_input_size, video_size);
set_cg_param(pass->vPrg, attr_tex_size, texture_size);
set_cg_param(pass->fPrg, attr_tex_size, texture_size);
CGparameter param = cgGetNamedParameter(pass.fPrg, attr_texture);
CGparameter param = cgGetNamedParameter(pass->fPrg, attr_texture);
if (param)
{
unsigned index = cgGetParameterResourceIndex(param);
@ -449,10 +449,10 @@ void renderchain_bind_prev(void *data, Pass &pass)
chain->dev->SetSamplerState(index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
}
param = cgGetNamedParameter(pass.vPrg, attr_coord);
param = cgGetNamedParameter(pass->vPrg, attr_coord);
if (param)
{
unsigned index = pass.attrib_map[cgGetParameterResourceIndex(param)];
unsigned index = pass->attrib_map[cgGetParameterResourceIndex(param)];
LPDIRECT3DVERTEXBUFFER vert_buf = (LPDIRECT3DVERTEXBUFFER)
chain->prev.vertex_buf[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
chain->bound_vert.push_back(index);
@ -462,13 +462,13 @@ void renderchain_bind_prev(void *data, Pass &pass)
}
}
void renderchain_bind_luts(void *data, Pass &pass)
void renderchain_bind_luts(void *data, Pass *pass)
{
renderchain_t *chain = (renderchain_t*)data;
for (unsigned i = 0; i < chain->luts.size(); i++)
{
CGparameter fparam = cgGetNamedParameter(
pass.fPrg, chain->luts[i].id.c_str());
pass->fPrg, chain->luts[i].id.c_str());
int bound_index = -1;
if (fparam)
@ -488,7 +488,7 @@ void renderchain_bind_luts(void *data, Pass &pass)
}
CGparameter vparam = cgGetNamedParameter(
pass.vPrg, chain->luts[i].id.c_str());
pass->vPrg, chain->luts[i].id.c_str());
if (vparam)
{
@ -510,7 +510,7 @@ void renderchain_bind_luts(void *data, Pass &pass)
}
}
void renderchain_bind_pass(void *data, Pass &pass, unsigned pass_index)
void renderchain_bind_pass(void *data, Pass *pass, unsigned pass_index)
{
renderchain_t *chain = (renderchain_t*)data;
@ -540,12 +540,12 @@ void renderchain_bind_pass(void *data, Pass &pass, unsigned pass_index)
texture_size.x = chain->passes[i].info.tex_w;
texture_size.y = chain->passes[i].info.tex_h;
set_cg_param(pass.vPrg, attr_video_size.c_str(), video_size);
set_cg_param(pass.fPrg, attr_video_size.c_str(), video_size);
set_cg_param(pass.vPrg, attr_texture_size.c_str(), texture_size);
set_cg_param(pass.fPrg, attr_texture_size.c_str(), texture_size);
set_cg_param(pass->vPrg, attr_video_size.c_str(), video_size);
set_cg_param(pass->fPrg, attr_video_size.c_str(), video_size);
set_cg_param(pass->vPrg, attr_texture_size.c_str(), texture_size);
set_cg_param(pass->fPrg, attr_texture_size.c_str(), texture_size);
CGparameter param = cgGetNamedParameter(pass.fPrg, attr_texture.c_str());
CGparameter param = cgGetNamedParameter(pass->fPrg, attr_texture.c_str());
if (param)
{
unsigned index = cgGetParameterResourceIndex(param);
@ -562,10 +562,10 @@ void renderchain_bind_pass(void *data, Pass &pass, unsigned pass_index)
D3DTADDRESS_BORDER);
}
param = cgGetNamedParameter(pass.vPrg, attr_tex_coord.c_str());
param = cgGetNamedParameter(pass->vPrg, attr_tex_coord.c_str());
if (param)
{
unsigned index = pass.attrib_map[cgGetParameterResourceIndex(param)];
unsigned index = pass->attrib_map[cgGetParameterResourceIndex(param)];
chain->dev->SetStreamSource(index, chain->passes[i].vertex_buf,
0, sizeof(Vertex));
chain->bound_vert.push_back(index);