glsl: Fix precise variable declaration
and add some more separation in the shader for better debugability when dumped
This commit is contained in:
parent
8c684b3e23
commit
59576b82a8
@ -150,7 +150,7 @@ void SetupOutPerVertex(Stage stage, const Info& info, std::string& header) {
|
|||||||
if (info.stores_clip_distance) {
|
if (info.stores_clip_distance) {
|
||||||
header += "float gl_ClipDistance[];";
|
header += "float gl_ClipDistance[];";
|
||||||
}
|
}
|
||||||
header += "};";
|
header += "};\n";
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -223,6 +223,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
|
|||||||
header += declaration;
|
header += declaration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
header += "\n";
|
||||||
DefineConstantBuffers(bindings);
|
DefineConstantBuffers(bindings);
|
||||||
DefineStorageBuffers(bindings);
|
DefineStorageBuffers(bindings);
|
||||||
SetupImages(bindings);
|
SetupImages(bindings);
|
||||||
|
@ -180,13 +180,15 @@ void DefineVariables(const EmitContext& ctx, std::string& header) {
|
|||||||
const auto type{static_cast<GlslVarType>(i)};
|
const auto type{static_cast<GlslVarType>(i)};
|
||||||
const auto& tracker{ctx.var_alloc.GetUseTracker(type)};
|
const auto& tracker{ctx.var_alloc.GetUseTracker(type)};
|
||||||
const auto type_name{ctx.var_alloc.GetGlslType(type)};
|
const auto type_name{ctx.var_alloc.GetGlslType(type)};
|
||||||
|
const auto precise{
|
||||||
|
(type == GlslVarType::PrecF32 || type == GlslVarType::PrecF64) ? "precise " : ""};
|
||||||
// Temps/return types that are never used are stored at index 0
|
// Temps/return types that are never used are stored at index 0
|
||||||
if (tracker.uses_temp) {
|
if (tracker.uses_temp) {
|
||||||
header += fmt::format("{}{}={}(0);", type_name, ctx.var_alloc.Representation(0, type),
|
header += fmt::format("{}{} {}={}(0);", precise, type_name,
|
||||||
type_name);
|
ctx.var_alloc.Representation(0, type), type_name);
|
||||||
}
|
}
|
||||||
for (u32 index = 1; index <= tracker.num_used; ++index) {
|
for (u32 index = 1; index <= tracker.num_used; ++index) {
|
||||||
header += fmt::format("{}{}={}(0);", type_name,
|
header += fmt::format("{}{} {}={}(0);", precise, type_name,
|
||||||
ctx.var_alloc.Representation(index, type), type_name);
|
ctx.var_alloc.Representation(index, type), type_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,7 +200,7 @@ std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR
|
|||||||
EmitContext ctx{program, bindings, profile, runtime_info};
|
EmitContext ctx{program, bindings, profile, runtime_info};
|
||||||
Precolor(program);
|
Precolor(program);
|
||||||
EmitCode(ctx, program);
|
EmitCode(ctx, program);
|
||||||
const std::string version{fmt::format("#version 450{}\n", GlslVersionSpecifier(ctx))};
|
const std::string version{fmt::format("#version 460{}\n", GlslVersionSpecifier(ctx))};
|
||||||
ctx.header.insert(0, version);
|
ctx.header.insert(0, version);
|
||||||
if (program.local_memory_size > 0) {
|
if (program.local_memory_size > 0) {
|
||||||
ctx.header += fmt::format("uint lmem[{}];", program.local_memory_size / 4);
|
ctx.header += fmt::format("uint lmem[{}];", program.local_memory_size / 4);
|
||||||
@ -206,7 +208,7 @@ std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR
|
|||||||
if (program.shared_memory_size > 0) {
|
if (program.shared_memory_size > 0) {
|
||||||
ctx.header += fmt::format("shared uint smem[{}];", program.shared_memory_size / 4);
|
ctx.header += fmt::format("shared uint smem[{}];", program.shared_memory_size / 4);
|
||||||
}
|
}
|
||||||
ctx.header += "void main(){\n";
|
ctx.header += "\nvoid main(){\n";
|
||||||
if (program.stage == Stage::VertexA || program.stage == Stage::VertexB) {
|
if (program.stage == Stage::VertexA || program.stage == Stage::VertexB) {
|
||||||
ctx.header += "gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);";
|
ctx.header += "gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);";
|
||||||
// TODO: Properly resolve attribute issues
|
// TODO: Properly resolve attribute issues
|
||||||
|
@ -202,37 +202,35 @@ GlslVarType VarAlloc::RegType(IR::Type type) const {
|
|||||||
std::string VarAlloc::GetGlslType(GlslVarType type) const {
|
std::string VarAlloc::GetGlslType(GlslVarType type) const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GlslVarType::U1:
|
case GlslVarType::U1:
|
||||||
return "bool ";
|
return "bool";
|
||||||
case GlslVarType::F16x2:
|
case GlslVarType::F16x2:
|
||||||
return "f16vec2 ";
|
return "f16vec2";
|
||||||
case GlslVarType::U32:
|
case GlslVarType::U32:
|
||||||
return "uint ";
|
return "uint";
|
||||||
case GlslVarType::S32:
|
case GlslVarType::S32:
|
||||||
return "int ";
|
return "int";
|
||||||
case GlslVarType::F32:
|
case GlslVarType::F32:
|
||||||
return "float ";
|
|
||||||
case GlslVarType::S64:
|
|
||||||
return "int64_t ";
|
|
||||||
case GlslVarType::U64:
|
|
||||||
return "uint64_t ";
|
|
||||||
case GlslVarType::F64:
|
|
||||||
return "double ";
|
|
||||||
case GlslVarType::U32x2:
|
|
||||||
return "uvec2 ";
|
|
||||||
case GlslVarType::F32x2:
|
|
||||||
return "vec2 ";
|
|
||||||
case GlslVarType::U32x3:
|
|
||||||
return "uvec3 ";
|
|
||||||
case GlslVarType::F32x3:
|
|
||||||
return "vec3 ";
|
|
||||||
case GlslVarType::U32x4:
|
|
||||||
return "uvec4 ";
|
|
||||||
case GlslVarType::F32x4:
|
|
||||||
return "vec4 ";
|
|
||||||
case GlslVarType::PrecF32:
|
case GlslVarType::PrecF32:
|
||||||
return "precise float ";
|
return "float";
|
||||||
|
case GlslVarType::S64:
|
||||||
|
return "int64_t";
|
||||||
|
case GlslVarType::U64:
|
||||||
|
return "uint64_t";
|
||||||
|
case GlslVarType::F64:
|
||||||
case GlslVarType::PrecF64:
|
case GlslVarType::PrecF64:
|
||||||
return "precise double ";
|
return "double";
|
||||||
|
case GlslVarType::U32x2:
|
||||||
|
return "uvec2";
|
||||||
|
case GlslVarType::F32x2:
|
||||||
|
return "vec2";
|
||||||
|
case GlslVarType::U32x3:
|
||||||
|
return "uvec3";
|
||||||
|
case GlslVarType::F32x3:
|
||||||
|
return "vec3";
|
||||||
|
case GlslVarType::U32x4:
|
||||||
|
return "uvec4";
|
||||||
|
case GlslVarType::F32x4:
|
||||||
|
return "vec4";
|
||||||
case GlslVarType::Void:
|
case GlslVarType::Void:
|
||||||
return "";
|
return "";
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user