2021-05-20 03:58:32 +02:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "shader_recompiler/backend/bindings.h"
|
|
|
|
#include "shader_recompiler/backend/glsl/emit_context.h"
|
|
|
|
#include "shader_recompiler/frontend/ir/program.h"
|
2021-05-26 01:55:40 +02:00
|
|
|
#include "shader_recompiler/profile.h"
|
2021-06-16 08:22:56 +02:00
|
|
|
#include "shader_recompiler/runtime_info.h"
|
2021-05-20 03:58:32 +02:00
|
|
|
|
|
|
|
namespace Shader::Backend::GLSL {
|
2021-05-27 03:18:17 +02:00
|
|
|
namespace {
|
2021-06-04 02:24:56 +02:00
|
|
|
u32 CbufIndex(size_t offset) {
|
2021-06-04 01:15:36 +02:00
|
|
|
return (offset / 4) % 4;
|
|
|
|
}
|
|
|
|
|
2021-06-11 06:33:33 +02:00
|
|
|
char Swizzle(size_t offset) {
|
2021-06-04 01:15:36 +02:00
|
|
|
return "xyzw"[CbufIndex(offset)];
|
|
|
|
}
|
|
|
|
|
2021-05-27 03:18:17 +02:00
|
|
|
std::string_view InterpDecorator(Interpolation interp) {
|
|
|
|
switch (interp) {
|
|
|
|
case Interpolation::Smooth:
|
|
|
|
return "";
|
|
|
|
case Interpolation::Flat:
|
2021-06-04 02:57:52 +02:00
|
|
|
return "flat ";
|
2021-05-27 03:18:17 +02:00
|
|
|
case Interpolation::NoPerspective:
|
2021-06-04 02:57:52 +02:00
|
|
|
return "noperspective ";
|
2021-05-27 03:18:17 +02:00
|
|
|
}
|
|
|
|
throw InvalidArgument("Invalid interpolation {}", interp);
|
|
|
|
}
|
2021-05-28 04:28:33 +02:00
|
|
|
|
2021-06-01 05:07:13 +02:00
|
|
|
std::string_view InputArrayDecorator(Stage stage) {
|
2021-05-31 19:28:53 +02:00
|
|
|
switch (stage) {
|
|
|
|
case Stage::Geometry:
|
2021-06-01 05:07:13 +02:00
|
|
|
case Stage::TessellationControl:
|
|
|
|
case Stage::TessellationEval:
|
|
|
|
return "[]";
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 07:49:24 +02:00
|
|
|
bool StoresPerVertexAttributes(Stage stage) {
|
|
|
|
switch (stage) {
|
|
|
|
case Stage::VertexA:
|
|
|
|
case Stage::VertexB:
|
|
|
|
case Stage::Geometry:
|
|
|
|
case Stage::TessellationEval:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 05:07:13 +02:00
|
|
|
std::string OutputDecorator(Stage stage, u32 size) {
|
|
|
|
switch (stage) {
|
|
|
|
case Stage::TessellationControl:
|
|
|
|
return fmt::format("[{}]", size);
|
2021-05-31 19:28:53 +02:00
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-29 07:53:32 +02:00
|
|
|
std::string_view SamplerType(TextureType type, bool is_depth) {
|
|
|
|
if (is_depth) {
|
|
|
|
switch (type) {
|
|
|
|
case TextureType::Color1D:
|
|
|
|
return "sampler1DShadow";
|
|
|
|
case TextureType::ColorArray1D:
|
|
|
|
return "sampler1DArrayShadow";
|
|
|
|
case TextureType::Color2D:
|
|
|
|
return "sampler2DShadow";
|
|
|
|
case TextureType::ColorArray2D:
|
|
|
|
return "sampler2DArrayShadow";
|
|
|
|
case TextureType::ColorCube:
|
|
|
|
return "samplerCubeShadow";
|
|
|
|
case TextureType::ColorArrayCube:
|
|
|
|
return "samplerCubeArrayShadow";
|
|
|
|
default:
|
|
|
|
throw NotImplementedException("Texture type: {}", type);
|
|
|
|
}
|
|
|
|
}
|
2021-05-28 04:28:33 +02:00
|
|
|
switch (type) {
|
2021-05-29 07:06:29 +02:00
|
|
|
case TextureType::Color1D:
|
|
|
|
return "sampler1D";
|
|
|
|
case TextureType::ColorArray1D:
|
|
|
|
return "sampler1DArray";
|
2021-05-28 04:28:33 +02:00
|
|
|
case TextureType::Color2D:
|
|
|
|
return "sampler2D";
|
|
|
|
case TextureType::ColorArray2D:
|
|
|
|
return "sampler2DArray";
|
|
|
|
case TextureType::Color3D:
|
|
|
|
return "sampler3D";
|
2021-05-28 19:54:09 +02:00
|
|
|
case TextureType::ColorCube:
|
|
|
|
return "samplerCube";
|
2021-05-29 07:06:29 +02:00
|
|
|
case TextureType::ColorArrayCube:
|
|
|
|
return "samplerCubeArray";
|
|
|
|
case TextureType::Buffer:
|
|
|
|
return "samplerBuffer";
|
2021-05-28 04:28:33 +02:00
|
|
|
default:
|
|
|
|
throw NotImplementedException("Texture type: {}", type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 02:37:24 +02:00
|
|
|
std::string_view ImageType(TextureType type) {
|
|
|
|
switch (type) {
|
2021-06-08 02:39:30 +02:00
|
|
|
case TextureType::Color1D:
|
|
|
|
return "uimage1D";
|
|
|
|
case TextureType::ColorArray1D:
|
|
|
|
return "uimage1DArray";
|
2021-06-03 02:37:24 +02:00
|
|
|
case TextureType::Color2D:
|
|
|
|
return "uimage2D";
|
2021-06-08 02:39:30 +02:00
|
|
|
case TextureType::ColorArray2D:
|
|
|
|
return "uimage2DArray";
|
|
|
|
case TextureType::Color3D:
|
|
|
|
return "uimage3D";
|
|
|
|
case TextureType::ColorCube:
|
|
|
|
return "uimageCube";
|
|
|
|
case TextureType::ColorArrayCube:
|
|
|
|
return "uimageCubeArray";
|
|
|
|
case TextureType::Buffer:
|
|
|
|
return "uimageBuffer";
|
2021-06-03 02:37:24 +02:00
|
|
|
default:
|
|
|
|
throw NotImplementedException("Image type: {}", type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string_view ImageFormatString(ImageFormat format) {
|
|
|
|
switch (format) {
|
|
|
|
case ImageFormat::Typeless:
|
|
|
|
return "";
|
|
|
|
case ImageFormat::R8_UINT:
|
|
|
|
return ",r8ui";
|
|
|
|
case ImageFormat::R8_SINT:
|
|
|
|
return ",r8i";
|
|
|
|
case ImageFormat::R16_UINT:
|
|
|
|
return ",r16ui";
|
|
|
|
case ImageFormat::R16_SINT:
|
|
|
|
return ",r16i";
|
|
|
|
case ImageFormat::R32_UINT:
|
|
|
|
return ",r32ui";
|
|
|
|
case ImageFormat::R32G32_UINT:
|
|
|
|
return ",rg32ui";
|
|
|
|
case ImageFormat::R32G32B32A32_UINT:
|
|
|
|
return ",rgba32ui";
|
|
|
|
default:
|
|
|
|
throw NotImplementedException("Image format: {}", format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 23:23:57 +02:00
|
|
|
std::string_view ImageAccessQualifier(bool is_written, bool is_read) {
|
|
|
|
if (is_written && !is_read) {
|
|
|
|
return "writeonly ";
|
|
|
|
}
|
|
|
|
if (is_read && !is_written) {
|
|
|
|
return "readonly ";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-06-01 05:07:13 +02:00
|
|
|
std::string_view GetTessMode(TessPrimitive primitive) {
|
|
|
|
switch (primitive) {
|
|
|
|
case TessPrimitive::Triangles:
|
|
|
|
return "triangles";
|
|
|
|
case TessPrimitive::Quads:
|
|
|
|
return "quads";
|
|
|
|
case TessPrimitive::Isolines:
|
|
|
|
return "isolines";
|
|
|
|
}
|
|
|
|
throw InvalidArgument("Invalid tessellation primitive {}", primitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string_view GetTessSpacing(TessSpacing spacing) {
|
|
|
|
switch (spacing) {
|
|
|
|
case TessSpacing::Equal:
|
|
|
|
return "equal_spacing";
|
|
|
|
case TessSpacing::FractionalOdd:
|
|
|
|
return "fractional_odd_spacing";
|
|
|
|
case TessSpacing::FractionalEven:
|
|
|
|
return "fractional_even_spacing";
|
|
|
|
}
|
|
|
|
throw InvalidArgument("Invalid tessellation spacing {}", spacing);
|
|
|
|
}
|
|
|
|
|
2021-05-31 19:28:53 +02:00
|
|
|
std::string_view InputPrimitive(InputTopology topology) {
|
|
|
|
switch (topology) {
|
|
|
|
case InputTopology::Points:
|
|
|
|
return "points";
|
|
|
|
case InputTopology::Lines:
|
|
|
|
return "lines";
|
|
|
|
case InputTopology::LinesAdjacency:
|
|
|
|
return "lines_adjacency";
|
|
|
|
case InputTopology::Triangles:
|
|
|
|
return "triangles";
|
|
|
|
case InputTopology::TrianglesAdjacency:
|
|
|
|
return "triangles_adjacency";
|
|
|
|
}
|
|
|
|
throw InvalidArgument("Invalid input topology {}", topology);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string_view OutputPrimitive(OutputTopology topology) {
|
|
|
|
switch (topology) {
|
|
|
|
case OutputTopology::PointList:
|
|
|
|
return "points";
|
|
|
|
case OutputTopology::LineStrip:
|
|
|
|
return "line_strip";
|
|
|
|
case OutputTopology::TriangleStrip:
|
|
|
|
return "triangle_strip";
|
|
|
|
}
|
|
|
|
throw InvalidArgument("Invalid output topology {}", topology);
|
|
|
|
}
|
2021-06-01 05:07:13 +02:00
|
|
|
|
2021-06-13 02:14:56 +02:00
|
|
|
void SetupLegacyOutPerVertex(EmitContext& ctx, std::string& header) {
|
2021-06-24 07:41:09 +02:00
|
|
|
if (!ctx.info.stores.Legacy()) {
|
2021-06-13 02:14:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores.FixedFunctionTexture()) {
|
2021-06-13 02:14:56 +02:00
|
|
|
header += "vec4 gl_TexCoord[8];";
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
2021-06-13 02:14:56 +02:00
|
|
|
header += "vec4 gl_FrontColor;";
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) {
|
2021-06-13 02:14:56 +02:00
|
|
|
header += "vec4 gl_FrontSecondaryColor;";
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) {
|
2021-06-13 02:14:56 +02:00
|
|
|
header += "vec4 gl_BackColor;";
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) {
|
2021-06-13 02:14:56 +02:00
|
|
|
header += "vec4 gl_BackSecondaryColor;";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-02 06:48:49 +02:00
|
|
|
void SetupOutPerVertex(EmitContext& ctx, std::string& header) {
|
|
|
|
if (!StoresPerVertexAttributes(ctx.stage)) {
|
2021-06-01 05:07:13 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-06-25 02:13:21 +02:00
|
|
|
if (ctx.uses_geometry_passthrough) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-04 02:57:52 +02:00
|
|
|
header += "out gl_PerVertex{vec4 gl_Position;";
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores[IR::Attribute::PointSize]) {
|
2021-06-01 05:07:13 +02:00
|
|
|
header += "float gl_PointSize;";
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores.ClipDistances()) {
|
2021-06-01 05:07:13 +02:00
|
|
|
header += "float gl_ClipDistance[];";
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores[IR::Attribute::ViewportIndex] &&
|
|
|
|
ctx.profile.support_viewport_index_layer_non_geometry && ctx.stage != Stage::Geometry) {
|
2021-06-01 07:49:24 +02:00
|
|
|
header += "int gl_ViewportIndex;";
|
|
|
|
}
|
2021-06-13 02:14:56 +02:00
|
|
|
SetupLegacyOutPerVertex(ctx, header);
|
2021-06-04 02:57:52 +02:00
|
|
|
header += "};";
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.stores[IR::Attribute::ViewportIndex] && ctx.stage == Stage::Geometry) {
|
2021-06-01 07:04:32 +02:00
|
|
|
header += "out int gl_ViewportIndex;";
|
|
|
|
}
|
2021-06-01 05:07:13 +02:00
|
|
|
}
|
2021-06-13 02:14:56 +02:00
|
|
|
|
|
|
|
void SetupLegacyInPerFragment(EmitContext& ctx, std::string& header) {
|
2021-06-24 07:41:09 +02:00
|
|
|
if (!ctx.info.loads.Legacy()) {
|
2021-06-13 02:14:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
header += "in gl_PerFragment{";
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.loads.FixedFunctionTexture()) {
|
2021-06-13 02:14:56 +02:00
|
|
|
header += "vec4 gl_TexCoord[8];";
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (ctx.info.loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
2021-06-13 02:14:56 +02:00
|
|
|
header += "vec4 gl_Color;";
|
|
|
|
}
|
|
|
|
header += "};";
|
|
|
|
}
|
|
|
|
|
2021-06-04 02:57:52 +02:00
|
|
|
} // Anonymous namespace
|
2021-05-20 03:58:32 +02:00
|
|
|
|
2021-05-28 02:31:03 +02:00
|
|
|
EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
|
|
|
const RuntimeInfo& runtime_info_)
|
2021-06-25 02:13:21 +02:00
|
|
|
: info{program.info}, profile{profile_}, runtime_info{runtime_info_}, stage{program.stage},
|
|
|
|
uses_geometry_passthrough{program.is_geometry_passthrough &&
|
|
|
|
profile.support_geometry_shader_passthrough} {
|
2021-06-15 23:23:57 +02:00
|
|
|
if (profile.need_fastmath_off) {
|
|
|
|
header += "#pragma optionNV(fastmath off)\n";
|
|
|
|
}
|
2021-06-13 02:14:56 +02:00
|
|
|
SetupExtensions();
|
2021-05-26 06:16:20 +02:00
|
|
|
switch (program.stage) {
|
|
|
|
case Stage::VertexA:
|
|
|
|
case Stage::VertexB:
|
2021-05-28 04:28:33 +02:00
|
|
|
stage_name = "vs";
|
2021-05-26 06:16:20 +02:00
|
|
|
break;
|
|
|
|
case Stage::TessellationControl:
|
2021-06-04 02:57:52 +02:00
|
|
|
stage_name = "tcs";
|
|
|
|
header += fmt::format("layout(vertices={})out;", program.invocations);
|
2021-06-01 05:07:13 +02:00
|
|
|
break;
|
2021-05-26 06:16:20 +02:00
|
|
|
case Stage::TessellationEval:
|
2021-06-04 02:57:52 +02:00
|
|
|
stage_name = "tes";
|
|
|
|
header += fmt::format("layout({},{},{})in;", GetTessMode(runtime_info.tess_primitive),
|
2021-06-01 05:07:13 +02:00
|
|
|
GetTessSpacing(runtime_info.tess_spacing),
|
|
|
|
runtime_info.tess_clockwise ? "cw" : "ccw");
|
2021-05-26 06:16:20 +02:00
|
|
|
break;
|
|
|
|
case Stage::Geometry:
|
2021-05-28 04:28:33 +02:00
|
|
|
stage_name = "gs";
|
2021-06-25 02:13:21 +02:00
|
|
|
header += fmt::format("layout({})in;", InputPrimitive(runtime_info.input_topology));
|
|
|
|
if (uses_geometry_passthrough) {
|
|
|
|
header += "layout(passthrough)in gl_PerVertex{vec4 gl_Position;};";
|
|
|
|
break;
|
|
|
|
} else if (program.is_geometry_passthrough &&
|
|
|
|
!profile.support_geometry_shader_passthrough) {
|
|
|
|
LOG_WARNING(Shader_GLSL, "Passthrough geometry program used but not supported");
|
|
|
|
}
|
|
|
|
header += fmt::format(
|
|
|
|
"layout({},max_vertices={})out;in gl_PerVertex{{vec4 gl_Position;}}gl_in[];",
|
|
|
|
OutputPrimitive(program.output_topology), program.output_vertices);
|
2021-05-26 06:16:20 +02:00
|
|
|
break;
|
|
|
|
case Stage::Fragment:
|
2021-05-28 04:28:33 +02:00
|
|
|
stage_name = "fs";
|
2021-06-08 02:39:30 +02:00
|
|
|
position_name = "gl_FragCoord";
|
2021-06-09 07:16:25 +02:00
|
|
|
if (runtime_info.force_early_z) {
|
|
|
|
header += "layout(early_fragment_tests)in;";
|
|
|
|
}
|
2021-06-10 06:01:56 +02:00
|
|
|
if (info.uses_sample_id) {
|
|
|
|
header += "in int gl_SampleID;";
|
|
|
|
}
|
|
|
|
if (info.stores_sample_mask) {
|
|
|
|
header += "out int gl_SampleMask[];";
|
|
|
|
}
|
2021-05-26 06:16:20 +02:00
|
|
|
break;
|
|
|
|
case Stage::Compute:
|
2021-05-28 04:28:33 +02:00
|
|
|
stage_name = "cs";
|
2021-06-14 01:12:03 +02:00
|
|
|
const u32 local_x{std::max(program.workgroup_size[0], 1u)};
|
|
|
|
const u32 local_y{std::max(program.workgroup_size[1], 1u)};
|
|
|
|
const u32 local_z{std::max(program.workgroup_size[2], 1u)};
|
2021-06-04 02:57:52 +02:00
|
|
|
header += fmt::format("layout(local_size_x={},local_size_y={},local_size_z={}) in;",
|
2021-06-14 01:12:03 +02:00
|
|
|
local_x, local_y, local_z);
|
2021-05-26 06:16:20 +02:00
|
|
|
break;
|
2021-05-21 05:38:38 +02:00
|
|
|
}
|
2021-06-02 06:48:49 +02:00
|
|
|
SetupOutPerVertex(*this, header);
|
2021-06-13 02:14:56 +02:00
|
|
|
SetupLegacyInPerFragment(*this, header);
|
|
|
|
|
2021-06-24 07:41:09 +02:00
|
|
|
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
|
|
|
if (!info.loads.Generic(index) || !runtime_info.previous_stage_stores.Generic(index)) {
|
2021-06-16 09:59:30 +02:00
|
|
|
continue;
|
2021-06-01 05:07:13 +02:00
|
|
|
}
|
2021-06-25 02:13:21 +02:00
|
|
|
const auto qualifier{uses_geometry_passthrough ? "passthrough"
|
|
|
|
: fmt::format("location={}", index)};
|
|
|
|
header += fmt::format("layout({}){}in vec4 in_attr{}{};", qualifier,
|
2021-06-24 07:41:09 +02:00
|
|
|
InterpDecorator(info.interpolation[index]), index,
|
|
|
|
InputArrayDecorator(stage));
|
2021-06-01 05:07:13 +02:00
|
|
|
}
|
|
|
|
for (size_t index = 0; index < info.uses_patches.size(); ++index) {
|
|
|
|
if (!info.uses_patches[index]) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-06-04 02:57:52 +02:00
|
|
|
const auto qualifier{stage == Stage::TessellationControl ? "out" : "in"};
|
|
|
|
header += fmt::format("layout(location={})patch {} vec4 patch{};", index, qualifier, index);
|
2021-05-26 06:16:20 +02:00
|
|
|
}
|
2021-06-16 09:48:05 +02:00
|
|
|
if (stage == Stage::Fragment) {
|
|
|
|
for (size_t index = 0; index < info.stores_frag_color.size(); ++index) {
|
|
|
|
if (!info.stores_frag_color[index] && !profile.need_declared_frag_colors) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
header += fmt::format("layout(location={})out vec4 frag_color{};", index, index);
|
2021-05-26 06:16:20 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
|
|
|
if (info.stores.Generic(index)) {
|
|
|
|
DefineGenericOutput(index, program.invocations);
|
2021-05-26 06:16:20 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-28 04:28:33 +02:00
|
|
|
DefineConstantBuffers(bindings);
|
|
|
|
DefineStorageBuffers(bindings);
|
2021-05-27 03:18:17 +02:00
|
|
|
SetupImages(bindings);
|
2021-06-04 02:57:52 +02:00
|
|
|
SetupTextures(bindings);
|
2021-05-28 04:28:33 +02:00
|
|
|
DefineHelperFunctions();
|
2021-06-08 07:55:12 +02:00
|
|
|
DefineConstants();
|
2021-05-20 03:58:32 +02:00
|
|
|
}
|
|
|
|
|
2021-06-13 02:14:56 +02:00
|
|
|
void EmitContext::SetupExtensions() {
|
2021-06-14 01:12:03 +02:00
|
|
|
if (info.uses_shadow_lod && profile.support_gl_texture_shadow_lod) {
|
2021-06-04 06:46:46 +02:00
|
|
|
header += "#extension GL_EXT_texture_shadow_lod : enable\n";
|
|
|
|
}
|
2021-05-22 02:56:46 +02:00
|
|
|
if (info.uses_int64) {
|
|
|
|
header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
|
|
|
|
}
|
2021-05-25 00:35:37 +02:00
|
|
|
if (info.uses_int64_bit_atomics) {
|
|
|
|
header += "#extension GL_NV_shader_atomic_int64 : enable\n";
|
|
|
|
}
|
|
|
|
if (info.uses_atomic_f32_add) {
|
|
|
|
header += "#extension GL_NV_shader_atomic_float : enable\n";
|
|
|
|
}
|
|
|
|
if (info.uses_atomic_f16x2_add || info.uses_atomic_f16x2_min || info.uses_atomic_f16x2_max) {
|
2021-06-15 23:23:57 +02:00
|
|
|
header += "#extension GL_NV_shader_atomic_fp16_vector : enable\n";
|
2021-05-25 00:35:37 +02:00
|
|
|
}
|
2021-05-25 07:52:02 +02:00
|
|
|
if (info.uses_fp16) {
|
2021-05-26 01:55:40 +02:00
|
|
|
if (profile.support_gl_nv_gpu_shader_5) {
|
|
|
|
header += "#extension GL_NV_gpu_shader5 : enable\n";
|
|
|
|
}
|
|
|
|
if (profile.support_gl_amd_gpu_shader_half_float) {
|
|
|
|
header += "#extension GL_AMD_gpu_shader_half_float : enable\n";
|
|
|
|
}
|
2021-05-25 07:52:02 +02:00
|
|
|
}
|
2021-05-29 03:24:52 +02:00
|
|
|
if (info.uses_subgroup_invocation_id || info.uses_subgroup_mask || info.uses_subgroup_vote ||
|
|
|
|
info.uses_subgroup_shuffles || info.uses_fswzadd) {
|
2021-06-04 02:57:52 +02:00
|
|
|
header += "#extension GL_ARB_shader_ballot : enable\n"
|
|
|
|
"#extension GL_ARB_shader_group_vote : enable\n";
|
2021-05-30 06:53:26 +02:00
|
|
|
if (!info.uses_int64) {
|
|
|
|
header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
|
|
|
|
}
|
2021-06-08 07:55:12 +02:00
|
|
|
if (profile.support_gl_warp_intrinsics) {
|
|
|
|
header += "#extension GL_NV_shader_thread_shuffle : enable\n";
|
|
|
|
}
|
2021-05-29 03:24:52 +02:00
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if ((info.stores[IR::Attribute::ViewportIndex] || info.stores[IR::Attribute::Layer]) &&
|
2021-06-11 06:33:33 +02:00
|
|
|
profile.support_viewport_index_layer_non_geometry && stage != Stage::Geometry) {
|
2021-05-31 19:28:53 +02:00
|
|
|
header += "#extension GL_ARB_shader_viewport_layer_array : enable\n";
|
|
|
|
}
|
2021-06-13 06:05:19 +02:00
|
|
|
if (info.uses_sparse_residency && profile.support_gl_sparse_textures) {
|
2021-06-08 01:20:32 +02:00
|
|
|
header += "#extension GL_ARB_sparse_texture2 : enable\n";
|
|
|
|
}
|
2021-06-24 07:41:09 +02:00
|
|
|
if (info.stores[IR::Attribute::ViewportMask] && profile.support_viewport_mask) {
|
2021-06-09 03:22:50 +02:00
|
|
|
header += "#extension GL_NV_viewport_array2 : enable\n";
|
|
|
|
}
|
2021-06-15 23:23:57 +02:00
|
|
|
if (info.uses_typeless_image_reads) {
|
2021-06-08 00:29:13 +02:00
|
|
|
header += "#extension GL_EXT_shader_image_load_formatted : enable\n";
|
|
|
|
}
|
2021-06-15 05:33:26 +02:00
|
|
|
if (info.uses_derivatives && profile.support_gl_derivative_control) {
|
|
|
|
header += "#extension GL_ARB_derivative_control : enable\n";
|
|
|
|
}
|
2021-06-25 02:13:21 +02:00
|
|
|
if (uses_geometry_passthrough) {
|
|
|
|
header += "#extension GL_NV_geometry_shader_passthrough : enable\n";
|
|
|
|
}
|
2021-05-22 02:56:46 +02:00
|
|
|
}
|
|
|
|
|
2021-05-28 04:28:33 +02:00
|
|
|
void EmitContext::DefineConstantBuffers(Bindings& bindings) {
|
2021-05-20 03:58:32 +02:00
|
|
|
if (info.constant_buffer_descriptors.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const auto& desc : info.constant_buffer_descriptors) {
|
2021-05-28 19:54:09 +02:00
|
|
|
header += fmt::format(
|
|
|
|
"layout(std140,binding={}) uniform {}_cbuf_{}{{vec4 {}_cbuf{}[{}];}};",
|
2021-05-28 04:28:33 +02:00
|
|
|
bindings.uniform_buffer, stage_name, desc.index, stage_name, desc.index, 4 * 1024);
|
|
|
|
bindings.uniform_buffer += desc.count;
|
2021-05-21 05:38:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 04:28:33 +02:00
|
|
|
void EmitContext::DefineStorageBuffers(Bindings& bindings) {
|
2021-05-21 05:38:38 +02:00
|
|
|
if (info.storage_buffers_descriptors.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-31 02:02:44 +02:00
|
|
|
u32 index{};
|
2021-05-21 05:38:38 +02:00
|
|
|
for (const auto& desc : info.storage_buffers_descriptors) {
|
2021-05-31 02:02:44 +02:00
|
|
|
header += fmt::format("layout(std430,binding={}) buffer {}_ssbo_{}{{uint {}_ssbo{}[];}};",
|
|
|
|
bindings.storage_buffer, stage_name, bindings.storage_buffer,
|
|
|
|
stage_name, index);
|
2021-05-28 04:28:33 +02:00
|
|
|
bindings.storage_buffer += desc.count;
|
2021-05-31 02:02:44 +02:00
|
|
|
index += desc.count;
|
2021-05-20 03:58:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-02 06:33:03 +02:00
|
|
|
void EmitContext::DefineGenericOutput(size_t index, u32 invocations) {
|
|
|
|
static constexpr std::string_view swizzle{"xyzw"};
|
|
|
|
const size_t base_index{static_cast<size_t>(IR::Attribute::Generic0X) + index * 4};
|
|
|
|
u32 element{0};
|
|
|
|
while (element < 4) {
|
|
|
|
std::string definition{fmt::format("layout(location={}", index)};
|
|
|
|
const u32 remainder{4 - element};
|
|
|
|
const TransformFeedbackVarying* xfb_varying{};
|
|
|
|
if (!runtime_info.xfb_varyings.empty()) {
|
|
|
|
xfb_varying = &runtime_info.xfb_varyings[base_index + element];
|
|
|
|
xfb_varying = xfb_varying && xfb_varying->components > 0 ? xfb_varying : nullptr;
|
|
|
|
}
|
|
|
|
const u32 num_components{xfb_varying ? xfb_varying->components : remainder};
|
|
|
|
if (element > 0) {
|
|
|
|
definition += fmt::format(",component={}", element);
|
|
|
|
}
|
|
|
|
if (xfb_varying) {
|
|
|
|
definition +=
|
|
|
|
fmt::format(",xfb_buffer={},xfb_stride={},xfb_offset={}", xfb_varying->buffer,
|
|
|
|
xfb_varying->stride, xfb_varying->offset);
|
|
|
|
}
|
|
|
|
std::string name{fmt::format("out_attr{}", index)};
|
|
|
|
if (num_components < 4 || element > 0) {
|
|
|
|
name += fmt::format("_{}", swizzle.substr(element, num_components));
|
|
|
|
}
|
|
|
|
const auto type{num_components == 1 ? "float" : fmt::format("vec{}", num_components)};
|
|
|
|
definition += fmt::format(")out {} {}{};", type, name, OutputDecorator(stage, invocations));
|
|
|
|
header += definition;
|
|
|
|
|
|
|
|
const GenericElementInfo element_info{
|
|
|
|
.name = name,
|
|
|
|
.first_element = element,
|
|
|
|
.num_components = num_components,
|
|
|
|
};
|
|
|
|
std::fill_n(output_generics[index].begin() + element, num_components, element_info);
|
|
|
|
element += num_components;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 00:35:37 +02:00
|
|
|
void EmitContext::DefineHelperFunctions() {
|
2021-06-04 01:15:36 +02:00
|
|
|
header += "\n#define ftoi floatBitsToInt\n#define ftou floatBitsToUint\n"
|
|
|
|
"#define itof intBitsToFloat\n#define utof uintBitsToFloat\n";
|
2021-05-30 20:31:59 +02:00
|
|
|
if (info.uses_global_increment || info.uses_shared_increment) {
|
2021-06-04 02:57:52 +02:00
|
|
|
header += "uint CasIncrement(uint op_a,uint op_b){return op_a>=op_b?0u:(op_a+1u);}";
|
2021-05-25 00:35:37 +02:00
|
|
|
}
|
2021-05-30 20:31:59 +02:00
|
|
|
if (info.uses_global_decrement || info.uses_shared_decrement) {
|
2021-06-11 06:33:33 +02:00
|
|
|
header += "uint CasDecrement(uint op_a,uint op_b){"
|
|
|
|
"return op_a==0||op_a>op_b?op_b:(op_a-1u);}";
|
2021-05-25 00:35:37 +02:00
|
|
|
}
|
2021-05-25 07:35:30 +02:00
|
|
|
if (info.uses_atomic_f32_add) {
|
2021-06-11 06:33:33 +02:00
|
|
|
header += "uint CasFloatAdd(uint op_a,float op_b){"
|
|
|
|
"return ftou(utof(op_a)+op_b);}";
|
2021-05-25 07:35:30 +02:00
|
|
|
}
|
|
|
|
if (info.uses_atomic_f32x2_add) {
|
2021-06-11 06:33:33 +02:00
|
|
|
header += "uint CasFloatAdd32x2(uint op_a,vec2 op_b){"
|
|
|
|
"return packHalf2x16(unpackHalf2x16(op_a)+op_b);}";
|
2021-05-25 07:35:30 +02:00
|
|
|
}
|
|
|
|
if (info.uses_atomic_f32x2_min) {
|
2021-05-28 19:54:09 +02:00
|
|
|
header += "uint CasFloatMin32x2(uint op_a,vec2 op_b){return "
|
2021-06-04 02:57:52 +02:00
|
|
|
"packHalf2x16(min(unpackHalf2x16(op_a),op_b));}";
|
2021-05-25 07:35:30 +02:00
|
|
|
}
|
|
|
|
if (info.uses_atomic_f32x2_max) {
|
2021-05-28 19:54:09 +02:00
|
|
|
header += "uint CasFloatMax32x2(uint op_a,vec2 op_b){return "
|
2021-06-04 02:57:52 +02:00
|
|
|
"packHalf2x16(max(unpackHalf2x16(op_a),op_b));}";
|
2021-05-25 07:35:30 +02:00
|
|
|
}
|
2021-05-25 07:52:02 +02:00
|
|
|
if (info.uses_atomic_f16x2_add) {
|
2021-05-28 19:54:09 +02:00
|
|
|
header += "uint CasFloatAdd16x2(uint op_a,f16vec2 op_b){return "
|
2021-06-04 02:57:52 +02:00
|
|
|
"packFloat2x16(unpackFloat2x16(op_a)+op_b);}";
|
2021-05-25 07:52:02 +02:00
|
|
|
}
|
|
|
|
if (info.uses_atomic_f16x2_min) {
|
2021-05-28 19:54:09 +02:00
|
|
|
header += "uint CasFloatMin16x2(uint op_a,f16vec2 op_b){return "
|
2021-06-04 02:57:52 +02:00
|
|
|
"packFloat2x16(min(unpackFloat2x16(op_a),op_b));}";
|
2021-05-25 07:52:02 +02:00
|
|
|
}
|
|
|
|
if (info.uses_atomic_f16x2_max) {
|
2021-05-28 19:54:09 +02:00
|
|
|
header += "uint CasFloatMax16x2(uint op_a,f16vec2 op_b){return "
|
2021-06-04 02:57:52 +02:00
|
|
|
"packFloat2x16(max(unpackFloat2x16(op_a),op_b));}";
|
2021-05-25 07:52:02 +02:00
|
|
|
}
|
2021-05-26 04:13:50 +02:00
|
|
|
if (info.uses_atomic_s32_min) {
|
2021-05-28 19:54:09 +02:00
|
|
|
header += "uint CasMinS32(uint op_a,uint op_b){return uint(min(int(op_a),int(op_b)));}";
|
2021-05-26 04:13:50 +02:00
|
|
|
}
|
|
|
|
if (info.uses_atomic_s32_max) {
|
2021-05-28 19:54:09 +02:00
|
|
|
header += "uint CasMaxS32(uint op_a,uint op_b){return uint(max(int(op_a),int(op_b)));}";
|
2021-05-26 04:13:50 +02:00
|
|
|
}
|
2021-06-04 01:15:36 +02:00
|
|
|
if (info.uses_global_memory) {
|
2021-06-04 02:24:56 +02:00
|
|
|
header += DefineGlobalMemoryFunctions();
|
|
|
|
}
|
2021-06-08 02:39:30 +02:00
|
|
|
if (info.loads_indexed_attributes) {
|
|
|
|
const bool is_array{stage == Stage::Geometry};
|
|
|
|
const auto vertex_arg{is_array ? ",uint vertex" : ""};
|
|
|
|
std::string func{
|
|
|
|
fmt::format("float IndexedAttrLoad(int offset{}){{int base_index=offset>>2;uint "
|
|
|
|
"masked_index=uint(base_index)&3u;switch(base_index>>2){{",
|
|
|
|
vertex_arg)};
|
2021-06-24 07:41:09 +02:00
|
|
|
if (info.loads.AnyComponent(IR::Attribute::PositionX)) {
|
2021-06-08 02:39:30 +02:00
|
|
|
const auto position_idx{is_array ? "gl_in[vertex]." : ""};
|
2021-06-11 06:33:33 +02:00
|
|
|
func += fmt::format("case {}:return {}{}[masked_index];",
|
|
|
|
static_cast<u32>(IR::Attribute::PositionX) >> 2, position_idx,
|
|
|
|
position_name);
|
2021-06-08 02:39:30 +02:00
|
|
|
}
|
|
|
|
const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
|
2021-06-24 07:41:09 +02:00
|
|
|
for (u32 index = 0; index < IR::NUM_GENERICS; ++index) {
|
|
|
|
if (!info.loads.Generic(index)) {
|
2021-06-08 02:39:30 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto vertex_idx{is_array ? "[vertex]" : ""};
|
2021-06-11 06:33:33 +02:00
|
|
|
func += fmt::format("case {}:return in_attr{}{}[masked_index];",
|
2021-06-24 07:41:09 +02:00
|
|
|
base_attribute_value + index, index, vertex_idx);
|
2021-06-08 02:39:30 +02:00
|
|
|
}
|
|
|
|
func += "default: return 0.0;}}";
|
|
|
|
header += func;
|
|
|
|
}
|
|
|
|
if (info.stores_indexed_attributes) {
|
|
|
|
// TODO
|
|
|
|
}
|
2021-06-04 02:24:56 +02:00
|
|
|
}
|
2021-06-04 01:15:36 +02:00
|
|
|
|
2021-06-04 02:24:56 +02:00
|
|
|
std::string EmitContext::DefineGlobalMemoryFunctions() {
|
2021-06-04 04:25:06 +02:00
|
|
|
const auto define_body{[&](std::string& func, size_t index, std::string_view return_statement) {
|
2021-06-04 02:24:56 +02:00
|
|
|
const auto& ssbo{info.storage_buffers_descriptors[index]};
|
|
|
|
const u32 size_cbuf_offset{ssbo.cbuf_offset + 8};
|
|
|
|
const auto ssbo_addr{fmt::format("ssbo_addr{}", index)};
|
|
|
|
const auto cbuf{fmt::format("{}_cbuf{}", stage_name, ssbo.cbuf_index)};
|
|
|
|
std::array<std::string, 2> addr_xy;
|
|
|
|
std::array<std::string, 2> size_xy;
|
|
|
|
for (size_t i = 0; i < addr_xy.size(); ++i) {
|
|
|
|
const auto addr_loc{ssbo.cbuf_offset + 4 * i};
|
|
|
|
const auto size_loc{size_cbuf_offset + 4 * i};
|
2021-06-11 06:33:33 +02:00
|
|
|
addr_xy[i] = fmt::format("ftou({}[{}].{})", cbuf, addr_loc / 16, Swizzle(addr_loc));
|
|
|
|
size_xy[i] = fmt::format("ftou({}[{}].{})", cbuf, size_loc / 16, Swizzle(size_loc));
|
2021-06-04 02:24:56 +02:00
|
|
|
}
|
|
|
|
const auto addr_pack{fmt::format("packUint2x32(uvec2({},{}))", addr_xy[0], addr_xy[1])};
|
|
|
|
const auto addr_statment{fmt::format("uint64_t {}={};", ssbo_addr, addr_pack)};
|
|
|
|
func += addr_statment;
|
2021-06-04 01:15:36 +02:00
|
|
|
|
2021-06-04 02:24:56 +02:00
|
|
|
const auto size_vec{fmt::format("uvec2({},{})", size_xy[0], size_xy[1])};
|
|
|
|
const auto comp_lhs{fmt::format("(addr>={})", ssbo_addr)};
|
|
|
|
const auto comp_rhs{fmt::format("(addr<({}+uint64_t({})))", ssbo_addr, size_vec)};
|
|
|
|
const auto comparison{fmt::format("if({}&&{}){{", comp_lhs, comp_rhs)};
|
|
|
|
func += comparison;
|
2021-06-04 01:15:36 +02:00
|
|
|
|
2021-06-04 02:24:56 +02:00
|
|
|
const auto ssbo_name{fmt::format("{}_ssbo{}", stage_name, index)};
|
2021-06-29 05:44:03 +02:00
|
|
|
func += fmt::format(fmt::runtime(return_statement), ssbo_name, ssbo_addr);
|
2021-06-04 02:24:56 +02:00
|
|
|
}};
|
2021-06-04 04:25:06 +02:00
|
|
|
std::string write_func{"void WriteGlobal32(uint64_t addr,uint data){"};
|
|
|
|
std::string write_func_64{"void WriteGlobal64(uint64_t addr,uvec2 data){"};
|
|
|
|
std::string write_func_128{"void WriteGlobal128(uint64_t addr,uvec4 data){"};
|
|
|
|
std::string load_func{"uint LoadGlobal32(uint64_t addr){"};
|
|
|
|
std::string load_func_64{"uvec2 LoadGlobal64(uint64_t addr){"};
|
|
|
|
std::string load_func_128{"uvec4 LoadGlobal128(uint64_t addr){"};
|
2021-06-04 02:24:56 +02:00
|
|
|
const size_t num_buffers{info.storage_buffers_descriptors.size()};
|
|
|
|
for (size_t index = 0; index < num_buffers; ++index) {
|
|
|
|
if (!info.nvn_buffer_used[index]) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-06-04 04:25:06 +02:00
|
|
|
define_body(write_func, index, "{0}[uint(addr-{1})>>2]=data;return;}}");
|
|
|
|
define_body(write_func_64, index,
|
|
|
|
"{0}[uint(addr-{1})>>2]=data.x;{0}[uint(addr-{1}+4)>>2]=data.y;return;}}");
|
|
|
|
define_body(write_func_128, index,
|
|
|
|
"{0}[uint(addr-{1})>>2]=data.x;{0}[uint(addr-{1}+4)>>2]=data.y;{0}[uint("
|
|
|
|
"addr-{1}+8)>>2]=data.z;{0}[uint(addr-{1}+12)>>2]=data.w;return;}}");
|
|
|
|
define_body(load_func, index, "return {0}[uint(addr-{1})>>2];}}");
|
|
|
|
define_body(load_func_64, index,
|
|
|
|
"return uvec2({0}[uint(addr-{1})>>2],{0}[uint(addr-{1}+4)>>2]);}}");
|
|
|
|
define_body(load_func_128, index,
|
|
|
|
"return uvec4({0}[uint(addr-{1})>>2],{0}[uint(addr-{1}+4)>>2],{0}["
|
|
|
|
"uint(addr-{1}+8)>>2],{0}[uint(addr-{1}+12)>>2]);}}");
|
2021-06-04 02:24:56 +02:00
|
|
|
}
|
2021-06-15 23:23:57 +02:00
|
|
|
write_func += '}';
|
|
|
|
write_func_64 += '}';
|
|
|
|
write_func_128 += '}';
|
2021-06-04 02:24:56 +02:00
|
|
|
load_func += "return 0u;}";
|
|
|
|
load_func_64 += "return uvec2(0);}";
|
|
|
|
load_func_128 += "return uvec4(0);}";
|
|
|
|
return write_func + write_func_64 + write_func_128 + load_func + load_func_64 + load_func_128;
|
2021-05-25 00:35:37 +02:00
|
|
|
}
|
|
|
|
|
2021-05-27 03:18:17 +02:00
|
|
|
void EmitContext::SetupImages(Bindings& bindings) {
|
2021-06-11 08:50:30 +02:00
|
|
|
image_buffers.reserve(info.image_buffer_descriptors.size());
|
2021-05-27 03:18:17 +02:00
|
|
|
for (const auto& desc : info.image_buffer_descriptors) {
|
2021-06-11 08:50:30 +02:00
|
|
|
image_buffers.push_back({bindings.image, desc.count});
|
2021-06-05 08:41:29 +02:00
|
|
|
const auto format{ImageFormatString(desc.format)};
|
2021-06-15 23:23:57 +02:00
|
|
|
const auto qualifier{ImageAccessQualifier(desc.is_written, desc.is_read)};
|
2021-06-11 08:50:30 +02:00
|
|
|
const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
|
2021-06-15 23:23:57 +02:00
|
|
|
header += fmt::format("layout(binding={}{}) uniform {}uimageBuffer img{}{};",
|
|
|
|
bindings.image, format, qualifier, bindings.image, array_decorator);
|
2021-05-27 03:18:17 +02:00
|
|
|
bindings.image += desc.count;
|
|
|
|
}
|
2021-06-11 08:50:30 +02:00
|
|
|
images.reserve(info.image_descriptors.size());
|
2021-05-27 03:18:17 +02:00
|
|
|
for (const auto& desc : info.image_descriptors) {
|
2021-06-11 08:50:30 +02:00
|
|
|
images.push_back({bindings.image, desc.count});
|
2021-06-03 02:37:24 +02:00
|
|
|
const auto format{ImageFormatString(desc.format)};
|
|
|
|
const auto image_type{ImageType(desc.type)};
|
2021-06-15 23:23:57 +02:00
|
|
|
const auto qualifier{ImageAccessQualifier(desc.is_written, desc.is_read)};
|
2021-06-11 08:50:30 +02:00
|
|
|
const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
|
|
|
|
header += fmt::format("layout(binding={}{})uniform {}{} img{}{};", bindings.image, format,
|
|
|
|
qualifier, image_type, bindings.image, array_decorator);
|
2021-05-27 03:18:17 +02:00
|
|
|
bindings.image += desc.count;
|
|
|
|
}
|
2021-06-04 02:57:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmitContext::SetupTextures(Bindings& bindings) {
|
2021-06-11 08:50:30 +02:00
|
|
|
texture_buffers.reserve(info.texture_buffer_descriptors.size());
|
2021-05-27 03:18:17 +02:00
|
|
|
for (const auto& desc : info.texture_buffer_descriptors) {
|
2021-06-11 08:50:30 +02:00
|
|
|
texture_buffers.push_back({bindings.texture, desc.count});
|
2021-05-31 07:12:52 +02:00
|
|
|
const auto sampler_type{SamplerType(TextureType::Buffer, false)};
|
2021-06-11 08:50:30 +02:00
|
|
|
const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
|
|
|
|
header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture,
|
|
|
|
sampler_type, bindings.texture, array_decorator);
|
2021-05-27 03:18:17 +02:00
|
|
|
bindings.texture += desc.count;
|
|
|
|
}
|
2021-06-11 08:50:30 +02:00
|
|
|
textures.reserve(info.texture_descriptors.size());
|
2021-05-27 03:18:17 +02:00
|
|
|
for (const auto& desc : info.texture_descriptors) {
|
2021-06-11 08:50:30 +02:00
|
|
|
textures.push_back({bindings.texture, desc.count});
|
2021-05-29 07:53:32 +02:00
|
|
|
const auto sampler_type{SamplerType(desc.type, desc.is_depth)};
|
2021-06-11 08:50:30 +02:00
|
|
|
const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
|
|
|
|
header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture,
|
|
|
|
sampler_type, bindings.texture, array_decorator);
|
2021-05-27 03:18:17 +02:00
|
|
|
bindings.texture += desc.count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-08 07:55:12 +02:00
|
|
|
void EmitContext::DefineConstants() {
|
|
|
|
if (info.uses_fswzadd) {
|
|
|
|
header += "const float FSWZ_A[]=float[4](-1.f,1.f,-1.f,0.f);"
|
|
|
|
"const float FSWZ_B[]=float[4](-1.f,-1.f,1.f,-1.f);";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-20 03:58:32 +02:00
|
|
|
} // namespace Shader::Backend::GLSL
|