Sfoglia il codice sorgente

shader: Add IsTextureScaled opcode

ReinUsesLisp 5 anni fa
parent
commit
c15332c44f

+ 8 - 0
src/shader_recompiler/backend/glasm/emit_glasm_image.cpp

@@ -608,6 +608,14 @@ void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Re
     ctx.Add("STOREIM.{} {},{},{},{};", format, image, color, coord, type);
     ctx.Add("STOREIM.{} {},{},{},{};", format, image, color, coord, type);
 }
 }
 
 
+void EmitIsTextureScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index) {
+    if (!index.IsImmediate()) {
+        throw NotImplementedException("Non-constant texture rescaling");
+    }
+    UNIMPLEMENTED();
+    ctx.Add("MOV.S {}.x,-1;", inst);
+}
+
 void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
 void EmitImageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
                            ScalarU32 value) {
                            ScalarU32 value) {
     ImageAtomic(ctx, inst, index, coord, value, "ADD.U32");
     ImageAtomic(ctx, inst, index, coord, value, "ADD.U32");

+ 1 - 0
src/shader_recompiler/backend/glasm/emit_glasm_instructions.h

@@ -556,6 +556,7 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
 void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord);
 void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord);
 void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
 void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
                     Register color);
                     Register color);
+void EmitIsTextureScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index);
 void EmitBindlessImageAtomicIAdd32(EmitContext&);
 void EmitBindlessImageAtomicIAdd32(EmitContext&);
 void EmitBindlessImageAtomicSMin32(EmitContext&);
 void EmitBindlessImageAtomicSMin32(EmitContext&);
 void EmitBindlessImageAtomicUMin32(EmitContext&);
 void EmitBindlessImageAtomicUMin32(EmitContext&);

+ 8 - 0
src/shader_recompiler/backend/glsl/emit_glsl_image.cpp

@@ -612,6 +612,14 @@ void EmitImageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value
                value);
                value);
 }
 }
 
 
+void EmitIsTextureScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index) {
+    if (!index.IsImmediate()) {
+        throw NotImplementedException("Non-constant texture rescaling");
+    }
+    UNIMPLEMENTED();
+    ctx.AddU1("{}=true;", inst);
+}
+
 void EmitBindlessImageSampleImplicitLod(EmitContext&) {
 void EmitBindlessImageSampleImplicitLod(EmitContext&) {
     NotImplemented();
     NotImplemented();
 }
 }

+ 2 - 0
src/shader_recompiler/backend/glsl/emit_glsl_instructions.h

@@ -630,6 +630,8 @@ void EmitImageRead(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
                    std::string_view coords);
                    std::string_view coords);
 void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
 void EmitImageWrite(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
                     std::string_view coords, std::string_view color);
                     std::string_view coords, std::string_view color);
+void EmitIsTextureScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index);
+void EmitIsImageScaled(EmitContext& ctx, IR::Inst& inst, const IR::Value& index);
 void EmitBindlessImageAtomicIAdd32(EmitContext&);
 void EmitBindlessImageAtomicIAdd32(EmitContext&);
 void EmitBindlessImageAtomicSMin32(EmitContext&);
 void EmitBindlessImageAtomicSMin32(EmitContext&);
 void EmitBindlessImageAtomicUMin32(EmitContext&);
 void EmitBindlessImageAtomicUMin32(EmitContext&);

+ 4 - 0
src/shader_recompiler/backend/spirv/emit_spirv_image.cpp

@@ -470,4 +470,8 @@ void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id
     ctx.OpImageWrite(Image(ctx, index, info), coords, color);
     ctx.OpImageWrite(Image(ctx, index, info), coords, color);
 }
 }
 
 
+Id EmitIsTextureScaled([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& index) {
+    return ctx.false_value;
+}
+
 } // namespace Shader::Backend::SPIRV
 } // namespace Shader::Backend::SPIRV

+ 1 - 0
src/shader_recompiler/backend/spirv/emit_spirv_instructions.h

@@ -513,6 +513,7 @@ Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, I
                      Id derivates, Id offset, Id lod_clamp);
                      Id derivates, Id offset, Id lod_clamp);
 Id EmitImageRead(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords);
 Id EmitImageRead(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords);
 void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id color);
 void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id color);
+Id EmitIsTextureScaled(EmitContext& ctx, const IR::Value& index);
 Id EmitBindlessImageAtomicIAdd32(EmitContext&);
 Id EmitBindlessImageAtomicIAdd32(EmitContext&);
 Id EmitBindlessImageAtomicSMin32(EmitContext&);
 Id EmitBindlessImageAtomicSMin32(EmitContext&);
 Id EmitBindlessImageAtomicUMin32(EmitContext&);
 Id EmitBindlessImageAtomicUMin32(EmitContext&);

+ 4 - 0
src/shader_recompiler/frontend/ir/ir_emitter.cpp

@@ -1946,6 +1946,10 @@ Value IREmitter::ImageAtomicExchange(const Value& handle, const Value& coords, c
     return Inst(op, Flags{info}, handle, coords, value);
     return Inst(op, Flags{info}, handle, coords, value);
 }
 }
 
 
+U1 IREmitter::IsTextureScaled(const U32& index) {
+    return Inst<U1>(Opcode::IsTextureScaled, index);
+}
+
 U1 IREmitter::VoteAll(const U1& value) {
 U1 IREmitter::VoteAll(const U1& value) {
     return Inst<U1>(Opcode::VoteAll, value);
     return Inst<U1>(Opcode::VoteAll, value);
 }
 }

+ 3 - 0
src/shader_recompiler/frontend/ir/ir_emitter.h

@@ -359,6 +359,9 @@ public:
                                        TextureInstInfo info);
                                        TextureInstInfo info);
     [[nodiscard]] Value ImageAtomicExchange(const Value& handle, const Value& coords,
     [[nodiscard]] Value ImageAtomicExchange(const Value& handle, const Value& coords,
                                             const Value& value, TextureInstInfo info);
                                             const Value& value, TextureInstInfo info);
+
+    [[nodiscard]] U1 IsTextureScaled(const U32& index);
+
     [[nodiscard]] U1 VoteAll(const U1& value);
     [[nodiscard]] U1 VoteAll(const U1& value);
     [[nodiscard]] U1 VoteAny(const U1& value);
     [[nodiscard]] U1 VoteAny(const U1& value);
     [[nodiscard]] U1 VoteEqual(const U1& value);
     [[nodiscard]] U1 VoteEqual(const U1& value);

+ 2 - 0
src/shader_recompiler/frontend/ir/opcodes.inc

@@ -493,6 +493,8 @@ OPCODE(ImageGradient,                                       F32x4,          Opaq
 OPCODE(ImageRead,                                           U32x4,          Opaque,         Opaque,                                                         )
 OPCODE(ImageRead,                                           U32x4,          Opaque,         Opaque,                                                         )
 OPCODE(ImageWrite,                                          Void,           Opaque,         Opaque,         U32x4,                                          )
 OPCODE(ImageWrite,                                          Void,           Opaque,         Opaque,         U32x4,                                          )
 
 
+OPCODE(IsTextureScaled,                                     U1,             U32,                                                                            )
+
 // Atomic Image operations
 // Atomic Image operations
 
 
 OPCODE(BindlessImageAtomicIAdd32,                           U32,            U32,            Opaque,            U32,                                         )
 OPCODE(BindlessImageAtomicIAdd32,                           U32,            U32,            Opaque,            U32,                                         )

+ 1 - 0
src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp

@@ -431,6 +431,7 @@ void VisitUsages(Info& info, IR::Inst& inst) {
         info.uses_is_helper_invocation = true;
         info.uses_is_helper_invocation = true;
         break;
         break;
     case IR::Opcode::ResolutionDownFactor:
     case IR::Opcode::ResolutionDownFactor:
+    case IR::Opcode::IsTextureScaled:
         info.uses_rescaling_uniform = true;
         info.uses_rescaling_uniform = true;
         break;
         break;
     case IR::Opcode::LaneId:
     case IR::Opcode::LaneId: