Add options for 3d acceleration (#1386)

When enabling video_accel3d, as graphics_gl is typically required, will 
by default set it to true unless explicitly set to false.

Enabling these should result in a significant performance improvement 
for any VM where the desktop is being used.

Fixes: #893
Fixes: #1009
This commit is contained in:
Aleksandr Mezin
2021-10-26 15:11:30 +06:00
committed by GitHub
parent 6c9ec5a190
commit dcbfea2f49
7 changed files with 63 additions and 4 deletions

View File

@@ -598,6 +598,8 @@ end
* `graphics_autoport` - Sets autoport for graphics, Libvirt in this case
ignores graphics_port value, Defaults to 'yes'. Possible value are "yes" and
"no"
* `graphics_gl` - Set to `true` to enable OpenGL. Defaults to `true` if
`video_accel3d` is `true`.
* `keymap` - Set keymap for vm. default: en-us
* `kvm_hidden` - [Hide the hypervisor from the
guest](https://libvirt.org/formatdomain.html#elementsFeatures). Useful for
@@ -608,6 +610,8 @@ end
"cirrus", "vmvga", "xen", "vbox", or "qxl".
* `video_vram` - Used by some graphics card types to vary the amount of RAM
dedicated to video. Defaults to 9216.
* `video_accel3d` - Set to `true` to enable 3D acceleration. Defaults to
`false`.
* `sound_type` - [Set the virtual sound card](https://libvirt.org/formatdomain.html#elementsSound)
Defaults to "ich6".
* `machine_type` - Sets machine type. Equivalent to qemu `-machine`. Use

View File

@@ -78,9 +78,11 @@ module VagrantPlugins
else
"passwd='#{config.graphics_passwd}'"
end
@graphics_gl = config.graphics_gl
@video_type = config.video_type
@sound_type = config.sound_type
@video_vram = config.video_vram
@video_accel3d = config.video_accel3d
@keymap = config.keymap
@kvm_hidden = config.kvm_hidden
@@ -299,6 +301,7 @@ module VagrantPlugins
env[:ui].info(" -- Graphics Password: #{@graphics_passwd.empty? ? 'Not defined' : 'Defined'}")
env[:ui].info(" -- Video Type: #{@video_type}")
env[:ui].info(" -- Video VRAM: #{@video_vram}")
env[:ui].info(" -- Video 3D accel: #{@video_accel3d}")
env[:ui].info(" -- Sound Type: #{@sound_type}")
env[:ui].info(" -- Keymap: #{@keymap}")
env[:ui].info(" -- TPM Backend: #{@tpm_type}")

View File

@@ -222,6 +222,24 @@ module VagrantPlugins
graphics.attributes['passwd'] = config.graphics_passwd
end
end
graphics_gl = REXML::XPath.first(xml_descr, '/domain/devices/graphics/gl')
if graphics_gl.nil?
if config.graphics_gl
graphics_gl = REXML::Element.new('gl', REXML::XPath.first(xml_descr, '/domain/devices/graphics'))
graphics_gl.attributes['enable'] = 'yes'
descr_changed = true
end
else
if config.graphics_gl
if graphics_gl.attributes['enable'] != 'yes'
graphics_gl.attributes['enable'] = 'yes'
descr_changed = true
end
else
graphics_gl.parent.delete_element(graphics_gl)
descr_changed = true
end
end
else
# graphics_type = none, remove entire element
graphics.parent.delete_element(graphics) unless graphics.nil?
@@ -280,6 +298,24 @@ module VagrantPlugins
video_model.attributes['vram'] = config.video_vram
end
end
video_accel = REXML::XPath.first(xml_descr, '/domain/devices/video/model/acceleration')
if video_accel.nil?
if config.video_accel3d
video_accel = REXML::Element.new('acceleration', REXML::XPath.first(xml_descr, '/domain/devices/video/model'))
video_accel.attributes['accel3d'] = 'yes'
descr_changed = true
end
else
if config.video_accel3d
if video_accel.attributes['accel3d'] != 'yes'
video_accel.attributes['accel3d'] = 'yes'
descr_changed = true
end
else
video_accel.parent.delete_element(video_accel)
descr_changed = true
end
end
end
# Sound device

View File

@@ -119,8 +119,10 @@ module VagrantPlugins
attr_accessor :graphics_port
attr_accessor :graphics_passwd
attr_accessor :graphics_ip
attr_accessor :graphics_gl
attr_accessor :video_type
attr_accessor :video_vram
attr_accessor :video_accel3d
attr_accessor :keymap
attr_accessor :kvm_hidden
attr_accessor :sound_type
@@ -270,8 +272,10 @@ module VagrantPlugins
@graphics_port = UNSET_VALUE
@graphics_ip = UNSET_VALUE
@graphics_passwd = UNSET_VALUE
@graphics_gl = UNSET_VALUE
@video_type = UNSET_VALUE
@video_vram = UNSET_VALUE
@video_accel3d = UNSET_VALUE
@sound_type = UNSET_VALUE
@keymap = UNSET_VALUE
@kvm_hidden = UNSET_VALUE
@@ -890,6 +894,8 @@ module VagrantPlugins
@graphics_ip = '127.0.0.1' if @graphics_ip == UNSET_VALUE
@video_type = 'cirrus' if @video_type == UNSET_VALUE
@video_vram = 9216 if @video_vram == UNSET_VALUE
@video_accel3d = false if @video_accel3d == UNSET_VALUE
@graphics_gl = @video_accel3d if @graphics_gl == UNSET_VALUE
@sound_type = nil if @sound_type == UNSET_VALUE
@keymap = 'en-us' if @keymap == UNSET_VALUE
@kvm_hidden = false if @kvm_hidden == UNSET_VALUE

View File

@@ -216,9 +216,13 @@
<% end %>
<% if @graphics_type != 'none' %>
<%# Video device -%>
<graphics type='<%= @graphics_type %>' port='<%= @graphics_port %>' autoport='<%= @graphics_autoport %>' listen='<%= @graphics_ip %>' keymap='<%= @keymap %>' <%= @graphics_passwd%> />
<graphics type='<%= @graphics_type %>' port='<%= @graphics_port %>' autoport='<%= @graphics_autoport %>' listen='<%= @graphics_ip %>' keymap='<%= @keymap %>' <%= @graphics_passwd %> <% if not @graphics_gl %>/><% else %>>
<gl enable='yes' />
</graphics><% end %>
<video>
<model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'/>
<model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'<% if not @video_accel3d %>/><% else %>>
<acceleration accel3d='yes'/>
</model><% end %>
</video>
<%#End Video -%>
<% end %>

View File

@@ -112,9 +112,13 @@
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' />
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' >
<gl enable='yes' />
</graphics>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<model type='cirrus' vram='9216' heads='1'>
<acceleration accel3d='yes'/>
</model>
</video>
<rng model='virtio'>
<backend model='random'>/dev/random</backend>

View File

@@ -112,6 +112,8 @@ describe 'templates/domain' do
domain.shares = '1024'
domain.cpuset = '1-4,^3,6'
domain.nodeset = '1-4,^3,6'
domain.video_accel3d = true
end
let(:test_file) { 'domain_all_settings.xml' }
it 'renders template' do