libs/vkd3d-shader: Use vkd3d_get_spirv_builtin() directly.

This commit is contained in:
Józef Kucia 2017-07-18 17:32:26 +02:00
parent 9d944ad96c
commit 78a085199f

View File

@ -1933,40 +1933,11 @@ static const struct vkd3d_spirv_builtin *vkd3d_get_spirv_builtin(enum vkd3d_shad
return NULL;
}
static enum vkd3d_component_type vkd3d_component_type_for_register(enum vkd3d_shader_register_type reg_type,
enum vkd3d_shader_input_sysval_semantic sysval)
{
const struct vkd3d_spirv_builtin *builtin;
if ((builtin = vkd3d_get_spirv_builtin(reg_type, sysval)))
return builtin->component_type;
return VKD3D_TYPE_FLOAT;
}
static unsigned int vkd3d_component_count_for_register(enum vkd3d_shader_register_type reg_type,
enum vkd3d_shader_input_sysval_semantic sysval)
{
const struct vkd3d_spirv_builtin *builtin;
if ((builtin = vkd3d_get_spirv_builtin(reg_type, sysval)))
return builtin->component_count;
return 0;
}
static void vkd3d_dxbc_compiler_decorate_builtin(struct vkd3d_dxbc_compiler *compiler,
uint32_t target_id, enum vkd3d_shader_register_type reg_type,
enum vkd3d_shader_input_sysval_semantic sysval)
uint32_t target_id, SpvBuiltIn builtin)
{
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
const struct vkd3d_spirv_builtin *builtin_info;
SpvBuiltIn builtin;
if (!(builtin_info = vkd3d_get_spirv_builtin(reg_type, sysval)))
return;
builtin = builtin_info->spirv_builtin;
if (compiler->shader_type == VKD3D_SHADER_TYPE_PIXEL && builtin == SpvBuiltInPosition)
builtin = SpvBuiltInFragCoord;
@ -1978,6 +1949,7 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi
{
unsigned int component_idx, component_count, input_component_count;
struct vkd3d_spirv_builder *builder = &compiler->spirv_builder;
const struct vkd3d_spirv_builtin *builtin;
enum vkd3d_component_type component_type;
uint32_t val_id = 0, input_id, var_id;
struct vkd3d_symbol reg_symbol;
@ -1985,6 +1957,8 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi
struct rb_entry *entry = NULL;
bool use_private_var = false;
builtin = vkd3d_get_spirv_builtin(dst->reg.type, sysval);
/* vThreadIDInGroupFlattened is declared with no write mask in shader
* bytecode generated by fxc. */
if (!dst->write_mask && dst->reg.type == VKD3DSPR_LOCALTHREADINDEX)
@ -1997,19 +1971,25 @@ static uint32_t vkd3d_dxbc_compiler_emit_input(struct vkd3d_dxbc_compiler *compi
component_idx = vkd3d_write_mask_get_component_idx(dst->write_mask);
component_count = vkd3d_write_mask_component_count(dst->write_mask);
}
component_type = vkd3d_component_type_for_register(dst->reg.type, sysval);
if (!(input_component_count = vkd3d_component_count_for_register(dst->reg.type, sysval)))
if (builtin)
{
component_type = builtin->component_type;
input_component_count = builtin->component_count;
}
else
{
component_type = VKD3D_TYPE_FLOAT;
input_component_count = component_count;
}
assert(component_count <= input_component_count);
storage_class = SpvStorageClassInput;
input_id = vkd3d_dxbc_compiler_emit_variable(compiler, &builder->global_stream,
storage_class, component_type, input_component_count);
vkd3d_spirv_add_iface_variable(builder, input_id);
if (dst->reg.type == VKD3DSPR_THREADID || dst->reg.type == VKD3DSPR_LOCALTHREADID
|| dst->reg.type == VKD3DSPR_LOCALTHREADINDEX || sysval)
if (builtin)
{
vkd3d_dxbc_compiler_decorate_builtin(compiler, input_id, dst->reg.type, sysval);
vkd3d_dxbc_compiler_decorate_builtin(compiler, input_id, builtin->spirv_builtin);
if (component_idx)
FIXME("Unhandled component index %u.\n", component_idx);
}
@ -2073,6 +2053,7 @@ static uint32_t vkd3d_dxbc_compiler_emit_output(struct vkd3d_dxbc_compiler *comp
const struct vkd3d_shader_signature_element *signature_element;
const struct vkd3d_shader_register *reg = &dst->reg;
const struct vkd3d_shader_signature *signature;
const struct vkd3d_spirv_builtin *builtin;
enum vkd3d_component_type component_type;
struct vkd3d_symbol reg_symbol;
SpvStorageClass storage_class;
@ -2081,12 +2062,21 @@ static uint32_t vkd3d_dxbc_compiler_emit_output(struct vkd3d_dxbc_compiler *comp
bool use_private_variable;
uint32_t id, var_id;
builtin = vkd3d_get_spirv_builtin(dst->reg.type, sysval);
component_idx = vkd3d_write_mask_get_component_idx(dst->write_mask);
component_count = vkd3d_write_mask_component_count(dst->write_mask);
if (builtin)
{
component_type = builtin->component_type;
output_component_count = builtin->component_count;
}
else
{
/* FIXME: Consider output signature when choosing component type for output variable. */
component_type = vkd3d_component_type_for_register(reg->type, sysval);
if (!(output_component_count = vkd3d_component_count_for_register(reg->type, sysval)))
component_type = VKD3D_TYPE_FLOAT;
output_component_count = component_count;
}
assert(component_count <= output_component_count);
signature_element = NULL;
@ -2110,9 +2100,9 @@ static uint32_t vkd3d_dxbc_compiler_emit_output(struct vkd3d_dxbc_compiler *comp
id = vkd3d_dxbc_compiler_emit_variable(compiler, &builder->global_stream,
storage_class, component_type, component_count);
vkd3d_spirv_add_iface_variable(builder, id);
if (sysval)
if (builtin)
{
vkd3d_dxbc_compiler_decorate_builtin(compiler, id, reg->type, sysval);
vkd3d_dxbc_compiler_decorate_builtin(compiler, id, builtin->spirv_builtin);
if (component_idx)
FIXME("Unhandled component index %u.\n", component_idx);
}