2017-09-04 23:50:13 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2017-12-11 23:55:31 -08:00
|
|
|
*
|
2017-09-04 23:50:13 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-04-22 14:27:39 +02:00
|
|
|
#define CINTERFACE
|
|
|
|
|
2018-05-16 15:52:11 +02:00
|
|
|
#include <compat/strl.h>
|
|
|
|
#include <string/stdstring.h>
|
|
|
|
#include <file/file_path.h>
|
2017-09-04 23:50:13 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <retro_inline.h>
|
2017-09-05 03:21:58 +02:00
|
|
|
#include <retro_math.h>
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-01-26 04:09:35 +01:00
|
|
|
#include <d3d9.h>
|
2018-05-16 15:52:11 +02:00
|
|
|
#include <d3dx9shader.h>
|
|
|
|
|
|
|
|
#include "../drivers/d3d_shaders/opaque.hlsl.d3d9.h"
|
2018-01-26 04:09:35 +01:00
|
|
|
|
2018-01-25 11:50:07 +01:00
|
|
|
#include "../../defines/d3d_defines.h"
|
2017-09-04 23:50:13 +02:00
|
|
|
#include "../common/d3d_common.h"
|
2018-03-03 15:28:58 +01:00
|
|
|
#include "../common/d3d9_common.h"
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-16 15:52:11 +02:00
|
|
|
#include "../video_shader_parse.h"
|
|
|
|
#include "../../managers/state_manager.h"
|
2017-09-04 23:50:13 +02:00
|
|
|
#include "../../configuration.h"
|
2018-04-23 15:32:47 +02:00
|
|
|
#include "../../retroarch.h"
|
2017-09-04 23:50:13 +02:00
|
|
|
#include "../../verbosity.h"
|
|
|
|
|
2018-05-16 15:52:11 +02:00
|
|
|
#define RARCH_HLSL_MAX_SHADERS 16
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
#include "d3d9_renderchain.h"
|
|
|
|
|
2018-05-17 22:22:10 +02:00
|
|
|
typedef struct hlsl_renderchain
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-17 16:42:27 +02:00
|
|
|
struct d3d9_renderchain chain;
|
2018-05-18 00:36:51 +02:00
|
|
|
struct shader_pass stock_shader;
|
2018-05-17 22:22:10 +02:00
|
|
|
} hlsl_renderchain_t;
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-17 19:13:39 +02:00
|
|
|
static void *d3d9_hlsl_get_constant_by_name(void *data, const char *name)
|
|
|
|
{
|
|
|
|
LPD3DXCONSTANTTABLE prog = (LPD3DXCONSTANTTABLE)data;
|
|
|
|
char lbl[64];
|
|
|
|
lbl[0] = '\0';
|
|
|
|
snprintf(lbl, sizeof(lbl), "$%s", name);
|
|
|
|
return d3d9x_constant_table_get_constant_by_name(prog, NULL, lbl);
|
|
|
|
}
|
|
|
|
|
2018-05-17 19:33:47 +02:00
|
|
|
static INLINE void d3d9_hlsl_set_param_2f(void *data, void *userdata, const char *name, const void *values)
|
|
|
|
{
|
|
|
|
LPD3DXCONSTANTTABLE prog = (LPD3DXCONSTANTTABLE)data;
|
2018-07-06 04:45:52 +02:00
|
|
|
D3DXHANDLE param = (D3DXHANDLE)d3d9_hlsl_get_constant_by_name(prog, name);
|
2018-05-17 19:33:47 +02:00
|
|
|
if (param)
|
|
|
|
d3d9x_constant_table_set_float_array((LPDIRECT3DDEVICE9)userdata, prog, (void*)param, values, 2);
|
|
|
|
}
|
|
|
|
|
2018-05-17 19:26:52 +02:00
|
|
|
static INLINE void d3d9_hlsl_set_param_1f(void *data, void *userdata, const char *name, const void *value)
|
|
|
|
{
|
|
|
|
LPD3DXCONSTANTTABLE prog = (LPD3DXCONSTANTTABLE)data;
|
2018-07-06 04:45:52 +02:00
|
|
|
D3DXHANDLE param = (D3DXHANDLE)d3d9_hlsl_get_constant_by_name(prog, name);
|
2018-05-17 19:26:52 +02:00
|
|
|
float *val = (float*)value;
|
|
|
|
if (param)
|
|
|
|
d3d9x_constant_table_set_float(prog, (LPDIRECT3DDEVICE9)userdata, (void*)param, *val);
|
|
|
|
}
|
|
|
|
|
2018-05-17 23:25:43 +02:00
|
|
|
static INLINE void d3d9_hlsl_bind_program(void *data,
|
|
|
|
LPDIRECT3DDEVICE9 dev)
|
|
|
|
{
|
|
|
|
struct shader_pass *pass = (struct shader_pass*)data;
|
|
|
|
if (!pass)
|
|
|
|
return;
|
|
|
|
d3d9_set_vertex_shader(dev, (LPDIRECT3DVERTEXSHADER9)pass->vprg);
|
|
|
|
d3d9_set_pixel_shader(dev, (LPDIRECT3DPIXELSHADER9)pass->fprg);
|
|
|
|
}
|
|
|
|
|
2018-05-17 19:55:08 +02:00
|
|
|
static INLINE void d3d9_hlsl_set_param_matrix(void *data, void *userdata,
|
|
|
|
const char *name, const void *values)
|
|
|
|
{
|
|
|
|
LPD3DXCONSTANTTABLE prog = (LPD3DXCONSTANTTABLE)data;
|
2018-07-06 04:45:52 +02:00
|
|
|
D3DXHANDLE param = (D3DXHANDLE)d3d9_hlsl_get_constant_by_name(prog, name);
|
2018-05-17 19:55:08 +02:00
|
|
|
if (param)
|
2019-02-03 15:49:35 -08:00
|
|
|
d3d9x_constant_table_set_matrix((LPDIRECT3DDEVICE9)userdata, prog,
|
2018-05-17 19:55:08 +02:00
|
|
|
(void*)param, (D3DMATRIX*)values);
|
|
|
|
}
|
|
|
|
|
2018-05-18 08:49:52 +02:00
|
|
|
static bool d3d9_hlsl_load_program_from_file(
|
|
|
|
LPDIRECT3DDEVICE9 dev,
|
|
|
|
struct shader_pass *pass,
|
|
|
|
const char *prog)
|
|
|
|
{
|
|
|
|
ID3DXBuffer *listing_f = NULL;
|
|
|
|
ID3DXBuffer *listing_v = NULL;
|
|
|
|
ID3DXBuffer *code_f = NULL;
|
|
|
|
ID3DXBuffer *code_v = NULL;
|
|
|
|
|
|
|
|
if (string_is_empty(prog))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!d3d9x_compile_shader_from_file(prog, NULL, NULL,
|
|
|
|
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &pass->ftable))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Could not compile fragment shader program (%s)..\n", prog);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!d3d9x_compile_shader_from_file(prog, NULL, NULL,
|
|
|
|
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &pass->vtable))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Could not compile vertex shader program (%s)..\n", prog);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
d3d9_create_pixel_shader(dev, (const DWORD*)d3d9x_get_buffer_ptr(code_f), (void**)&pass->fprg);
|
|
|
|
d3d9_create_vertex_shader(dev, (const DWORD*)d3d9x_get_buffer_ptr(code_v), (void**)&pass->vprg);
|
|
|
|
d3d9x_buffer_release((void*)code_f);
|
|
|
|
d3d9x_buffer_release((void*)code_v);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("Cg/HLSL error:\n");
|
|
|
|
if (listing_f)
|
|
|
|
RARCH_ERR("Fragment:\n%s\n", (char*)d3d9x_get_buffer_ptr(listing_f));
|
|
|
|
if (listing_v)
|
|
|
|
RARCH_ERR("Vertex:\n%s\n", (char*)d3d9x_get_buffer_ptr(listing_v));
|
|
|
|
d3d9x_buffer_release((void*)listing_f);
|
|
|
|
d3d9x_buffer_release((void*)listing_v);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-17 18:46:39 +02:00
|
|
|
static bool d3d9_hlsl_load_program(
|
2018-05-17 21:26:11 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev,
|
2018-05-18 00:17:47 +02:00
|
|
|
struct shader_pass *pass,
|
2018-05-18 08:49:52 +02:00
|
|
|
const char *prog)
|
2018-05-16 15:52:11 +02:00
|
|
|
{
|
|
|
|
ID3DXBuffer *listing_f = NULL;
|
|
|
|
ID3DXBuffer *listing_v = NULL;
|
|
|
|
ID3DXBuffer *code_f = NULL;
|
|
|
|
ID3DXBuffer *code_v = NULL;
|
|
|
|
|
2018-05-18 08:49:52 +02:00
|
|
|
if (!d3d9x_compile_shader(prog, strlen(prog), NULL, NULL,
|
|
|
|
"main_fragment", "ps_3_0", 0, &code_f, &listing_f,
|
|
|
|
&pass->ftable ))
|
2018-05-16 15:52:11 +02:00
|
|
|
{
|
2018-05-18 08:49:52 +02:00
|
|
|
RARCH_ERR("Could not compile stock fragment shader..\n");
|
|
|
|
goto error;
|
2018-05-16 15:52:11 +02:00
|
|
|
}
|
2018-05-18 08:49:52 +02:00
|
|
|
if (!d3d9x_compile_shader(prog, strlen(prog), NULL, NULL,
|
|
|
|
"main_vertex", "vs_3_0", 0, &code_v, &listing_v,
|
|
|
|
&pass->vtable ))
|
2018-05-16 15:52:11 +02:00
|
|
|
{
|
2018-05-18 08:49:52 +02:00
|
|
|
RARCH_ERR("Could not compile stock vertex shader..\n");
|
|
|
|
goto error;
|
2018-05-16 15:52:11 +02:00
|
|
|
}
|
|
|
|
|
2018-05-18 00:17:47 +02:00
|
|
|
d3d9_create_pixel_shader(dev, (const DWORD*)d3d9x_get_buffer_ptr(code_f), (void**)&pass->fprg);
|
|
|
|
d3d9_create_vertex_shader(dev, (const DWORD*)d3d9x_get_buffer_ptr(code_v), (void**)&pass->vprg);
|
2018-05-16 15:52:11 +02:00
|
|
|
d3d9x_buffer_release((void*)code_f);
|
|
|
|
d3d9x_buffer_release((void*)code_v);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("Cg/HLSL error:\n");
|
|
|
|
if (listing_f)
|
|
|
|
RARCH_ERR("Fragment:\n%s\n", (char*)d3d9x_get_buffer_ptr(listing_f));
|
|
|
|
if (listing_v)
|
|
|
|
RARCH_ERR("Vertex:\n%s\n", (char*)d3d9x_get_buffer_ptr(listing_v));
|
|
|
|
d3d9x_buffer_release((void*)listing_f);
|
|
|
|
d3d9x_buffer_release((void*)listing_v);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-17 20:01:20 +02:00
|
|
|
static void hlsl_d3d9_renderchain_set_shader_params(
|
2018-05-17 20:45:26 +02:00
|
|
|
d3d9_renderchain_t *chain,
|
2018-05-17 20:15:47 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev,
|
2018-05-17 20:45:26 +02:00
|
|
|
struct shader_pass *pass,
|
|
|
|
unsigned video_w, unsigned video_h,
|
|
|
|
unsigned tex_w, unsigned tex_h,
|
|
|
|
unsigned viewport_w, unsigned viewport_h)
|
2018-05-16 15:52:11 +02:00
|
|
|
{
|
2018-05-17 20:45:26 +02:00
|
|
|
float frame_cnt;
|
|
|
|
float video_size[2];
|
|
|
|
float texture_size[2];
|
|
|
|
float output_size[2];
|
2018-05-18 00:46:39 +02:00
|
|
|
void *fprg = pass->ftable;
|
|
|
|
void *vprg = pass->vtable;
|
2018-05-17 19:13:39 +02:00
|
|
|
|
2018-05-17 20:45:26 +02:00
|
|
|
video_size[0] = video_w;
|
|
|
|
video_size[1] = video_h;
|
|
|
|
texture_size[0] = tex_w;
|
|
|
|
texture_size[1] = tex_h;
|
|
|
|
output_size[0] = viewport_w;
|
|
|
|
output_size[1] = viewport_h;
|
2018-05-16 15:52:11 +02:00
|
|
|
|
2018-05-17 20:15:47 +02:00
|
|
|
d3d9x_constant_table_set_defaults(dev, fprg);
|
|
|
|
d3d9x_constant_table_set_defaults(dev, vprg);
|
2018-05-16 15:52:11 +02:00
|
|
|
|
2018-05-17 20:45:26 +02:00
|
|
|
d3d9_hlsl_set_param_2f(vprg, dev, "IN.video_size", &video_size);
|
|
|
|
d3d9_hlsl_set_param_2f(fprg, dev, "IN.video_size", &video_size);
|
|
|
|
d3d9_hlsl_set_param_2f(vprg, dev, "IN.texture_size", &texture_size);
|
|
|
|
d3d9_hlsl_set_param_2f(fprg, dev, "IN.texture_size", &texture_size);
|
|
|
|
d3d9_hlsl_set_param_2f(vprg, dev, "IN.output_size", &output_size);
|
|
|
|
d3d9_hlsl_set_param_2f(fprg, dev, "IN.output_size", &output_size);
|
2018-05-17 20:15:47 +02:00
|
|
|
|
2018-05-17 20:45:26 +02:00
|
|
|
frame_cnt = chain->frame_count;
|
2018-05-16 15:52:11 +02:00
|
|
|
|
2018-05-17 20:45:26 +02:00
|
|
|
if (pass->info.pass->frame_count_mod)
|
2019-02-03 15:49:35 -08:00
|
|
|
frame_cnt = chain->frame_count
|
2018-05-17 20:45:26 +02:00
|
|
|
% pass->info.pass->frame_count_mod;
|
|
|
|
|
|
|
|
d3d9_hlsl_set_param_1f(fprg, dev, "IN.frame_count", &frame_cnt);
|
|
|
|
d3d9_hlsl_set_param_1f(vprg, dev, "IN.frame_count", &frame_cnt);
|
2018-05-16 15:52:11 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 21:10:14 +02:00
|
|
|
static bool hlsl_d3d9_renderchain_init_shader_fvf(
|
2018-05-17 17:52:44 +02:00
|
|
|
d3d9_renderchain_t *chain,
|
2018-05-17 16:42:27 +02:00
|
|
|
struct shader_pass *pass)
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-14 21:10:14 +02:00
|
|
|
static const D3DVERTEXELEMENT9 decl[] =
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
|
|
|
{ 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
|
2018-05-14 03:17:26 +02:00
|
|
|
D3D9_DECL_FVF_TEXCOORD(0, 2, 0),
|
2017-09-04 23:50:13 +02:00
|
|
|
D3DDECL_END()
|
|
|
|
};
|
|
|
|
|
2018-05-17 17:52:44 +02:00
|
|
|
return d3d9_vertex_declaration_new(chain->dev,
|
2018-05-14 21:10:14 +02:00
|
|
|
decl, (void**)&pass->vertex_decl);
|
2017-09-04 23:50:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 03:06:19 +02:00
|
|
|
static bool hlsl_d3d9_renderchain_create_first_pass(
|
|
|
|
LPDIRECT3DDEVICE9 dev,
|
2018-05-17 17:52:44 +02:00
|
|
|
d3d9_renderchain_t *chain,
|
2018-05-14 20:50:02 +02:00
|
|
|
const struct LinkInfo *info,
|
|
|
|
unsigned _fmt)
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-14 21:10:14 +02:00
|
|
|
unsigned i;
|
2018-05-17 16:42:27 +02:00
|
|
|
struct shader_pass pass;
|
2019-02-03 15:49:35 -08:00
|
|
|
unsigned fmt =
|
|
|
|
(_fmt == RETRO_PIXEL_FORMAT_RGB565) ?
|
2018-05-14 20:50:02 +02:00
|
|
|
d3d9_get_rgb565_format() : d3d9_get_xrgb8888_format();
|
|
|
|
|
2018-05-14 21:10:14 +02:00
|
|
|
pass.info = *info;
|
|
|
|
pass.last_width = 0;
|
|
|
|
pass.last_height = 0;
|
|
|
|
pass.attrib_map = (struct unsigned_vector_list*)
|
|
|
|
unsigned_vector_list_new();
|
|
|
|
|
2018-05-17 17:52:44 +02:00
|
|
|
chain->prev.ptr = 0;
|
2018-05-14 21:10:14 +02:00
|
|
|
|
|
|
|
for (i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
2018-05-17 17:52:44 +02:00
|
|
|
chain->prev.last_width[i] = 0;
|
|
|
|
chain->prev.last_height[i] = 0;
|
|
|
|
chain->prev.vertex_buf[i] = (LPDIRECT3DVERTEXBUFFER9)
|
2018-05-14 21:10:14 +02:00
|
|
|
d3d9_vertex_buffer_new(
|
2018-05-17 17:52:44 +02:00
|
|
|
chain->dev, 4 * sizeof(struct D3D9Vertex),
|
2018-05-14 21:10:14 +02:00
|
|
|
D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, NULL);
|
|
|
|
|
2018-05-17 17:52:44 +02:00
|
|
|
if (!chain->prev.vertex_buf[i])
|
2018-05-14 21:10:14 +02:00
|
|
|
return false;
|
|
|
|
|
2018-05-17 17:52:44 +02:00
|
|
|
chain->prev.tex[i] = (LPDIRECT3DTEXTURE9)
|
|
|
|
d3d9_texture_new(chain->dev, NULL,
|
2018-05-14 21:10:14 +02:00
|
|
|
info->tex_w, info->tex_h, 1, 0, fmt,
|
|
|
|
D3DPOOL_MANAGED, 0, 0, 0, NULL, NULL, false);
|
|
|
|
|
2018-05-17 17:52:44 +02:00
|
|
|
if (!chain->prev.tex[i])
|
2018-05-14 21:10:14 +02:00
|
|
|
return false;
|
|
|
|
|
2018-05-17 17:52:44 +02:00
|
|
|
d3d9_set_texture(chain->dev, 0, chain->prev.tex[i]);
|
2018-05-14 21:10:14 +02:00
|
|
|
d3d9_set_sampler_minfilter(dev, 0,
|
|
|
|
d3d_translate_filter(info->pass->filter));
|
|
|
|
d3d9_set_sampler_magfilter(dev, 0,
|
|
|
|
d3d_translate_filter(info->pass->filter));
|
|
|
|
d3d9_set_sampler_address_u(dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(dev, 0, D3DTADDRESS_BORDER);
|
2018-05-17 17:52:44 +02:00
|
|
|
d3d9_set_texture(chain->dev, 0, NULL);
|
2018-05-14 21:10:14 +02:00
|
|
|
}
|
|
|
|
|
2018-05-18 08:49:52 +02:00
|
|
|
d3d9_hlsl_load_program_from_file(chain->dev, &pass, info->pass->source.path);
|
2018-05-18 00:46:39 +02:00
|
|
|
|
2018-05-14 21:10:14 +02:00
|
|
|
if (!hlsl_d3d9_renderchain_init_shader_fvf(chain, &pass))
|
2017-09-04 23:50:13 +02:00
|
|
|
return false;
|
2018-05-17 17:52:44 +02:00
|
|
|
shader_pass_vector_list_append(chain->passes, pass);
|
2017-09-04 23:50:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-17 22:22:10 +02:00
|
|
|
static void hlsl_d3d9_renderchain_calc_and_set_shader_mvp(
|
|
|
|
hlsl_renderchain_t *chain,
|
2018-05-18 00:36:51 +02:00
|
|
|
struct shader_pass *pass,
|
2018-05-17 02:16:19 +02:00
|
|
|
unsigned vp_width, unsigned vp_height,
|
|
|
|
unsigned rotation)
|
|
|
|
{
|
|
|
|
struct d3d_matrix proj, ortho, rot, matrix;
|
|
|
|
|
|
|
|
d3d_matrix_ortho_off_center_lh(&ortho, 0, vp_width, 0, vp_height, 0, 1);
|
|
|
|
d3d_matrix_identity(&rot);
|
|
|
|
d3d_matrix_rotation_z(&rot, rotation * (D3D_PI / 2.0));
|
|
|
|
|
|
|
|
d3d_matrix_multiply(&proj, &ortho, &rot);
|
|
|
|
d3d_matrix_transpose(&matrix, &proj);
|
|
|
|
|
2018-05-18 00:36:51 +02:00
|
|
|
d3d9_hlsl_set_param_matrix(pass->vtable,
|
2018-05-17 22:50:37 +02:00
|
|
|
chain->chain.dev, "modelViewProj", (const void*)&matrix);
|
2018-05-17 02:16:19 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 16:51:29 +01:00
|
|
|
static void hlsl_d3d9_renderchain_set_vertices(
|
2018-05-13 06:22:12 +02:00
|
|
|
d3d9_video_t *d3d,
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *chain,
|
2018-05-17 16:42:27 +02:00
|
|
|
struct shader_pass *pass,
|
2018-05-17 02:16:19 +02:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
unsigned out_width, unsigned out_height,
|
|
|
|
unsigned vp_width, unsigned vp_height,
|
|
|
|
uint64_t frame_count,
|
|
|
|
unsigned rotation)
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-17 02:16:19 +02:00
|
|
|
if (pass->last_width != width || pass->last_height != height)
|
2018-05-17 21:07:44 +02:00
|
|
|
d3d9_renderchain_set_vertices_on_change(&chain->chain,
|
|
|
|
pass, width, height, out_width, out_height,
|
|
|
|
vp_width, vp_height, rotation);
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-18 00:36:51 +02:00
|
|
|
hlsl_d3d9_renderchain_calc_and_set_shader_mvp(chain, pass,
|
|
|
|
vp_width, vp_height, rotation);
|
2018-05-17 21:07:44 +02:00
|
|
|
hlsl_d3d9_renderchain_set_shader_params(&chain->chain,
|
2018-05-18 00:46:39 +02:00
|
|
|
chain->chain.dev,
|
2018-05-17 21:07:44 +02:00
|
|
|
pass,
|
|
|
|
width, height,
|
|
|
|
pass->info.tex_w, pass->info.tex_h,
|
|
|
|
vp_width, vp_height);
|
2017-09-04 23:50:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-17 22:22:10 +02:00
|
|
|
static void d3d9_hlsl_deinit_progs(hlsl_renderchain_t *chain)
|
2018-05-14 20:42:28 +02:00
|
|
|
{
|
|
|
|
RARCH_LOG("[D3D9 HLSL]: Destroying programs.\n");
|
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
if (chain->chain.passes->count >= 1)
|
2018-05-14 20:42:28 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_vertex_buffer_free(NULL, chain->chain.passes->data[0].vertex_decl);
|
2018-05-14 20:42:28 +02:00
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
for (i = 1; i < chain->chain.passes->count; i++)
|
2018-05-14 20:42:28 +02:00
|
|
|
{
|
2018-05-17 16:42:27 +02:00
|
|
|
if (chain->chain.passes->data[i].tex)
|
|
|
|
d3d9_texture_free(chain->chain.passes->data[i].tex);
|
|
|
|
chain->chain.passes->data[i].tex = NULL;
|
2018-05-14 20:42:28 +02:00
|
|
|
d3d9_vertex_buffer_free(
|
2018-05-17 16:42:27 +02:00
|
|
|
chain->chain.passes->data[i].vertex_buf,
|
|
|
|
chain->chain.passes->data[i].vertex_decl);
|
2018-05-14 20:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 22:22:10 +02:00
|
|
|
static void d3d9_hlsl_destroy_resources(hlsl_renderchain_t *chain)
|
2018-05-14 20:42:28 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
2018-05-17 16:42:27 +02:00
|
|
|
if (chain->chain.prev.tex[i])
|
|
|
|
d3d9_texture_free(chain->chain.prev.tex[i]);
|
|
|
|
if (chain->chain.prev.vertex_buf[i])
|
|
|
|
d3d9_vertex_buffer_free(chain->chain.prev.vertex_buf[i], NULL);
|
2018-05-14 20:42:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
d3d9_hlsl_deinit_progs(chain);
|
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
for (i = 0; i < chain->chain.luts->count; i++)
|
2018-05-14 20:42:28 +02:00
|
|
|
{
|
2018-05-17 16:42:27 +02:00
|
|
|
if (chain->chain.luts->data[i].tex)
|
|
|
|
d3d9_texture_free(chain->chain.luts->data[i].tex);
|
2018-05-14 20:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 00:00:17 +02:00
|
|
|
static void hlsl_d3d9_renderchain_free(void *data)
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *chain = (hlsl_renderchain_t*)data;
|
2017-09-04 23:50:13 +02:00
|
|
|
|
|
|
|
if (!chain)
|
|
|
|
return;
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
d3d9_hlsl_destroy_resources(chain);
|
2018-05-17 17:59:42 +02:00
|
|
|
d3d9_renderchain_destroy_passes_and_luts(&chain->chain);
|
2018-05-13 06:22:12 +02:00
|
|
|
free(chain);
|
2017-09-04 23:50:13 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 00:00:17 +02:00
|
|
|
void *hlsl_d3d9_renderchain_new(void)
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *renderchain =
|
|
|
|
(hlsl_renderchain_t*)calloc(1, sizeof(*renderchain));
|
2017-09-04 23:50:13 +02:00
|
|
|
if (!renderchain)
|
|
|
|
return NULL;
|
|
|
|
|
2018-05-17 17:15:04 +02:00
|
|
|
d3d9_init_renderchain(&renderchain->chain);
|
2018-05-14 20:42:28 +02:00
|
|
|
|
2017-09-04 23:50:13 +02:00
|
|
|
return renderchain;
|
|
|
|
}
|
|
|
|
|
2018-05-13 06:22:12 +02:00
|
|
|
static bool hlsl_d3d9_renderchain_init_shader(d3d9_video_t *d3d,
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *chain)
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9]: Using HLSL shader backend.\n");
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-16 15:52:11 +02:00
|
|
|
return true;
|
2017-09-04 23:50:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 06:22:12 +02:00
|
|
|
static bool hlsl_d3d9_renderchain_init(
|
|
|
|
d3d9_video_t *d3d,
|
2018-05-13 17:28:40 +02:00
|
|
|
const video_info_t *video_info,
|
2018-05-13 18:24:19 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev,
|
|
|
|
const D3DVIEWPORT9 *final_viewport,
|
|
|
|
const struct LinkInfo *info,
|
2017-09-04 23:50:13 +02:00
|
|
|
bool rgb32
|
|
|
|
)
|
|
|
|
{
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *chain = (hlsl_renderchain_t*)
|
2017-09-19 15:02:51 +02:00
|
|
|
d3d->renderchain_data;
|
2017-12-11 23:55:31 -08:00
|
|
|
unsigned fmt = (rgb32)
|
2017-09-19 15:02:51 +02:00
|
|
|
? RETRO_PIXEL_FORMAT_XRGB8888 : RETRO_PIXEL_FORMAT_RGB565;
|
|
|
|
|
2018-05-14 03:06:19 +02:00
|
|
|
if (!chain)
|
|
|
|
return false;
|
2018-05-13 06:22:12 +02:00
|
|
|
if (!hlsl_d3d9_renderchain_init_shader(d3d, chain))
|
2018-05-13 18:59:57 +02:00
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D9 HLSL]: Failed to initialize shader subsystem.\n");
|
2017-09-04 23:50:13 +02:00
|
|
|
return false;
|
2018-05-13 18:59:57 +02:00
|
|
|
}
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
chain->chain.dev = dev;
|
|
|
|
chain->chain.final_viewport = (D3DVIEWPORT9*)final_viewport;
|
|
|
|
chain->chain.frame_count = 0;
|
|
|
|
chain->chain.pixel_size = (fmt == RETRO_PIXEL_FORMAT_RGB565) ? 2 : 4;
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-17 17:52:44 +02:00
|
|
|
if (!hlsl_d3d9_renderchain_create_first_pass(dev, &chain->chain, info, fmt))
|
2017-09-04 23:50:13 +02:00
|
|
|
return false;
|
2018-05-18 08:49:52 +02:00
|
|
|
if (!d3d9_hlsl_load_program(chain->chain.dev, &chain->stock_shader, stock_hlsl_program))
|
2018-05-18 00:36:51 +02:00
|
|
|
return false;
|
2018-05-18 00:51:45 +02:00
|
|
|
|
2018-05-18 00:36:51 +02:00
|
|
|
d3d9_hlsl_bind_program(&chain->stock_shader, dev);
|
2017-09-04 23:50:13 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-13 06:22:12 +02:00
|
|
|
static void hlsl_d3d9_renderchain_set_final_viewport(
|
|
|
|
d3d9_video_t *d3d,
|
2018-05-14 23:14:26 +02:00
|
|
|
void *renderchain_data,
|
|
|
|
const D3DVIEWPORT9 *final_viewport)
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *_chain = (hlsl_renderchain_t*)renderchain_data;
|
2018-05-17 17:50:33 +02:00
|
|
|
d3d9_renderchain_t *chain = (d3d9_renderchain_t*)&_chain->chain;
|
2018-05-14 23:14:26 +02:00
|
|
|
|
|
|
|
if (chain && final_viewport)
|
2018-05-17 17:50:33 +02:00
|
|
|
chain->final_viewport = (D3DVIEWPORT9*)final_viewport;
|
2018-05-14 23:14:26 +02:00
|
|
|
|
2018-05-17 17:50:33 +02:00
|
|
|
d3d9_recompute_pass_sizes(chain->dev, chain, d3d);
|
2017-09-04 23:50:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 21:26:52 +02:00
|
|
|
static void hlsl_d3d9_renderchain_render_pass(
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *chain,
|
2018-05-17 16:42:27 +02:00
|
|
|
struct shader_pass *pass,
|
2018-05-14 21:26:52 +02:00
|
|
|
unsigned pass_index)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2018-05-18 00:24:19 +02:00
|
|
|
d3d9_hlsl_bind_program(pass, chain->chain.dev);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_set_texture(chain->chain.dev, 0, pass->tex);
|
|
|
|
d3d9_set_sampler_minfilter(chain->chain.dev, 0,
|
2018-05-14 21:26:52 +02:00
|
|
|
d3d_translate_filter(pass->info.pass->filter));
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_set_sampler_magfilter(chain->chain.dev, 0,
|
2018-05-14 21:26:52 +02:00
|
|
|
d3d_translate_filter(pass->info.pass->filter));
|
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_set_vertex_declaration(chain->chain.dev, pass->vertex_decl);
|
2018-05-14 21:26:52 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_set_stream_source(chain->chain.dev, i,
|
2018-05-14 21:26:52 +02:00
|
|
|
pass->vertex_buf, 0,
|
2018-05-17 17:10:44 +02:00
|
|
|
sizeof(struct D3D9Vertex));
|
2018-05-14 21:26:52 +02:00
|
|
|
|
2018-05-17 05:36:56 +02:00
|
|
|
#if 0
|
|
|
|
/* Set orig texture. */
|
2018-05-17 20:31:16 +02:00
|
|
|
d3d9_hlsl_renderchain_bind_orig(chain, chain->dev, pass);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
/* Set prev textures. */
|
2018-05-17 20:31:16 +02:00
|
|
|
d3d9_hlsl_renderchain_bind_prev(chain, chain->dev, pass);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
/* Set lookup textures */
|
2018-05-17 20:31:16 +02:00
|
|
|
for (i = 0; i < chain->luts->count; i++)
|
2018-05-17 05:36:56 +02:00
|
|
|
{
|
|
|
|
CGparameter vparam;
|
2018-05-17 20:31:16 +02:00
|
|
|
CGparameter fparam = d3d9_hlsl_get_constant_by_name(
|
|
|
|
pass->fprg, chain->luts->data[i].id);
|
2018-05-17 05:36:56 +02:00
|
|
|
int bound_index = -1;
|
|
|
|
|
|
|
|
if (fparam)
|
|
|
|
{
|
|
|
|
unsigned index = cgGetParameterResourceIndex(fparam);
|
|
|
|
bound_index = index;
|
|
|
|
|
2018-05-17 20:31:16 +02:00
|
|
|
d3d9_renderchain_add_lut_internal(chain, index, i);
|
2018-05-17 05:36:56 +02:00
|
|
|
}
|
|
|
|
|
2018-05-17 20:31:16 +02:00
|
|
|
vparam = d3d9_hlsl_get_constant_by_name(pass->vprg,
|
|
|
|
chain->luts->data[i].id);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
if (vparam)
|
|
|
|
{
|
|
|
|
unsigned index = cgGetParameterResourceIndex(vparam);
|
|
|
|
if (index != (unsigned)bound_index)
|
2018-05-17 20:31:16 +02:00
|
|
|
d3d9_renderchain_add_lut_internal(chain, index, i);
|
2018-05-17 05:36:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 20:31:16 +02:00
|
|
|
/* We only bother binding passes which are two indices behind. */
|
2018-05-17 05:36:56 +02:00
|
|
|
if (pass_index >= 3)
|
2018-05-17 21:11:43 +02:00
|
|
|
d3d9_hlsl_renderchain_bind_pass(chain, chain->chain.dev, pass, pass_index);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_draw_primitive(chain->chain.dev, D3DPT_TRIANGLESTRIP, 0, 2);
|
2018-05-14 21:26:52 +02:00
|
|
|
|
|
|
|
/* So we don't render with linear filter into render targets,
|
|
|
|
* which apparently looked odd (too blurry). */
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_set_sampler_minfilter(chain->chain.dev, 0, D3DTEXF_POINT);
|
|
|
|
d3d9_set_sampler_magfilter(chain->chain.dev, 0, D3DTEXF_POINT);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
2018-05-17 17:27:56 +02:00
|
|
|
d3d9_renderchain_unbind_all(&chain->chain);
|
2018-05-14 21:26:52 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 06:22:12 +02:00
|
|
|
static bool hlsl_d3d9_renderchain_render(
|
|
|
|
d3d9_video_t *d3d,
|
2018-05-15 06:02:10 +02:00
|
|
|
const video_frame_info_t *video_info,
|
2018-05-13 06:22:12 +02:00
|
|
|
const void *frame,
|
2018-05-14 21:26:52 +02:00
|
|
|
unsigned width, unsigned height,
|
2017-09-04 23:50:13 +02:00
|
|
|
unsigned pitch, unsigned rotation)
|
|
|
|
{
|
2018-05-17 05:36:56 +02:00
|
|
|
LPDIRECT3DSURFACE9 back_buffer, target;
|
2018-05-14 21:26:52 +02:00
|
|
|
unsigned i, current_width, current_height, out_width = 0, out_height = 0;
|
2018-05-17 16:42:27 +02:00
|
|
|
struct shader_pass *last_pass = NULL;
|
|
|
|
struct shader_pass *first_pass = NULL;
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *chain = (hlsl_renderchain_t*)
|
2018-05-13 18:33:16 +02:00
|
|
|
d3d->renderchain_data;
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-17 17:38:42 +02:00
|
|
|
d3d9_renderchain_start_render(&chain->chain);
|
2018-05-17 04:19:35 +02:00
|
|
|
|
2018-05-14 21:26:52 +02:00
|
|
|
current_width = width;
|
|
|
|
current_height = height;
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
first_pass = (struct shader_pass*)
|
|
|
|
&chain->chain.passes->data[0];
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-14 23:14:26 +02:00
|
|
|
d3d9_convert_geometry(
|
|
|
|
&first_pass->info,
|
|
|
|
&out_width, &out_height,
|
2018-05-17 16:42:27 +02:00
|
|
|
current_width, current_height, chain->chain.final_viewport);
|
2018-05-14 23:14:26 +02:00
|
|
|
|
2018-05-14 21:26:52 +02:00
|
|
|
d3d9_renderchain_blit_to_texture(first_pass->tex,
|
2018-05-14 19:11:45 +02:00
|
|
|
frame,
|
2018-05-14 21:26:52 +02:00
|
|
|
first_pass->info.tex_w,
|
|
|
|
first_pass->info.tex_h,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
first_pass->last_width,
|
|
|
|
first_pass->last_height,
|
2018-05-14 19:11:45 +02:00
|
|
|
pitch,
|
2018-05-17 16:42:27 +02:00
|
|
|
chain->chain.pixel_size);
|
2018-05-14 19:11:45 +02:00
|
|
|
|
2018-05-17 05:36:56 +02:00
|
|
|
/* Grab back buffer. */
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_device_get_render_target(chain->chain.dev, 0, (void**)&back_buffer);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
/* In-between render target passes. */
|
2018-05-17 16:42:27 +02:00
|
|
|
for (i = 0; i < chain->chain.passes->count - 1; i++)
|
2018-05-17 05:36:56 +02:00
|
|
|
{
|
|
|
|
D3DVIEWPORT9 viewport = {0};
|
2018-05-17 16:42:27 +02:00
|
|
|
struct shader_pass *from_pass = (struct shader_pass*)
|
|
|
|
&chain->chain.passes->data[i];
|
|
|
|
struct shader_pass *to_pass = (struct shader_pass*)
|
|
|
|
&chain->chain.passes->data[i + 1];
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
d3d9_texture_get_surface_level(to_pass->tex, 0, (void**)&target);
|
|
|
|
|
2019-07-26 17:29:53 +02:00
|
|
|
d3d9_device_set_render_target(chain->chain.dev, 0, target);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
d3d9_convert_geometry(&from_pass->info,
|
|
|
|
&out_width, &out_height,
|
2018-05-17 16:42:27 +02:00
|
|
|
current_width, current_height, chain->chain.final_viewport);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_set_viewports(chain->chain.dev, &viewport);
|
|
|
|
d3d9_clear(chain->chain.dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
|
|
|
viewport.Width = out_width;
|
|
|
|
viewport.Height = out_height;
|
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_set_viewports(chain->chain.dev, &viewport);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
2018-05-17 20:50:32 +02:00
|
|
|
hlsl_d3d9_renderchain_set_vertices(
|
|
|
|
d3d,
|
2018-05-18 00:46:39 +02:00
|
|
|
chain, from_pass,
|
2018-05-17 05:36:56 +02:00
|
|
|
current_width, current_height,
|
|
|
|
out_width, out_height,
|
|
|
|
out_width, out_height,
|
2018-05-17 16:42:27 +02:00
|
|
|
chain->chain.frame_count, 0);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
2018-05-18 00:51:45 +02:00
|
|
|
hlsl_d3d9_renderchain_render_pass(chain,
|
2019-07-09 07:39:08 +02:00
|
|
|
from_pass,
|
2018-05-17 05:36:56 +02:00
|
|
|
i + 1);
|
|
|
|
|
|
|
|
current_width = out_width;
|
|
|
|
current_height = out_height;
|
|
|
|
d3d9_surface_free(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Final pass */
|
2019-07-26 17:29:53 +02:00
|
|
|
d3d9_device_set_render_target(chain->chain.dev, 0, back_buffer);
|
2018-05-17 05:36:56 +02:00
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
last_pass = (struct shader_pass*)&chain->chain.passes->
|
|
|
|
data[chain->chain.passes->count - 1];
|
2018-05-17 05:36:56 +02:00
|
|
|
|
2018-05-14 23:14:26 +02:00
|
|
|
d3d9_convert_geometry(&last_pass->info,
|
|
|
|
&out_width, &out_height,
|
2018-05-17 16:42:27 +02:00
|
|
|
current_width, current_height, chain->chain.final_viewport);
|
2018-05-14 23:14:26 +02:00
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
d3d9_set_viewports(chain->chain.dev, chain->chain.final_viewport);
|
2018-05-14 21:26:52 +02:00
|
|
|
|
2018-05-17 20:50:32 +02:00
|
|
|
hlsl_d3d9_renderchain_set_vertices(
|
|
|
|
d3d,
|
2018-05-18 00:46:39 +02:00
|
|
|
chain, last_pass,
|
2018-05-17 02:16:19 +02:00
|
|
|
current_width, current_height,
|
|
|
|
out_width, out_height,
|
2018-05-17 16:42:27 +02:00
|
|
|
chain->chain.final_viewport->Width,
|
|
|
|
chain->chain.final_viewport->Height,
|
|
|
|
chain->chain.frame_count, rotation);
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-14 21:26:52 +02:00
|
|
|
hlsl_d3d9_renderchain_render_pass(chain, last_pass,
|
2018-05-17 16:42:27 +02:00
|
|
|
chain->chain.passes->count);
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-17 16:42:27 +02:00
|
|
|
chain->chain.frame_count++;
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-17 05:36:56 +02:00
|
|
|
d3d9_surface_free(back_buffer);
|
2018-05-17 04:19:35 +02:00
|
|
|
|
2018-05-17 17:38:42 +02:00
|
|
|
d3d9_renderchain_end_render(&chain->chain);
|
2018-05-18 00:24:19 +02:00
|
|
|
d3d9_hlsl_bind_program(&chain->stock_shader, chain->chain.dev);
|
2018-05-18 00:36:51 +02:00
|
|
|
hlsl_d3d9_renderchain_calc_and_set_shader_mvp(chain, &chain->stock_shader,
|
|
|
|
chain->chain.final_viewport->Width,
|
2018-05-17 16:42:27 +02:00
|
|
|
chain->chain.final_viewport->Height, 0);
|
2018-05-15 05:53:15 +02:00
|
|
|
|
2017-09-04 23:50:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-15 16:51:29 +01:00
|
|
|
static bool hlsl_d3d9_renderchain_add_pass(
|
2018-05-13 18:33:16 +02:00
|
|
|
void *data, const struct LinkInfo *info)
|
2017-09-04 23:50:13 +02:00
|
|
|
{
|
2018-05-18 00:27:07 +02:00
|
|
|
struct shader_pass pass;
|
|
|
|
hlsl_renderchain_t *chain = (hlsl_renderchain_t*)data;
|
2017-09-04 23:50:13 +02:00
|
|
|
|
2018-05-18 00:27:07 +02:00
|
|
|
pass.info = *info;
|
|
|
|
pass.last_width = 0;
|
|
|
|
pass.last_height = 0;
|
|
|
|
pass.attrib_map = (struct unsigned_vector_list*)
|
|
|
|
unsigned_vector_list_new();
|
|
|
|
pass.pool = D3DPOOL_DEFAULT;
|
|
|
|
|
2018-05-18 08:49:52 +02:00
|
|
|
d3d9_hlsl_load_program_from_file(chain->chain.dev, &pass, info->pass->source.path);
|
2018-05-18 00:27:07 +02:00
|
|
|
|
|
|
|
if (!hlsl_d3d9_renderchain_init_shader_fvf(&chain->chain, &pass))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return d3d9_renderchain_add_pass(&chain->chain, &pass,
|
|
|
|
info);
|
2017-09-04 23:50:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-17 17:23:53 +02:00
|
|
|
static bool hlsl_d3d9_renderchain_add_lut(void *data,
|
|
|
|
const char *id, const char *path, bool smooth)
|
|
|
|
{
|
2018-05-17 22:22:10 +02:00
|
|
|
hlsl_renderchain_t *_chain = (hlsl_renderchain_t*)data;
|
|
|
|
d3d9_renderchain_t *chain = (d3d9_renderchain_t*)&_chain->chain;
|
2018-05-17 17:23:53 +02:00
|
|
|
|
|
|
|
return d3d9_renderchain_add_lut(chain, id, path, smooth);
|
|
|
|
}
|
|
|
|
|
2018-05-13 06:03:26 +02:00
|
|
|
d3d9_renderchain_driver_t hlsl_d3d9_renderchain = {
|
2017-09-05 00:00:17 +02:00
|
|
|
hlsl_d3d9_renderchain_free,
|
|
|
|
hlsl_d3d9_renderchain_new,
|
|
|
|
hlsl_d3d9_renderchain_init,
|
|
|
|
hlsl_d3d9_renderchain_set_final_viewport,
|
|
|
|
hlsl_d3d9_renderchain_add_pass,
|
2018-05-17 17:23:53 +02:00
|
|
|
hlsl_d3d9_renderchain_add_lut,
|
2017-09-05 00:00:17 +02:00
|
|
|
hlsl_d3d9_renderchain_render,
|
|
|
|
"hlsl_d3d9",
|
2017-09-04 23:50:13 +02:00
|
|
|
};
|