2012-10-26 21:09:30 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2017-10-02 19:07:05 -04:00
|
|
|
*
|
2012-10-26 21:09:30 +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
|
|
|
|
|
2014-01-15 17:24:24 +01:00
|
|
|
#include <string.h>
|
2015-11-23 22:29:27 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2016-09-11 15:07:07 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2017-04-19 02:17:34 +02:00
|
|
|
#include "../include/Cg/cg.h"
|
|
|
|
#include "../include/Cg/cgD3D9.h"
|
2015-09-19 03:50:35 +02:00
|
|
|
|
|
|
|
#include <retro_inline.h>
|
2017-06-28 04:41:38 +02:00
|
|
|
#include <retro_math.h>
|
2015-09-19 03:50:35 +02:00
|
|
|
#include <compat/strl.h>
|
2016-01-09 02:37:48 +01:00
|
|
|
#include <string/stdstring.h>
|
2015-09-19 03:50:35 +02:00
|
|
|
|
2018-01-25 11:50:07 +01:00
|
|
|
#include "../common/d3d_common.h"
|
2017-04-19 16:11:00 +02:00
|
|
|
#include "../drivers/d3d_shaders/opaque.cg.d3d9.h"
|
2016-09-11 15:07:07 +02:00
|
|
|
|
2017-04-19 02:17:34 +02:00
|
|
|
#include "../video_driver.h"
|
|
|
|
#include "../../configuration.h"
|
|
|
|
#include "../../verbosity.h"
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-03-02 18:32:14 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma comment(lib, "cgd3d9")
|
|
|
|
#endif
|
|
|
|
|
2017-10-02 20:18:36 +02:00
|
|
|
#define D3D_DEFAULT_NONPOW2 ((UINT)-2)
|
|
|
|
#define D3D_FILTER_LINEAR (3 << 0)
|
|
|
|
#define D3D_FILTER_POINT (2 << 0)
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
#define d3d9_cg_set_param_1f(param, x) if (param) cgD3D9SetUniform(param, x)
|
2017-04-19 16:11:00 +02:00
|
|
|
|
2017-09-19 14:54:55 +02:00
|
|
|
#define set_cg_param(prog, param, val) do { \
|
|
|
|
CGparameter cgp = cgGetNamedParameter(prog, param); \
|
|
|
|
if (cgp) \
|
|
|
|
cgD3D9SetUniform(cgp, &val); \
|
|
|
|
} while(0)
|
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
struct CGVertex
|
|
|
|
{
|
|
|
|
float x, y, z;
|
|
|
|
float u, v;
|
|
|
|
float lut_u, lut_v;
|
|
|
|
float r, g, b, a;
|
|
|
|
};
|
2015-04-05 18:44:12 +02:00
|
|
|
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass
|
2017-10-02 19:07:05 -04:00
|
|
|
{
|
2018-01-25 11:50:07 +01:00
|
|
|
unsigned last_width, last_height;
|
2017-10-03 02:45:06 +02:00
|
|
|
struct LinkInfo info;
|
2018-01-16 00:08:10 +01:00
|
|
|
D3DPOOL pool;
|
2018-01-25 04:28:50 +01:00
|
|
|
LPDIRECT3DTEXTURE9 tex;
|
2018-01-25 11:50:07 +01:00
|
|
|
LPDIRECT3DVERTEXBUFFER9 vertex_buf;
|
|
|
|
LPDIRECT3DVERTEXDECLARATION9 vertex_decl;
|
2018-05-14 18:40:36 +02:00
|
|
|
void *attrib_map;
|
2018-05-14 20:42:28 +02:00
|
|
|
CGprogram vPrg, fPrg;
|
2015-04-05 18:40:19 +02:00
|
|
|
};
|
2017-04-19 16:11:00 +02:00
|
|
|
|
2018-05-14 03:12:09 +02:00
|
|
|
#define VECTOR_LIST_TYPE struct cg_pass
|
2018-05-14 18:48:47 +02:00
|
|
|
#define VECTOR_LIST_NAME cg_pass
|
2017-10-02 19:07:05 -04:00
|
|
|
#include "../../libretro-common/lists/vector_list.c"
|
|
|
|
#undef VECTOR_LIST_TYPE
|
|
|
|
#undef VECTOR_LIST_NAME
|
|
|
|
|
2018-05-14 18:40:36 +02:00
|
|
|
#include "d3d9_renderchain.h"
|
2017-10-02 19:07:05 -04:00
|
|
|
|
2015-04-06 00:29:53 +02:00
|
|
|
typedef struct cg_renderchain
|
2015-04-05 05:01:47 +02:00
|
|
|
{
|
|
|
|
unsigned pixel_size;
|
2018-05-13 18:11:48 +02:00
|
|
|
uint64_t frame_count;
|
2015-04-05 05:01:47 +02:00
|
|
|
struct
|
|
|
|
{
|
2018-01-25 04:28:50 +01:00
|
|
|
LPDIRECT3DTEXTURE9 tex[TEXTURES];
|
2018-01-25 11:50:07 +01:00
|
|
|
LPDIRECT3DVERTEXBUFFER9 vertex_buf[TEXTURES];
|
2015-04-05 05:01:47 +02:00
|
|
|
unsigned ptr;
|
|
|
|
unsigned last_width[TEXTURES];
|
|
|
|
unsigned last_height[TEXTURES];
|
|
|
|
} prev;
|
2017-10-02 03:52:53 +02:00
|
|
|
CGprogram vStock;
|
|
|
|
CGprogram fStock;
|
2018-05-13 18:11:48 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev;
|
2018-01-25 10:03:34 +01:00
|
|
|
D3DVIEWPORT9 *final_viewport;
|
2018-05-14 18:48:47 +02:00
|
|
|
struct cg_pass_vector_list *passes;
|
2017-10-02 19:07:05 -04:00
|
|
|
struct unsigned_vector_list *bound_tex;
|
|
|
|
struct unsigned_vector_list *bound_vert;
|
2018-01-26 06:50:11 +01:00
|
|
|
struct lut_info_vector_list *luts;
|
|
|
|
CGcontext cgCtx;
|
2015-04-06 00:32:07 +02:00
|
|
|
} cg_renderchain_t;
|
2015-04-05 05:01:47 +02:00
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static INLINE bool d3d9_cg_validate_param_name(const char *name)
|
2015-04-05 05:09:05 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
static const char *illegal[] = {
|
|
|
|
"PREV.",
|
|
|
|
"PREV1.",
|
|
|
|
"PREV2.",
|
|
|
|
"PREV3.",
|
|
|
|
"PREV4.",
|
|
|
|
"PREV5.",
|
|
|
|
"PREV6.",
|
|
|
|
"ORIG.",
|
|
|
|
"IN.",
|
|
|
|
"PASS",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(illegal) / sizeof(illegal[0]); i++)
|
|
|
|
if (strstr(name, illegal[i]) == name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-09 06:28:26 +01:00
|
|
|
static INLINE CGparameter d3d9_cg_find_param_from_semantic(
|
2015-04-05 05:09:05 +02:00
|
|
|
CGparameter param, const char *sem)
|
|
|
|
{
|
2016-01-08 18:12:49 +01:00
|
|
|
for (; param; param = cgGetNextParameter(param))
|
2015-04-05 05:09:05 +02:00
|
|
|
{
|
2016-01-08 18:12:49 +01:00
|
|
|
const char *semantic = NULL;
|
2015-04-05 05:09:05 +02:00
|
|
|
if (cgGetParameterType(param) == CG_STRUCT)
|
|
|
|
{
|
2016-01-09 07:26:45 +01:00
|
|
|
CGparameter ret = d3d9_cg_find_param_from_semantic(
|
2015-04-05 05:09:05 +02:00
|
|
|
cgGetFirstStructParameter(param), sem);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2016-01-08 18:12:49 +01:00
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
if ( cgGetParameterDirection(param) != CG_IN
|
2016-01-08 18:12:49 +01:00
|
|
|
|| cgGetParameterVariability(param) != CG_VARYING)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
semantic = cgGetParameterSemantic(param);
|
|
|
|
if (!semantic)
|
|
|
|
continue;
|
|
|
|
|
2016-01-20 04:14:55 +01:00
|
|
|
if (string_is_equal(sem, semantic) &&
|
2017-09-05 04:08:44 +02:00
|
|
|
d3d9_cg_validate_param_name(cgGetParameterName(param)))
|
2016-01-08 18:12:49 +01:00
|
|
|
return param;
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-09 02:06:45 +01:00
|
|
|
static bool d3d9_cg_load_program(void *data,
|
2017-09-05 04:08:44 +02:00
|
|
|
void *fragment_data, void *vertex_data,
|
|
|
|
const char *prog, bool path_is_file)
|
2015-04-05 05:09:05 +02:00
|
|
|
{
|
2016-04-17 03:51:24 +02:00
|
|
|
const char *list = NULL;
|
2016-01-09 02:02:02 +01:00
|
|
|
char *listing_f = NULL;
|
|
|
|
char *listing_v = NULL;
|
2015-04-05 05:09:05 +02:00
|
|
|
CGprogram *fPrg = (CGprogram*)fragment_data;
|
|
|
|
CGprogram *vPrg = (CGprogram*)vertex_data;
|
2016-01-08 18:38:00 +01:00
|
|
|
CGprofile vertex_profile = cgD3D9GetLatestVertexProfile();
|
|
|
|
CGprofile fragment_profile = cgD3D9GetLatestPixelProfile();
|
|
|
|
const char **fragment_opts = cgD3D9GetOptimalOptions(fragment_profile);
|
|
|
|
const char **vertex_opts = cgD3D9GetOptimalOptions(vertex_profile);
|
2018-05-14 20:42:28 +02:00
|
|
|
cg_renderchain_t *chain = (cg_renderchain_t*)data;
|
2016-01-08 18:38:00 +01:00
|
|
|
|
2018-01-26 06:36:24 +01:00
|
|
|
if (
|
|
|
|
fragment_profile == CG_PROFILE_UNKNOWN ||
|
|
|
|
vertex_profile == CG_PROFILE_UNKNOWN)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Invalid profile type\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9 Cg]: Vertex profile: %s\n", cgGetProfileString(vertex_profile));
|
|
|
|
RARCH_LOG("[D3D9 Cg]: Fragment profile: %s\n", cgGetProfileString(fragment_profile));
|
2015-04-05 05:09:05 +02:00
|
|
|
|
2016-01-09 03:13:58 +01:00
|
|
|
if (path_is_file && !string_is_empty(prog))
|
2018-05-14 20:42:28 +02:00
|
|
|
*fPrg = cgCreateProgramFromFile(chain->cgCtx, CG_SOURCE,
|
2016-01-09 03:13:58 +01:00
|
|
|
prog, fragment_profile, "main_fragment", fragment_opts);
|
2015-04-05 05:09:05 +02:00
|
|
|
else
|
2018-05-14 20:42:28 +02:00
|
|
|
*fPrg = cgCreateProgram(chain->cgCtx, CG_SOURCE, stock_cg_d3d9_program,
|
2016-01-09 02:16:09 +01:00
|
|
|
fragment_profile, "main_fragment", fragment_opts);
|
2016-04-17 03:51:24 +02:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
list = cgGetLastListing(chain->cgCtx);
|
2016-04-17 03:51:24 +02:00
|
|
|
if (list)
|
|
|
|
listing_f = strdup(list);
|
|
|
|
|
|
|
|
if (path_is_file && !string_is_empty(prog))
|
2018-05-14 20:42:28 +02:00
|
|
|
*vPrg = cgCreateProgramFromFile(chain->cgCtx, CG_SOURCE,
|
2016-04-17 03:51:24 +02:00
|
|
|
prog, vertex_profile, "main_vertex", vertex_opts);
|
|
|
|
else
|
2018-05-14 20:42:28 +02:00
|
|
|
*vPrg = cgCreateProgram(chain->cgCtx, CG_SOURCE, stock_cg_d3d9_program,
|
2016-01-09 02:16:09 +01:00
|
|
|
vertex_profile, "main_vertex", vertex_opts);
|
2016-04-17 03:51:24 +02:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
list = cgGetLastListing(chain->cgCtx);
|
2016-04-17 03:51:24 +02:00
|
|
|
if (list)
|
|
|
|
listing_v = strdup(list);
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
if (!fPrg || !vPrg)
|
2016-10-08 08:39:30 +02:00
|
|
|
goto error;
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
cgD3D9LoadProgram(*fPrg, true, 0);
|
|
|
|
cgD3D9LoadProgram(*vPrg, true, 0);
|
2016-04-17 03:51:24 +02:00
|
|
|
|
2016-01-09 02:02:02 +01:00
|
|
|
free(listing_f);
|
|
|
|
free(listing_v);
|
2016-10-08 08:39:30 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("CG error: %s\n", cgGetErrorString(cgGetError()));
|
|
|
|
if (listing_f)
|
|
|
|
RARCH_ERR("Fragment:\n%s\n", listing_f);
|
|
|
|
else if (listing_v)
|
|
|
|
RARCH_ERR("Vertex:\n%s\n", listing_v);
|
|
|
|
free(listing_f);
|
|
|
|
free(listing_v);
|
|
|
|
|
|
|
|
return false;
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void d3d9_cg_renderchain_set_shader_params(
|
|
|
|
cg_renderchain_t *chain,
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass *pass,
|
2015-11-09 17:03:25 +01:00
|
|
|
unsigned video_w, unsigned video_h,
|
|
|
|
unsigned tex_w, unsigned tex_h,
|
|
|
|
unsigned viewport_w, unsigned viewport_h)
|
2015-04-05 05:09:05 +02:00
|
|
|
{
|
|
|
|
float frame_cnt;
|
2017-10-02 20:18:36 +02:00
|
|
|
float video_size[2];
|
|
|
|
float texture_size[2];
|
|
|
|
float output_size[2];
|
2015-11-09 17:03:25 +01:00
|
|
|
|
2017-10-02 20:18:36 +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;
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-04-23 11:34:30 +02:00
|
|
|
#define DECL_FVF_COLOR(stream, offset, index) \
|
|
|
|
{ (WORD)(stream), (WORD)(offset * sizeof(float)), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, \
|
|
|
|
D3DDECLUSAGE_COLOR, (BYTE)(index) } \
|
2015-04-05 05:09:05 +02:00
|
|
|
|
2018-05-14 21:10:14 +02:00
|
|
|
static bool d3d9_cg_renderchain_init_shader_fvf(
|
|
|
|
cg_renderchain_t *chain,
|
|
|
|
struct cg_pass *pass)
|
2015-04-05 05:09:05 +02:00
|
|
|
{
|
|
|
|
CGparameter param;
|
|
|
|
unsigned index, i, count;
|
|
|
|
unsigned tex_index = 0;
|
|
|
|
bool texcoord0_taken = false;
|
|
|
|
bool texcoord1_taken = false;
|
|
|
|
bool stream_taken[4] = {false};
|
2018-01-25 11:50:07 +01:00
|
|
|
static const D3DVERTEXELEMENT9 decl_end = D3DDECL_END();
|
|
|
|
D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH] = {{0}};
|
2017-10-02 19:07:05 -04:00
|
|
|
bool *indices = NULL;
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
if (cgD3D9GetVertexDeclaration(pass->vPrg, decl) == CG_FALSE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (count = 0; count < MAXD3DDECLLENGTH; count++)
|
|
|
|
{
|
2018-01-17 00:53:31 +01:00
|
|
|
if (string_is_equal_fast(&decl_end, &decl[count], sizeof(decl_end)))
|
2015-04-05 05:09:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is completely insane.
|
|
|
|
* We do not have a good and easy way of setting up our
|
|
|
|
* attribute streams, so we have to do it ourselves, yay!
|
|
|
|
*
|
|
|
|
* Stream 0 => POSITION
|
|
|
|
* Stream 1 => TEXCOORD0
|
|
|
|
* Stream 2 => TEXCOORD1
|
|
|
|
* Stream 3 => COLOR (Not really used for anything.)
|
2017-10-02 19:07:05 -04:00
|
|
|
* Stream {4..N} => Texture coord streams for varying resources
|
2015-04-05 05:09:05 +02:00
|
|
|
* which have no semantics.
|
|
|
|
*/
|
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
indices = (bool*)calloc(1, count * sizeof(*indices));
|
2015-04-05 05:09:05 +02:00
|
|
|
|
2016-01-09 07:26:45 +01:00
|
|
|
param = d3d9_cg_find_param_from_semantic(cgGetFirstParameter(pass->vPrg, CG_PROGRAM), "POSITION");
|
2015-04-05 05:09:05 +02:00
|
|
|
if (!param)
|
2016-01-09 07:26:45 +01:00
|
|
|
param = d3d9_cg_find_param_from_semantic(cgGetFirstParameter(pass->vPrg, CG_PROGRAM), "POSITION0");
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
if (param)
|
|
|
|
{
|
2018-01-25 11:50:07 +01:00
|
|
|
static const D3DVERTEXELEMENT9 element =
|
2017-09-05 03:42:39 +02:00
|
|
|
{
|
|
|
|
0, 0 * sizeof(float),
|
|
|
|
D3DDECLTYPE_FLOAT3,
|
|
|
|
D3DDECLMETHOD_DEFAULT,
|
|
|
|
D3DDECLUSAGE_POSITION,
|
|
|
|
0
|
|
|
|
};
|
2015-04-05 05:09:05 +02:00
|
|
|
stream_taken[0] = true;
|
|
|
|
index = cgGetParameterResourceIndex(param);
|
2016-04-23 14:17:32 +02:00
|
|
|
decl[index] = element;
|
2015-04-05 05:09:05 +02:00
|
|
|
indices[index] = true;
|
2016-04-23 14:17:32 +02:00
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9 Cg]: FVF POSITION semantic found.\n");
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
|
2016-01-09 07:26:45 +01:00
|
|
|
param = d3d9_cg_find_param_from_semantic(cgGetFirstParameter(pass->vPrg, CG_PROGRAM), "TEXCOORD");
|
2015-04-05 05:09:05 +02:00
|
|
|
if (!param)
|
2016-01-09 07:26:45 +01:00
|
|
|
param = d3d9_cg_find_param_from_semantic(cgGetFirstParameter(pass->vPrg, CG_PROGRAM), "TEXCOORD0");
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
if (param)
|
|
|
|
{
|
2018-05-14 03:17:26 +02:00
|
|
|
static const D3DVERTEXELEMENT9 tex_coord0 = D3D9_DECL_FVF_TEXCOORD(1, 3, 0);
|
2015-04-05 05:09:05 +02:00
|
|
|
stream_taken[1] = true;
|
|
|
|
texcoord0_taken = true;
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9 Cg]: FVF TEXCOORD0 semantic found.\n");
|
2015-04-05 05:09:05 +02:00
|
|
|
index = cgGetParameterResourceIndex(param);
|
|
|
|
decl[index] = tex_coord0;
|
|
|
|
indices[index] = true;
|
|
|
|
}
|
|
|
|
|
2016-01-09 07:26:45 +01:00
|
|
|
param = d3d9_cg_find_param_from_semantic(cgGetFirstParameter(pass->vPrg, CG_PROGRAM), "TEXCOORD1");
|
2015-04-05 05:09:05 +02:00
|
|
|
if (param)
|
|
|
|
{
|
2018-05-14 03:17:26 +02:00
|
|
|
static const D3DVERTEXELEMENT9 tex_coord1 = D3D9_DECL_FVF_TEXCOORD(2, 5, 1);
|
2015-04-05 05:09:05 +02:00
|
|
|
stream_taken[2] = true;
|
|
|
|
texcoord1_taken = true;
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9 Cg]: FVF TEXCOORD1 semantic found.\n");
|
2015-04-05 05:09:05 +02:00
|
|
|
index = cgGetParameterResourceIndex(param);
|
|
|
|
decl[index] = tex_coord1;
|
|
|
|
indices[index] = true;
|
|
|
|
}
|
|
|
|
|
2016-01-09 07:26:45 +01:00
|
|
|
param = d3d9_cg_find_param_from_semantic(cgGetFirstParameter(pass->vPrg, CG_PROGRAM), "COLOR");
|
2015-04-05 05:09:05 +02:00
|
|
|
if (!param)
|
2016-01-09 07:26:45 +01:00
|
|
|
param = d3d9_cg_find_param_from_semantic(cgGetFirstParameter(pass->vPrg, CG_PROGRAM), "COLOR0");
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
if (param)
|
|
|
|
{
|
2018-01-25 11:50:07 +01:00
|
|
|
static const D3DVERTEXELEMENT9 color = DECL_FVF_COLOR(3, 7, 0);
|
2015-04-05 05:09:05 +02:00
|
|
|
stream_taken[3] = true;
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9 Cg]: FVF COLOR0 semantic found.\n");
|
2015-04-05 05:09:05 +02:00
|
|
|
index = cgGetParameterResourceIndex(param);
|
2016-04-23 11:34:30 +02:00
|
|
|
decl[index] = color;
|
2015-04-05 05:09:05 +02:00
|
|
|
indices[index] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stream {0, 1, 2, 3} might be already taken. Find first vacant stream. */
|
2016-04-23 14:17:32 +02:00
|
|
|
for (index = 0; index < 4; index++)
|
|
|
|
{
|
2017-09-05 03:42:39 +02:00
|
|
|
if (stream_taken[index] == false)
|
|
|
|
break;
|
2016-04-23 14:17:32 +02:00
|
|
|
}
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
/* Find first vacant texcoord declaration. */
|
|
|
|
if (texcoord0_taken && texcoord1_taken)
|
|
|
|
tex_index = 2;
|
|
|
|
else if (texcoord1_taken && !texcoord0_taken)
|
|
|
|
tex_index = 0;
|
|
|
|
else if (texcoord0_taken && !texcoord1_taken)
|
|
|
|
tex_index = 1;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (indices[i])
|
2018-05-14 18:40:36 +02:00
|
|
|
unsigned_vector_list_append((struct unsigned_vector_list *)
|
|
|
|
pass->attrib_map, 0);
|
2015-04-05 05:09:05 +02:00
|
|
|
else
|
|
|
|
{
|
2018-05-14 03:17:26 +02:00
|
|
|
D3DVERTEXELEMENT9 elem = D3D9_DECL_FVF_TEXCOORD(index, 3, tex_index);
|
2016-04-23 11:34:30 +02:00
|
|
|
|
2018-05-14 18:40:36 +02:00
|
|
|
unsigned_vector_list_append((struct unsigned_vector_list *)
|
|
|
|
pass->attrib_map, index);
|
2015-04-05 05:09:05 +02:00
|
|
|
|
2016-04-23 11:34:30 +02:00
|
|
|
decl[i] = elem;
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
/* Find next vacant stream. */
|
2016-04-23 14:17:32 +02:00
|
|
|
while ((++index < 4) && stream_taken[index])
|
2015-04-05 05:09:05 +02:00
|
|
|
index++;
|
|
|
|
|
|
|
|
/* Find next vacant texcoord declaration. */
|
2016-04-23 14:17:32 +02:00
|
|
|
if ((++tex_index == 1) && texcoord1_taken)
|
2015-04-05 05:09:05 +02:00
|
|
|
tex_index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
free(indices);
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
return d3d9_vertex_declaration_new(chain->dev,
|
2017-10-01 22:23:04 +02:00
|
|
|
decl, (void**)&pass->vertex_decl);
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 18:42:53 +02:00
|
|
|
static void d3d9_cg_renderchain_bind_orig(
|
|
|
|
cg_renderchain_t *chain,
|
|
|
|
struct cg_pass *pass)
|
2015-04-05 05:09:05 +02:00
|
|
|
{
|
|
|
|
CGparameter param;
|
2017-10-02 20:18:36 +02:00
|
|
|
float video_size[2];
|
|
|
|
float texture_size[2];
|
2018-05-14 22:07:07 +02:00
|
|
|
struct cg_pass *first_pass = (struct cg_pass*)&chain->passes->data[0];
|
|
|
|
video_size[0] = first_pass->last_width;
|
|
|
|
video_size[1] = first_pass->last_height;
|
|
|
|
texture_size[0] = first_pass->info.tex_w;
|
|
|
|
texture_size[1] = first_pass->info.tex_h;
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
param = cgGetNamedParameter(pass->fPrg, "ORIG.texture");
|
2018-05-14 18:42:53 +02:00
|
|
|
|
2015-04-05 05:09:05 +02:00
|
|
|
if (param)
|
|
|
|
{
|
2018-05-14 18:40:36 +02:00
|
|
|
unsigned index = cgGetParameterResourceIndex(param);
|
2018-05-14 22:07:07 +02:00
|
|
|
d3d9_set_texture(chain->dev, index, first_pass->tex);
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_magfilter(chain->dev, index,
|
2018-05-14 22:07:07 +02:00
|
|
|
d3d_translate_filter(first_pass->info.pass->filter));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_minfilter(chain->dev, index,
|
2018-05-14 22:07:07 +02:00
|
|
|
d3d_translate_filter(first_pass->info.pass->filter));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER);
|
2017-10-02 19:07:05 -04:00
|
|
|
unsigned_vector_list_append(chain->bound_tex, index);
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
param = cgGetNamedParameter(pass->vPrg, "ORIG.tex_coord");
|
|
|
|
if (param)
|
|
|
|
{
|
2018-05-14 22:07:07 +02:00
|
|
|
LPDIRECT3DVERTEXBUFFER9 vert_buf = (LPDIRECT3DVERTEXBUFFER9)first_pass->vertex_buf;
|
2018-05-14 18:40:36 +02:00
|
|
|
struct unsigned_vector_list *attrib_map = (struct unsigned_vector_list*)
|
|
|
|
pass->attrib_map;
|
|
|
|
unsigned index = attrib_map->data[cgGetParameterResourceIndex(param)];
|
2015-04-05 17:33:54 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_stream_source(chain->dev, index,
|
2017-10-03 02:45:06 +02:00
|
|
|
vert_buf, 0, sizeof(struct CGVertex));
|
2017-10-02 19:07:05 -04:00
|
|
|
unsigned_vector_list_append(chain->bound_vert, index);
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 18:42:53 +02:00
|
|
|
static void d3d9_cg_renderchain_bind_prev(cg_renderchain_t *chain,
|
|
|
|
struct cg_pass *pass)
|
2015-04-05 05:09:05 +02:00
|
|
|
{
|
2018-05-14 18:40:36 +02:00
|
|
|
unsigned i;
|
2017-10-02 20:18:36 +02:00
|
|
|
float texture_size[2];
|
2015-06-13 02:10:06 +02:00
|
|
|
char attr_texture[64] = {0};
|
|
|
|
char attr_input_size[64] = {0};
|
|
|
|
char attr_tex_size[64] = {0};
|
|
|
|
char attr_coord[64] = {0};
|
2015-04-05 05:09:05 +02:00
|
|
|
static const char *prev_names[] = {
|
|
|
|
"PREV",
|
|
|
|
"PREV1",
|
|
|
|
"PREV2",
|
|
|
|
"PREV3",
|
|
|
|
"PREV4",
|
|
|
|
"PREV5",
|
|
|
|
"PREV6",
|
|
|
|
};
|
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
texture_size[0] = chain->passes->data[0].info.tex_w;
|
|
|
|
texture_size[1] = chain->passes->data[0].info.tex_h;
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
for (i = 0; i < TEXTURES - 1; i++)
|
|
|
|
{
|
|
|
|
CGparameter param;
|
2017-10-02 20:18:36 +02:00
|
|
|
float video_size[2];
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
snprintf(attr_texture, sizeof(attr_texture), "%s.texture", prev_names[i]);
|
|
|
|
snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", prev_names[i]);
|
|
|
|
snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", prev_names[i]);
|
|
|
|
snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", prev_names[i]);
|
|
|
|
|
2017-10-02 20:18:36 +02:00
|
|
|
video_size[0] = chain->prev.last_width[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
|
|
|
|
video_size[1] = chain->prev.last_height[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
param = cgGetNamedParameter(pass->fPrg, attr_texture);
|
|
|
|
if (param)
|
|
|
|
{
|
2018-01-25 04:28:50 +01:00
|
|
|
LPDIRECT3DTEXTURE9 tex;
|
2018-05-14 18:40:36 +02:00
|
|
|
unsigned index = cgGetParameterResourceIndex(param);
|
2015-04-05 05:09:05 +02:00
|
|
|
|
2018-01-25 04:28:50 +01:00
|
|
|
tex = (LPDIRECT3DTEXTURE9)
|
2015-04-05 05:09:05 +02:00
|
|
|
chain->prev.tex[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_texture(chain->dev, index, tex);
|
2017-10-02 19:07:05 -04:00
|
|
|
unsigned_vector_list_append(chain->bound_tex, index);
|
2015-04-05 05:09:05 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_magfilter(chain->dev, index,
|
2018-04-22 15:45:11 +02:00
|
|
|
d3d_translate_filter(chain->passes->data[0].info.pass->filter));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_minfilter(chain->dev, index,
|
2018-04-22 15:45:11 +02:00
|
|
|
d3d_translate_filter(chain->passes->data[0].info.pass->filter));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER);
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
param = cgGetNamedParameter(pass->vPrg, attr_coord);
|
|
|
|
if (param)
|
|
|
|
{
|
2018-01-25 11:50:07 +01:00
|
|
|
LPDIRECT3DVERTEXBUFFER9 vert_buf = (LPDIRECT3DVERTEXBUFFER9)
|
2015-11-09 17:03:25 +01:00
|
|
|
chain->prev.vertex_buf[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
|
2018-05-14 18:40:36 +02:00
|
|
|
struct unsigned_vector_list *attrib_map = (struct unsigned_vector_list*)pass->attrib_map;
|
|
|
|
unsigned index = attrib_map->data[cgGetParameterResourceIndex(param)];
|
2015-11-09 17:03:25 +01:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_stream_source(chain->dev, index,
|
2017-10-03 02:45:06 +02:00
|
|
|
vert_buf, 0, sizeof(struct CGVertex));
|
2017-10-02 19:07:05 -04:00
|
|
|
unsigned_vector_list_append(chain->bound_vert, index);
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 22:20:26 +02:00
|
|
|
static void d3d9_cg_renderchain_add_lut_internal(
|
|
|
|
cg_renderchain_t *chain,
|
2015-04-05 05:09:05 +02:00
|
|
|
unsigned index, unsigned i)
|
|
|
|
{
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_texture(chain->dev, index, chain->luts->data[i].tex);
|
|
|
|
d3d9_set_sampler_magfilter(chain->dev, index,
|
2018-04-22 15:45:11 +02:00
|
|
|
d3d_translate_filter(chain->luts->data[i].smooth ? RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_minfilter(chain->dev, index,
|
2018-04-22 15:45:11 +02:00
|
|
|
d3d_translate_filter(chain->luts->data[i].smooth ? RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER);
|
2017-10-02 19:07:05 -04:00
|
|
|
unsigned_vector_list_append(chain->bound_tex, index);
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void d3d9_cg_renderchain_bind_pass(
|
|
|
|
cg_renderchain_t *chain,
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass *pass, unsigned pass_index)
|
2015-04-05 05:09:05 +02:00
|
|
|
{
|
2018-05-14 18:40:36 +02:00
|
|
|
unsigned i;
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
for (i = 1; i < pass_index - 1; i++)
|
|
|
|
{
|
|
|
|
CGparameter param;
|
2017-10-02 20:18:36 +02:00
|
|
|
float video_size[2];
|
|
|
|
float texture_size[2];
|
2018-05-14 22:07:07 +02:00
|
|
|
char pass_base[64] = {0};
|
|
|
|
char attr_texture[64] = {0};
|
|
|
|
char attr_input_size[64] = {0};
|
|
|
|
char attr_tex_size[64] = {0};
|
|
|
|
char attr_coord[64] = {0};
|
|
|
|
struct cg_pass *curr_pass = (struct cg_pass*)&chain->passes->data[i];
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
snprintf(pass_base, sizeof(pass_base), "PASS%u", i);
|
|
|
|
snprintf(attr_texture, sizeof(attr_texture), "%s.texture", pass_base);
|
|
|
|
snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size", pass_base);
|
|
|
|
snprintf(attr_tex_size, sizeof(attr_tex_size), "%s.texture_size", pass_base);
|
|
|
|
snprintf(attr_coord, sizeof(attr_coord), "%s.tex_coord", pass_base);
|
|
|
|
|
2018-05-14 22:07:07 +02:00
|
|
|
video_size[0] = curr_pass->last_width;
|
|
|
|
video_size[1] = curr_pass->last_height;
|
|
|
|
texture_size[0] = curr_pass->info.tex_w;
|
|
|
|
texture_size[1] = curr_pass->info.tex_h;
|
2015-04-05 05:09:05 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
param = cgGetNamedParameter(pass->fPrg, attr_texture);
|
|
|
|
if (param)
|
|
|
|
{
|
2018-05-14 18:40:36 +02:00
|
|
|
unsigned index = cgGetParameterResourceIndex(param);
|
2017-10-02 19:07:05 -04:00
|
|
|
unsigned_vector_list_append(chain->bound_tex, index);
|
2015-04-05 05:09:05 +02:00
|
|
|
|
2018-05-14 22:07:07 +02:00
|
|
|
d3d9_set_texture(chain->dev, index, curr_pass->tex);
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_magfilter(chain->dev, index,
|
2018-05-14 22:07:07 +02:00
|
|
|
d3d_translate_filter(curr_pass->info.pass->filter));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_minfilter(chain->dev, index,
|
2018-05-14 22:07:07 +02:00
|
|
|
d3d_translate_filter(curr_pass->info.pass->filter));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER);
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
param = cgGetNamedParameter(pass->vPrg, attr_coord);
|
|
|
|
if (param)
|
|
|
|
{
|
2018-05-14 18:40:36 +02:00
|
|
|
struct unsigned_vector_list *attrib_map =
|
|
|
|
(struct unsigned_vector_list*)pass->attrib_map;
|
|
|
|
unsigned index = attrib_map->data[cgGetParameterResourceIndex(param)];
|
2015-04-05 17:33:54 +02:00
|
|
|
|
2018-05-14 22:07:07 +02:00
|
|
|
d3d9_set_stream_source(chain->dev, index, curr_pass->vertex_buf,
|
2017-10-03 02:45:06 +02:00
|
|
|
0, sizeof(struct CGVertex));
|
2017-10-02 19:07:05 -04:00
|
|
|
unsigned_vector_list_append(chain->bound_vert, index);
|
2015-04-05 05:09:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
static void d3d9_cg_deinit_progs(cg_renderchain_t *chain)
|
2015-04-05 23:19:10 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9 Cg]: Destroying programs.\n");
|
2016-01-08 18:23:40 +01:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
if (chain->passes->count >= 1)
|
2015-04-05 23:19:10 +02:00
|
|
|
{
|
2018-05-14 20:42:28 +02:00
|
|
|
d3d9_vertex_buffer_free(NULL, chain->passes->data[0].vertex_decl);
|
2016-01-08 19:16:11 +01:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
for (i = 1; i < chain->passes->count; i++)
|
2016-01-08 19:16:11 +01:00
|
|
|
{
|
2018-05-14 20:42:28 +02:00
|
|
|
if (chain->passes->data[i].tex)
|
|
|
|
d3d9_texture_free(chain->passes->data[i].tex);
|
|
|
|
chain->passes->data[i].tex = NULL;
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_vertex_buffer_free(
|
2018-05-14 20:42:28 +02:00
|
|
|
chain->passes->data[i].vertex_buf,
|
|
|
|
chain->passes->data[i].vertex_decl);
|
2016-01-09 01:12:50 +01:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
if (chain->passes->data[i].fPrg)
|
|
|
|
cgDestroyProgram(chain->passes->data[i].fPrg);
|
|
|
|
if (chain->passes->data[i].vPrg)
|
|
|
|
cgDestroyProgram(chain->passes->data[i].vPrg);
|
2016-01-08 19:16:11 +01:00
|
|
|
}
|
2015-04-05 23:19:10 +02:00
|
|
|
}
|
2016-01-08 19:16:11 +01:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
if (chain->fStock)
|
|
|
|
cgDestroyProgram(chain->fStock);
|
|
|
|
if (chain->vStock)
|
|
|
|
cgDestroyProgram(chain->vStock);
|
2015-11-09 17:18:21 +01:00
|
|
|
}
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
static void d3d9_cg_destroy_resources(cg_renderchain_t *chain)
|
2015-11-09 17:18:21 +01:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
2018-05-14 20:42:28 +02:00
|
|
|
if (chain->prev.tex[i])
|
|
|
|
d3d9_texture_free(chain->prev.tex[i]);
|
|
|
|
if (chain->prev.vertex_buf[i])
|
|
|
|
d3d9_vertex_buffer_free(chain->prev.vertex_buf[i], NULL);
|
2015-11-09 17:18:21 +01:00
|
|
|
}
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
d3d9_cg_deinit_progs(chain);
|
2015-04-05 23:19:10 +02:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
for (i = 0; i < chain->luts->count; i++)
|
2015-04-05 23:19:10 +02:00
|
|
|
{
|
2018-05-14 20:42:28 +02:00
|
|
|
if (chain->luts->data[i].tex)
|
|
|
|
d3d9_texture_free(chain->luts->data[i].tex);
|
2015-04-05 23:19:10 +02:00
|
|
|
}
|
|
|
|
|
2016-01-08 19:16:11 +01:00
|
|
|
cgD3D9UnloadAllPrograms();
|
|
|
|
cgD3D9SetDevice(NULL);
|
2015-04-05 23:19:10 +02:00
|
|
|
}
|
|
|
|
|
2016-01-08 18:23:40 +01:00
|
|
|
static void d3d9_cg_deinit_context_state(void *data)
|
2015-04-06 21:32:49 +02:00
|
|
|
{
|
2018-05-14 20:42:28 +02:00
|
|
|
cg_renderchain_t *chain = (cg_renderchain_t*)data;
|
|
|
|
|
|
|
|
if (chain->cgCtx)
|
2016-01-08 18:23:40 +01:00
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9 Cg]: Destroying context.\n");
|
2018-05-14 20:42:28 +02:00
|
|
|
cgDestroyContext(chain->cgCtx);
|
2016-01-08 18:23:40 +01:00
|
|
|
}
|
2018-05-14 20:42:28 +02:00
|
|
|
|
|
|
|
chain->cgCtx = NULL;
|
2015-04-06 21:32:49 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
void d3d9_cg_renderchain_free(void *data)
|
2014-03-04 18:19:47 +01:00
|
|
|
{
|
2018-05-14 20:42:28 +02:00
|
|
|
cg_renderchain_t *chain = (cg_renderchain_t*)data;
|
2014-03-07 19:13:20 +01:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
if (!chain)
|
2014-09-15 08:17:16 -04:00
|
|
|
return;
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
d3d9_cg_destroy_resources(chain);
|
2017-10-02 19:07:05 -04:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
if (chain->passes)
|
2017-10-02 19:07:05 -04:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
for (i = 0; i < chain->passes->count; i++)
|
2017-10-02 19:07:05 -04:00
|
|
|
{
|
2018-05-14 20:42:28 +02:00
|
|
|
if (chain->passes->data[i].attrib_map)
|
|
|
|
free(chain->passes->data[i].attrib_map);
|
2017-10-02 19:07:05 -04:00
|
|
|
}
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
cg_pass_vector_list_free(chain->passes);
|
2017-10-02 19:07:05 -04:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
chain->passes = NULL;
|
2017-10-02 19:07:05 -04:00
|
|
|
}
|
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
lut_info_vector_list_free(chain->luts);
|
|
|
|
unsigned_vector_list_free(chain->bound_tex);
|
|
|
|
unsigned_vector_list_free(chain->bound_vert);
|
2017-10-02 19:07:05 -04:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
chain->luts = NULL;
|
|
|
|
chain->bound_tex = NULL;
|
|
|
|
chain->bound_vert = NULL;
|
2017-10-02 19:07:05 -04:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
d3d9_cg_deinit_context_state(chain);
|
2017-10-02 19:07:05 -04:00
|
|
|
|
2018-05-14 20:42:28 +02:00
|
|
|
free(chain);
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void *d3d9_cg_renderchain_new(void)
|
2015-04-05 04:54:50 +02:00
|
|
|
{
|
2017-10-03 02:45:06 +02:00
|
|
|
cg_renderchain_t *renderchain = (cg_renderchain_t*)calloc(1, sizeof(*renderchain));
|
2015-04-05 04:54:50 +02:00
|
|
|
if (!renderchain)
|
|
|
|
return NULL;
|
|
|
|
|
2018-05-14 18:48:47 +02:00
|
|
|
renderchain->passes = cg_pass_vector_list_new();
|
2017-10-03 02:45:06 +02:00
|
|
|
renderchain->luts = lut_info_vector_list_new();
|
|
|
|
renderchain->bound_tex = unsigned_vector_list_new();
|
2017-10-02 19:07:05 -04:00
|
|
|
renderchain->bound_vert = unsigned_vector_list_new();
|
|
|
|
|
2015-04-05 04:54:50 +02:00
|
|
|
return renderchain;
|
|
|
|
}
|
|
|
|
|
2018-05-13 06:22:12 +02:00
|
|
|
static bool d3d9_cg_renderchain_init_shader(d3d9_video_t *d3d,
|
|
|
|
cg_renderchain_t *renderchain)
|
2015-04-05 17:59:03 +02:00
|
|
|
{
|
2018-05-13 06:22:12 +02:00
|
|
|
CGcontext cgCtx = cgCreateContext();
|
2015-04-05 17:59:03 +02:00
|
|
|
|
2018-05-13 06:22:12 +02:00
|
|
|
if (!cgCtx)
|
2016-01-08 20:46:33 +01:00
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to create Cg context.\n");
|
2015-04-05 17:59:03 +02:00
|
|
|
return false;
|
2016-01-08 20:46:33 +01:00
|
|
|
}
|
2015-04-05 17:59:03 +02:00
|
|
|
|
2018-05-13 06:22:12 +02:00
|
|
|
renderchain->cgCtx = cgCtx;
|
|
|
|
|
2017-10-03 02:49:06 +02:00
|
|
|
if (FAILED(cgD3D9SetDevice((IDirect3DDevice9*)d3d->dev)))
|
2015-04-05 17:59:03 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static bool d3d9_cg_renderchain_create_first_pass(
|
2018-05-14 03:06:19 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev,
|
2017-09-05 04:08:44 +02:00
|
|
|
cg_renderchain_t *chain,
|
2018-05-14 20:50:02 +02:00
|
|
|
const struct LinkInfo *info, unsigned _fmt)
|
2015-04-05 23:19:10 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass pass;
|
2018-05-14 04:55:33 +02:00
|
|
|
struct d3d_matrix ident;
|
2018-05-14 20:50:02 +02:00
|
|
|
unsigned fmt = (_fmt == RETRO_PIXEL_FORMAT_RGB565) ?
|
|
|
|
d3d9_get_rgb565_format() : d3d9_get_xrgb8888_format();
|
2015-04-05 23:19:10 +02:00
|
|
|
|
2017-10-02 19:01:23 +02:00
|
|
|
d3d_matrix_identity(&ident);
|
2015-04-05 23:19:10 +02:00
|
|
|
|
2018-05-14 04:55:33 +02:00
|
|
|
d3d9_set_transform(dev, D3DTS_WORLD, (D3DMATRIX*)&ident);
|
|
|
|
d3d9_set_transform(dev, D3DTS_VIEW, (D3DMATRIX*)&ident);
|
2015-04-05 23:19:10 +02:00
|
|
|
|
|
|
|
pass.info = *info;
|
|
|
|
pass.last_width = 0;
|
|
|
|
pass.last_height = 0;
|
2018-05-14 18:40:36 +02:00
|
|
|
pass.attrib_map = (struct unsigned_vector_list*)
|
|
|
|
unsigned_vector_list_new();
|
2015-04-05 23:19:10 +02:00
|
|
|
|
|
|
|
chain->prev.ptr = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < TEXTURES; i++)
|
|
|
|
{
|
|
|
|
chain->prev.last_width[i] = 0;
|
|
|
|
chain->prev.last_height[i] = 0;
|
2018-01-25 16:42:10 +01:00
|
|
|
chain->prev.vertex_buf[i] = (LPDIRECT3DVERTEXBUFFER9)
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_vertex_buffer_new(
|
2017-10-03 02:45:06 +02:00
|
|
|
chain->dev, 4 * sizeof(struct CGVertex),
|
2018-01-14 02:21:48 +01:00
|
|
|
D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, NULL);
|
2015-04-05 23:19:10 +02:00
|
|
|
|
|
|
|
if (!chain->prev.vertex_buf[i])
|
|
|
|
return false;
|
|
|
|
|
2018-01-25 16:42:10 +01:00
|
|
|
chain->prev.tex[i] = (LPDIRECT3DTEXTURE9)
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_texture_new(chain->dev, NULL,
|
2018-05-14 20:50:02 +02:00
|
|
|
info->tex_w, info->tex_h, 1, 0, fmt,
|
2018-01-16 09:11:14 +01:00
|
|
|
D3DPOOL_MANAGED, 0, 0, 0, NULL, NULL, false);
|
2015-04-05 23:19:10 +02:00
|
|
|
|
|
|
|
if (!chain->prev.tex[i])
|
|
|
|
return false;
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_texture(chain->dev, 0, chain->prev.tex[i]);
|
2018-05-14 03:06:19 +02:00
|
|
|
d3d9_set_sampler_minfilter(dev, 0,
|
2018-04-22 15:45:11 +02:00
|
|
|
d3d_translate_filter(info->pass->filter));
|
2018-05-14 03:06:19 +02:00
|
|
|
d3d9_set_sampler_magfilter(dev, 0,
|
2018-04-22 15:45:11 +02:00
|
|
|
d3d_translate_filter(info->pass->filter));
|
2018-05-14 03:06:19 +02:00
|
|
|
d3d9_set_sampler_address_u(dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(dev, 0, D3DTADDRESS_BORDER);
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_texture(chain->dev, 0, NULL);
|
2015-04-05 23:19:10 +02:00
|
|
|
}
|
|
|
|
|
2016-01-09 02:06:45 +01:00
|
|
|
d3d9_cg_load_program(chain, &pass.fPrg,
|
2016-01-09 02:17:43 +01:00
|
|
|
&pass.vPrg, info->pass->source.path, true);
|
2015-04-05 23:19:10 +02:00
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
if (!d3d9_cg_renderchain_init_shader_fvf(chain, &pass))
|
2015-04-05 23:19:10 +02:00
|
|
|
return false;
|
2018-05-14 18:48:47 +02:00
|
|
|
cg_pass_vector_list_append(chain->passes, pass);
|
2015-04-05 23:19:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-13 06:22:12 +02:00
|
|
|
static bool d3d9_cg_renderchain_init(
|
|
|
|
d3d9_video_t *d3d,
|
|
|
|
const video_info_t *video_info,
|
2018-05-13 18:24:19 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev,
|
|
|
|
const D3DVIEWPORT9 *final_viewport,
|
|
|
|
const struct LinkInfo *info,
|
|
|
|
bool rgb32)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2015-11-11 02:42:15 +01:00
|
|
|
cg_renderchain_t *chain = (cg_renderchain_t*)d3d->renderchain_data;
|
|
|
|
unsigned fmt = (rgb32) ? RETRO_PIXEL_FORMAT_XRGB8888 : RETRO_PIXEL_FORMAT_RGB565;
|
2017-09-05 03:42:39 +02:00
|
|
|
|
2014-03-07 19:13:20 +01:00
|
|
|
if (!chain)
|
2014-01-01 16:51:40 +01:00
|
|
|
return false;
|
2017-09-05 04:08:44 +02:00
|
|
|
if (!d3d9_cg_renderchain_init_shader(d3d, chain))
|
2016-01-09 03:57:13 +01:00
|
|
|
{
|
2018-05-13 18:59:57 +02:00
|
|
|
RARCH_ERR("[D3D9 Cg]: Failed to initialize shader subsystem.\n");
|
2016-01-09 03:57:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-03-07 19:13:20 +01:00
|
|
|
|
2018-05-13 18:24:19 +02:00
|
|
|
chain->dev = dev;
|
|
|
|
chain->final_viewport = (D3DVIEWPORT9*)final_viewport;
|
2015-04-05 01:15:54 +02:00
|
|
|
chain->frame_count = 0;
|
2015-04-05 16:48:22 +02:00
|
|
|
chain->pixel_size = (fmt == RETRO_PIXEL_FORMAT_RGB565) ? 2 : 4;
|
2015-04-05 01:15:54 +02:00
|
|
|
|
2018-05-14 03:06:19 +02:00
|
|
|
if (!d3d9_cg_renderchain_create_first_pass(dev, chain, info, fmt))
|
2014-03-07 19:13:20 +01:00
|
|
|
return false;
|
2016-01-09 02:37:48 +01:00
|
|
|
if (!d3d9_cg_load_program(chain, &chain->fStock, &chain->vStock, NULL, false))
|
2014-01-01 16:51:40 +01:00
|
|
|
return false;
|
|
|
|
|
2017-09-19 14:54:55 +02:00
|
|
|
cgD3D9BindProgram(chain->fStock);
|
|
|
|
cgD3D9BindProgram(chain->vStock);
|
2016-01-09 03:53:06 +01:00
|
|
|
|
2014-01-01 16:51:40 +01:00
|
|
|
return true;
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 22:20:26 +02:00
|
|
|
static bool d3d9_cg_set_pass_size(
|
|
|
|
LPDIRECT3DDEVICE9 dev,
|
|
|
|
struct cg_pass *pass,
|
|
|
|
struct cg_pass *pass2,
|
2018-05-14 22:01:21 +02:00
|
|
|
unsigned width, unsigned height)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2015-04-05 23:19:10 +02:00
|
|
|
if (width != pass->info.tex_w || height != pass->info.tex_h)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_texture_free(pass->tex);
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2015-04-05 23:19:10 +02:00
|
|
|
pass->info.tex_w = width;
|
|
|
|
pass->info.tex_h = height;
|
2018-01-16 00:08:10 +01:00
|
|
|
pass->pool = D3DPOOL_DEFAULT;
|
2018-01-25 16:42:10 +01:00
|
|
|
pass->tex = (LPDIRECT3DTEXTURE9)
|
2018-05-14 22:20:26 +02:00
|
|
|
d3d9_texture_new(dev, NULL,
|
2015-11-11 04:16:18 +01:00
|
|
|
width, height, 1,
|
|
|
|
D3DUSAGE_RENDERTARGET,
|
2018-05-14 22:20:26 +02:00
|
|
|
pass2->info.pass->fbo.fp_fbo ?
|
2018-03-03 15:28:58 +01:00
|
|
|
D3DFMT_A32B32G32R32F : d3d9_get_argb8888_format(),
|
2015-11-11 04:16:18 +01:00
|
|
|
D3DPOOL_DEFAULT, 0, 0, 0,
|
2018-01-16 09:11:14 +01:00
|
|
|
NULL, NULL, false);
|
2017-09-05 03:42:39 +02:00
|
|
|
|
2015-04-05 23:19:10 +02:00
|
|
|
if (!pass->tex)
|
|
|
|
return false;
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-05-14 22:20:26 +02:00
|
|
|
d3d9_set_texture(dev, 0, pass->tex);
|
|
|
|
d3d9_set_sampler_address_u(dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_texture(dev, 0, NULL);
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2015-04-05 23:19:10 +02:00
|
|
|
return true;
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 22:24:02 +02:00
|
|
|
static void d3d9_cg_recompute_pass_sizes(
|
2018-05-14 22:20:26 +02:00
|
|
|
LPDIRECT3DDEVICE9 dev,
|
|
|
|
cg_renderchain_t *chain,
|
2018-05-03 22:03:12 +02:00
|
|
|
d3d9_video_t *d3d)
|
2015-04-05 18:31:07 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
2018-01-19 03:54:07 +01:00
|
|
|
struct LinkInfo link_info;
|
2018-05-14 22:01:21 +02:00
|
|
|
unsigned input_scale = d3d->video_info.input_scale
|
|
|
|
* RARCH_SCALE_BASE;
|
|
|
|
unsigned current_width = input_scale;
|
|
|
|
unsigned current_height = input_scale;
|
2015-04-05 18:31:07 +02:00
|
|
|
unsigned out_width = 0;
|
|
|
|
unsigned out_height = 0;
|
|
|
|
|
2017-10-03 02:49:06 +02:00
|
|
|
link_info.pass = &d3d->shader.pass[0];
|
|
|
|
link_info.tex_w = current_width;
|
|
|
|
link_info.tex_h = current_height;
|
|
|
|
|
2018-05-14 22:01:21 +02:00
|
|
|
|
2018-05-14 22:20:26 +02:00
|
|
|
if (!d3d9_cg_set_pass_size(dev,
|
2018-05-14 22:01:21 +02:00
|
|
|
(struct cg_pass*)&chain->passes->data[0],
|
2018-05-14 22:20:26 +02:00
|
|
|
(struct cg_pass*)&chain->passes->data[chain->passes->count - 1],
|
2015-04-05 18:31:07 +02:00
|
|
|
current_width, current_height))
|
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9 Cg]: Failed to set pass size.\n");
|
2015-04-05 18:31:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i < d3d->shader.passes; i++)
|
|
|
|
{
|
2018-05-14 21:32:14 +02:00
|
|
|
d3d9_convert_geometry(
|
2017-09-05 03:42:39 +02:00
|
|
|
&link_info,
|
2015-04-05 18:31:07 +02:00
|
|
|
&out_width, &out_height,
|
|
|
|
current_width, current_height, &d3d->final_viewport);
|
|
|
|
|
|
|
|
link_info.tex_w = next_pow2(out_width);
|
|
|
|
link_info.tex_h = next_pow2(out_height);
|
|
|
|
|
2018-05-14 22:20:26 +02:00
|
|
|
if (!d3d9_cg_set_pass_size(dev,
|
2018-05-14 22:01:21 +02:00
|
|
|
(struct cg_pass*)&chain->passes->data[i],
|
2018-05-14 22:20:26 +02:00
|
|
|
(struct cg_pass*)&chain->passes->data[chain->passes->count - 1],
|
2015-04-05 18:31:07 +02:00
|
|
|
link_info.tex_w, link_info.tex_h))
|
|
|
|
{
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_ERR("[D3D9 Cg]: Failed to set pass size.\n");
|
2015-04-05 18:31:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-06 16:15:29 +02:00
|
|
|
current_width = out_width;
|
2015-04-05 18:31:07 +02:00
|
|
|
current_height = out_height;
|
|
|
|
|
|
|
|
link_info.pass = &d3d->shader.pass[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void d3d9_cg_renderchain_set_final_viewport(
|
2018-05-13 06:22:12 +02:00
|
|
|
d3d9_video_t *d3d,
|
2017-04-19 01:25:19 +02:00
|
|
|
void *renderchain_data,
|
2018-05-13 18:33:16 +02:00
|
|
|
const D3DVIEWPORT9 *final_viewport)
|
2013-04-21 14:04:16 +02:00
|
|
|
{
|
2018-01-16 03:28:47 +01:00
|
|
|
cg_renderchain_t *chain = (cg_renderchain_t*)renderchain_data;
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2018-01-25 10:03:34 +01:00
|
|
|
if (chain && final_viewport)
|
|
|
|
chain->final_viewport = (D3DVIEWPORT9*)final_viewport;
|
2015-04-05 18:31:07 +02:00
|
|
|
|
2018-05-14 22:24:02 +02:00
|
|
|
d3d9_cg_recompute_pass_sizes(chain->dev, chain, d3d);
|
2013-04-21 14:04:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static bool d3d9_cg_renderchain_add_pass(
|
2017-04-19 01:25:19 +02:00
|
|
|
void *data,
|
2018-05-13 18:33:16 +02:00
|
|
|
const struct LinkInfo *info)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass pass;
|
2017-10-03 02:45:06 +02:00
|
|
|
cg_renderchain_t *chain = (cg_renderchain_t*)data;
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2017-10-03 02:45:06 +02:00
|
|
|
pass.info = *info;
|
|
|
|
pass.last_width = 0;
|
|
|
|
pass.last_height = 0;
|
2018-05-14 18:40:36 +02:00
|
|
|
pass.attrib_map = (struct unsigned_vector_list*)
|
|
|
|
unsigned_vector_list_new();
|
2018-01-16 00:08:10 +01:00
|
|
|
pass.pool = D3DPOOL_DEFAULT;
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
d3d9_cg_load_program(chain, &pass.fPrg,
|
2017-09-05 03:42:39 +02:00
|
|
|
&pass.vPrg, info->pass->source.path, true);
|
2014-09-08 20:08:49 +02:00
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
if (!d3d9_cg_renderchain_init_shader_fvf(chain, &pass))
|
2014-01-01 16:51:40 +01:00
|
|
|
return false;
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-01-25 16:42:10 +01:00
|
|
|
pass.vertex_buf = (LPDIRECT3DVERTEXBUFFER9)
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_vertex_buffer_new(chain->dev,
|
2017-10-03 02:45:06 +02:00
|
|
|
4 * sizeof(struct CGVertex),
|
2018-01-14 02:21:48 +01:00
|
|
|
D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, NULL);
|
2014-09-13 17:56:33 +02:00
|
|
|
|
|
|
|
if (!pass.vertex_buf)
|
2014-01-01 16:51:40 +01:00
|
|
|
return false;
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
pass.tex = (LPDIRECT3DTEXTURE9)d3d9_texture_new(
|
2016-01-07 06:38:28 +01:00
|
|
|
chain->dev,
|
|
|
|
NULL,
|
|
|
|
info->tex_w,
|
|
|
|
info->tex_h,
|
|
|
|
1,
|
|
|
|
D3DUSAGE_RENDERTARGET,
|
2017-10-02 19:07:05 -04:00
|
|
|
chain->passes->data[chain->passes->count - 1].info.pass->fbo.fp_fbo
|
2018-03-03 15:28:58 +01:00
|
|
|
? D3DFMT_A32B32G32R32F : d3d9_get_argb8888_format(),
|
2018-01-16 09:11:14 +01:00
|
|
|
D3DPOOL_DEFAULT, 0, 0, 0, NULL, NULL, false);
|
2014-09-13 18:36:35 +02:00
|
|
|
|
|
|
|
if (!pass.tex)
|
2014-01-01 16:51:40 +01:00
|
|
|
return false;
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_texture(chain->dev, 0, pass.tex);
|
|
|
|
d3d9_set_sampler_address_u(chain->dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(chain->dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_texture(chain->dev, 0, NULL);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-05-14 18:48:47 +02:00
|
|
|
cg_pass_vector_list_append(chain->passes, pass);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2014-01-01 16:51:40 +01:00
|
|
|
return true;
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static bool d3d9_cg_renderchain_add_lut(void *data,
|
2015-04-06 18:02:42 +02:00
|
|
|
const char *id, const char *path, bool smooth)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2017-10-03 02:45:06 +02:00
|
|
|
struct lut_info info;
|
2015-11-11 02:04:42 +01:00
|
|
|
cg_renderchain_t *chain = (cg_renderchain_t*)data;
|
2018-01-25 16:42:10 +01:00
|
|
|
LPDIRECT3DTEXTURE9 lut = (LPDIRECT3DTEXTURE9)
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_texture_new(
|
2016-01-07 06:38:28 +01:00
|
|
|
chain->dev,
|
2017-09-05 03:42:39 +02:00
|
|
|
path,
|
2017-10-02 20:18:36 +02:00
|
|
|
D3D_DEFAULT_NONPOW2,
|
|
|
|
D3D_DEFAULT_NONPOW2,
|
2017-09-05 03:42:39 +02:00
|
|
|
0,
|
|
|
|
0,
|
2018-02-03 13:11:31 +01:00
|
|
|
((D3DFORMAT)-3), /* D3DFMT_FROM_FILE */
|
2017-09-05 03:42:39 +02:00
|
|
|
D3DPOOL_MANAGED,
|
2017-10-02 20:18:36 +02:00
|
|
|
smooth ? D3D_FILTER_LINEAR : D3D_FILTER_POINT,
|
2017-09-05 03:42:39 +02:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
2018-01-16 09:11:14 +01:00
|
|
|
NULL,
|
|
|
|
false
|
2017-09-05 03:42:39 +02:00
|
|
|
);
|
2015-04-05 02:31:24 +02:00
|
|
|
|
2018-05-13 18:51:05 +02:00
|
|
|
RARCH_LOG("[D3D9 Cg]: LUT texture loaded: %s.\n", path);
|
2015-04-05 02:31:24 +02:00
|
|
|
|
2016-01-07 04:42:49 +01:00
|
|
|
info.tex = lut;
|
|
|
|
info.smooth = smooth;
|
2016-06-27 08:09:34 +02:00
|
|
|
strlcpy(info.id, id, sizeof(info.id));
|
2014-09-13 18:25:31 +02:00
|
|
|
if (!lut)
|
2014-01-01 16:51:40 +01:00
|
|
|
return false;
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_texture(chain->dev, 0, lut);
|
|
|
|
d3d9_set_sampler_address_u(chain->dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_sampler_address_v(chain->dev, 0, D3DTADDRESS_BORDER);
|
|
|
|
d3d9_set_texture(chain->dev, 0, NULL);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
lut_info_vector_list_append(chain->luts, info);
|
2015-11-18 00:24:36 +01:00
|
|
|
|
2014-01-01 16:51:40 +01:00
|
|
|
return true;
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void d3d9_cg_renderchain_start_render(cg_renderchain_t *chain)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2017-10-02 19:07:05 -04:00
|
|
|
chain->passes->data[0].tex = chain->prev.tex[chain->prev.ptr];
|
|
|
|
chain->passes->data[0].vertex_buf = chain->prev.vertex_buf[chain->prev.ptr];
|
|
|
|
chain->passes->data[0].last_width = chain->prev.last_width[chain->prev.ptr];
|
|
|
|
chain->passes->data[0].last_height = chain->prev.last_height[chain->prev.ptr];
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void d3d9_cg_renderchain_end_render(cg_renderchain_t *chain)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2017-10-02 19:07:05 -04:00
|
|
|
chain->prev.last_width[chain->prev.ptr] = chain->passes->data[0].last_width;
|
|
|
|
chain->prev.last_height[chain->prev.ptr] = chain->passes->data[0].last_height;
|
2014-03-07 19:13:20 +01:00
|
|
|
chain->prev.ptr = (chain->prev.ptr + 1) & TEXTURESMASK;
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2018-01-15 03:45:37 +01:00
|
|
|
static void d3d9_cg_renderchain_calc_and_set_shader_mvp(
|
2018-05-14 21:54:28 +02:00
|
|
|
CGprogram vPrg,
|
2015-04-05 18:54:14 +02:00
|
|
|
unsigned vp_width, unsigned vp_height,
|
|
|
|
unsigned rotation)
|
|
|
|
{
|
2018-05-14 04:55:33 +02:00
|
|
|
struct d3d_matrix proj, ortho, rot, matrix;
|
2018-05-14 21:54:28 +02:00
|
|
|
CGparameter cgpModelViewProj = cgGetNamedParameter(vPrg, "modelViewProj");
|
2015-04-05 18:54:14 +02:00
|
|
|
|
2017-10-02 19:01:23 +02:00
|
|
|
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));
|
2015-04-05 18:54:14 +02:00
|
|
|
|
2017-10-02 19:01:23 +02:00
|
|
|
d3d_matrix_multiply(&proj, &ortho, &rot);
|
2018-01-14 02:21:48 +01:00
|
|
|
d3d_matrix_transpose(&matrix, &proj);
|
|
|
|
|
2018-05-14 21:54:28 +02:00
|
|
|
if (cgpModelViewProj)
|
|
|
|
cgD3D9SetUniformMatrix(cgpModelViewProj, (D3DMATRIX*)&matrix);
|
2018-01-14 02:21:48 +01:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void cg_d3d9_renderchain_set_vertices(
|
2018-05-15 06:02:10 +02:00
|
|
|
const video_frame_info_t *video_info,
|
2015-11-09 17:03:25 +01:00
|
|
|
cg_renderchain_t *chain,
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass *pass,
|
2015-04-05 18:52:44 +02:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
unsigned out_width, unsigned out_height,
|
|
|
|
unsigned vp_width, unsigned vp_height,
|
|
|
|
unsigned rotation)
|
|
|
|
{
|
2017-10-03 02:45:06 +02:00
|
|
|
const struct LinkInfo *info = (const struct LinkInfo*)&pass->info;
|
2015-04-05 18:52:44 +02:00
|
|
|
|
|
|
|
if (pass->last_width != width || pass->last_height != height)
|
|
|
|
{
|
2017-10-03 02:45:06 +02:00
|
|
|
struct CGVertex vert[4];
|
2015-04-05 18:52:44 +02:00
|
|
|
unsigned i;
|
|
|
|
void *verts = NULL;
|
2017-10-03 02:45:06 +02:00
|
|
|
float _u = (float)(width) / info->tex_w;
|
|
|
|
float _v = (float)(height) / info->tex_h;
|
2015-04-05 18:52:44 +02:00
|
|
|
|
|
|
|
pass->last_width = width;
|
|
|
|
pass->last_height = height;
|
|
|
|
|
|
|
|
vert[0].x = 0.0f;
|
|
|
|
vert[0].y = out_height;
|
2016-10-08 08:39:30 +02:00
|
|
|
vert[0].z = 0.5f;
|
2015-04-05 18:52:44 +02:00
|
|
|
vert[0].u = 0.0f;
|
|
|
|
vert[0].v = 0.0f;
|
|
|
|
vert[0].lut_u = 0.0f;
|
|
|
|
vert[0].lut_v = 0.0f;
|
2016-10-08 08:39:30 +02:00
|
|
|
vert[0].r = 1.0f;
|
|
|
|
vert[0].g = 1.0f;
|
|
|
|
vert[0].b = 1.0f;
|
|
|
|
vert[0].a = 1.0f;
|
|
|
|
|
|
|
|
vert[1].x = out_width;
|
|
|
|
vert[1].y = out_height;
|
|
|
|
vert[1].z = 0.5f;
|
|
|
|
vert[1].u = _u;
|
|
|
|
vert[1].v = 0.0f;
|
|
|
|
vert[1].lut_u = 1.0f;
|
2015-04-05 18:52:44 +02:00
|
|
|
vert[1].lut_v = 0.0f;
|
2016-10-08 08:39:30 +02:00
|
|
|
vert[1].r = 1.0f;
|
|
|
|
vert[1].g = 1.0f;
|
|
|
|
vert[1].b = 1.0f;
|
|
|
|
vert[1].a = 1.0f;
|
|
|
|
|
|
|
|
vert[2].x = 0.0f;
|
|
|
|
vert[2].y = 0.0f;
|
|
|
|
vert[2].z = 0.5f;
|
|
|
|
vert[2].u = 0.0f;
|
|
|
|
vert[2].v = _v;
|
|
|
|
vert[2].lut_u = 0.0f;
|
2015-04-05 18:52:44 +02:00
|
|
|
vert[2].lut_v = 1.0f;
|
2016-10-08 08:39:30 +02:00
|
|
|
vert[2].r = 1.0f;
|
|
|
|
vert[2].g = 1.0f;
|
|
|
|
vert[2].b = 1.0f;
|
|
|
|
vert[2].a = 1.0f;
|
2015-04-05 18:52:44 +02:00
|
|
|
|
2016-10-08 08:39:30 +02:00
|
|
|
vert[3].x = out_width;
|
|
|
|
vert[3].y = 0.0f;
|
|
|
|
vert[3].z = 0.5f;
|
|
|
|
vert[3].u = _u;
|
|
|
|
vert[3].v = _v;
|
|
|
|
vert[3].lut_u = 1.0f;
|
|
|
|
vert[3].lut_v = 1.0f;
|
|
|
|
vert[3].r = 1.0f;
|
|
|
|
vert[3].g = 1.0f;
|
|
|
|
vert[3].b = 1.0f;
|
|
|
|
vert[3].a = 1.0f;
|
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
/* Align texels and vertices.
|
2016-10-08 08:39:30 +02:00
|
|
|
*
|
|
|
|
* Fixes infamous 'half-texel offset' issue of D3D9
|
|
|
|
* http://msdn.microsoft.com/en-us/library/bb219690%28VS.85%29.aspx.
|
|
|
|
*/
|
2015-04-05 18:52:44 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
vert[i].x -= 0.5f;
|
|
|
|
vert[i].y += 0.5f;
|
|
|
|
}
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
verts = d3d9_vertex_buffer_lock(pass->vertex_buf);
|
2015-04-05 18:52:44 +02:00
|
|
|
memcpy(verts, vert, sizeof(vert));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_vertex_buffer_unlock(pass->vertex_buf);
|
2015-04-05 18:52:44 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 21:54:28 +02:00
|
|
|
d3d9_cg_renderchain_calc_and_set_shader_mvp(
|
|
|
|
pass->vPrg, vp_width, vp_height, rotation);
|
|
|
|
d3d9_cg_renderchain_set_shader_params(chain, pass,
|
|
|
|
width, height,
|
|
|
|
info->tex_w, info->tex_h,
|
|
|
|
vp_width, vp_height);
|
2015-04-05 18:52:44 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void cg_d3d9_renderchain_unbind_all(cg_renderchain_t *chain)
|
2015-04-06 00:08:15 +02:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* Have to be a bit anal about it.
|
|
|
|
* Render targets hate it when they have filters apparently.
|
|
|
|
*/
|
2017-10-02 19:07:05 -04:00
|
|
|
for (i = 0; i < chain->bound_tex->count; i++)
|
2015-04-06 00:08:15 +02:00
|
|
|
{
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_minfilter(chain->dev,
|
2017-10-02 19:07:05 -04:00
|
|
|
chain->bound_tex->data[i], D3DTEXF_POINT);
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_magfilter(chain->dev,
|
2017-10-02 19:07:05 -04:00
|
|
|
chain->bound_tex->data[i], D3DTEXF_POINT);
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_texture(chain->dev, chain->bound_tex->data[i], NULL);
|
2015-04-06 00:08:15 +02:00
|
|
|
}
|
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
for (i = 0; i < chain->bound_vert->count; i++)
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_stream_source(chain->dev, chain->bound_vert->data[i], 0, 0, 0);
|
2015-04-06 00:08:15 +02:00
|
|
|
|
2017-10-02 19:07:05 -04:00
|
|
|
if (chain->bound_tex)
|
|
|
|
{
|
|
|
|
unsigned_vector_list_free(chain->bound_tex);
|
|
|
|
chain->bound_tex = unsigned_vector_list_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chain->bound_vert)
|
|
|
|
{
|
|
|
|
unsigned_vector_list_free(chain->bound_vert);
|
|
|
|
chain->bound_vert = unsigned_vector_list_new();
|
|
|
|
}
|
2015-04-06 00:08:15 +02:00
|
|
|
}
|
|
|
|
|
2018-01-26 06:50:11 +01:00
|
|
|
static void cg_d3d9_renderchain_set_params(
|
|
|
|
cg_renderchain_t *chain,
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass *pass,
|
2018-05-14 06:33:26 +02:00
|
|
|
state_tracker_t *tracker,
|
2018-01-26 06:50:11 +01:00
|
|
|
unsigned pass_index)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
/* Set state parameters. */
|
2018-05-14 06:33:26 +02:00
|
|
|
/* Only query uniforms in first pass. */
|
|
|
|
static struct state_tracker_uniform tracker_info[GFX_MAX_VARIABLES];
|
|
|
|
static unsigned cnt = 0;
|
2018-01-26 06:50:11 +01:00
|
|
|
|
2018-05-14 06:33:26 +02:00
|
|
|
if (pass_index == 1)
|
2018-05-14 06:37:01 +02:00
|
|
|
cnt = state_tracker_get_uniform(tracker, tracker_info,
|
2018-05-14 06:33:26 +02:00
|
|
|
GFX_MAX_VARIABLES, chain->frame_count);
|
2018-01-26 06:50:11 +01:00
|
|
|
|
2018-05-14 06:33:26 +02:00
|
|
|
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);
|
|
|
|
d3d9_cg_set_param_1f(param_f, &tracker_info[i].value);
|
|
|
|
d3d9_cg_set_param_1f(param_v, &tracker_info[i].value);
|
2018-01-26 06:50:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static void cg_d3d9_renderchain_render_pass(
|
2015-11-09 17:03:25 +01:00
|
|
|
cg_renderchain_t *chain,
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass *pass,
|
2018-05-14 06:33:26 +02:00
|
|
|
state_tracker_t *tracker,
|
2015-11-09 17:03:25 +01:00
|
|
|
unsigned pass_index)
|
2015-04-06 00:07:25 +02:00
|
|
|
{
|
2018-05-14 18:46:06 +02:00
|
|
|
unsigned i;
|
2015-11-09 17:03:25 +01:00
|
|
|
|
2017-09-19 14:54:55 +02:00
|
|
|
cgD3D9BindProgram(pass->fPrg);
|
|
|
|
cgD3D9BindProgram(pass->vPrg);
|
2015-04-06 00:07:25 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_texture(chain->dev, 0, pass->tex);
|
|
|
|
d3d9_set_sampler_minfilter(chain->dev, 0,
|
2018-04-22 15:45:11 +02:00
|
|
|
d3d_translate_filter(pass->info.pass->filter));
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_magfilter(chain->dev, 0,
|
2018-04-22 15:45:11 +02:00
|
|
|
d3d_translate_filter(pass->info.pass->filter));
|
2015-04-06 00:07:25 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_vertex_declaration(chain->dev, pass->vertex_decl);
|
2015-04-06 00:07:25 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_stream_source(chain->dev, i,
|
2017-10-03 02:45:06 +02:00
|
|
|
pass->vertex_buf, 0,
|
|
|
|
sizeof(struct CGVertex));
|
2015-04-06 00:07:25 +02:00
|
|
|
|
2016-01-09 03:19:03 +01:00
|
|
|
/* Set orig texture. */
|
2017-09-05 04:08:44 +02:00
|
|
|
d3d9_cg_renderchain_bind_orig(chain, pass);
|
2016-01-08 20:28:18 +01:00
|
|
|
|
2016-01-09 03:19:03 +01:00
|
|
|
/* Set prev textures. */
|
2018-05-14 18:42:53 +02:00
|
|
|
d3d9_cg_renderchain_bind_prev(chain, pass);
|
2016-01-08 20:28:18 +01:00
|
|
|
|
|
|
|
/* Set lookup textures */
|
2017-10-02 19:07:05 -04:00
|
|
|
for (i = 0; i < chain->luts->count; i++)
|
2016-01-08 20:28:18 +01:00
|
|
|
{
|
|
|
|
CGparameter vparam;
|
|
|
|
CGparameter fparam = cgGetNamedParameter(
|
2017-10-02 19:07:05 -04:00
|
|
|
pass->fPrg, chain->luts->data[i].id);
|
2016-01-08 20:28:18 +01:00
|
|
|
int bound_index = -1;
|
|
|
|
|
|
|
|
if (fparam)
|
|
|
|
{
|
2018-05-14 18:46:06 +02:00
|
|
|
unsigned index = cgGetParameterResourceIndex(fparam);
|
2016-01-08 20:28:18 +01:00
|
|
|
bound_index = index;
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
d3d9_cg_renderchain_add_lut_internal(chain, index, i);
|
2016-01-08 20:28:18 +01:00
|
|
|
}
|
|
|
|
|
2018-05-14 18:46:06 +02:00
|
|
|
vparam = cgGetNamedParameter(pass->vPrg, chain->luts->data[i].id);
|
2016-01-08 20:28:18 +01:00
|
|
|
|
|
|
|
if (vparam)
|
|
|
|
{
|
2018-05-14 18:46:06 +02:00
|
|
|
unsigned index = cgGetParameterResourceIndex(vparam);
|
2016-01-08 20:28:18 +01:00
|
|
|
if (index != (unsigned)bound_index)
|
2017-09-05 04:08:44 +02:00
|
|
|
d3d9_cg_renderchain_add_lut_internal(chain, index, i);
|
2016-01-08 20:28:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 05:36:56 +02:00
|
|
|
/* We only bother binding passes which are two indices behind. */
|
|
|
|
if (pass_index >= 3)
|
|
|
|
d3d9_cg_renderchain_bind_pass(chain, pass, pass_index);
|
2016-01-09 03:19:03 +01:00
|
|
|
|
2018-05-14 06:33:26 +02:00
|
|
|
if (tracker)
|
|
|
|
cg_d3d9_renderchain_set_params(chain, pass, tracker, pass_index);
|
2015-04-06 00:07:25 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_draw_primitive(chain->dev, D3DPT_TRIANGLESTRIP, 0, 2);
|
2015-04-06 00:07:25 +02:00
|
|
|
|
|
|
|
/* So we don't render with linear filter into render targets,
|
|
|
|
* which apparently looked odd (too blurry). */
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_sampler_minfilter(chain->dev, 0, D3DTEXF_POINT);
|
|
|
|
d3d9_set_sampler_magfilter(chain->dev, 0, D3DTEXF_POINT);
|
2015-04-06 00:07:25 +02:00
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
cg_d3d9_renderchain_unbind_all(chain);
|
2015-04-06 00:07:25 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static bool d3d9_cg_renderchain_render(
|
2018-05-13 06:22:12 +02:00
|
|
|
d3d9_video_t *d3d,
|
2018-05-15 06:02:10 +02:00
|
|
|
const video_frame_info_t *video_info,
|
2018-05-14 06:33:26 +02:00
|
|
|
state_tracker_t *tracker,
|
2015-11-11 02:04:42 +01:00
|
|
|
const void *frame_data,
|
2015-11-11 02:01:00 +01:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
unsigned pitch, unsigned rotation)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2018-01-25 14:34:20 +01:00
|
|
|
LPDIRECT3DSURFACE9 back_buffer, target;
|
2015-01-17 06:30:39 +01:00
|
|
|
unsigned i, current_width, current_height, out_width = 0, out_height = 0;
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass *last_pass = NULL;
|
2018-05-14 21:26:52 +02:00
|
|
|
struct cg_pass *first_pass = NULL;
|
2018-05-14 16:57:34 +02:00
|
|
|
cg_renderchain_t *chain = d3d ?
|
|
|
|
(cg_renderchain_t*)d3d->renderchain_data : NULL;
|
2018-01-16 03:22:13 +01:00
|
|
|
|
2018-01-25 01:45:03 +01:00
|
|
|
d3d9_cg_renderchain_start_render(chain);
|
2014-03-07 19:13:20 +01:00
|
|
|
|
2018-05-14 19:11:45 +02:00
|
|
|
current_width = width;
|
|
|
|
current_height = height;
|
|
|
|
|
|
|
|
first_pass = (struct cg_pass*)&chain->passes->data[0];
|
2018-05-14 16:57:34 +02:00
|
|
|
|
2018-05-14 21:42:14 +02:00
|
|
|
d3d9_convert_geometry(
|
2018-05-14 19:11:45 +02:00
|
|
|
&first_pass->info,
|
2015-04-05 00:44:54 +02:00
|
|
|
&out_width, &out_height,
|
2014-03-07 19:13:20 +01:00
|
|
|
current_width, current_height, chain->final_viewport);
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2018-05-14 19:11:45 +02:00
|
|
|
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);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2015-01-17 06:30:39 +01:00
|
|
|
/* Grab back buffer. */
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_device_get_render_target(chain->dev, 0, (void**)&back_buffer);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2015-01-17 06:30:39 +01:00
|
|
|
/* In-between render target passes. */
|
2017-10-02 19:07:05 -04:00
|
|
|
for (i = 0; i < chain->passes->count - 1; i++)
|
2012-10-26 21:09:30 +02:00
|
|
|
{
|
2018-01-25 10:03:34 +01:00
|
|
|
D3DVIEWPORT9 viewport = {0};
|
2018-05-14 03:12:09 +02:00
|
|
|
struct cg_pass *from_pass = (struct cg_pass*)&chain->passes->data[i];
|
|
|
|
struct cg_pass *to_pass = (struct cg_pass*)&chain->passes->data[i + 1];
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_texture_get_surface_level(to_pass->tex, 0, (void**)&target);
|
2017-10-01 23:19:44 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_device_set_render_target(chain->dev, 0, (void*)target);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-05-14 21:32:14 +02:00
|
|
|
d3d9_convert_geometry(&from_pass->info,
|
2015-04-05 00:44:54 +02:00
|
|
|
&out_width, &out_height,
|
2014-03-07 19:13:20 +01:00
|
|
|
current_width, current_height, chain->final_viewport);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2014-09-13 17:33:58 +02:00
|
|
|
/* Clear out whole FBO. */
|
2015-04-05 01:15:54 +02:00
|
|
|
viewport.Width = to_pass->info.tex_w;
|
2014-09-13 17:33:58 +02:00
|
|
|
viewport.Height = to_pass->info.tex_h;
|
2015-04-05 01:15:54 +02:00
|
|
|
viewport.MinZ = 0.0f;
|
|
|
|
viewport.MaxZ = 1.0f;
|
2015-04-05 15:53:06 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_viewports(chain->dev, &viewport);
|
|
|
|
d3d9_clear(chain->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);
|
2017-09-05 03:42:39 +02:00
|
|
|
|
2015-04-05 01:15:54 +02:00
|
|
|
viewport.Width = out_width;
|
2013-04-21 15:39:14 +02:00
|
|
|
viewport.Height = out_height;
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_viewports(chain->dev, &viewport);
|
2017-09-05 04:08:44 +02:00
|
|
|
|
2018-05-15 06:02:10 +02:00
|
|
|
cg_d3d9_renderchain_set_vertices(video_info,
|
|
|
|
chain, from_pass,
|
2012-10-26 21:09:30 +02:00
|
|
|
current_width, current_height,
|
|
|
|
out_width, out_height,
|
|
|
|
out_width, out_height, 0);
|
|
|
|
|
2018-05-14 21:26:52 +02:00
|
|
|
cg_d3d9_renderchain_render_pass(chain, from_pass, tracker,
|
|
|
|
i + 1);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
|
|
|
current_width = out_width;
|
|
|
|
current_height = out_height;
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_surface_free(target);
|
2012-10-26 21:09:30 +02:00
|
|
|
}
|
|
|
|
|
2014-09-13 17:33:58 +02:00
|
|
|
/* Final pass */
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_device_set_render_target(chain->dev, 0, (void*)back_buffer);
|
2015-04-05 01:48:44 +02:00
|
|
|
|
2018-05-14 03:12:09 +02:00
|
|
|
last_pass = (struct cg_pass*)&chain->passes->
|
2017-10-03 02:45:06 +02:00
|
|
|
data[chain->passes->count - 1];
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-05-14 21:32:14 +02:00
|
|
|
d3d9_convert_geometry(&last_pass->info,
|
2015-04-05 00:44:54 +02:00
|
|
|
&out_width, &out_height,
|
2014-03-07 19:13:20 +01:00
|
|
|
current_width, current_height, chain->final_viewport);
|
2017-09-05 04:08:44 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_set_viewports(chain->dev, chain->final_viewport);
|
2017-09-05 04:08:44 +02:00
|
|
|
|
2018-05-15 06:02:10 +02:00
|
|
|
cg_d3d9_renderchain_set_vertices(video_info,
|
|
|
|
chain, last_pass,
|
2017-09-05 03:42:39 +02:00
|
|
|
current_width, current_height,
|
|
|
|
out_width, out_height,
|
|
|
|
chain->final_viewport->Width, chain->final_viewport->Height,
|
|
|
|
rotation);
|
2017-09-05 04:08:44 +02:00
|
|
|
|
2018-05-14 19:11:45 +02:00
|
|
|
cg_d3d9_renderchain_render_pass(chain, last_pass,
|
|
|
|
tracker,
|
|
|
|
chain->passes->count);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2014-03-07 19:13:20 +01:00
|
|
|
chain->frame_count++;
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_surface_free(back_buffer);
|
2012-10-26 21:09:30 +02:00
|
|
|
|
2018-05-14 21:26:52 +02:00
|
|
|
d3d9_cg_renderchain_end_render(chain);
|
|
|
|
cgD3D9BindProgram(chain->fStock);
|
|
|
|
cgD3D9BindProgram(chain->vStock);
|
|
|
|
d3d9_cg_renderchain_calc_and_set_shader_mvp(
|
2018-05-14 21:54:28 +02:00
|
|
|
chain->vStock, chain->final_viewport->Width,
|
2018-05-14 21:26:52 +02:00
|
|
|
chain->final_viewport->Height, 0);
|
2015-01-17 06:30:39 +01:00
|
|
|
|
2012-10-26 21:09:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-05 04:08:44 +02:00
|
|
|
static bool d3d9_cg_renderchain_read_viewport(
|
2018-05-13 06:22:12 +02:00
|
|
|
d3d9_video_t *d3d, uint8_t *buffer, bool is_idle)
|
2015-11-11 01:34:00 +01:00
|
|
|
{
|
|
|
|
unsigned width, height;
|
|
|
|
D3DLOCKED_RECT rect;
|
2018-01-25 14:34:20 +01:00
|
|
|
LPDIRECT3DSURFACE9 target = NULL;
|
|
|
|
LPDIRECT3DSURFACE9 dest = NULL;
|
|
|
|
bool ret = true;
|
2018-05-03 22:08:14 +02:00
|
|
|
LPDIRECT3DDEVICE9 d3dr = d3d->dev;
|
2015-11-11 01:34:00 +01:00
|
|
|
|
|
|
|
video_driver_get_size(&width, &height);
|
|
|
|
|
2017-10-02 00:38:05 +02:00
|
|
|
if (
|
2018-03-03 15:28:58 +01:00
|
|
|
!d3d9_device_get_render_target(d3dr, 0, (void**)&target) ||
|
|
|
|
!d3d9_device_create_offscreen_plain_surface(d3dr, width, height,
|
|
|
|
d3d9_get_xrgb8888_format(),
|
2018-01-20 16:45:45 +01:00
|
|
|
D3DPOOL_SYSTEMMEM, (void**)&dest, NULL) ||
|
2018-03-03 15:28:58 +01:00
|
|
|
!d3d9_device_get_render_target_data(d3dr, (void*)target, (void*)dest)
|
2017-10-02 00:38:05 +02:00
|
|
|
)
|
2015-11-11 01:34:00 +01:00
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
if (d3d9_surface_lock_rect(dest, (void*)&rect))
|
2015-11-11 01:34:00 +01:00
|
|
|
{
|
|
|
|
unsigned x, y;
|
|
|
|
unsigned pitchpix = rect.Pitch / 4;
|
|
|
|
const uint32_t *pixels = (const uint32_t*)rect.pBits;
|
|
|
|
|
2018-05-13 18:24:19 +02:00
|
|
|
pixels += d3d->final_viewport.X;
|
|
|
|
pixels += (d3d->final_viewport.Height - 1) * pitchpix;
|
|
|
|
pixels -= d3d->final_viewport.Y * pitchpix;
|
2015-11-11 01:34:00 +01:00
|
|
|
|
2018-05-13 18:24:19 +02:00
|
|
|
for (y = 0; y < d3d->final_viewport.Height; y++, pixels -= pitchpix)
|
2015-11-11 01:34:00 +01:00
|
|
|
{
|
2018-05-13 18:24:19 +02:00
|
|
|
for (x = 0; x < d3d->final_viewport.Width; x++)
|
2015-11-11 01:34:00 +01:00
|
|
|
{
|
|
|
|
*buffer++ = (pixels[x] >> 0) & 0xff;
|
|
|
|
*buffer++ = (pixels[x] >> 8) & 0xff;
|
|
|
|
*buffer++ = (pixels[x] >> 16) & 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_surface_unlock_rect((void*)dest);
|
2015-11-11 01:34:00 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = false;
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (target)
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_surface_free(target);
|
2015-11-11 01:34:00 +01:00
|
|
|
if (dest)
|
2018-03-03 15:28:58 +01:00
|
|
|
d3d9_surface_free(dest);
|
2015-11-11 01:34:00 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-13 06:03:26 +02:00
|
|
|
d3d9_renderchain_driver_t cg_d3d9_renderchain = {
|
2017-09-05 04:08:44 +02:00
|
|
|
d3d9_cg_renderchain_free,
|
|
|
|
d3d9_cg_renderchain_new,
|
|
|
|
d3d9_cg_renderchain_init,
|
|
|
|
d3d9_cg_renderchain_set_final_viewport,
|
|
|
|
d3d9_cg_renderchain_add_pass,
|
|
|
|
d3d9_cg_renderchain_add_lut,
|
|
|
|
d3d9_cg_renderchain_render,
|
|
|
|
d3d9_cg_renderchain_read_viewport,
|
2015-04-06 15:52:41 +02:00
|
|
|
"cg_d3d9",
|
|
|
|
};
|