(HLSL) No longer depend on driver struct

This commit is contained in:
twinaphex 2015-11-30 02:28:35 +01:00
parent 321322ab7d
commit 7cc7305263

View File

@ -89,13 +89,12 @@ typedef struct hlsl_shader_data
struct video_shader *cg_shader;
} hlsl_shader_data_t;
static hlsl_shader_data_t *hlsl_data;
void hlsl_set_proj_matrix(XMMATRIX rotation_value)
{
driver_t *driver = driver_get_ptr();
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)driver->video_shader_data;
if (hlsl)
hlsl->prg[hlsl->active_idx].mvp_val = rotation_value;
if (hlsl_data)
hlsl_data->prg[hlsl_data->active_idx].mvp_val = rotation_value;
}
#define set_param_2f(param, xy, constanttable) \
@ -118,8 +117,7 @@ static void hlsl_set_params(void *data, unsigned width, unsigned height,
const struct gfx_tex_info *prev_info = (const struct gfx_tex_info*)_prev_info;
(void)_feedback_info;
const struct gfx_tex_info *fbo_info = (const struct gfx_tex_info*)_fbo_info;
driver_t *driver = driver_get_ptr();
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)driver->video_shader_data;
hlsl_shader_data_t *hlsl = hlsl_data;
if (!hlsl)
return;
@ -147,7 +145,7 @@ static void hlsl_set_params(void *data, unsigned width, unsigned height,
/* TODO - set lookup textures/FBO textures/state parameters/etc */
}
static bool load_program(hlsl_shader_data_t *hlsl,
static bool hlsl_load_program(hlsl_shader_data_t *hlsl,
void *data, unsigned idx, const char *prog, bool path_is_file)
{
d3d_video_t *d3d = (d3d_video_t*)data;
@ -199,9 +197,9 @@ end:
return ret;
}
static bool load_stock(hlsl_shader_data_t *hlsl, void *data)
static bool hlsl_load_stock(hlsl_shader_data_t *hlsl, void *data)
{
if (!load_program(hlsl, data, 0, stock_hlsl_program, false))
if (!hlsl_load_program(hlsl, data, 0, stock_hlsl_program, false))
{
RARCH_ERR("Failed to compile passthrough shader, is something wrong with your environment?\n");
return false;
@ -210,7 +208,7 @@ static bool load_stock(hlsl_shader_data_t *hlsl, void *data)
return true;
}
static void set_program_attributes(hlsl_shader_data_t *hlsl, unsigned i)
static void hlsl_set_program_attributes(hlsl_shader_data_t *hlsl, unsigned i)
{
if (!hlsl)
return;
@ -229,7 +227,7 @@ static void set_program_attributes(hlsl_shader_data_t *hlsl, unsigned i)
hlsl->prg[i].mvp_val = XMMatrixIdentity();
}
static bool load_shader(hlsl_shader_data_t *hlsl,
static bool hlsl_load_shader(hlsl_shader_data_t *hlsl,
void *data, const char *cgp_path, unsigned i)
{
char path_buf[PATH_MAX_LENGTH] = {0};
@ -239,15 +237,15 @@ static bool load_shader(hlsl_shader_data_t *hlsl,
RARCH_LOG("Loading Cg/HLSL shader: \"%s\".\n", path_buf);
if (!load_program(hlsl, data, i + 1, path_buf, true))
if (!hlsl_load_program(hlsl, data, i + 1, path_buf, true))
return false;
return true;
}
static bool load_plain(hlsl_shader_data_t *hlsl, void *data, const char *path)
static bool hlsl_load_plain(hlsl_shader_data_t *hlsl, void *data, const char *path)
{
if (!load_stock(hlsl, data))
if (!hlsl_load_stock(hlsl, data))
return false;
hlsl->cg_shader = (struct video_shader*)calloc(1, sizeof(*hlsl->cg_shader));
@ -261,7 +259,7 @@ static bool load_plain(hlsl_shader_data_t *hlsl, void *data, const char *path)
RARCH_LOG("Loading Cg/HLSL file: %s\n", path);
strlcpy(hlsl->cg_shader->pass[0].source.path,
path, sizeof(hlsl->cg_shader->pass[0].source.path));
if (!load_program(hlsl, data, 1, path, true))
if (!hlsl_load_program(hlsl, data, 1, path, true))
return false;
}
else
@ -304,9 +302,9 @@ static void hlsl_deinit_state(hlsl_shader_data_t *hlsl)
hlsl->cg_shader = NULL;
}
static bool load_preset(hlsl_shader_data_t *hlsl, void *data, const char *path)
static bool hlsl_load_preset(hlsl_shader_data_t *hlsl, void *data, const char *path)
{
if (!load_stock(hlsl, data))
if (!hlsl_load_stock(hlsl, data))
return false;
RARCH_LOG("Loading Cg meta-shader: %s\n", path);
@ -342,7 +340,7 @@ static bool load_preset(hlsl_shader_data_t *hlsl, void *data, const char *path)
}
for (unsigned i = 0; i < hlsl->cg_shader->passes; i++)
{
if (!load_shader(hlsl, data, path, i))
if (!hlsl_load_shader(hlsl, data, path, i))
{
RARCH_ERR("Failed to load shaders ...\n");
return false;
@ -356,92 +354,78 @@ static bool load_preset(hlsl_shader_data_t *hlsl, void *data, const char *path)
static bool hlsl_init(void *data, const char *path)
{
unsigned i;
d3d_video_t *d3d = (d3d_video_t*)data;
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)
calloc(1, sizeof(hlsl_shader_data_t));
driver_t *driver = driver_get_ptr();
hlsl_data = (hlsl_shader_data_t*)calloc(1, sizeof(hlsl_shader_data_t));
if (!hlsl)
if (!hlsl_data)
return false;
if (path && !strcmp(path_get_extension(path), ".cgp"))
{
if (!load_preset(hlsl, d3d, path))
if (!hlsl_load_preset(hlsl_data, d3d, path))
goto error;
}
else
{
if (!load_plain(hlsl, d3d, path))
if (!hlsl_load_plain(hlsl_data, d3d, path))
goto error;
}
for(unsigned i = 1; i <= hlsl->cg_shader->passes; i++)
set_program_attributes(hlsl, i);
for(i = 1; i <= hlsl_data->cg_shader->passes; i++)
hlsl_set_program_attributes(hlsl_data, i);
d3d_set_vertex_shader(d3d->dev, 1, hlsl->prg[1].vprg);
d3d->dev->SetPixelShader(hlsl->prg[1].fprg);
driver->video_shader_data = hlsl;
d3d_set_vertex_shader(d3d->dev, 1, hlsl_data->prg[1].vprg);
d3d->dev->SetPixelShader(hlsl_data->prg[1].fprg);
return true;
error:
if (hlsl)
free(hlsl);
if (hlsl_data)
free(hlsl_data);
hlsl_data = NULL;
return false;
}
// Full deinit.
static void hlsl_deinit(void)
{
driver_t *driver = driver_get_ptr();
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)driver->video_shader_data;
if (!hlsl)
return;
hlsl_deinit_state(hlsl_data);
hlsl_deinit_state(hlsl);
if (driver->video_shader_data)
free(driver->video_shader_data);
driver->video_shader_data = NULL;
if (hlsl_data)
free(hlsl_data);
hlsl_data = NULL;
}
static void hlsl_use(void *data, unsigned idx)
{
d3d_video_t *d3d = (d3d_video_t*)data;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev;
driver_t *driver = driver_get_ptr();
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)driver->video_shader_data;
if (hlsl && hlsl->prg[idx].vprg && hlsl->prg[idx].fprg)
if (hlsl_data && hlsl_data->prg[idx].vprg && hlsl_data->prg[idx].fprg)
{
hlsl->active_idx = idx;
d3d_set_vertex_shader(d3dr, idx, hlsl->prg[idx].vprg);
hlsl_data->active_idx = idx;
d3d_set_vertex_shader(d3dr, idx, hlsl_data->prg[idx].vprg);
#ifdef _XBOX
D3DDevice_SetPixelShader(d3dr, hlsl->prg[idx].fprg);
D3DDevice_SetPixelShader(d3dr, hlsl_data->prg[idx].fprg);
#else
d3dr->SetPixelShader(hlsl->prg[idx].fprg);
d3dr->SetPixelShader(hlsl_data->prg[idx].fprg);
#endif
}
}
static unsigned hlsl_num(void)
{
driver_t *driver = driver_get_ptr();
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)driver->video_shader_data;
if (hlsl)
return hlsl->cg_shader->passes;
if (hlsl_data)
return hlsl_data->cg_shader->passes;
return 0;
}
static bool hlsl_filter_type(unsigned idx, bool *smooth)
{
driver_t *driver = driver_get_ptr();
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)driver->video_shader_data;
if (hlsl && idx
&& (hlsl->cg_shader->pass[idx - 1].filter != RARCH_FILTER_UNSPEC))
if (hlsl_data && idx
&& (hlsl_data->cg_shader->pass[idx - 1].filter != RARCH_FILTER_UNSPEC))
{
*smooth = hlsl->cg_shader->pass[idx - 1].filter = RARCH_FILTER_LINEAR;
*smooth = hlsl_data->cg_shader->pass[idx - 1].filter = RARCH_FILTER_LINEAR;
return true;
}
return false;
@ -449,10 +433,8 @@ static bool hlsl_filter_type(unsigned idx, bool *smooth)
static void hlsl_shader_scale(unsigned idx, struct gfx_fbo_scale *scale)
{
driver_t *driver = driver_get_ptr();
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)driver->video_shader_data;
if (hlsl && idx)
*scale = hlsl->cg_shader->pass[idx - 1].fbo;
if (hlsl_data && idx)
*scale = hlsl_data->cg_shader->pass[idx - 1].fbo;
else
scale->valid = false;
}
@ -461,14 +443,12 @@ static bool hlsl_set_mvp(void *data, const math_matrix_4x4 *mat)
{
d3d_video_t *d3d = (d3d_video_t*)data;
LPDIRECT3DDEVICE d3d_device_ptr = (LPDIRECT3DDEVICE)d3d->dev;
driver_t *driver = driver_get_ptr();
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)driver->video_shader_data;
if(hlsl && hlsl->prg[hlsl->active_idx].mvp)
if(hlsl_data && hlsl_data->prg[hlsl_data->active_idx].mvp)
{
hlsl->prg[hlsl->active_idx].v_ctable->SetMatrix(d3d_device_ptr,
hlsl->prg[hlsl->active_idx].mvp,
(D3DXMATRIX*)&hlsl->prg[hlsl->active_idx].mvp_val);
hlsl_data->prg[hlsl_data->active_idx].v_ctable->SetMatrix(d3d_device_ptr,
hlsl_data->prg[hlsl_data->active_idx].mvp,
(D3DXMATRIX*)&hlsl_data->prg[hlsl_data->active_idx].mvp_val);
return true;
}
return false;