为什么 Linux 没有 DirectX API?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11121258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:58:36  来源:igfitidea点击:

Why is there no DirectX API for Linux?

linuxdirectxdrivers

提问by Brian

Upon considering the driver side implementation for DirectX API on windows systems for modern video cards I was wondering why this implementation is not available on non-windows system, most notably linux.

在考虑用于现代显卡的 Windows 系统上 DirectX API 的驱动程序端实现时,我想知道为什么这个实现在非 Windows 系统上不可用,尤其是 linux。

Since there is an obvious absence of this functionality I can only assume there is a good reason which I am blind to, but in my primitive understanding I simply see the DirectX calls as no more than function entry points on the hardware device. And for the record I am not referring to a compatibility layer (most notably WINE, a project I am amazed by every single day) but a library making direct hardware calls.

由于明显没有这个功能,我只能假设有一个我看不到的充分理由,但在我的原始理解中,我只是将 DirectX 调用视为硬件设备上的函数入口点。根据记录,我指的不是兼容层(最显着的是 WINE,一个我每天都感到惊讶的项目),而是一个直接调用硬件的库。

Is it possible to create an open source version of directx? Would it be possible but obscenely difficult?

是否可以创建一个开源版本的 directx?有可能但非常困难吗?

采纳答案by Zang MingJie

AFAIK, the DirectX contains 3 parts

AFAIK,DirectX 包含 3 个部分

  • Vendor driver (provide low level API defined by DX)
  • DirectX library (use low level API defined by DX to access hardware, provide DirectX API)
  • Software (use DirectX API, ex. game)
  • 供应商驱动程序(提供DX定义的低级API)
  • DirectX 库(使用 DX 定义的底层 API 访问硬件,提供 DirectX API)
  • 软件(使用 DirectX API,例如游戏)

There are no driver providing the low level API defined by DX on linux, so even it is possible to provide the DirectX library, but it won't work without proper vendor driver, and I can't see if there is any vendor is going to create one for their hardware platform.

linux上没有提供DX定义的低级API的驱动程序,所以即使提供DirectX库也是可能的,但如果没有合适的供应商驱动程序,它就无法工作,我也看不出有没有供应商去为他们的硬件平台创建一个。

回答by Ani

Why not just use OpenGL? It supports all the functionality that DirectX does. Do you have a specific reason to use DirectX? As for a reason, Microsoft made DirectXand I guess they didn't see any need to allow it to run on Linux.

为什么不直接使用 OpenGL?它支持 DirectX 的所有功能。您有使用 DirectX 的特定原因吗?至于一个原因,微软制作了 DirectX,我猜他们认为没有必要让它在 Linux 上运行。

You can run DirectX games in Linux using Wine. You can program XNA on Linux using MonoGame. But all of these use OpenGL to provide hardware-accelerated rendering. AFAIK, OpenGL has been (and probably will be) the only option on Linux for the foreseeable future.

您可以使用 Wine 在 Linux 中运行DirectX 游戏。您可以使用MonoGame在 Linux 上对 XNA 进行编程。但所有这些都使用 OpenGL 来提供硬件加速渲染。AFAIK,在可预见的未来,OpenGL 一直是(并且可能将是)Linux 上的唯一选择。

Is it possible to write your own DirectX implementation? Sure - but it involves writing drivers, proprietary knowledge and probably too much cost for anyone to REALLY benefit from it.

是否可以编写自己的 DirectX 实现?当然 - 但它涉及编写驱动程序、专有知识以及可能让任何人真正从中受益的成本太高。

EDIT: These days, DXVKis a very real and performant way to run DirectX applications on Linux.

编辑:如今DXVK是在 Linux 上运行 DirectX 应用程序的一种非常真实且高效的方式。

回答by Zang MingJie

The work to create a port for DirectX would create the same problems as you encounter in WINE. It will never be the same as on Windows. Derived from that principle you would have to look into OpenGL and related multi-platform libraries.

为 DirectX 创建端口的工作会产生与您在 WINE 中遇到的相同的问题。它永远不会与 Windows 相同。根据该原则,您将不得不研究 OpenGL 和相关的多平台库。

At this very moment WINE would be your closest medium if you want to accomplish something with DirectX code you already have. Then again, I'm not sure in what manner Visual Studio or plain typing would get you closer yo a fluent environment. The WINE libraries aren't that far from native, but there always exists emulation, what is acceptable to a certain point in my honest opinion.

此时此刻,如果您想用已有的 DirectX 代码完成某些事情,WINE 将是您最接近的媒介。再说一次,我不确定 Visual Studio 或普通键入会以何种方式让您更接近流畅的环境。WINE 库与原生库相距不远,但始终存在仿真,在我的诚实看来,在某种程度上可以接受。

If I look at how superbly Final Fantasy XIV ran on full settings on my iMac (2011) I think it's not that bad to rely on WINE's implementation. The game exactly rendered as on Bootcamp (Windows) on my iMac.

如果我看看《最终幻想 XIV》在我的 iMac (2011) 上的完整设置上运行得多么出色,我认为依赖 WINE 的实现并没有那么糟糕。在我的 iMac 上完全按照 Bootcamp (Windows) 渲染的游戏。

If you really want to make work on this front you could try to ask WINE Devs at their forums or mailing lists how you could maybe use the implementation of their DirectX compatibility only and use that in your project. Where you maybe can call libraries instead of requesting DirectX through Windows-emulated system calls.

如果您真的想在这方面开展工作,您可以尝试在他们的论坛或邮件列表中询问 WINE 开发人员如何仅使用他们的 DirectX 兼容性的实现并在您的项目中使用它。您可以在其中调用库而不是通过 Windows 模拟系统调用请求 DirectX。

Edit: I fully agree with user956030's answer too.

编辑:我也完全同意 user956030 的回答。

回答by Wintery

DirectX is a suit of API's:

DirectX 是一套 API:

  • Direct3D(drawing 3D graphics)
  • DirectX Graphics Infrastructure(enumerating adapters and monitors and managing swap chains)
  • Direct2D(drawing 2D graphics)
  • DirectWrite(fonts)
  • DirectCompute(GPU Computing)
  • DirectSound3D(playback of 3D sounds)
  • DirectX Media(DirectAnimation for 2D/3D web animation, DirectShow for multimedia playback and streaming media, DirectX Transform for web interactivity, and Direct3D Retained Mode for higher level 3D graphics)
  • DirectX Diagnostics(tool for diagnosing and generating reports on components related to DirectX, such as audio, video, and input drivers)
  • DirectX Media Objects(support for streaming objects such as encoders, decoders, and effects)
  • DirectSetup(installation of DirectX components, and the detection of the current DirectX version)
  • Direct3D(绘制 3D 图形)
  • DirectX 图形基础结构(枚举适配器和监视器以及管理交换链)
  • Direct2D(绘制二维图形)
  • DirectWrite(字体)
  • DirectCompute(GPU 计算)
  • DirectSound3D(播放 3D 声音)
  • DirectX 媒体(用于 2D/3D 网络动画的 DirectAnimation,用于多媒体播放和流媒体的 DirectShow,用于网络交互的 DirectX 变换,以及用于更高级别 3D 图形的 Direct3D 保留模式)
  • DirectX 诊断(用于诊断和生成与 DirectX 相关的组件(例如音频、视频和输入驱动程序)的报告的工具)
  • DirectX 媒体对象(支持编码器、解码器和效果器等流媒体对象)
  • DirectSetup(安装 DirectX 组件,以及检测当前 DirectX 版本)

DirectX components deprecated, but still supported

DirectX 组件已弃用,但仍受支持

  • DirectDraw
  • DirectInput
  • DirectPlay
  • DirectSound
  • DirectMusic
  • 直接绘图
  • 直接输入
  • 直接播放
  • 直达声
  • 直接音乐

As you can see many parts of the DirectX suit of API's would need to be rewritten with functionality for Drivers written for Linux. Also some parts of the DirectX suit are likely going to make calls to the Windows OS and that code would have to rewritten for a Linux machine without infringement of the copy-written parts of either DirectX or the Windows OS.

正如您所看到的,DirectX API 套件的许多部分需要使用为 Linux 编写的驱动程序的功能进行重写。此外,DirectX 诉讼的某些部分可能会调用 Windows 操作系统,并且必须为 Linux 机器重写该代码,而不会侵犯 DirectX 或 Windows 操作系统的复制编写部分。

Yes you could write a open source API suit which does the same kind of thing as DirectX for Linux, however without a great knowledge of sound and graphic drivers/support by their manufactures for Linux, it would be a very hard task to do.

是的,您可以编写一个开源 API 套件,它与 Linux 的 DirectX 做同样的事情,但是如果没有他们对 Linux 制造商的声音和图形驱动程序/支持的丰富知识,这将是一项非常艰巨的任务。

However if you question was more of a "Can I get/write something to be able to run games and programs made with DirectX to run on Linux?" in it's meaning, in short no due to more likely copyright infringement.

但是,如果您的问题更多是“我可以得到/编写一些能够在 Linux 上运行使用 DirectX 制作的游戏和程序的东西吗?” 就其意义而言,简而言之,不是因为更可能侵犯版权。

回答by Steve

DirectX is a propriety products designed for Microsoft targets, so for this to happen would be very unusual

DirectX 是专为 Microsoft 目标设计的专有产品,因此发生这种情况非常不寻常

There are two other pieces of software that come to mind, SDL and OpenGL

我想到了另外两个软件,SDL 和 OpenGL

OpenGL provides the hardware alternative to DirectX, and SDL works with OpenGL to provide the software support you would expect from DirectX

OpenGL 提供 DirectX 的硬件替代方案,SDL 与 OpenGL 一起提供您期望从 DirectX 获得的软件支持

回答by noone

Your question is wrong in 2019. DXVKis an implementation of D3D11 and D3D10 implementation for Linux using Vulkan and Wine

你的问题在 2019 年是错误的。DXVK是使用 Vulkan 和 Wine 为 Linux 实现的 D3D11 和 D3D10 实现

Also mesa has native Direct3D 9 implementation but in my knowledge, no one uses it except wine

mesa 也有原生 Direct3D 9 实现,但据我所知,除了 wine 没有人使用它