summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_image.cpp56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
index d721b018b..78e2d5bac 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
@@ -38,6 +38,24 @@ std::string CastToIntVec(std::string_view value, const IR::TextureInstInfo& info
38 } 38 }
39} 39}
40 40
41std::string TexelFetchCastToInt(std::string_view value, const IR::TextureInstInfo& info) {
42 switch (info.type) {
43 case TextureType::Color1D:
44 return fmt::format("int({})", value);
45 case TextureType::ColorArray1D:
46 case TextureType::Color2D:
47 return fmt::format("ivec2({})", value);
48 case TextureType::ColorArray2D:
49 case TextureType::Color3D:
50 case TextureType::ColorCube:
51 return fmt::format("ivec3({})", value);
52 case TextureType::ColorArrayCube:
53 return fmt::format("ivec4({})", value);
54 default:
55 throw NotImplementedException("Offset type {}", info.type.Value());
56 }
57}
58
41std::string ShadowSamplerVecCast(TextureType type) { 59std::string ShadowSamplerVecCast(TextureType type) {
42 switch (type) { 60 switch (type) {
43 case TextureType::ColorArray2D: 61 case TextureType::ColorArray2D:
@@ -138,6 +156,10 @@ void EmitImageSampleDrefImplicitLod([[maybe_unused]] EmitContext& ctx,
138 [[maybe_unused]] std::string_view bias_lc, 156 [[maybe_unused]] std::string_view bias_lc,
139 [[maybe_unused]] const IR::Value& offset) { 157 [[maybe_unused]] const IR::Value& offset) {
140 const auto info{inst.Flags<IR::TextureInstInfo>()}; 158 const auto info{inst.Flags<IR::TextureInstInfo>()};
159 const auto sparse_inst{PrepareSparse(inst)};
160 if (sparse_inst) {
161 throw NotImplementedException("Sparse texture samples");
162 }
141 if (info.has_bias) { 163 if (info.has_bias) {
142 throw NotImplementedException("Bias texture samples"); 164 throw NotImplementedException("Bias texture samples");
143 } 165 }
@@ -165,6 +187,10 @@ void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx,
165 [[maybe_unused]] std::string_view lod_lc, 187 [[maybe_unused]] std::string_view lod_lc,
166 [[maybe_unused]] const IR::Value& offset) { 188 [[maybe_unused]] const IR::Value& offset) {
167 const auto info{inst.Flags<IR::TextureInstInfo>()}; 189 const auto info{inst.Flags<IR::TextureInstInfo>()};
190 const auto sparse_inst{PrepareSparse(inst)};
191 if (sparse_inst) {
192 throw NotImplementedException("Sparse texture samples");
193 }
168 if (info.has_bias) { 194 if (info.has_bias) {
169 throw NotImplementedException("Bias texture samples"); 195 throw NotImplementedException("Bias texture samples");
170 } 196 }
@@ -204,7 +230,35 @@ void EmitImageFetch([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst
204 [[maybe_unused]] std::string_view coords, 230 [[maybe_unused]] std::string_view coords,
205 [[maybe_unused]] std::string_view offset, [[maybe_unused]] std::string_view lod, 231 [[maybe_unused]] std::string_view offset, [[maybe_unused]] std::string_view lod,
206 [[maybe_unused]] std::string_view ms) { 232 [[maybe_unused]] std::string_view ms) {
207 throw NotImplementedException("GLSL Instruction"); 233 const auto info{inst.Flags<IR::TextureInstInfo>()};
234 if (info.has_bias) {
235 throw NotImplementedException("Bias texture samples");
236 }
237 if (info.has_lod_clamp) {
238 throw NotImplementedException("Lod clamp samples");
239 }
240 const auto texture{Texture(ctx, info, index)};
241 const auto sparse_inst{PrepareSparse(inst)};
242 const auto texel{ctx.reg_alloc.Define(inst, Type::F32x4)};
243 if (!sparse_inst) {
244 if (!offset.empty()) {
245 ctx.Add("{}=texelFetchOffset({},{},int({}),{});", texel, texture,
246 TexelFetchCastToInt(coords, info), lod, TexelFetchCastToInt(offset, info));
247 } else {
248 ctx.Add("{}=texelFetch({},{},int({}));", texel, texture,
249 TexelFetchCastToInt(coords, info), lod);
250 }
251 return;
252 }
253 // TODO: Query sparseTexels extension support
254 if (!offset.empty()) {
255 ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchOffsetARB({},{},int({}),{},{}));",
256 *sparse_inst, texture, CastToIntVec(coords, info), lod,
257 CastToIntVec(offset, info), texel);
258 } else {
259 ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchARB({},{},{},{}));", *sparse_inst,
260 texture, CastToIntVec(coords, info), lod, texel);
261 }
208} 262}
209 263
210void EmitImageQueryDimensions([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 264void EmitImageQueryDimensions([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,