2016-12-20 15:50:50 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2010-2017 - Hans-Kristian Arntzen
|
2019-02-03 15:49:35 -08:00
|
|
|
*
|
2016-12-20 15:50:50 +01:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "slang_preprocess.h"
|
2018-02-01 15:07:12 +01:00
|
|
|
#include "glslang_util.h"
|
2016-12-20 15:50:50 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
2018-04-23 14:56:02 +02:00
|
|
|
|
|
|
|
#include <compat/strl.h>
|
|
|
|
|
2016-12-20 15:50:50 +01:00
|
|
|
#include "../../verbosity.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
bool slang_preprocess_parse_parameters(glslang_meta& meta,
|
2016-12-20 15:50:50 +01:00
|
|
|
struct video_shader *shader)
|
|
|
|
{
|
2019-04-25 04:07:18 +02:00
|
|
|
unsigned i;
|
2016-12-20 15:50:50 +01:00
|
|
|
unsigned old_num_parameters = shader->num_parameters;
|
|
|
|
|
2019-02-03 15:49:35 -08:00
|
|
|
/* Assumes num_parameters is
|
2018-04-23 14:56:02 +02:00
|
|
|
* initialized to something sane. */
|
2019-04-25 04:07:18 +02:00
|
|
|
for (i = 0; i < meta.parameters.size(); i++)
|
2016-12-20 15:50:50 +01:00
|
|
|
{
|
|
|
|
bool mismatch_dup = false;
|
2018-04-23 14:56:02 +02:00
|
|
|
bool dup = false;
|
|
|
|
auto itr = find_if(shader->parameters,
|
|
|
|
shader->parameters + shader->num_parameters,
|
2019-04-25 04:07:18 +02:00
|
|
|
[&](const video_shader_parameter &parsed_param)
|
|
|
|
{
|
|
|
|
return meta.parameters[i].id == parsed_param.id;
|
|
|
|
});
|
2016-12-20 15:50:50 +01:00
|
|
|
|
|
|
|
if (itr != shader->parameters + shader->num_parameters)
|
|
|
|
{
|
|
|
|
dup = true;
|
2019-02-03 15:49:35 -08:00
|
|
|
/* Allow duplicate #pragma parameter, but only
|
2018-04-23 14:56:02 +02:00
|
|
|
* if they are exactly the same. */
|
2019-04-25 04:07:18 +02:00
|
|
|
if ( meta.parameters[i].desc != itr->desc ||
|
|
|
|
meta.parameters[i].initial != itr->initial ||
|
|
|
|
meta.parameters[i].minimum != itr->minimum ||
|
|
|
|
meta.parameters[i].maximum != itr->maximum ||
|
|
|
|
meta.parameters[i].step != itr->step)
|
2016-12-20 15:50:50 +01:00
|
|
|
{
|
2019-03-02 11:53:14 +01:00
|
|
|
RARCH_ERR("[slang]: Duplicate parameters"
|
2018-04-23 14:56:02 +02:00
|
|
|
" found for \"%s\", but arguments do not match.\n",
|
2016-12-20 15:50:50 +01:00
|
|
|
itr->id);
|
|
|
|
mismatch_dup = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dup && !mismatch_dup)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mismatch_dup || shader->num_parameters == GFX_MAX_PARAMETERS)
|
|
|
|
{
|
|
|
|
shader->num_parameters = old_num_parameters;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-25 04:07:18 +02:00
|
|
|
struct video_shader_parameter *p = (struct video_shader_parameter*)
|
|
|
|
&shader->parameters[shader->num_parameters++];
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
strlcpy(p->id, meta.parameters[i].id.c_str(), sizeof(p->id));
|
|
|
|
strlcpy(p->desc, meta.parameters[i].desc.c_str(), sizeof(p->desc));
|
|
|
|
p->initial = meta.parameters[i].initial;
|
|
|
|
p->minimum = meta.parameters[i].minimum;
|
|
|
|
p->maximum = meta.parameters[i].maximum;
|
|
|
|
p->step = meta.parameters[i].step;
|
|
|
|
p->current = meta.parameters[i].initial;
|
2016-12-20 15:50:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
bool slang_preprocess_parse_parameters(const char *shader_path,
|
|
|
|
struct video_shader *shader)
|
|
|
|
{
|
|
|
|
glslang_meta meta;
|
|
|
|
vector<string> lines;
|
2018-04-23 14:56:02 +02:00
|
|
|
|
2018-01-31 01:08:36 +01:00
|
|
|
if (!glslang_read_shader_file(shader_path, &lines, true))
|
|
|
|
return false;
|
|
|
|
if (!glslang_parse_meta(lines, &meta))
|
|
|
|
return false;
|
|
|
|
return slang_preprocess_parse_parameters(meta, shader);
|
|
|
|
}
|