mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
Cleanups
This commit is contained in:
parent
58233137b0
commit
cfc7f4c8c7
@ -22,33 +22,6 @@
|
||||
using namespace std;
|
||||
using namespace spirv_cross;
|
||||
|
||||
static bool slang_texture_semantic_is_array(slang_texture_semantic sem)
|
||||
{
|
||||
switch (sem)
|
||||
{
|
||||
case SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY:
|
||||
case SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT:
|
||||
case SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK:
|
||||
case SLANG_TEXTURE_SEMANTIC_USER:
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
slang_reflection::slang_reflection()
|
||||
{
|
||||
for (unsigned i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
|
||||
{
|
||||
semantic_textures[i].resize(
|
||||
slang_texture_semantic_is_array(static_cast<slang_texture_semantic>(i))
|
||||
? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *texture_semantic_names[] = {
|
||||
"Original",
|
||||
"Source",
|
||||
@ -76,6 +49,33 @@ static const char *semantic_uniform_names[] = {
|
||||
"FrameCount",
|
||||
};
|
||||
|
||||
static bool slang_texture_semantic_is_array(slang_texture_semantic sem)
|
||||
{
|
||||
switch (sem)
|
||||
{
|
||||
case SLANG_TEXTURE_SEMANTIC_ORIGINAL_HISTORY:
|
||||
case SLANG_TEXTURE_SEMANTIC_PASS_OUTPUT:
|
||||
case SLANG_TEXTURE_SEMANTIC_PASS_FEEDBACK:
|
||||
case SLANG_TEXTURE_SEMANTIC_USER:
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
slang_reflection::slang_reflection()
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
|
||||
semantic_textures[i].resize(
|
||||
slang_texture_semantic_is_array(static_cast<slang_texture_semantic>(i))
|
||||
? 0 : 1);
|
||||
}
|
||||
|
||||
static slang_texture_semantic slang_name_to_texture_semantic_array(const string &name, const char **names,
|
||||
unsigned *index)
|
||||
{
|
||||
@ -139,16 +139,17 @@ static slang_semantic slang_uniform_name_to_semantic(
|
||||
const unordered_map<string, slang_semantic_map> &semantic_map,
|
||||
const string &name, unsigned *index)
|
||||
{
|
||||
unsigned i = 0;
|
||||
auto itr = semantic_map.find(name);
|
||||
|
||||
if (itr != end(semantic_map))
|
||||
{
|
||||
*index = itr->second.index;
|
||||
return itr->second.semantic;
|
||||
}
|
||||
|
||||
// No builtin semantics are arrayed.
|
||||
/* No builtin semantics are arrayed. */
|
||||
*index = 0;
|
||||
unsigned i = 0;
|
||||
for (auto n : semantic_uniform_names)
|
||||
{
|
||||
if (name == n)
|
||||
@ -272,20 +273,17 @@ static bool validate_type_for_semantic(const SPIRType &type, slang_semantic sem)
|
||||
|
||||
switch (sem)
|
||||
{
|
||||
/* mat4 */
|
||||
case SLANG_SEMANTIC_MVP:
|
||||
// mat4
|
||||
return type.basetype == SPIRType::Float && type.vecsize == 4 && type.columns == 4;
|
||||
|
||||
/* uint */
|
||||
case SLANG_SEMANTIC_FRAME_COUNT:
|
||||
// uint
|
||||
return type.basetype == SPIRType::UInt && type.vecsize == 1 && type.columns == 1;
|
||||
|
||||
/* float */
|
||||
case SLANG_SEMANTIC_FLOAT_PARAMETER:
|
||||
// float
|
||||
return type.basetype == SPIRType::Float && type.vecsize == 1 && type.columns == 1;
|
||||
|
||||
/* vec4 */
|
||||
default:
|
||||
// vec4
|
||||
return type.basetype == SPIRType::Float && type.vecsize == 4 && type.columns == 1;
|
||||
}
|
||||
}
|
||||
@ -300,7 +298,7 @@ static bool validate_type_for_texture_semantic(const SPIRType &type)
|
||||
static bool add_active_buffer_ranges(const Compiler &compiler, const Resource &resource,
|
||||
slang_reflection *reflection, bool push_constant)
|
||||
{
|
||||
// Get which uniforms are actually in use by this shader.
|
||||
/* Get which uniforms are actually in use by this shader. */
|
||||
auto ranges = compiler.get_active_buffer_ranges(resource.id);
|
||||
for (auto &range : ranges)
|
||||
{
|
||||
@ -365,7 +363,11 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
const ShaderResources &vertex, const ShaderResources &fragment,
|
||||
slang_reflection *reflection)
|
||||
{
|
||||
// Validate use of unexpected types.
|
||||
uint32_t location_mask = 0;
|
||||
uint32_t binding_mask = 0;
|
||||
unsigned i = 0;
|
||||
|
||||
/* Validate use of unexpected types. */
|
||||
if (
|
||||
!vertex.sampled_images.empty() ||
|
||||
!vertex.storage_buffers.empty() ||
|
||||
@ -381,7 +383,7 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate vertex input.
|
||||
/* Validate vertex input. */
|
||||
if (vertex.stage_inputs.size() != 2)
|
||||
{
|
||||
RARCH_ERR("[slang]: Vertex must have two attributes.\n");
|
||||
@ -400,7 +402,6 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t location_mask = 0;
|
||||
for (auto &input : vertex.stage_inputs)
|
||||
location_mask |= 1 << vertex_compiler.get_decoration(input.id, spv::DecorationLocation);
|
||||
|
||||
@ -410,7 +411,7 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the single uniform buffer.
|
||||
/* Validate the single uniform buffer. */
|
||||
if (vertex.uniform_buffers.size() > 1)
|
||||
{
|
||||
RARCH_ERR("[slang]: Vertex must use zero or one uniform buffer.\n");
|
||||
@ -423,7 +424,7 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the single push constant buffer.
|
||||
/* Validate the single push constant buffer. */
|
||||
if (vertex.push_constant_buffers.size() > 1)
|
||||
{
|
||||
RARCH_ERR("[slang]: Vertex must use zero or one push constant buffers.\n");
|
||||
@ -511,14 +512,14 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
fragment_compiler.get_declared_struct_size(fragment_compiler.get_type(fragment.push_constant_buffers[0].base_type_id)));
|
||||
}
|
||||
|
||||
// Validate push constant size against Vulkan's minimum spec to avoid cross-vendor issues.
|
||||
/* Validate push constant size against Vulkan's minimum spec to avoid cross-vendor issues. */
|
||||
if (reflection->push_constant_size > 128)
|
||||
{
|
||||
RARCH_ERR("[slang]: Exceeded maximum size of 128 bytes for push constant buffer.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find all relevant uniforms and push constants.
|
||||
/* Find all relevant uniforms and push constants. */
|
||||
if (vertex_ubo && !add_active_buffer_ranges(vertex_compiler, vertex.uniform_buffers[0], reflection, false))
|
||||
return false;
|
||||
if (fragment_ubo && !add_active_buffer_ranges(fragment_compiler, fragment.uniform_buffers[0], reflection, false))
|
||||
@ -528,11 +529,13 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
if (fragment_push && !add_active_buffer_ranges(fragment_compiler, fragment.push_constant_buffers[0], reflection, true))
|
||||
return false;
|
||||
|
||||
uint32_t binding_mask = has_ubo ? (1 << ubo_binding) : 0;
|
||||
if (has_ubo)
|
||||
binding_mask = 1 << ubo_binding;
|
||||
|
||||
// On to textures.
|
||||
/* On to textures. */
|
||||
for (auto &texture : fragment.sampled_images)
|
||||
{
|
||||
unsigned array_index = 0;
|
||||
unsigned set = fragment_compiler.get_decoration(texture.id,
|
||||
spv::DecorationDescriptorSet);
|
||||
unsigned binding = fragment_compiler.get_decoration(texture.id,
|
||||
@ -557,7 +560,6 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
}
|
||||
binding_mask |= 1 << binding;
|
||||
|
||||
unsigned array_index = 0;
|
||||
slang_texture_semantic index = slang_name_to_texture_semantic(*reflection->texture_semantic_map,
|
||||
texture.name, &array_index);
|
||||
|
||||
@ -576,7 +578,8 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
|
||||
RARCH_LOG("[slang]: Reflection\n");
|
||||
RARCH_LOG("[slang]: Textures:\n");
|
||||
for (unsigned i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
|
||||
|
||||
for (i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
|
||||
{
|
||||
unsigned index = 0;
|
||||
for (auto &sem : reflection->semantic_textures[i])
|
||||
@ -595,7 +598,7 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
reflection->push_constant_stage_mask & SLANG_STAGE_VERTEX_MASK ? "yes": "no",
|
||||
reflection->push_constant_stage_mask & SLANG_STAGE_FRAGMENT_MASK ? "yes": "no");
|
||||
|
||||
for (unsigned i = 0; i < SLANG_NUM_SEMANTICS; i++)
|
||||
for (i = 0; i < SLANG_NUM_SEMANTICS; i++)
|
||||
{
|
||||
if (reflection->semantics[i].uniform)
|
||||
{
|
||||
@ -610,7 +613,7 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
|
||||
for (i = 0; i < SLANG_NUM_TEXTURE_SEMANTICS; i++)
|
||||
{
|
||||
unsigned index = 0;
|
||||
for (auto &sem : reflection->semantic_textures[i])
|
||||
@ -634,7 +637,6 @@ static bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragm
|
||||
|
||||
RARCH_LOG("[slang]:\n");
|
||||
RARCH_LOG("[slang]: Parameters:\n");
|
||||
unsigned i = 0;
|
||||
for (auto ¶m : reflection->semantic_float_parameters)
|
||||
{
|
||||
if (param.uniform)
|
||||
|
@ -282,6 +282,8 @@ enum menu_toggle_reason
|
||||
MENU_TOGGLE_REASON_MESSAGE
|
||||
};
|
||||
|
||||
typedef uintptr_t menu_texture_item;
|
||||
|
||||
typedef struct menu_display_ctx_clearcolor
|
||||
{
|
||||
float r;
|
||||
@ -295,6 +297,26 @@ typedef struct menu_display_frame_info
|
||||
bool shadows_enable;
|
||||
} menu_display_frame_info_t;
|
||||
|
||||
typedef struct menu_display_ctx_driver
|
||||
{
|
||||
void (*draw)(void *data);
|
||||
void (*draw_pipeline)(void *data);
|
||||
void (*viewport)(void *data);
|
||||
void (*blend_begin)(void);
|
||||
void (*blend_end)(void);
|
||||
void (*restore_clear_color)(void);
|
||||
void (*clear_color)(menu_display_ctx_clearcolor_t *clearcolor);
|
||||
void *(*get_default_mvp)(void);
|
||||
const float *(*get_default_vertices)(void);
|
||||
const float *(*get_default_tex_coords)(void);
|
||||
bool (*font_init_first)(
|
||||
void **font_handle, void *video_data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded);
|
||||
enum menu_display_driver_type type;
|
||||
const char *ident;
|
||||
} menu_display_ctx_driver_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -558,27 +580,6 @@ size_t menu_navigation_get_selection(void);
|
||||
|
||||
void menu_navigation_set_selection(size_t val);
|
||||
|
||||
typedef struct menu_display_ctx_driver
|
||||
{
|
||||
void (*draw)(void *data);
|
||||
void (*draw_pipeline)(void *data);
|
||||
void (*viewport)(void *data);
|
||||
void (*blend_begin)(void);
|
||||
void (*blend_end)(void);
|
||||
void (*restore_clear_color)(void);
|
||||
void (*clear_color)(menu_display_ctx_clearcolor_t *clearcolor);
|
||||
void *(*get_default_mvp)(void);
|
||||
const float *(*get_default_vertices)(void);
|
||||
const float *(*get_default_tex_coords)(void);
|
||||
bool (*font_init_first)(
|
||||
void **font_handle, void *video_data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded);
|
||||
enum menu_display_driver_type type;
|
||||
const char *ident;
|
||||
} menu_display_ctx_driver_t;
|
||||
|
||||
typedef uintptr_t menu_texture_item;
|
||||
|
||||
enum menu_toggle_reason menu_display_toggle_get_reason(void);
|
||||
void menu_display_toggle_set_reason(enum menu_toggle_reason reason);
|
||||
|
Loading…
x
Reference in New Issue
Block a user