diff --git a/src/libs/dxmt-0.60/Makefile.kmk b/src/libs/dxmt-0.60/Makefile.kmk index 171ad1d1f5b4..53ccbdcccc46 100644 --- a/src/libs/dxmt-0.60/Makefile.kmk +++ b/src/libs/dxmt-0.60/Makefile.kmk @@ -42,9 +42,61 @@ include $(KBUILD_TOOL_PATHS)/VBoxXClangMacho.kmk VBOX_PATH_DXMT := $(PATH_SUB_CURRENT) # -# The LLVM static libraries required for DXMT -# -VBOX_LLVM_PATH ?= $(lastword $(sort $(wildcard $(KBUILD_DEVTOOLS_TRG)/llvm/v*))) +# LLVM for DXMT. Prefer llvm-config when available so the link line follows +# the configured LLVM package, including shared libLLVM-N installs. Some +# VirtualBox devtools trees do not ship llvm-config, so keep the component +# library list as a fallback below. +# +VBOX_LLVM_PATH ?= $(lastword $(sort $(wildcard $(KBUILD_DEVTOOLS_TRG)/llvm/v*))) +VBOX_LLVM_CONFIG ?= $(VBOX_LLVM_PATH)/bin/llvm-config +VBOX_DXMT_LLVM_LIBDIR := $(VBOX_LLVM_PATH)/lib +ifneq ($(wildcard $(VBOX_LLVM_CONFIG)),) + VBOX_DXMT_LLVM_CONFIG_LIBDIR := $(shell $(VBOX_LLVM_CONFIG) --libdir 2>/dev/null) + ifneq ($(VBOX_DXMT_LLVM_CONFIG_LIBDIR),) + VBOX_DXMT_LLVM_LIBDIR := $(VBOX_DXMT_LLVM_CONFIG_LIBDIR) + endif + VBOX_DXMT_LLVM_CONFIG_LIBS := $(shell $(VBOX_LLVM_CONFIG) --libs bitwriter passes 2>/dev/null) + VBOX_DXMT_LLVM_CONFIG_LIB_NAMES := $(patsubst -l%,%,$(filter -l%,$(VBOX_DXMT_LLVM_CONFIG_LIBS))) + VBOX_DXMT_LLVM_LINK_LIB = $(firstword $(wildcard $(VBOX_DXMT_LLVM_LIBDIR)/lib$(1)$(VBOX_SUFF_LIB) $(VBOX_DXMT_LLVM_LIBDIR)/lib$(1)$(VBOX_SUFF_DLL)) -l$(1)) + VBOX_DXMT_LLVM_CONFIG_LINK_LIBS := $(foreach lib,$(VBOX_DXMT_LLVM_CONFIG_LIB_NAMES),$(call VBOX_DXMT_LLVM_LINK_LIB,$(lib))) +endif + +VBOX_DXMT_LLVM_FALLBACK_LIBS = \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMPasses$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMTarget$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMObjCARCOpts$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMCoroutines$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMipo$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMInstrumentation$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMVectorize$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMLinker$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMIRReader$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMAsmParser$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMFrontendOpenMP$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMScalarOpts$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMInstCombine$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMAggressiveInstCombine$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMTransformUtils$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMBitWriter$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMAnalysis$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMProfileData$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMDebugInfoDWARF$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMObject$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMTextAPI$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMMCParser$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMMC$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMBitReader$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMCore$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMRemarks$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMBitstreamReader$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMBinaryFormat$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMSupport$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBDIR)/libLLVMDemangle$(VBOX_SUFF_LIB) +ifneq ($(VBOX_DXMT_LLVM_CONFIG_LINK_LIBS),) + VBOX_DXMT_LLVM_LIBS := $(VBOX_DXMT_LLVM_CONFIG_LINK_LIBS) +else + VBOX_DXMT_LLVM_LIBS := $(VBOX_DXMT_LLVM_FALLBACK_LIBS) +endif # The metal shader compiler @@ -280,37 +332,10 @@ VBoxDxMt_LIBS = \ $(PATH_STAGE_LIB)/VBox-DxMtNativeUtil$(VBOX_SUFF_LIB) \ $(PATH_STAGE_LIB)/VBox-DxMtNativeDxbcParser$(VBOX_SUFF_LIB) \ $(PATH_STAGE_LIB)/VBox-DxMtNativeMetal$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMPasses$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMTarget$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMObjCARCOpts$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMCoroutines$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMipo$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMInstrumentation$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMVectorize$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMLinker$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMIRReader$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMAsmParser$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMFrontendOpenMP$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMScalarOpts$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMInstCombine$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMAggressiveInstCombine$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMTransformUtils$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMBitWriter$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMAnalysis$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMProfileData$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMDebugInfoDWARF$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMObject$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMTextAPI$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMMCParser$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMMC$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMBitReader$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMCore$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMRemarks$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMBitstreamReader$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMBinaryFormat$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMSupport$(VBOX_SUFF_LIB) \ - $(VBOX_LLVM_PATH)/lib/libLLVMDemangle$(VBOX_SUFF_LIB) \ + $(VBOX_DXMT_LLVM_LIBS) \ $(LIB_RUNTIME) +VBoxDxMt_LIBPATH += \ + $(VBOX_DXMT_LLVM_LIBDIR) VBoxDxMt_LDFLAGS += \ -weak_framework CoreFoundation \ -weak_framework Metal \ @@ -321,4 +346,3 @@ VBoxDxMt_LDFLAGS += \ -weak_framework Cocoa include $(FILE_KBUILD_SUB_FOOTER) - diff --git a/src/libs/dxmt-0.60/libs/DXBCParser/DXBCUtils.cpp b/src/libs/dxmt-0.60/libs/DXBCParser/DXBCUtils.cpp index 02fd8c9e2684..62a0f2588f48 100644 --- a/src/libs/dxmt-0.60/libs/DXBCParser/DXBCUtils.cpp +++ b/src/libs/dxmt-0.60/libs/DXBCParser/DXBCUtils.cpp @@ -6,6 +6,7 @@ #include "winerror.h" #include #include +#include #include #include @@ -1272,4 +1273,4 @@ void CSignatureParser::ClearAlwaysReadsNeverWritesMask() } } -} \ No newline at end of file +} diff --git a/src/libs/dxmt-0.60/libs/DXBCParser/ShaderBinary.h b/src/libs/dxmt-0.60/libs/DXBCParser/ShaderBinary.h index a532d18ffdd4..73427cdeddc0 100644 --- a/src/libs/dxmt-0.60/libs/DXBCParser/ShaderBinary.h +++ b/src/libs/dxmt-0.60/libs/DXBCParser/ShaderBinary.h @@ -7,6 +7,7 @@ #include "d3d12tokenizedprogramformat.hpp" #include #include +#include #include "minwindef.h" typedef UINT CShaderToken; diff --git a/src/libs/dxmt-0.60/src/airconv/air_operations.cpp b/src/libs/dxmt-0.60/src/airconv/air_operations.cpp index 2961875e399a..e6b4b8cefdaf 100644 --- a/src/libs/dxmt-0.60/src/airconv/air_operations.cpp +++ b/src/libs/dxmt-0.60/src/airconv/air_operations.cpp @@ -1,7 +1,19 @@ #include "air_operations.hpp" +#include "llvm/Config/llvm-config.h" +#if LLVM_VERSION_MAJOR >= 16 +# include "llvm/Support/ModRef.h" +#endif namespace dxmt::air { +static llvm::Attribute arg_mem_only_attribute(llvm::LLVMContext &context) { +#if LLVM_VERSION_MAJOR >= 16 + return llvm::Attribute::getWithMemoryEffects(context, llvm::MemoryEffects::argMemOnly()); +#else + return llvm::Attribute::get(context, llvm::Attribute::AttrKind::ArgMemOnly); +#endif +} + std::string type_overload_suffix(llvm::Type *type, Sign sign = Sign::inapplicable) { if (type->isFloatTy()) { @@ -501,7 +513,7 @@ AIRBuilderResult call_sample( {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {2U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {2U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::Convergent)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, @@ -592,7 +604,7 @@ AIRBuilderResult call_sample_grad( {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {2U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {2U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, {~0U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, @@ -674,7 +686,7 @@ AIRBuilderResult call_sample_compare( {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {2U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {2U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::Convergent)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, @@ -771,7 +783,7 @@ AIRBuilderResult call_gather( {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {2U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {2U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, {~0U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, @@ -848,7 +860,7 @@ AIRBuilderResult call_gather_compare( {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {2U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {2U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, {~0U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, @@ -921,7 +933,7 @@ AIRBuilderResult call_read( { {1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, {~0U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, @@ -1007,7 +1019,7 @@ AIRBuilderResult call_write( context, { {1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, } @@ -1077,7 +1089,7 @@ AIRBuilderResult call_calc_lod( {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {2U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {2U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::Convergent)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, @@ -1125,7 +1137,7 @@ AIRBuilderResult call_get_texture_info( { {1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, {~0U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, @@ -2023,7 +2035,7 @@ call_set_mesh_properties(pvalue mesh_grid_props, pvalue grid_size) { {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::MustProgress)}} ); auto fn = (module.getOrInsertFunction( @@ -2049,7 +2061,7 @@ call_interpolate_at_center(pvalue interpolant, bool perspective) { {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}} ); auto fn = (module.getOrInsertFunction( @@ -2075,7 +2087,7 @@ call_interpolate_at_centroid(pvalue interpolant, bool perspective) { {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}} ); auto fn = (module.getOrInsertFunction( @@ -2102,7 +2114,7 @@ AIRBuilderResult call_interpolate_at_offset( {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}, + {~0U, arg_mem_only_attribute(context)}, {~0U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}} ); auto fn = (module.getOrInsertFunction( @@ -2129,7 +2141,7 @@ call_interpolate_at_sample(pvalue interpolant, bool perspective, pvalue index) { {1U, Attribute::get(context, Attribute::AttrKind::ReadOnly)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( perspective ? "air.interpolate_sample_perspective.v4f32" @@ -2154,7 +2166,7 @@ call_set_mesh_render_target_array_index(pvalue mesh, pvalue vid, pvalue render_t context, {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( "air.set_render_target_array_index_mesh.i32", @@ -2177,7 +2189,7 @@ AIRBuilderResult call_set_mesh_viewport_array_index(pvalue mesh, pvalue vid, pva context, {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( "air.set_viewport_array_index_mesh.i32", @@ -2200,7 +2212,7 @@ AIRBuilderResult call_set_mesh_position(pvalue mesh, pvalue vid, pvalue position context, {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( "air.set_position_mesh", @@ -2223,7 +2235,7 @@ AIRBuilderResult call_set_mesh_clip_distance(pvalue mesh, uint32_t idx, pvalue v context, {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( "air.set_clip_distance_mesh", @@ -2247,7 +2259,7 @@ call_set_mesh_vertex_data(pvalue mesh, uint32_t idx, pvalue vid, pvalue value) { context, {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( "air.set_vertex_data_mesh" + type_overload_suffix(value->getType()), @@ -2271,7 +2283,7 @@ call_set_mesh_primitive_data(pvalue mesh, uint32_t idx, pvalue pid, pvalue value context, {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( "air.set_primitive_data_mesh" + type_overload_suffix(value->getType()), @@ -2294,7 +2306,7 @@ AIRBuilderResult call_set_mesh_index(pvalue mesh, pvalue index, pvalue vertex) { context, {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( "air.set_index_mesh", @@ -2317,7 +2329,7 @@ AIRBuilderResult call_set_mesh_primitive_count(pvalue mesh, pvalue count) { context, {{1U, Attribute::get(context, Attribute::AttrKind::NoCapture)}, {~0U, Attribute::get(context, Attribute::AttrKind::NoUnwind)}, {~0U, Attribute::get(context, Attribute::AttrKind::WillReturn)}, - {~0U, Attribute::get(context, Attribute::AttrKind::ArgMemOnly)}} + {~0U, arg_mem_only_attribute(context)}} ); auto fn = (module.getOrInsertFunction( "air.set_primitive_count_mesh", @@ -2331,4 +2343,4 @@ AIRBuilderResult call_set_mesh_primitive_count(pvalue mesh, pvalue count) { }); } -}; // namespace dxmt::air \ No newline at end of file +}; // namespace dxmt::air diff --git a/src/libs/dxmt-0.60/src/airconv/air_signature.cpp b/src/libs/dxmt-0.60/src/airconv/air_signature.cpp index ed078f06acd1..d5ef5493e4ba 100644 --- a/src/libs/dxmt-0.60/src/airconv/air_signature.cpp +++ b/src/libs/dxmt-0.60/src/airconv/air_signature.cpp @@ -424,7 +424,7 @@ auto ArgumentBufferBuilder::Build( uint32_t FunctionSignatureBuilder::DefineInput(const FunctionInput &input) { uint32_t index = inputs.size(); - for (auto &element : enumerate(inputs)) { + for (auto element : enumerate(inputs)) { if (element.value().index() == input.index()) { if (std::visit( patterns{ @@ -537,7 +537,7 @@ auto FunctionSignatureBuilder::CreateFunction( } }; - for (auto &item : enumerate(mesh_vertex_outputs)) { + for (auto item : enumerate(mesh_vertex_outputs)) { auto output = item.value(); StreamMDHelper md; std::visit( @@ -574,7 +574,7 @@ auto FunctionSignatureBuilder::CreateFunction( metadata_mesh_vertex_output.push_back(md.BuildTuple(context)); } - for (auto &item : enumerate(mesh_primitive_outputs)) { + for (auto item : enumerate(mesh_primitive_outputs)) { auto output = item.value(); StreamMDHelper md; std::visit( @@ -608,7 +608,7 @@ auto FunctionSignatureBuilder::CreateFunction( metadata_mesh_primitive_output.push_back(md.BuildTuple(context)); } - for (auto &item : enumerate(inputs)) { + for (auto item : enumerate(inputs)) { auto i = item.index(); auto input = item.value(); StreamMDHelper metadata_field; @@ -878,7 +878,7 @@ auto FunctionSignatureBuilder::CreateFunction( metadata_input.push_back(metadata_field.BuildTuple(context)); type_input.push_back(field_type); }; - for (auto &item : enumerate(outputs)) { + for (auto item : enumerate(outputs)) { if (skip_output) continue; auto output = item.value(); diff --git a/src/libs/dxmt-0.60/src/airconv/dxbc_converter.cpp b/src/libs/dxmt-0.60/src/airconv/dxbc_converter.cpp index 8486b10929e5..aec9392487a3 100644 --- a/src/libs/dxmt-0.60/src/airconv/dxbc_converter.cpp +++ b/src/libs/dxmt-0.60/src/airconv/dxbc_converter.cpp @@ -94,20 +94,14 @@ uint32_t next_pow2(uint32_t x) { return x == 1 ? 1 : 1 << (32 - __builtin_clz(x - 1)); } -auto get_item_in_argbuf_binding_table(uint32_t argbuf_index, uint32_t index) { +auto get_item_in_argbuf_binding_table( + uint32_t argbuf_index, llvm::StructType *argbuf_struct_type, uint32_t index +) { return make_irvalue([=](context ctx) { auto argbuf = ctx.function->getArg(argbuf_index); - auto argbuf_struct_type = llvm::cast( - llvm::cast(argbuf->getType()) - ->getNonOpaquePointerElementType() - ); return ctx.builder.CreateLoad( argbuf_struct_type->getElementType(index), - ctx.builder.CreateStructGEP( - llvm::cast(argbuf->getType()) - ->getNonOpaquePointerElementType(), - argbuf, index - ) + ctx.builder.CreateStructGEP(argbuf_struct_type, argbuf, index) ); }); }; @@ -118,10 +112,13 @@ void setup_binding_table( ) { uint32_t binding_table_index = ~0u; uint32_t cbuf_table_index = ~0u; + llvm::StructType *binding_table_type = nullptr; + llvm::StructType *cbuf_table_type = nullptr; if (!shader_info->binding_table.Empty()) { auto [type, metadata] = shader_info->binding_table.Build( module.getContext(), module.getDataLayout() ); + binding_table_type = type; binding_table_index = func_signature.DefineInput(air::ArgumentBindingIndirectBuffer{ .location_index = 30, // kArgumentBufferBindIndex @@ -137,6 +134,7 @@ void setup_binding_table( auto [type, metadata] = shader_info->binding_table_cbuffer.Build( module.getContext(), module.getDataLayout() ); + cbuf_table_type = type; cbuf_table_index = func_signature.DefineInput(air::ArgumentBindingIndirectBuffer{ .location_index = 29, // kConstantBufferBindIndex @@ -154,7 +152,7 @@ void setup_binding_table( auto index = cbv.arg_index; resource_map.cb_range_map[range_id] = [=](pvalue) { // ignore index in SM 5.0 - return get_item_in_argbuf_binding_table(cbuf_table_index, index); + return get_item_in_argbuf_binding_table(cbuf_table_index, cbuf_table_type, index); }; } for (auto &[range_id, sampler] : shader_info->samplerMap) { @@ -162,11 +160,11 @@ void setup_binding_table( resource_map.sampler_range_map[range_id] = { [=, index = sampler.arg_index](pvalue) { // ignore index in SM 5.0 - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); }, [=, index = sampler.arg_metadata_index](pvalue) { // ignore index in SM 5.0 - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); } }; } @@ -186,21 +184,21 @@ void setup_binding_table( }, [=, index = srv.arg_index](pvalue) { // ignore index in SM 5.0 - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); }, [=, index = srv.arg_metadata_index](pvalue) { // ignore index in SM 5.0 - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); } }; } else { resource_map.srv_buf_range_map[range_id] = { srv.strucure_stride, [=, index = srv.arg_index](pvalue) { - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); }, [=, index = srv.arg_metadata_index](pvalue) { - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); } }; } @@ -221,28 +219,28 @@ void setup_binding_table( }, [=, index = uav.arg_index](pvalue) { // ignore index in SM 5.0 - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); }, [=, index = uav.arg_metadata_index](pvalue) { // ignore index in SM 5.0 - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); } }; } else { resource_map.uav_buf_range_map[range_id] = { uav.strucure_stride, [=, index = uav.arg_index](pvalue) { - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); }, [=, index = uav.arg_metadata_index](pvalue) { - return get_item_in_argbuf_binding_table(binding_table_index, index); + return get_item_in_argbuf_binding_table(binding_table_index, binding_table_type, index); } }; if (uav.with_counter) { auto argbuf_index_counterptr = uav.arg_counter_index; resource_map.uav_counter_range_map[range_id] = [=](pvalue) { return get_item_in_argbuf_binding_table( - binding_table_index, argbuf_index_counterptr + binding_table_index, binding_table_type, argbuf_index_counterptr ); }; } @@ -694,8 +692,7 @@ llvm::Error convert_dxbc_hull_shader( auto pc_scalar = pShaderInternal->patch_constant_scalars[i]; auto dst_ptr = builder.CreateConstGEP1_32(types._int, pc_out, i); auto src_ptr = builder.CreateGEP( - resource_map.patch_constant_output.ptr_int4->getType() - ->getNonOpaquePointerElementType(), + llvm::ArrayType::get(types._int4, max_patch_constant_output_register), resource_map.patch_constant_output.ptr_int4, {builder.getInt32(0), builder.getInt32(pc_scalar.reg), builder.getInt32(pc_scalar.component)} @@ -962,8 +959,7 @@ llvm::Error convert_dxbc_domain_shader( unsigned clip_distance_idx = 0; for (auto &scalar : pShaderInternal->clip_distance_scalars) { auto src_ptr = builder.CreateGEP( - resource_map.output.ptr_float4->getType() - ->getNonOpaquePointerElementType(), + llvm::ArrayType::get(types._float4, 1), resource_map.output.ptr_float4, {builder.getInt32(0), builder.getInt32(scalar.reg), builder.getInt32(scalar.component)} @@ -982,8 +978,7 @@ llvm::Error convert_dxbc_domain_shader( } else { if (rta_idx_out != ~0u) { auto src_ptr = builder.CreateGEP( - resource_map.output.ptr_int4->getType()->getNonOpaquePointerElementType( - ), + llvm::ArrayType::get(types._int4, 1), resource_map.output.ptr_int4, {builder.getInt32(0), builder.getInt32(gs_passthrough->RenderTargetArrayIndexReg), @@ -995,8 +990,7 @@ llvm::Error convert_dxbc_domain_shader( } if (va_idx_out != ~0u) { auto src_ptr = builder.CreateGEP( - resource_map.output.ptr_int4->getType()->getNonOpaquePointerElementType( - ), + llvm::ArrayType::get(types._int4, 1), resource_map.output.ptr_int4, {builder.getInt32(0), builder.getInt32(gs_passthrough->ViewportArrayIndexReg), @@ -1462,8 +1456,7 @@ llvm::Error convert_dxbc_vertex_shader( unsigned clip_distance_idx = 0; for (auto &scalar : pShaderInternal->clip_distance_scalars) { auto src_ptr = builder.CreateGEP( - resource_map.output.ptr_float4->getType() - ->getNonOpaquePointerElementType(), + llvm::ArrayType::get(types._float4, 1), resource_map.output.ptr_float4, {builder.getInt32(0), builder.getInt32(scalar.reg), builder.getInt32(scalar.component)} @@ -1482,8 +1475,7 @@ llvm::Error convert_dxbc_vertex_shader( } else { if (rta_idx_out != ~0u) { auto src_ptr = builder.CreateGEP( - resource_map.output.ptr_int4->getType()->getNonOpaquePointerElementType( - ), + llvm::ArrayType::get(types._int4, 1), resource_map.output.ptr_int4, {builder.getInt32(0), builder.getInt32(gs_passthrough->RenderTargetArrayIndexReg), @@ -1495,8 +1487,7 @@ llvm::Error convert_dxbc_vertex_shader( } if (va_idx_out != ~0u) { auto src_ptr = builder.CreateGEP( - resource_map.output.ptr_int4->getType()->getNonOpaquePointerElementType( - ), + llvm::ArrayType::get(types._int4, 1), resource_map.output.ptr_int4, {builder.getInt32(0), builder.getInt32(gs_passthrough->ViewportArrayIndexReg), @@ -1679,7 +1670,7 @@ llvm::Error convert_dxbc_vertex_for_hull_shader( ->getPointerTo((uint32_t)air::AddressSpace::object_data) ); resource_map.output.ptr_int4 = builder.CreateGEP( - resource_map.output.ptr_int4->getType()->getNonOpaquePointerElementType(), + llvm::ArrayType::get(types._int4, max_output_register), resource_map.output.ptr_int4, {control_point_index_in_threadgroup} ); resource_map.output.ptr_float4 = builder.CreateBitCast( @@ -1687,7 +1678,7 @@ llvm::Error convert_dxbc_vertex_for_hull_shader( ->getPointerTo((uint32_t)air::AddressSpace::object_data) ); resource_map.output.ptr_float4 = builder.CreateGEP( - resource_map.output.ptr_float4->getType()->getNonOpaquePointerElementType(), + llvm::ArrayType::get(types._float4, max_output_register), resource_map.output.ptr_float4, {control_point_index_in_threadgroup} ); @@ -1720,7 +1711,7 @@ llvm::Error convert_dxbc_vertex_for_hull_shader( auto start_index = builder.CreateExtractValue(draw_arguments, 2); auto index_buffer = function->getArg(index_buffer_idx); auto index_buffer_element_type = - index_buffer->getType()->getNonOpaquePointerElementType(); + ia_layout->index_buffer_format == 1 ? types._short : types._int; auto vertex_id = builder.CreateLoad( index_buffer_element_type, builder.CreateGEP( diff --git a/src/libs/dxmt-0.60/src/airconv/dxbc_converter_basicblock.cpp b/src/libs/dxmt-0.60/src/airconv/dxbc_converter_basicblock.cpp index 6cb72683bfb8..aa8ddb526158 100644 --- a/src/libs/dxmt-0.60/src/airconv/dxbc_converter_basicblock.cpp +++ b/src/libs/dxmt-0.60/src/airconv/dxbc_converter_basicblock.cpp @@ -20,6 +20,7 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" +#include "llvm/Config/llvm-config.h" #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" #include @@ -28,6 +29,44 @@ char dxmt::UnsupportedFeature::ID; namespace dxmt::dxbc { +static constexpr int kMaskedShuffleElem = -1; + +static llvm::Type * +get_typed_pointer_element_type(llvm::Value *ptr) { +#if LLVM_VERSION_MAJOR <= 15 + auto *ptr_type = llvm::dyn_cast(ptr->getType()->getScalarType()); + if (ptr_type && !ptr_type->isOpaque()) + return ptr_type->getPointerElementType(); +#endif + return nullptr; +} + +static pvalue +create_vec_array_element_gep(llvm::IRBuilder<> &builder, llvm::Value *array, llvm::Type *vec_type, pvalue index) { + if (auto *element_type = get_typed_pointer_element_type(array)) { + if (llvm::isa(element_type)) + return builder.CreateGEP(element_type, array, {builder.getInt32(0), index}); + } + return builder.CreateGEP(vec_type, array, {index}); +} + +static pvalue +create_vec_array_component_gep( + llvm::IRBuilder<> &builder, llvm::Value *array, llvm::Type *vec_type, + pvalue index, unsigned component +) { + if (auto *element_type = get_typed_pointer_element_type(array)) { + if (llvm::isa(element_type)) + return builder.CreateGEP( + element_type, array, {builder.getInt32(0), index, builder.getInt32(component)} + ); + } + return builder.CreateGEP( + llvm::ArrayType::get(vec_type, 1), + array, {builder.getInt32(0), index, builder.getInt32(component)} + ); +} + template ReaderIO throwUnsupported(llvm::StringRef ref) { return ReaderIO( @@ -345,7 +384,7 @@ auto to_desired_type_from_int_vec4(pvalue vec4, llvm::Type *desired, uint32_t ma std::function convert = [&ctx, &convert, mask](pvalue vec4, llvm::Type *desired) { auto masked = [mask](int i) { - return (mask & (1 << i)) ? i : llvm::UndefMaskElem; + return (mask & (1 << i)) ? i : kMaskedShuffleElem; }; if (desired == ctx.types._int4) return ctx.builder.CreateShuffleVector( @@ -456,35 +495,25 @@ auto cmp_float(llvm::CmpInst::Predicate cmp, pvalue a, pvalue b) { }); }; -auto load_from_array_at(llvm::Value *array, pvalue index) -> IRValue { +auto load_from_array_at(llvm::Value *array, llvm::Type *vec_type, pvalue index) -> IRValue { return make_irvalue([=](context ctx) { - auto array_ty = llvm::cast( // force line break - llvm::cast(array->getType()) - ->getNonOpaquePointerElementType() - ); - auto ptr = ctx.builder.CreateGEP( - array_ty, array, {ctx.builder.getInt32(0), index}, "", - llvm::isa(index) - ); - return ctx.builder.CreateLoad(array_ty->getElementType(), ptr); + auto ptr = create_vec_array_element_gep(ctx.builder, array, vec_type, index); + return ctx.builder.CreateLoad(vec_type, ptr); }); }; IRValue -load_from_vec4_array_masked(llvm::Value *array, pvalue index, uint32_t mask) { +load_from_vec4_array_masked(llvm::Value *array, llvm::Type *vec4_type, pvalue index, uint32_t mask) { if (mask == 0b1111) { - return load_from_array_at(array, index); + return load_from_array_at(array, vec4_type, index); } return make_irvalue([=](context ctx) { - auto array_type = llvm::cast(array->getType())->getNonOpaquePointerElementType(); - auto vec4_type = llvm::cast(array_type)->getArrayElementType(); auto ele_type = llvm::cast(vec4_type)->getElementType(); pvalue value = llvm::ConstantAggregateZero::get(vec4_type); for (unsigned i = 0; i < 4; i++) { if ((mask & (1 << i)) == 0) continue; - auto component_ptr = - ctx.builder.CreateGEP(array_type, array, {ctx.builder.getInt32(0), index, ctx.builder.getInt32(i)}); + auto component_ptr = create_vec_array_component_gep(ctx.builder, array, vec4_type, index, i); value = ctx.builder.CreateInsertElement(value, ctx.builder.CreateLoad(ele_type, component_ptr), uint64_t(i)); } return value; @@ -495,11 +524,7 @@ auto store_to_array_at( llvm::Value *array, pvalue index, pvalue vec4_type_matched ) -> IREffect { return make_effect([=](context ctx) { - auto ptr = ctx.builder.CreateInBoundsGEP( - llvm::cast(array->getType()) - ->getNonOpaquePointerElementType(), - array, {ctx.builder.getInt32(0), index} - ); + auto ptr = create_vec_array_element_gep(ctx.builder, array, vec4_type_matched->getType(), index); ctx.builder.CreateStore(vec4_type_matched, ptr); return std::monostate(); }); @@ -516,11 +541,7 @@ IREffect store_at_vec4_array_masked( for (unsigned i = 0; i < 4; i++) { if ((mask & (1 << i)) == 0) continue; - auto component_ptr = ctx.builder.CreateGEP( - llvm::cast(array->getType()) - ->getNonOpaquePointerElementType(), - array, {ctx.builder.getInt32(0), index, ctx.builder.getInt32(i)} - ); + auto component_ptr = create_vec_array_component_gep(ctx.builder, array, vec4->getType(), index, i); ctx.builder.CreateStore( ctx.builder.CreateExtractElement(vec4, i), component_ptr ); @@ -531,22 +552,14 @@ IREffect store_at_vec4_array_masked( }; auto store_at_vec_array_masked( - llvm::Value *array, pvalue index, pvalue maybe_vec4, uint32_t mask + llvm::Value *array, llvm::Type *vec_type, pvalue index, pvalue maybe_vec4, uint32_t mask ) -> IREffect { - auto array_ty = llvm::cast( // force line break - llvm::cast(array->getType()) - ->getNonOpaquePointerElementType() - ); - auto components = - cast(array_ty->getElementType())->getNumElements(); + auto components = cast(vec_type)->getNumElements(); return make_effect([=](context ctx) { for (unsigned i = 0; i < components; i++) { if ((mask & (1 << i)) == 0) continue; - auto component_ptr = ctx.builder.CreateGEP( - array_ty, - array, {ctx.builder.getInt32(0), index, ctx.builder.getInt32(i)} - ); + auto component_ptr = create_vec_array_component_gep(ctx.builder, array, vec_type, index, i); ctx.builder.CreateStore( ctx.builder.CreateExtractElement(maybe_vec4, i), component_ptr ); @@ -647,7 +660,7 @@ pop_output_reg(uint32_t from_reg, uint32_t mask, uint32_t to_element) { auto const_index = llvm::ConstantInt::get(ctx.llvm, llvm::APInt{32, from_reg, false}); return load_from_array_at( - ctx.resource.output.ptr_int4, const_index + ctx.resource.output.ptr_int4, ctx.types._int4, const_index ) >>= [=, &ctx](auto ivec4) { auto desired_type = ctx.function->getReturnType()->getStructElementType(to_element); @@ -664,7 +677,7 @@ std::function pop_output_reg_fix_unorm(uint32_t from_reg, uint3 return [=](pvalue ret) { return make_irvalue_bind([=](context ctx) -> IRValue { auto const_index = llvm::ConstantInt::get(ctx.llvm, llvm::APInt{32, from_reg, false}); - auto fvec4 = co_yield load_from_array_at(ctx.resource.output.ptr_float4, const_index); + auto fvec4 = co_yield load_from_array_at(ctx.resource.output.ptr_float4, ctx.types._float4, const_index); auto fixed = ctx.builder.CreateFSub(fvec4, co_yield get_float4_splat(1.0f / 127500.0f) /* magic delta ?! */); co_return ctx.builder.CreateInsertValue(ret, fixed, {to_element}); }); @@ -686,10 +699,7 @@ IREffect init_tess_factor_patch_constant(uint32_t to_reg, uint32_t mask, uint32_ air::Sign::with_sign /* intended */ ); auto array = ctx.resource.patch_constant_output.ptr_float4; - auto array_ty = llvm::cast( // force line break - llvm::cast(array->getType()) - ->getNonOpaquePointerElementType() - ); + auto array_ty = llvm::ArrayType::get(ctx.types._float4, 1); auto component_ptr = ctx.builder.CreateGEP( array_ty, array, {ctx.builder.getInt32(0), ctx.builder.getInt32(to_reg), @@ -706,10 +716,7 @@ std::function pop_output_tess_factor( return [=](pvalue ret) -> IRValue { auto ctx = co_yield get_context(); auto array = ctx.resource.patch_constant_output.ptr_float4; - auto array_ty = llvm::cast( // force line break - llvm::cast(array->getType()) - ->getNonOpaquePointerElementType() - ); + auto array_ty = llvm::ArrayType::get(ctx.types._float4, 1); auto component_ptr = ctx.builder.CreateGEP( array_ty, array, {ctx.builder.getInt32(0), ctx.builder.getInt32(from_reg), @@ -736,7 +743,7 @@ IREffect pop_mesh_output_render_taget_array_index(uint32_t from_reg, uint32_t mask, pvalue primitive_id) { auto ctx = co_yield get_context(); auto result = co_yield to_desired_type_from_int_vec4( - co_yield load_from_array_at(ctx.resource.output.ptr_int4, ctx.builder.getInt32(from_reg)), ctx.types._int, mask + co_yield load_from_array_at(ctx.resource.output.ptr_int4, ctx.types._int4, ctx.builder.getInt32(from_reg)), ctx.types._int, mask ); co_yield air::call_set_mesh_render_target_array_index(ctx.resource.mesh, primitive_id, result); co_return {}; @@ -746,7 +753,7 @@ IREffect pop_mesh_output_viewport_array_index(uint32_t from_reg, uint32_t mask, pvalue primitive_id) { auto ctx = co_yield get_context(); auto result = co_yield to_desired_type_from_int_vec4( - co_yield load_from_array_at(ctx.resource.output.ptr_int4, ctx.builder.getInt32(from_reg)), ctx.types._int, mask + co_yield load_from_array_at(ctx.resource.output.ptr_int4, ctx.types._int4, ctx.builder.getInt32(from_reg)), ctx.types._int, mask ); co_yield air::call_set_mesh_viewport_array_index(ctx.resource.mesh, primitive_id, result); co_return {}; @@ -755,7 +762,7 @@ pop_mesh_output_viewport_array_index(uint32_t from_reg, uint32_t mask, pvalue pr IREffect pop_mesh_output_position(uint32_t from_reg, uint32_t mask, pvalue vertex_id) { auto ctx = co_yield get_context(); - auto result = co_yield load_from_array_at(ctx.resource.output.ptr_float4, ctx.builder.getInt32(from_reg)); + auto result = co_yield load_from_array_at(ctx.resource.output.ptr_float4, ctx.types._float4, ctx.builder.getInt32(from_reg)); co_yield air::call_set_mesh_position(ctx.resource.mesh, vertex_id, result); co_return {}; } @@ -766,7 +773,7 @@ pop_mesh_output_vertex_data( ) { auto ctx = co_yield get_context(); auto result = co_yield to_desired_type_from_int_vec4( - co_yield load_from_vec4_array_masked(ctx.resource.output.ptr_int4, ctx.builder.getInt32(from_reg), mask), + co_yield load_from_vec4_array_masked(ctx.resource.output.ptr_int4, ctx.types._int4, ctx.builder.getInt32(from_reg), mask), air::get_llvm_type(desired_type, ctx.llvm), mask ); co_yield air::call_set_mesh_vertex_data(ctx.resource.mesh, idx, vertex_id, result); @@ -1090,7 +1097,7 @@ auto load_operand_index(OperandIndex idx) { reg = ctx.resource.phases[ot.phase].temp.ptr_int4; } auto temp = - load_from_array_at(reg, ctx.builder.getInt32(ot.regid)).build(ctx); + load_from_array_at(reg, ctx.types._int4, ctx.builder.getInt32(ot.regid)).build(ctx); if (auto err = temp.takeError()) { return std::move(err); } @@ -1163,7 +1170,7 @@ IRValue load_src( ) { auto ctx = co_yield get_context(); auto vec = co_yield load_from_array_at( - ctx.resource.icb, co_yield load_operand_index(cb.regindex) + ctx.resource.icb, ctx.types._int4, co_yield load_operand_index(cb.regindex) ); co_return vec; }; @@ -1174,7 +1181,7 @@ IRValue load_src( ) { auto ctx = co_yield get_context(); auto vec = co_yield load_from_array_at( - ctx.resource.icb_float, co_yield load_operand_index(cb.regindex) + ctx.resource.icb_float, ctx.types._float4, co_yield load_operand_index(cb.regindex) ); co_return vec; }; @@ -1198,7 +1205,7 @@ IRValue load_src(SrcOperandInputOCP input_ocp) { auto ctx = co_yield get_context(); co_return co_yield load_from_array_at( - ctx.resource.output.ptr_float4, + ctx.resource.output.ptr_float4, ctx.types._float4, ctx.builder.CreateAdd( ctx.builder.CreateMul( co_yield load_operand_index(input_ocp.cpid), @@ -1214,7 +1221,7 @@ IRValue load_src(SrcOperandInputOCP input_ocp) { auto ctx = co_yield get_context(); co_return co_yield load_from_array_at( - ctx.resource.output.ptr_int4, + ctx.resource.output.ptr_int4, ctx.types._int4, ctx.builder.CreateAdd( ctx.builder.CreateMul( co_yield load_operand_index(input_ocp.cpid), @@ -1230,7 +1237,7 @@ IRValue load_src(SrcOperandInputICP input2d) { auto ctx = co_yield get_context(); /* applies to both hull and domain shader */ co_return co_yield load_from_array_at( - ctx.resource.input.ptr_float4, + ctx.resource.input.ptr_float4, ctx.types._float4, ctx.builder.CreateAdd( ctx.builder.CreateMul( co_yield load_operand_index(input2d.cpid), @@ -1246,7 +1253,7 @@ IRValue load_src(SrcOperandInputICP input2d) { auto ctx = co_yield get_context(); /* applies to both hull and domain shader */ co_return co_yield load_from_array_at( - ctx.resource.input.ptr_int4, + ctx.resource.input.ptr_int4, ctx.types._int4, ctx.builder.CreateAdd( ctx.builder.CreateMul( co_yield load_operand_index(input2d.cpid), @@ -1262,7 +1269,7 @@ IRValue load_src(SrcOperandInputPC input_patch_constant ) { auto ctx = co_yield get_context(); co_return co_yield load_from_array_at( - ctx.resource.patch_constant_output.ptr_float4, + ctx.resource.patch_constant_output.ptr_float4, ctx.types._float4, co_yield load_operand_index(input_patch_constant.regindex) ); }; @@ -1272,7 +1279,7 @@ IRValue load_src(SrcOperandInputPC input_patch_constan ) { auto ctx = co_yield get_context(); co_return co_yield load_from_array_at( - ctx.resource.patch_constant_output.ptr_int4, + ctx.resource.patch_constant_output.ptr_int4, ctx.types._int4, co_yield load_operand_index(input_patch_constant.regindex) ); }; @@ -1282,12 +1289,12 @@ template <> IRValue load_src(SrcOperandTemp temp) { if (temp.phase != ~0u) { assert(temp.phase < ctx.resource.phases.size()); co_return co_yield load_from_array_at( - ctx.resource.phases[temp.phase].temp.ptr_float4, + ctx.resource.phases[temp.phase].temp.ptr_float4, ctx.types._float4, ctx.builder.getInt32(temp.regid) ); } co_return co_yield load_from_array_at( - ctx.resource.temp.ptr_float4, ctx.builder.getInt32(temp.regid) + ctx.resource.temp.ptr_float4, ctx.types._float4, ctx.builder.getInt32(temp.regid) ); }; @@ -1296,12 +1303,12 @@ template <> IRValue load_src(SrcOperandTemp temp) { if (temp.phase != ~0u) { assert(temp.phase < ctx.resource.phases.size()); co_return co_yield load_from_array_at( - ctx.resource.phases[temp.phase].temp.ptr_int4, + ctx.resource.phases[temp.phase].temp.ptr_int4, ctx.types._int4, ctx.builder.getInt32(temp.regid) ); } co_return co_yield load_from_array_at( - ctx.resource.temp.ptr_int4, ctx.builder.getInt32(temp.regid) + ctx.resource.temp.ptr_int4, ctx.types._int4, ctx.builder.getInt32(temp.regid) ); }; @@ -1317,7 +1324,9 @@ IRValue load_src(SrcOperandIndexableTemp itemp) { regfile = ctx.resource.indexable_temp_map[itemp.regfile]; } auto s = co_yield load_from_array_at( - regfile.ptr_float_vec, co_yield load_operand_index(itemp.regindex) + regfile.ptr_float_vec, + llvm::FixedVectorType::get(ctx.types._float, regfile.vec_size), + co_yield load_operand_index(itemp.regindex) ); co_return co_yield extend_to_vec4(s); }; @@ -1335,7 +1344,9 @@ IRValue load_src(SrcOperandIndexableTemp itemp regfile = ctx.resource.indexable_temp_map[itemp.regfile]; } auto s = co_yield load_from_array_at( - regfile.ptr_int_vec, co_yield load_operand_index(itemp.regindex) + regfile.ptr_int_vec, + llvm::FixedVectorType::get(ctx.types._int, regfile.vec_size), + co_yield load_operand_index(itemp.regindex) ); co_return co_yield extend_to_vec4(s); }; @@ -1343,7 +1354,7 @@ IRValue load_src(SrcOperandIndexableTemp itemp template <> IRValue load_src(SrcOperandInput input) { auto ctx = co_yield get_context(); auto s = co_yield load_from_array_at( - ctx.resource.input.ptr_float4, ctx.builder.getInt32(input.regid) + ctx.resource.input.ptr_float4, ctx.types._float4, ctx.builder.getInt32(input.regid) ); co_return s; }; @@ -1351,7 +1362,7 @@ template <> IRValue load_src(SrcOperandInput input) { template <> IRValue load_src(SrcOperandInput input) { auto ctx = co_yield get_context(); auto s = co_yield load_from_array_at( - ctx.resource.input.ptr_int4, ctx.builder.getInt32(input.regid) + ctx.resource.input.ptr_int4, ctx.types._int4, ctx.builder.getInt32(input.regid) ); co_return s; }; @@ -1361,7 +1372,7 @@ IRValue load_src(SrcOperandIndexableInput input ) { auto ctx = co_yield get_context(); auto s = co_yield load_from_array_at( - ctx.resource.input.ptr_float4, co_yield load_operand_index(input.regindex) + ctx.resource.input.ptr_float4, ctx.types._float4, co_yield load_operand_index(input.regindex) ); co_return co_yield extend_to_vec4(s); }; @@ -1371,7 +1382,7 @@ IRValue load_src(SrcOperandIndexableInput input ) { auto ctx = co_yield get_context(); auto s = co_yield load_from_array_at( - ctx.resource.input.ptr_int4, co_yield load_operand_index(input.regindex) + ctx.resource.input.ptr_int4, ctx.types._int4, co_yield load_operand_index(input.regindex) ); co_return co_yield extend_to_vec4(s); }; @@ -1540,7 +1551,7 @@ auto recover_mask(uint32_t mask) { assert(0 && "invalid mask"); } } - int p = llvm::UndefMaskElem; + int p = kMaskedShuffleElem; switch (mask) { case 0b1000: return ctx.builder.CreateShuffleVector(value, {p, p, p, 0}); @@ -1683,7 +1694,9 @@ IREffect store_dst( regfile = ctx.resource.indexable_temp_map[itemp.regfile]; } co_return co_yield store_at_vec_array_masked( - regfile.ptr_int_vec, co_yield load_operand_index(itemp.regindex), + regfile.ptr_int_vec, + llvm::FixedVectorType::get(ctx.types._int, regfile.vec_size), + co_yield load_operand_index(itemp.regindex), co_yield std::move(value), itemp._.mask ); } @@ -1706,7 +1719,9 @@ IREffect store_dst( regfile = ctx.resource.indexable_temp_map[itemp.regfile]; } co_return co_yield store_at_vec_array_masked( - regfile.ptr_float_vec, co_yield load_operand_index(itemp.regindex), + regfile.ptr_float_vec, + llvm::FixedVectorType::get(ctx.types._float, regfile.vec_size), + co_yield load_operand_index(itemp.regindex), co_yield std::move(value), itemp._.mask ); } @@ -2032,8 +2047,7 @@ auto store_tgsm( auto ctx = co_yield get_context(); for (uint32_t i = 0; i < written_components; i++) { auto ptr = ctx.builder.CreateInBoundsGEP( - llvm::cast(g->getType()) - ->getNonOpaquePointerElementType(), + llvm::cast(g)->getValueType(), g, {ctx.builder.getInt32(0), ctx.builder.CreateAdd(offset_in_4bytes, ctx.builder.getInt32(i))} @@ -5028,4 +5042,4 @@ struct environment_cast<::dxmt::dxbc::context, ::dxmt::air::AIRBuilderContext> { ::dxmt::air::AIRBuilderContext cast(const ::dxmt::dxbc::context &src) { return {src.llvm, src.module, src.builder, src.types}; }; -}; \ No newline at end of file +}; diff --git a/src/libs/dxmt-0.60/src/airconv/dxbc_converter_gs.cpp b/src/libs/dxmt-0.60/src/airconv/dxbc_converter_gs.cpp index b8c6170e479d..6ce4880ca5c8 100644 --- a/src/libs/dxmt-0.60/src/airconv/dxbc_converter_gs.cpp +++ b/src/libs/dxmt-0.60/src/airconv/dxbc_converter_gs.cpp @@ -611,7 +611,7 @@ convert_dxbc_vertex_for_geometry_shader( llvm::ArrayType::get(types._int4, max_output_register)->getPointerTo((uint32_t)air::AddressSpace::object_data) ); resource_map.output.ptr_int4 = builder.CreateGEP( - resource_map.output.ptr_int4->getType()->getNonOpaquePointerElementType(), resource_map.output.ptr_int4, + llvm::ArrayType::get(types._int4, max_output_register), resource_map.output.ptr_int4, {warp_vertex_id} ); resource_map.output.ptr_float4 = builder.CreateBitCast( @@ -619,7 +619,7 @@ convert_dxbc_vertex_for_geometry_shader( llvm::ArrayType::get(types._float4, max_output_register)->getPointerTo((uint32_t)air::AddressSpace::object_data) ); resource_map.output.ptr_float4 = builder.CreateGEP( - resource_map.output.ptr_float4->getType()->getNonOpaquePointerElementType(), resource_map.output.ptr_float4, + llvm::ArrayType::get(types._float4, max_output_register), resource_map.output.ptr_float4, {warp_vertex_id} ); @@ -678,7 +678,7 @@ convert_dxbc_vertex_for_geometry_shader( if (index_buffer_idx != ~0u) { auto start_index = builder.CreateExtractValue(draw_arguments, 2); auto index_buffer = function->getArg(index_buffer_idx); - auto index_buffer_element_type = index_buffer->getType()->getNonOpaquePointerElementType(); + auto index_buffer_element_type = ia_layout->index_buffer_format == 1 ? types._short : types._int; auto vertex_id = builder.CreateLoad( index_buffer_element_type, builder.CreateGEP(index_buffer_element_type, index_buffer, {builder.CreateAdd(start_index, global_index_id)})