Skip to content

Commit

Permalink
(HLSL) Refactor hlsl_compile_program
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Apr 14, 2016
1 parent e61e617 commit b9bb75c
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions gfx/drivers_shader/shader_hlsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ static bool hlsl_compile_program(
void *data,
void *device_data,
unsigned idx,
const char *prog,
bool path_is_file)
shader_program_data_t *program,
struct shader_program_info *program_info)
{
hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)data;
d3d_video_t *d3d = (d3d_video_t*)device_data;
Expand All @@ -167,20 +167,20 @@ static bool hlsl_compile_program(
ID3DXBuffer *code_f = NULL;
ID3DXBuffer *code_v = NULL;

if (path_is_file)
if (program_info->is_file)
{
ret_fp = D3DXCompileShaderFromFile(prog, NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &hlsl->prg[idx].f_ctable);
ret_vp = D3DXCompileShaderFromFile(prog, NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &hlsl->prg[idx].v_ctable);
ret_fp = D3DXCompileShaderFromFile(program_info->combined, NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &program->f_ctable);
ret_vp = D3DXCompileShaderFromFile(program_info->combined, NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &program->v_ctable);
}
else
{
/* TODO - crashes currently - to do with 'end of line' of stock shader */
ret_fp = D3DXCompileShader(prog, strlen(prog), NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &hlsl->prg[idx].f_ctable );
ret_vp = D3DXCompileShader(prog, strlen(prog), NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &hlsl->prg[idx].v_ctable );
ret_fp = D3DXCompileShader(program_info->combined, strlen(program_info->combined), NULL, NULL,
"main_fragment", "ps_3_0", 0, &code_f, &listing_f, &program->f_ctable );
ret_vp = D3DXCompileShader(program_info->combined, strlen(program_info->combined), NULL, NULL,
"main_vertex", "vs_3_0", 0, &code_v, &listing_v, &program->v_ctable );
}

if (ret_fp < 0 || ret_vp < 0 || listing_v || listing_f)
Expand All @@ -195,8 +195,8 @@ static bool hlsl_compile_program(
goto end;
}

d3d_device_ptr->CreatePixelShader((const DWORD*)code_f->GetBufferPointer(), &hlsl->prg[idx].fprg);
d3d_device_ptr->CreateVertexShader((const DWORD*)code_v->GetBufferPointer(), &hlsl->prg[idx].vprg);
d3d_device_ptr->CreatePixelShader((const DWORD*)code_f->GetBufferPointer(), &program->fprg);
d3d_device_ptr->CreateVertexShader((const DWORD*)code_v->GetBufferPointer(), &program->vprg);
code_f->Release();
code_v->Release();

Expand All @@ -210,7 +210,12 @@ static bool hlsl_compile_program(

static bool hlsl_load_stock(hlsl_shader_data_t *hlsl, void *data)
{
if (!hlsl_compile_program(hlsl, data, 0, stock_hlsl_program, false))
struct shader_program_info program_info;

program_info.combined = stock_hlsl_program;
program_info.is_file = false;

if (!hlsl_compile_program(hlsl, data, 0, &hlsl->prg[0], &program_info))
{
RARCH_ERR("Failed to compile passthrough shader, is something wrong with your environment?\n");
return false;
Expand Down Expand Up @@ -241,14 +246,18 @@ static void hlsl_set_program_attributes(hlsl_shader_data_t *hlsl, unsigned i)
static bool hlsl_load_shader(hlsl_shader_data_t *hlsl,
void *data, const char *cgp_path, unsigned i)
{
struct shader_program_info program_info;
char path_buf[PATH_MAX_LENGTH] = {0};

program_info.combined = path_buf;
program_info.is_file = true;

fill_pathname_resolve_relative(path_buf, cgp_path,
hlsl->cg_shader->pass[i].source.path, sizeof(path_buf));

RARCH_LOG("Loading Cg/HLSL shader: \"%s\".\n", path_buf);

if (!hlsl_compile_program(hlsl, data, i + 1, path_buf, true))
if (!hlsl_compile_program(hlsl, data, i + 1, &hlsl->prg[i + 1], &program_info))
return false;

return true;
Expand All @@ -267,10 +276,16 @@ static bool hlsl_load_plain(hlsl_shader_data_t *hlsl, void *data, const char *pa

if (!string_is_empty(path))
{
struct shader_program_info program_info;

program_info.combined = path;
program_info.is_file = true;

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 (!hlsl_compile_program(hlsl, data, 1, path, true))
if (!hlsl_compile_program(hlsl, data, 1, &hlsl->prg[1], &progarm_info))
return false;
}
else
Expand Down

0 comments on commit b9bb75c

Please sign in to comment.