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); d3dr->SetTexture(0, pass.tex); D3DDevice_SetSamplerState_MinFilter(d3dr, 0, translate_filter(pass.info.pass->filter)); D3DDevice_SetSamplerState_MagFilter(d3dr, 0, translate_filter(pass.info.pass->filter)); #ifdef _XBOX1 d3dr->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1); #else d3dr->SetVertexDeclaration(pass.vertex_decl); #endif for (unsigned i = 0; i < 4; i++) { D3DDevice_SetStreamSources(d3dr, i, pass.vertex_buf, 0, sizeof(Vertex)); } renderchain_bind_orig(chain, pass); renderchain_bind_prev(chain, pass); renderchain_bind_pass(chain, pass, pass_index); renderchain_bind_luts(chain, pass); renderchain_bind_tracker(chain, pass, pass_index); D3DDevice_DrawPrimitive(d3dr, D3DPT_TRIANGLESTRIP, 0, 2); // So we don't render with linear filter into render targets, // which apparently looked odd (too blurry). D3DDevice_SetSamplerState_MinFilter(d3dr, 0, D3DTEXF_POINT); D3DDevice_SetSamplerState_MagFilter(d3dr, 0, D3DTEXF_POINT); renderchain_unbind_all(chain); }
static void renderchain_render_pass( cg_renderchain_t *chain, Pass *pass, unsigned pass_index) { unsigned i; if (!chain) return; renderchain_set_shaders(chain, &pass->fPrg, &pass->vPrg); d3d_set_texture(chain->dev, 0, pass->tex); d3d_set_sampler_minfilter(chain->dev, 0, translate_filter(pass->info.pass->filter)); d3d_set_sampler_magfilter(chain->dev, 0, translate_filter(pass->info.pass->filter)); d3d_set_vertex_declaration(chain->dev, pass->vertex_decl); for (i = 0; i < 4; i++) d3d_set_stream_source(chain->dev, i, pass->vertex_buf, 0, sizeof(Vertex)); renderchain_bind_orig(chain, pass); renderchain_bind_prev(chain, pass); renderchain_bind_pass(chain, pass, pass_index); renderchain_bind_luts(chain, pass); renderchain_bind_tracker(chain, pass, pass_index); d3d_draw_primitive(chain->dev, D3DPT_TRIANGLESTRIP, 0, 2); /* So we don't render with linear filter into render targets, * which apparently looked odd (too blurry). */ d3d_set_sampler_minfilter(chain->dev, 0, D3DTEXF_POINT); d3d_set_sampler_magfilter(chain->dev, 0, D3DTEXF_POINT); renderchain_unbind_all(chain); }
static bool cg_d3d9_renderchain_init(void *data, const void *_video_info, void *dev_, const void *final_viewport_, const void *info_data, bool rgb32) { const LinkInfo *info = (const LinkInfo*)info_data; d3d_video_t *d3d = (d3d_video_t*)data; cg_renderchain_t *chain = (cg_renderchain_t*)d3d->renderchain_data; const video_info_t *video_info = (const video_info_t*)_video_info; unsigned fmt = (rgb32) ? RETRO_PIXEL_FORMAT_XRGB8888 : RETRO_PIXEL_FORMAT_RGB565; if (!chain) return false; if (!cg_d3d9_renderchain_init_shader(d3d, chain)) { RARCH_ERR("Failed to initialize shader subsystem.\n"); return false; } chain->dev = (LPDIRECT3DDEVICE)dev_; chain->video_info = video_info; chain->state_tracker = NULL; chain->final_viewport = (D3DVIEWPORT*)final_viewport_; chain->frame_count = 0; chain->pixel_size = (fmt == RETRO_PIXEL_FORMAT_RGB565) ? 2 : 4; if (!renderchain_create_first_pass(chain, info, fmt)) return false; renderchain_log_info(chain, info); if (!d3d9_cg_load_program(chain, &chain->fStock, &chain->vStock, NULL, false)) return false; renderchain_set_shaders(chain->fStock, chain->vStock); return true; }
static bool cg_d3d9_renderchain_render( void *data, const void *frame_data, unsigned width, unsigned height, unsigned pitch, unsigned rotation) { Pass *last_pass; LPDIRECT3DDEVICE d3dr; LPDIRECT3DSURFACE back_buffer, target; unsigned i, current_width, current_height, out_width = 0, out_height = 0; d3d_video_t *d3d = (d3d_video_t*)data; cg_renderchain_t *chain = d3d ? (cg_renderchain_t*)d3d->renderchain_data : NULL; if (chain) d3dr = (LPDIRECT3DDEVICE)chain->dev; renderchain_start_render(chain); current_width = width; current_height = height; cg_d3d9_renderchain_convert_geometry(chain, &chain->passes[0].info, &out_width, &out_height, current_width, current_height, chain->final_viewport); renderchain_blit_to_texture(chain, frame_data, width, height, pitch); /* Grab back buffer. */ d3dr->GetRenderTarget(0, &back_buffer); /* In-between render target passes. */ for (i = 0; i < chain->passes.size() - 1; i++) { D3DVIEWPORT viewport = {0}; Pass *from_pass = (Pass*)&chain->passes[i]; Pass *to_pass = (Pass*)&chain->passes[i + 1]; to_pass->tex->GetSurfaceLevel(0, &target); d3dr->SetRenderTarget(0, target); cg_d3d9_renderchain_convert_geometry(chain, &from_pass->info, &out_width, &out_height, current_width, current_height, chain->final_viewport); /* Clear out whole FBO. */ viewport.Width = to_pass->info.tex_w; viewport.Height = to_pass->info.tex_h; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; d3d_set_viewports(d3dr, &viewport); d3d_clear(d3dr, 0, 0, D3DCLEAR_TARGET, 0, 1, 0); viewport.Width = out_width; viewport.Height = out_height; renderchain_set_viewport(chain, &viewport); renderchain_set_vertices(chain, from_pass, current_width, current_height, out_width, out_height, out_width, out_height, 0); renderchain_render_pass(chain, from_pass, i + 1); current_width = out_width; current_height = out_height; target->Release(); } /* Final pass */ d3dr->SetRenderTarget(0, back_buffer); last_pass = (Pass*)&chain->passes.back(); cg_d3d9_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); renderchain_set_vertices(chain, last_pass, current_width, current_height, out_width, out_height, chain->final_viewport->Width, chain->final_viewport->Height, rotation); renderchain_render_pass(chain, last_pass, chain->passes.size()); chain->frame_count++; back_buffer->Release(); renderchain_end_render(chain); renderchain_set_shaders(chain->fStock, chain->vStock); renderchain_set_mvp(chain, chain->vStock, chain->final_viewport->Width, chain->final_viewport->Height, 0); return true; }
static void renderchain_render_pass( cg_renderchain_t *chain, Pass *pass, unsigned pass_index) { unsigned i, index; if (!chain) return; renderchain_set_shaders(pass->fPrg, pass->vPrg); d3d_set_texture(chain->dev, 0, pass->tex); d3d_set_sampler_minfilter(chain->dev, 0, d3d_translate_filter(pass->info.pass->filter)); d3d_set_sampler_magfilter(chain->dev, 0, d3d_translate_filter(pass->info.pass->filter)); d3d_set_vertex_declaration(chain->dev, pass->vertex_decl); for (i = 0; i < 4; i++) d3d_set_stream_source(chain->dev, i, pass->vertex_buf, 0, sizeof(Vertex)); /* Set orig texture. */ renderchain_bind_orig(chain, pass); /* Set prev textures. */ renderchain_bind_prev(chain, pass); /* Set lookup textures */ for (i = 0; i < chain->luts.size(); i++) { CGparameter vparam; CGparameter fparam = cgGetNamedParameter( pass->fPrg, chain->luts[i].id); int bound_index = -1; if (fparam) { index = cgGetParameterResourceIndex(fparam); bound_index = index; cg_d3d9_renderchain_add_lut_internal(chain, index, i); } vparam = cgGetNamedParameter(pass->vPrg, chain->luts[i].id); if (vparam) { index = cgGetParameterResourceIndex(vparam); if (index != (unsigned)bound_index) cg_d3d9_renderchain_add_lut_internal(chain, index, i); } } renderchain_bind_pass(chain, pass, pass_index); /* Set state parameters. */ if (chain->state_tracker) { /* Only query uniforms in first pass. */ static struct state_tracker_uniform tracker_info[GFX_MAX_VARIABLES]; static unsigned cnt = 0; if (pass_index == 1) cnt = state_tracker_get_uniform(chain->state_tracker, tracker_info, GFX_MAX_VARIABLES, chain->frame_count); for (i = 0; i < cnt; i++) { CGparameter param_f = cgGetNamedParameter( pass->fPrg, tracker_info[i].id); CGparameter param_v = cgGetNamedParameter( pass->vPrg, tracker_info[i].id); cg_d3d9_set_param_1f(param_f, &tracker_info[i].value); cg_d3d9_set_param_1f(param_v, &tracker_info[i].value); } } d3d_draw_primitive(chain->dev, D3DPT_TRIANGLESTRIP, 0, 2); /* So we don't render with linear filter into render targets, * which apparently looked odd (too blurry). */ d3d_set_sampler_minfilter(chain->dev, 0, D3DTEXF_POINT); d3d_set_sampler_magfilter(chain->dev, 0, D3DTEXF_POINT); renderchain_unbind_all(chain); }
bool renderchain_render(void *chain_data, const void *data, unsigned width, unsigned height, unsigned pitch, unsigned rotation) { renderchain_t *chain = (renderchain_t*)chain_data; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev; renderchain_start_render(chain); unsigned current_width = width; unsigned current_height = height; unsigned out_width = 0; unsigned out_height = 0; renderchain_convert_geometry(chain, &chain->passes[0].info, out_width, out_height, current_width, current_height, chain->final_viewport); #ifdef _XBOX1 d3dr->SetFlickerFilter(g_extern.console.screen.flicker_filter_index); d3dr->SetSoftDisplayFilter(g_extern.lifecycle_state & (1ULL << MODE_VIDEO_SOFT_FILTER_ENABLE)); #endif renderchain_blit_to_texture(chain, data, width, height, pitch); // Grab back buffer. LPDIRECT3DSURFACE back_buffer; d3dr->GetRenderTarget(0, &back_buffer); // 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]; LPDIRECT3DSURFACE target; to_pass.tex->GetSurfaceLevel(0, &target); d3dr->SetRenderTarget(0, target); renderchain_convert_geometry(chain, &from_pass.info, out_width, out_height, current_width, current_height, chain->final_viewport); // Clear out whole FBO. D3DVIEWPORT viewport = {0}; viewport.Width = to_pass.info.tex_w; viewport.Height = to_pass.info.tex_h; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; d3dr->SetViewport(&viewport); d3dr->Clear(0, 0, D3DCLEAR_TARGET, 0, 1, 0); viewport.Width = out_width; viewport.Height = out_height; renderchain_set_viewport(chain, &viewport); renderchain_set_vertices(chain, from_pass, current_width, current_height, out_width, out_height, out_width, out_height, 0); renderchain_render_pass(chain, from_pass, i + 1); current_width = out_width; current_height = out_height; target->Release(); } // Final pass d3dr->SetRenderTarget(0, back_buffer); Pass &last_pass = chain->passes.back(); 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); renderchain_set_vertices(chain, last_pass, current_width, current_height, out_width, out_height, chain->final_viewport->Width, chain->final_viewport->Height, rotation); renderchain_render_pass(chain, last_pass, chain->passes.size()); chain->frame_count++; back_buffer->Release(); renderchain_end_render(chain); renderchain_set_shaders(chain, chain->fStock, chain->vStock); renderchain_set_mvp(chain, chain->vStock, chain->final_viewport->Width, chain->final_viewport->Height, 0); return true; }