diff options
Diffstat (limited to 'src/shader_recompiler')
10 files changed, 44 insertions, 2 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp index a97b143e4..e67e80fac 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp | |||
| @@ -67,6 +67,7 @@ std::string_view TextureType(IR::TextureInstInfo info) { | |||
| 67 | case TextureType::ColorArray1D: | 67 | case TextureType::ColorArray1D: |
| 68 | return "SHADOWARRAY1D"; | 68 | return "SHADOWARRAY1D"; |
| 69 | case TextureType::Color2D: | 69 | case TextureType::Color2D: |
| 70 | case TextureType::Color2DRect: | ||
| 70 | return "SHADOW2D"; | 71 | return "SHADOW2D"; |
| 71 | case TextureType::ColorArray2D: | 72 | case TextureType::ColorArray2D: |
| 72 | return "SHADOWARRAY2D"; | 73 | return "SHADOWARRAY2D"; |
| @@ -86,6 +87,7 @@ std::string_view TextureType(IR::TextureInstInfo info) { | |||
| 86 | case TextureType::ColorArray1D: | 87 | case TextureType::ColorArray1D: |
| 87 | return "ARRAY1D"; | 88 | return "ARRAY1D"; |
| 88 | case TextureType::Color2D: | 89 | case TextureType::Color2D: |
| 90 | case TextureType::Color2DRect: | ||
| 89 | return "2D"; | 91 | return "2D"; |
| 90 | case TextureType::ColorArray2D: | 92 | case TextureType::ColorArray2D: |
| 91 | return "ARRAY2D"; | 93 | return "ARRAY2D"; |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp index 6af7e3fe6..cecdbb9d6 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | |||
| @@ -466,6 +466,7 @@ void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& | |||
| 466 | case TextureType::ColorArray1D: | 466 | case TextureType::ColorArray1D: |
| 467 | case TextureType::Color2D: | 467 | case TextureType::Color2D: |
| 468 | case TextureType::ColorCube: | 468 | case TextureType::ColorCube: |
| 469 | case TextureType::Color2DRect: | ||
| 469 | return ctx.AddU32x4( | 470 | return ctx.AddU32x4( |
| 470 | "{}=uvec4(uvec2(textureSize({},int({}))),0u,uint(textureQueryLevels({})));", inst, | 471 | "{}=uvec4(uvec2(textureSize({},int({}))),0u,uint(textureQueryLevels({})));", inst, |
| 471 | texture, lod, texture); | 472 | texture, lod, texture); |
diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp index 221b06328..c767a9dc3 100644 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | |||
| @@ -86,6 +86,7 @@ std::string_view SamplerType(TextureType type, bool is_depth) { | |||
| 86 | case TextureType::ColorArray1D: | 86 | case TextureType::ColorArray1D: |
| 87 | return "sampler1DArray"; | 87 | return "sampler1DArray"; |
| 88 | case TextureType::Color2D: | 88 | case TextureType::Color2D: |
| 89 | case TextureType::Color2DRect: | ||
| 89 | return "sampler2D"; | 90 | return "sampler2D"; |
| 90 | case TextureType::ColorArray2D: | 91 | case TextureType::ColorArray2D: |
| 91 | return "sampler2DArray"; | 92 | return "sampler2DArray"; |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp index d8d86c91a..fb5799c42 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | |||
| @@ -453,6 +453,7 @@ Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& i | |||
| 453 | case TextureType::ColorArray1D: | 453 | case TextureType::ColorArray1D: |
| 454 | case TextureType::Color2D: | 454 | case TextureType::Color2D: |
| 455 | case TextureType::ColorCube: | 455 | case TextureType::ColorCube: |
| 456 | case TextureType::Color2DRect: | ||
| 456 | return ctx.OpCompositeConstruct(ctx.U32[4], ctx.OpImageQuerySizeLod(ctx.U32[2], image, lod), | 457 | return ctx.OpCompositeConstruct(ctx.U32[4], ctx.OpImageQuerySizeLod(ctx.U32[2], image, lod), |
| 457 | zero, mips()); | 458 | zero, mips()); |
| 458 | case TextureType::ColorArray2D: | 459 | case TextureType::ColorArray2D: |
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index 98dd9035a..aecc4c612 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp | |||
| @@ -41,6 +41,7 @@ Id ImageType(EmitContext& ctx, const TextureDescriptor& desc) { | |||
| 41 | case TextureType::ColorArray1D: | 41 | case TextureType::ColorArray1D: |
| 42 | return ctx.TypeImage(type, spv::Dim::Dim1D, depth, true, false, 1, format); | 42 | return ctx.TypeImage(type, spv::Dim::Dim1D, depth, true, false, 1, format); |
| 43 | case TextureType::Color2D: | 43 | case TextureType::Color2D: |
| 44 | case TextureType::Color2DRect: | ||
| 44 | return ctx.TypeImage(type, spv::Dim::Dim2D, depth, false, false, 1, format); | 45 | return ctx.TypeImage(type, spv::Dim::Dim2D, depth, false, false, 1, format); |
| 45 | case TextureType::ColorArray2D: | 46 | case TextureType::ColorArray2D: |
| 46 | return ctx.TypeImage(type, spv::Dim::Dim2D, depth, true, false, 1, format); | 47 | return ctx.TypeImage(type, spv::Dim::Dim2D, depth, true, false, 1, format); |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index d2b658bca..11086ed8c 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -1832,6 +1832,11 @@ Value IREmitter::ImageQueryDimension(const Value& handle, const IR::U32& lod) { | |||
| 1832 | return Inst(op, handle, lod); | 1832 | return Inst(op, handle, lod); |
| 1833 | } | 1833 | } |
| 1834 | 1834 | ||
| 1835 | Value IREmitter::ImageQueryDimension(const Value& handle, const IR::U32& lod, | ||
| 1836 | TextureInstInfo info) { | ||
| 1837 | return Inst(Opcode::ImageQueryDimensions, Flags{info}, handle, lod); | ||
| 1838 | } | ||
| 1839 | |||
| 1835 | Value IREmitter::ImageQueryLod(const Value& handle, const Value& coords, TextureInstInfo info) { | 1840 | Value IREmitter::ImageQueryLod(const Value& handle, const Value& coords, TextureInstInfo info) { |
| 1836 | const Opcode op{handle.IsImmediate() ? Opcode::BoundImageQueryLod | 1841 | const Opcode op{handle.IsImmediate() ? Opcode::BoundImageQueryLod |
| 1837 | : Opcode::BindlessImageQueryLod}; | 1842 | : Opcode::BindlessImageQueryLod}; |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h index c29bda558..25839a371 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.h +++ b/src/shader_recompiler/frontend/ir/ir_emitter.h | |||
| @@ -315,6 +315,8 @@ public: | |||
| 315 | const F32& dref, const F32& lod, | 315 | const F32& dref, const F32& lod, |
| 316 | const Value& offset, TextureInstInfo info); | 316 | const Value& offset, TextureInstInfo info); |
| 317 | [[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod); | 317 | [[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod); |
| 318 | [[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod, | ||
| 319 | TextureInstInfo info); | ||
| 318 | 320 | ||
| 319 | [[nodiscard]] Value ImageQueryLod(const Value& handle, const Value& coords, | 321 | [[nodiscard]] Value ImageQueryLod(const Value& handle, const Value& coords, |
| 320 | TextureInstInfo info); | 322 | TextureInstInfo info); |
diff --git a/src/shader_recompiler/ir_opt/rescaling_pass.cpp b/src/shader_recompiler/ir_opt/rescaling_pass.cpp index 0d5f2e4d8..9198fa5f2 100644 --- a/src/shader_recompiler/ir_opt/rescaling_pass.cpp +++ b/src/shader_recompiler/ir_opt/rescaling_pass.cpp | |||
| @@ -16,6 +16,7 @@ namespace { | |||
| 16 | switch (type) { | 16 | switch (type) { |
| 17 | case TextureType::Color2D: | 17 | case TextureType::Color2D: |
| 18 | case TextureType::ColorArray2D: | 18 | case TextureType::ColorArray2D: |
| 19 | case TextureType::Color2DRect: | ||
| 19 | return true; | 20 | return true; |
| 20 | case TextureType::Color1D: | 21 | case TextureType::Color1D: |
| 21 | case TextureType::ColorArray1D: | 22 | case TextureType::ColorArray1D: |
| @@ -132,7 +133,8 @@ void PatchImageQueryDimensions(IR::Block& block, IR::Inst& inst) { | |||
| 132 | const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; | 133 | const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; |
| 133 | switch (info.type) { | 134 | switch (info.type) { |
| 134 | case TextureType::Color2D: | 135 | case TextureType::Color2D: |
| 135 | case TextureType::ColorArray2D: { | 136 | case TextureType::ColorArray2D: |
| 137 | case TextureType::Color2DRect: { | ||
| 136 | const IR::Value new_inst{&*block.PrependNewInst(it, inst)}; | 138 | const IR::Value new_inst{&*block.PrependNewInst(it, inst)}; |
| 137 | const IR::U32 width{DownScale(ir, is_scaled, IR::U32{ir.CompositeExtract(new_inst, 0)})}; | 139 | const IR::U32 width{DownScale(ir, is_scaled, IR::U32{ir.CompositeExtract(new_inst, 0)})}; |
| 138 | const IR::U32 height{DownScale(ir, is_scaled, IR::U32{ir.CompositeExtract(new_inst, 1)})}; | 140 | const IR::U32 height{DownScale(ir, is_scaled, IR::U32{ir.CompositeExtract(new_inst, 1)})}; |
| @@ -163,6 +165,7 @@ void ScaleIntegerComposite(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_s | |||
| 163 | const IR::U32 y{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(composite, 1)})}; | 165 | const IR::U32 y{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(composite, 1)})}; |
| 164 | switch (info.type) { | 166 | switch (info.type) { |
| 165 | case TextureType::Color2D: | 167 | case TextureType::Color2D: |
| 168 | case TextureType::Color2DRect: | ||
| 166 | inst.SetArg(index, ir.CompositeConstruct(x, y)); | 169 | inst.SetArg(index, ir.CompositeConstruct(x, y)); |
| 167 | break; | 170 | break; |
| 168 | case TextureType::ColorArray2D: { | 171 | case TextureType::ColorArray2D: { |
| @@ -193,6 +196,7 @@ void ScaleIntegerOffsetComposite(IR::IREmitter& ir, IR::Inst& inst, const IR::U1 | |||
| 193 | switch (info.type) { | 196 | switch (info.type) { |
| 194 | case TextureType::ColorArray2D: | 197 | case TextureType::ColorArray2D: |
| 195 | case TextureType::Color2D: | 198 | case TextureType::Color2D: |
| 199 | case TextureType::Color2DRect: | ||
| 196 | inst.SetArg(index, ir.CompositeConstruct(x, y)); | 200 | inst.SetArg(index, ir.CompositeConstruct(x, y)); |
| 197 | break; | 201 | break; |
| 198 | case TextureType::Color1D: | 202 | case TextureType::Color1D: |
| @@ -216,6 +220,7 @@ void SubScaleCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scaled) { | |||
| 216 | const IR::U32 scaled_y{SubScale(ir, is_scaled, coord_y, IR::Attribute::PositionY)}; | 220 | const IR::U32 scaled_y{SubScale(ir, is_scaled, coord_y, IR::Attribute::PositionY)}; |
| 217 | switch (info.type) { | 221 | switch (info.type) { |
| 218 | case TextureType::Color2D: | 222 | case TextureType::Color2D: |
| 223 | case TextureType::Color2DRect: | ||
| 219 | inst.SetArg(1, ir.CompositeConstruct(scaled_x, scaled_y)); | 224 | inst.SetArg(1, ir.CompositeConstruct(scaled_x, scaled_y)); |
| 220 | break; | 225 | break; |
| 221 | case TextureType::ColorArray2D: { | 226 | case TextureType::ColorArray2D: { |
diff --git a/src/shader_recompiler/ir_opt/texture_pass.cpp b/src/shader_recompiler/ir_opt/texture_pass.cpp index ca3e306e8..597112ba4 100644 --- a/src/shader_recompiler/ir_opt/texture_pass.cpp +++ b/src/shader_recompiler/ir_opt/texture_pass.cpp | |||
| @@ -362,6 +362,21 @@ private: | |||
| 362 | TextureDescriptors& texture_descriptors; | 362 | TextureDescriptors& texture_descriptors; |
| 363 | ImageDescriptors& image_descriptors; | 363 | ImageDescriptors& image_descriptors; |
| 364 | }; | 364 | }; |
| 365 | |||
| 366 | void PatchImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) { | ||
| 367 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; | ||
| 368 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | ||
| 369 | const IR::Value coord(inst.Arg(1)); | ||
| 370 | const IR::Value handle(ir.Imm32(0)); | ||
| 371 | const IR::U32 lod{ir.Imm32(0)}; | ||
| 372 | const IR::Value texture_size = ir.ImageQueryDimension(handle, lod, info); | ||
| 373 | inst.SetArg( | ||
| 374 | 1, ir.CompositeConstruct( | ||
| 375 | ir.FPMul(IR::F32(ir.CompositeExtract(coord, 0)), | ||
| 376 | ir.FPRecip(ir.ConvertUToF(32, 32, ir.CompositeExtract(texture_size, 0)))), | ||
| 377 | ir.FPMul(IR::F32(ir.CompositeExtract(coord, 1)), | ||
| 378 | ir.FPRecip(ir.ConvertUToF(32, 32, ir.CompositeExtract(texture_size, 1)))))); | ||
| 379 | } | ||
| 365 | } // Anonymous namespace | 380 | } // Anonymous namespace |
| 366 | 381 | ||
| 367 | void TexturePass(Environment& env, IR::Program& program) { | 382 | void TexturePass(Environment& env, IR::Program& program) { |
| @@ -399,6 +414,14 @@ void TexturePass(Environment& env, IR::Program& program) { | |||
| 399 | flags.type.Assign(ReadTextureType(env, cbuf)); | 414 | flags.type.Assign(ReadTextureType(env, cbuf)); |
| 400 | inst->SetFlags(flags); | 415 | inst->SetFlags(flags); |
| 401 | break; | 416 | break; |
| 417 | case IR::Opcode::ImageSampleImplicitLod: | ||
| 418 | if (flags.type != TextureType::Color2D) { | ||
| 419 | break; | ||
| 420 | } | ||
| 421 | if (ReadTextureType(env, cbuf) == TextureType::Color2DRect) { | ||
| 422 | PatchImageSampleImplicitLod(*texture_inst.block, *texture_inst.inst); | ||
| 423 | } | ||
| 424 | break; | ||
| 402 | case IR::Opcode::ImageFetch: | 425 | case IR::Opcode::ImageFetch: |
| 403 | if (flags.type != TextureType::Color1D) { | 426 | if (flags.type != TextureType::Color1D) { |
| 404 | break; | 427 | break; |
diff --git a/src/shader_recompiler/shader_info.h b/src/shader_recompiler/shader_info.h index fd2ef5336..f5690805c 100644 --- a/src/shader_recompiler/shader_info.h +++ b/src/shader_recompiler/shader_info.h | |||
| @@ -24,8 +24,9 @@ enum class TextureType : u32 { | |||
| 24 | ColorCube, | 24 | ColorCube, |
| 25 | ColorArrayCube, | 25 | ColorArrayCube, |
| 26 | Buffer, | 26 | Buffer, |
| 27 | Color2DRect, | ||
| 27 | }; | 28 | }; |
| 28 | constexpr u32 NUM_TEXTURE_TYPES = 8; | 29 | constexpr u32 NUM_TEXTURE_TYPES = 9; |
| 29 | 30 | ||
| 30 | enum class ImageFormat : u32 { | 31 | enum class ImageFormat : u32 { |
| 31 | Typeless, | 32 | Typeless, |