(slang) slang_process: simplify data mappings.

This commit is contained in:
aliaspider 2018-02-03 17:22:47 +01:00
parent 1464995fdc
commit 76d07cd6a7
4 changed files with 75 additions and 111 deletions

View File

@ -176,61 +176,47 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
for (i = 0; i < d3d11->shader_preset->passes; source = &d3d11->pass[i++].rt) for (i = 0; i < d3d11->shader_preset->passes; source = &d3d11->pass[i++].rt)
{ {
unsigned j; unsigned j;
texture_map_t texture_map /* clang-format off */
[3 + GFX_MAX_FRAME_HISTORY + 1 + GFX_MAX_SHADERS * 2 + GFX_MAX_TEXTURES + 1] = { semantics_map_t semantics_map = {
SL_TEXTURE_MAP( {
SLANG_TEXTURE_SEMANTIC_ORIGINAL, d3d11->frame.texture[0].view, /* Original */
d3d11->pass[i].sampler, d3d11->frame.texture[0].size_data), { &d3d11->frame.texture[0].view, 0,
SL_TEXTURE_MAP( &d3d11->frame.texture[0].size_data, 0,
SLANG_TEXTURE_SEMANTIC_SOURCE, source->view, d3d11->pass[i].sampler, &d3d11->pass[i].sampler, 0 },
source->size_data),
};
texture_map_t* ptr = texture_map;
while (ptr->texture_data) /* Source */
ptr++; { &source->view, 0,
&source->size_data, 0,
&d3d11->pass[i].sampler, 0 },
for (j = 0; j < GFX_MAX_FRAME_HISTORY + 1; j++) /* OriginalHistory */
{ { &d3d11->frame.texture[0].view, sizeof(*d3d11->frame.texture),
*ptr = (texture_map_t)SL_TEXTURE_MAP_ARRAY( &d3d11->frame.texture[0].size_data, sizeof(*d3d11->frame.texture),
SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY, j, d3d11->frame.texture[j].view, &d3d11->pass[i].sampler, 0 },
d3d11->pass[i].sampler, d3d11->frame.texture[j].size_data);
ptr++;
}
for (j = 0; j < i; j++) /* PassOutput */
{ { &d3d11->pass[0].rt.view, sizeof(*d3d11->pass),
*ptr = (texture_map_t)SL_TEXTURE_MAP_ARRAY( &d3d11->pass[0].rt.size_data, sizeof(*d3d11->pass),
SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT, j, d3d11->pass[j].rt.view, &d3d11->pass[i].sampler, 0 },
d3d11->pass[i].sampler, d3d11->pass[j].rt.size_data);
ptr++;
}
for (j = 0; j < GFX_MAX_SHADERS; j++) /* PassFeedback */
{ { &d3d11->pass[0].feedback.view, sizeof(*d3d11->pass),
*ptr = (texture_map_t)SL_TEXTURE_MAP_ARRAY( &d3d11->pass[0].feedback.size_data, sizeof(*d3d11->pass),
SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK, j, d3d11->pass[j].feedback.view, &d3d11->pass[i].sampler, 0 },
d3d11->pass[i].sampler, d3d11->pass[j].rt.size_data);
ptr++;
}
for (j = 0; j < d3d11->shader_preset->luts; j++) /* User */
{ { &d3d11->luts[0].view, sizeof(*d3d11->luts),
*ptr = (texture_map_t)SL_TEXTURE_MAP_ARRAY( &d3d11->luts[0].size_data, sizeof(*d3d11->luts),
SLANG_TEXTURE_SEMANTIC_USER, j, d3d11->luts[j].view, d3d11->luts[j].sampler, &d3d11->luts[0].sampler, sizeof(*d3d11->luts) },
d3d11->luts[j].size_data); },
ptr++; {
} &d3d11->mvp, /* MVP */
&d3d11->pass[i].rt.size_data, /* OutputSize */
uniform_map_t uniform_map[] = { &d3d11->frame.output_size, /* FinalViewportSize */
SL_UNIFORM_MAP(SLANG_SEMANTIC_MVP, d3d11->mvp), &d3d11->pass[i].frame_count, /* FrameCount */
SL_UNIFORM_MAP(SLANG_SEMANTIC_OUTPUT, d3d11->pass[i].rt.size_data), }
SL_UNIFORM_MAP(SLANG_SEMANTIC_FRAME_COUNT, d3d11->pass[i].frame_count),
SL_UNIFORM_MAP(SLANG_SEMANTIC_FINAL_VIEWPORT, d3d11->frame.output_size),
{ 0 }
}; };
/* clang-format on */
semantics_map_t semantics_map = { texture_map, uniform_map };
if (!slang_process( if (!slang_process(
d3d11->shader_preset, i, RARCH_SHADER_HLSL, 50, &semantics_map, d3d11->shader_preset, i, RARCH_SHADER_HLSL, 50, &semantics_map,

View File

@ -88,7 +88,7 @@ static bool slang_process_reflection(
const ShaderResources& ps_resources, const ShaderResources& ps_resources,
video_shader* shader_info, video_shader* shader_info,
unsigned pass_number, unsigned pass_number,
const semantics_map_t* semantics_map, const semantics_map_t* map,
pass_semantics_t* out) pass_semantics_t* out)
{ {
unordered_map<string, slang_texture_semantic_map> texture_semantic_map; unordered_map<string, slang_texture_semantic_map> texture_semantic_map;
@ -168,17 +168,15 @@ static bool slang_process_reflection(
vector<uniform_sem_t> uniforms[SLANG_CBUFFER_MAX]; vector<uniform_sem_t> uniforms[SLANG_CBUFFER_MAX];
vector<texture_sem_t> textures; vector<texture_sem_t> textures;
uniform_map_t* uniform_map = semantics_map->uniform_map; for (int semantic = 0; semantic < SLANG_NUM_BASE_SEMANTICS; semantic++)
while (uniform_map->data)
{ {
slang_semantic_meta& src = sl_reflection.semantics[uniform_map->semantic]; slang_semantic_meta& src = sl_reflection.semantics[semantic];
if (src.push_constant || src.uniform) if (src.push_constant || src.uniform)
{ {
uniform_sem_t uniform = { uniform_map->data, uniform_map->id, uniform_sem_t uniform = { map->uniforms[semantic],
src.num_components * (unsigned)sizeof(float) }; src.num_components * (unsigned)sizeof(float) };
string uniform_id = get_semantic_name(sl_reflection, uniform_map->semantic, 0); string uniform_id = get_semantic_name(sl_reflection, (slang_semantic)semantic, 0);
strncpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id)); strncpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id));
if (src.push_constant) if (src.push_constant)
@ -192,8 +190,6 @@ static bool slang_process_reflection(
uniforms[SLANG_CBUFFER_UBO].push_back(uniform); uniforms[SLANG_CBUFFER_UBO].push_back(uniform);
} }
} }
uniform_map++;
} }
for (int i = 0; i < sl_reflection.semantic_float_parameters.size(); i++) for (int i = 0; i < sl_reflection.semantic_float_parameters.size(); i++)
@ -202,8 +198,7 @@ static bool slang_process_reflection(
if (src.push_constant || src.uniform) if (src.push_constant || src.uniform)
{ {
uniform_sem_t uniform = { &shader_info->parameters[i].current, uniform_sem_t uniform = { &shader_info->parameters[i].current, sizeof(float) };
"shader_info->parameter[i].current", sizeof(float) };
string uniform_id = get_semantic_name(sl_reflection, SLANG_SEMANTIC_FLOAT_PARAMETER, i); string uniform_id = get_semantic_name(sl_reflection, SLANG_SEMANTIC_FLOAT_PARAMETER, i);
strncpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id)); strncpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id));
@ -221,42 +216,43 @@ static bool slang_process_reflection(
} }
} }
texture_map_t* texture_map = semantics_map->texture_map; for (int semantic = 0; semantic < SLANG_NUM_TEXTURE_SEMANTICS; semantic++)
while (texture_map->texture_data)
{ {
if (texture_map->index < sl_reflection.semantic_textures[texture_map->semantic].size()) for (int index = 0; index < sl_reflection.semantic_textures[semantic].size(); index++)
{ {
slang_texture_semantic_meta& src = slang_texture_semantic_meta& src = sl_reflection.semantic_textures[semantic][index];
sl_reflection.semantic_textures[texture_map->semantic][texture_map->index];
if (src.stage_mask) if (src.stage_mask)
{ {
texture_sem_t texture = { texture_map->texture_data, texture_map->texture_id, texture_sem_t texture = {
texture_map->sampler_data, texture_map->sampler_id }; (void*)((uintptr_t)map->textures[semantic].image + index * map->textures[semantic].image_stride),
texture.stage_mask = src.stage_mask; (void*)((uintptr_t)map->textures[semantic].sampler + index * map->textures[semantic].sampler_stride),
texture.binding = src.binding; };
string id = get_semantic_name(sl_reflection, texture_map->semantic, texture_map->index); texture.stage_mask = src.stage_mask;
texture.binding = src.binding;
string id = get_semantic_name(sl_reflection, (slang_texture_semantic)semantic, index);
strncpy(texture.id, id.c_str(), sizeof(texture.id)); strncpy(texture.id, id.c_str(), sizeof(texture.id));
textures.push_back(texture); textures.push_back(texture);
if (texture_map->semantic == SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK) if (semantic == SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK)
shader_info->pass[texture_map->index].feedback = true; shader_info->pass[index].feedback = true;
if (texture_map->semantic == SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY && if (semantic == SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY &&
shader_info->history_size < texture_map->index) shader_info->history_size < index)
shader_info->history_size = texture_map->index; shader_info->history_size = index;
} }
if (src.push_constant || src.uniform) if (src.push_constant || src.uniform)
{ {
uniform_sem_t uniform = { texture_map->size_data, texture_map->size_id, uniform_sem_t uniform = {
4 * sizeof(float) }; (void*)((uintptr_t)map->textures[semantic].size + index * map->textures[semantic].size_stride),
4 * sizeof(float)
};
string uniform_id = string uniform_id =
get_size_semantic_name(sl_reflection, texture_map->semantic, texture_map->index); get_size_semantic_name(sl_reflection, (slang_texture_semantic)semantic, index);
strncpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id)); strncpy(uniform.id, uniform_id.c_str(), sizeof(uniform.id));
@ -272,8 +268,6 @@ static bool slang_process_reflection(
} }
} }
} }
texture_map++;
} }
out->texture_count = textures.size(); out->texture_count = textures.size();

View File

@ -26,45 +26,29 @@
typedef struct typedef struct
{ {
enum slang_semantic semantic; void* ptr;
void* data; size_t stride;
const char* id; } data_map_t;
} uniform_map_t;
typedef struct typedef struct
{ {
enum slang_texture_semantic semantic; void* image;
int index; size_t image_stride;
void* texture_data; void* size;
const char* texture_id; size_t size_stride;
void* sampler_data; void* sampler;
const char* sampler_id; size_t sampler_stride;
void* size_data;
const char* size_id;
} texture_map_t; } texture_map_t;
#define SL_UNIFORM_MAP(sem, data) \
{ \
sem, &data, #data \
}
#define SL_TEXTURE_MAP_ARRAY(sem, index, tex, sampl, size) \
{ \
sem, index, &tex, #tex, &sampl, #sampl, &size, #size \
}
#define SL_TEXTURE_MAP(sem, tex, sampl, size) SL_TEXTURE_MAP_ARRAY(sem, 0, tex, sampl, size)
typedef struct typedef struct
{ {
texture_map_t* texture_map; texture_map_t textures[SLANG_NUM_TEXTURE_SEMANTICS];
uniform_map_t* uniform_map; void* uniforms[SLANG_NUM_BASE_SEMANTICS];
} semantics_map_t; } semantics_map_t;
typedef struct typedef struct
{ {
void* data; void* data;
const char* data_id;
unsigned size; unsigned size;
unsigned offset; unsigned offset;
char id[64]; char id[64];
@ -73,9 +57,7 @@ typedef struct
typedef struct typedef struct
{ {
void* texture_data; void* texture_data;
const char* texture_id;
void* sampler_data; void* sampler_data;
const char* sampler_id;
unsigned stage_mask; unsigned stage_mask;
unsigned binding; unsigned binding;
char id[64]; char id[64];

View File

@ -62,7 +62,9 @@ enum slang_semantic
// vec4, viewport size of final pass // vec4, viewport size of final pass
SLANG_SEMANTIC_FINAL_VIEWPORT = 2, SLANG_SEMANTIC_FINAL_VIEWPORT = 2,
// uint, frame count with modulo // uint, frame count with modulo
SLANG_SEMANTIC_FRAME_COUNT = 3, SLANG_SEMANTIC_FRAME_COUNT = 3,
SLANG_NUM_BASE_SEMANTICS,
// float, user defined parameter, arrayed // float, user defined parameter, arrayed
SLANG_SEMANTIC_FLOAT_PARAMETER = 4, SLANG_SEMANTIC_FLOAT_PARAMETER = 4,