Twitter

Pinboard Bookmarks

LinkedIn

Blog Tags

Blog

23:38
Thu
27
Apr 2017

I Implemented Video and GIF Playback with FFmpeg

I started my music visualization project with a possibility to load a collection of static images, accompanied with metadata that describe their parameters like dominant colors, whether it uses alpha transparency or whether it is tileable (description of these parameters could be a topic of another blog post). I then render them as textures, moving, rotating and changing colors randomly, blended together, with a possibility of feedback from previous frame. This mathod may sometimes generate quite interesting images, but it has its own limitations and becomes boring after some time.

Generating some interesting graphics procedurally from scratch is my ultimate goal. But while writing shaders is fun and can give amazing results (as we can see on ShaderToy), it's also the hard way. So to be able to show something interesting, for now I've implemented playback of videos and animated GIFs, using FFmpeg library.

FFmpeg is a free tool that contains its own codecs for various video and audio formats (so it doesn't use the codecs installed in Windows). It is known as a command-line program that can convert about any video format, but it's also a software library that offers this encoding/decoding features to developers. I learned to use this library because I needed to implement video playback for one of my shows.

Later I discovered that it can play animated GIFs as well. This is a great feature, because having hundreds of such GIFs downloaded and being able to switch between them in an instant can make quite interesting visuals. There are many abstract, geometric, psychedelic animations shared all around the Internet, like on Op Art or Fractalgasm Facebook pages. At the same time, possibility to play all popular video formats is much more comfortable than what Resolume offers, which requires converting all the footage to its own codec, called DXDI (by the way, FFmpeg is able to play this as well).

I won't show any source code this time, but if you are a developer and consider implementing support for video playback or encoding, I recommend FFmpeg library. Other option is libVLC - a library behind popular VLC media player, which also has its own set of codecs. I also used it some time ago. Playing anmimated GIF-s is also possible through Windows Imaging Component (WIC), which is part of standard Windows API.

Comments (0) | Tags: graphics video vj | Author: Adam Sawicki | Share

12:59
Mon
24
Apr 2017

New Job at AMD

It's already 3 months after I started a new job, so I think I can write something about it. Before that I've spent last 5 years living in Gdańsk and working at Intel. I've been developing shader compiler, which is part of the driver for Intel integrated GPU-s.

Now I moved back to Warsaw and I work at AMD. My position is called Developer Technology Engineer. (Other name is SMTS Software Developer Engineer - Senior Member of Technical Staff. You can find my colleagues on LinkedIn specifying one or the other.) This job is quite different. I'm responsible for cooperation with game development studios to make sure their PC games work well on AMD graphics cards. On the other hand, it's similar in the way that I still work with native C++ code, graphics APIs (like DirectX, Vulkan), shaders, and low-level GPU stuff,  yet it's not a work strictly in the game industry - so a very unique position.

Comments (1) | Tags: career | Author: Adam Sawicki | Share

20:33
Thu
20
Apr 2017

Revision 2017

I just came back from Revision - world's biggest pure demoscene party. It was held in Saarbrücken, Germany. That was first time I attended a demoparty abroad, as I've been going only to the ones in Poland so far, like RiverWash, WeCan, Silly Venture, or AmiWaWa.

I don't like the fact that it happens during Easter, when I usually go visit my parents, but I wanted to see it at least once. Revision was big, with around 700 participants, according to the page with non-mandatory registration - Visitors. There were various kinds of activities - from Seminars to techno party, and of course most importantly - competitions. Revision is a multiplatform demoparty, so there were compo categories dedicated to retro platforms (like Amiga, pixel art or tracker music), as well as modern PCs (like modern graphics, streaming music, PC 4K/8K/64K intro and demo). Entries can be found here: Revision 2017 @ pouet.net.

Many people said that PC 4K Intro category had best quality this year, so it's worth checking. Other than that, productions that I remembered the most are:

"Soul Splitter" by cocoon, 1st place, PC demo

"PC demo" by Aberration Creations, 2nd place, Animation

"Evolve" by Schengen Allstars, Invitation demo

Most exciting for me was watching Shader Showdown - a competition where two programmers had to write a pixel shader live on stage, without any documentation or other help, in a time frame of 25 minutes per round. Winner moved on to semifinals and then the final. During each round a DJ was playing some music and its live FFT was available as one of the inputs to the shader. It's amazing to see how good knowledge of programming, graphics and math allows to develop some nice looking visualizations in such a short period of time. I've also heard opinions that watching it gave a good glimpse of how graphics programming looks like and what does it take to make a demo, even for non-technical people.

Here is a gallery of my photos from the event:

Comments (0) | Tags: demoscene events gallery | Author: Adam Sawicki | Share

21:22
Sun
09
Apr 2017

EditorConfig to the Rescue for Multiple Projects

I was once asked to participate in a project where coding standard required to use indentation of 3 spaces - different than what I do normally, when I use 4 spaces. I was searching Internet for answer whether Visual Studio supports per-project settings for this and I've found out that it doesn't, but came across this instead: EditorConfig.

This technology is so simple you can learn all about it in just few minutes, still very useful for cases like mine. You can basically create text file called .editorconfig in root directory of your project and describe configuration for editors using a simple language. For example:

root = true
[**]
charset = utf-8
indent_style = space
indent_size = 3

Of course your text editor must support that. It turns out many of them support this standard natively. Editors I care about have plugins for that available. Unfortunately the one for jEdit doesn't seem to work (I've reported this issue), but the one for Visual Studio works perfectly. Now I could have per-project configuration for text editor, including character set, line ending type, and indentation type (tabs versus spaces and the number of spaces).

Comments (1) | Tags: ide | Author: Adam Sawicki | Share

19:32
Fri
07
Apr 2017

There are Too Many Messaging Apps

I can remember time when Internet was still young and the basic mean of communication was e-mail. Real-time chat was possible through IRC protocol. Later, changes came with the appearance of Instant Messaging (IM) apps, from which ICQ was probably the first. There were many of them, all having similar, basic functionality - list of contacts, seeing their status (available, away, offline) and chat. Gadu-Gadu (renamed later to GG) was local one very popular in Poland, but others were also in use, like AOL, MSN, Jabber.

Over time clients for those networks became bloated with more or less useful features, fancy skins and emoticons, and of course lots of ads - which all consumed additional RAM and CPU time, not to mention just being annoying. Then, something wonderful happened - alternative clients started to appear. Whether based on open protocols (like Jabber) or reverse-engineering others, these multi-communicators were often lightweight, supported alternative platforms (like Pidgin working on Linux) and integrated support for many protocols in a single app, with single list of contacts and unified user interface. My favorite one was Konnekt and later AQQ.

New era started probably with Skype, which for most of us was an introduction to new features like audio- and videochat. Next generation communication apps became more complex, provide more useful features, but at the same time they are even more resource-heavy and (in case of smartphones) drain battery. For some reasons they have no alternative clients (probably because their protocols are more complex, proprietary, and encrypted). And there are many of them. So here I am today, having multiple messaging apps installed on my smartphone. I do most of chatting with my friends via Facebook Messenger these days, but some of them prefer other program, so I ocasionally use also: Skype, Telegram, WhatsApp, Signal, Slack, Google Talk and Hangouts, plus of course the old good phone calls, SMS, and e-mail. What a mess!

At the same time I can see they all start to converge. They look similar as it becomes more and more clear what's the optimal user interface for such app. Features added to some of them quickly appear in others, like end-to-end encryption or (most recently) commenting others' messages with a smiley. So I think the future is once again to have a single messaging app. I only hope it will be just a GUI supporting multiple protocols, and not one of those "Big Brother" corporations (who already know everything about as) dominating all the messaging, just like Gmail dominated market of e-mail servers and readers.

Comments (1) | Tags: internet | Author: Adam Sawicki | Share

00:34
Thu
06
Apr 2017

Vulkan Bits and Pieces: Writing to an Attachment

One of the reasons why new generation graphics APIs (DirectX 12 and Vulkan) are so complicated, is that they have so many levels of indirection in referring to anything. For example, when you render pixels to a color attachment (also known as “render target” in other APIs), the path is as follows:

  1. GLSL fragment shader writes to a variable with some NAME, e.g. “outColor”:
    outColor = vec4(1.0, 0.0, 0.0, 1.0);
  2. The variable is defined earlier in this shader as output and bound to a specific LOCATION, e.g. number 0:
    layout(location = 0) out vec4 outColor;
  3. Switching to C/C++ code, this location is actually index to array pointed by VkSubpassDescription::​pColorAttachments - member of the structure that describes rendering subpass.
  4. Each element of this array in its member VkAttachmentReference::​attachment provides another INDEX, this time to an array pointed by VkRenderPassCreateInfo::​pAttachments - member of the structure that describes rendering pass.
  5. Elements of this array of type VkAttachmentDescription provide just few parameters, like format.
  6. But this index also refers to elements of array pointed by VkFramebufferCreateInfo::​pAttachments - member of a structure filled when creating a framebuffer that is going to be pointed by VkRenderPassBeginInfo::​framebuffer when starting actual execution of the render pass.
  7. Rest is business as usual. Elements of this array are of type VkImageView, so each of them is a VIEW to an image, pointed by VkImageViewCreateInfo::​image - member of a structure used when creating the view.
  8. The IMAGE (type VkImage) is either obtained from swap chain using function vkGetSwapchainImagesKHR, or created manually using function vkCreateImage.
  9. In the latter case, you must also allocate MEMORY (type VkDeviceMemory) with function vkAllocateMemory and bind its fragment to the image using function vkBindImageMemory. This is the memory that will be actually written.

Yeah, Vuklan is hard…

Comments (0) | Tags: vulkan graphics | Author: Adam Sawicki | Share

20:08
Thu
30
Mar 2017

Microsoft Visual Studio 2017 - My Experience

Visual Studio 2017 came out recently. The list of news looks like it has been written by some marketing rather than technial guys. It starts with "Unparalleled productivity for any dev, any app, and any platform. Use Visual Studio 2017 to develop apps for Android, iOS, Windows, Linux, web, and cloud. Code fast, debug and diagnose with ease, test often, and release with confidence. You can also extend and customize Visual Studio by building your own extensions. Use version control, be agile, and collaborate efficiently with this new release!" - I've never seen so many buzzwords in just one paragraph.

Rest of the page is not different. They even call their installer "a new setup experience". They've also introduced "Lightweight Solution load", which is disabled by default - like everyone is assumed to prefer slower option :) Some other changes: "Visual Studio starts faster, is more responsive, and uses less memory than before." - that's unexpected direction. "Performance improvement: basic_string::operator== now checks the string's size before comparing the strings' contents." - wow, that's genius! They should file a patent for that ;) I hope they do the same for std::vector and other STL containers.

OK, but jokes aside, I've installed it on my personal PC, it installed quite fast and it works good. It preserved my settings, like the list of Include and Library Directories. Upgrade of my home projects went smoothly, without any problems.

There are many changes valuable for native code developers. What's New for Visual C++ in Visual Studio 2017 page mentions over 250 bug fixes, other compiler improvements and improved support for C++11, 14, and 17. I've already heard stories of programs running much faster after recompilation with this new compiler.

Contrary to what I thought before, Microsoft didn't abandon Graphics Diagnostics embedded into MSVS after they released new standalone PIX. They've actually added some new features to it.

So I definitely recommend upgrading to Visual Studio 2017. It is IMHO the best C++ IDE, and the new version is just next step in the right direction.

It seems that there is no new version of "Microsoft Visual C++ Redistributable Package" this time. Programs compiled with VS 2017 use VCRUNTIME140.DLL, just like in 2015 version.

Comments (0) | Tags: c++ visual studio | Author: Adam Sawicki | Share

15:50
Sat
11
Mar 2017

How to change display mode using WinAPI?

If you write a graphics application or a game, you may want to make it fullscreen and set specific screen resolution. In DirectX there are functions for that, but if you use OpenGL or Vulkan, you need another way to accomplish that. I've researched the topic recently and I've found that Windows API supports enumerating display devices and modes with functions: EnumDisplayDevices, EnumDisplaySettings, as well as changing mode with function ChangeDisplaySettingsEx. It's a programatic access to more or less the same set of features that you can access manually by going to "Display settings" system window.

I've prepared an example C program demonstrating how to use these functions:

DisplaySettingsTest - github.com/sawickiap

First you may want to enumerate available Adapters. To do this, call function EnumDisplayDevices multiple times. Pass NULL as first parameter (LPCWSTR lpDevice). As the second parameter pass subsequent DWORD Adapter index, starting from 0. Enumeration should continue as long as the function returns BOOL nonzero. When it returns zero, it means there are no more Adapters and that Adapter with given index and any higher index could not be retrieved.

For each successfully retrieved Adapter, DISPLAY_DEVICE structure is filled by the function. It contains following members:

  • WCHAR DeviceName[32] - string with name of the Adapter, like "\\.\DISPLAY1".
  • WCHAR DeviceString[128] - string with more user-friendly name of the Adapter, like "AMD Radeon (TM) RX 480".
  • DWORD StateFlags - various flags, like DISPLAY_DEVICE_ACTIVE if the device is on, or DISPLAY_DEVICE_PRIMARY_DEVICE if this is the primary device.

There is a second level: Adapters contain Display Devices. To enumerate them, use the same function EnumDisplayDevices, but this time pass Adapter DeviceName as first parameter. This way you will enumerate Display Devices inside that Adapter, described by the same structure DISPLAY_DEVICE. For example, my system returns DeviceName = "\\.\DISPLAY1\Monitor0", DeviceString = "Generic PnP Monitor".

The meaning and the difference between "Adapter" and "Display Device" is not fully clear to me. You may think that Adapter is a single GPU (graphics card), but it turns out not to be the case. I have a single graphics card and yet my system reports 6 Adapters, each having 0 or 1 Display Device. That can mean Adapter is more like a single monitor output (e.g. HDMI, DisplayPort, VGA) on the graphics card. This seems true unless you have two monitors running in "Duplicate" mode - then two Display Devices are reported inside one Adapter.

Then there is a list of supported Display Settings (or Modes). You can enumerate them in similar fashion using EnumDisplaySettings function, which fills DEVMODE structure. It seems that Modes belong to an Adapter, not a Display Device, so as first parameter to this function you must to pass DISPLAY_DEVICE::DeviceName returned by EnumDisplayDevices(NULL, ...), not EnumDisplaySettings(adapter.DeviceName, ...). The structure is quite complex, but the function fills only following members:

  • DWORD dmPelsWidth, dmPelsHeight - resolution, in pixels.
  • DWORD dmBitsPerPel - bits per pixel (all Modes have 32 in my case).
  • DWORD dmDisplayFrequency - refresh rate, in Hz.
  • DWORD dmDisplayFlags - additional flags, like DM_INTERLACED for interlaced mode.

I have a single graphics card (AMD Radeon RX 480) with two Full HD (1920 x 1080) monitors connected. You can see example output of the program from my system here: ExampleOutput.txt.

To change display mode, use function ChangeDisplaySettingsEx.

  • As first parameter (LPCTSTR lpszDeviceName), pass DeviceName of the chosen Adapter (again, not Display Device!).
  • As second parameter (DEVMODE *lpDevMode), pass structure filled with desired Display Settings. You can fill it by yourself, but Microsoft recommends to pass the copy of the structure as it was retrieved from function EnumDisplaySettings.
  • As fourth parameter (DWORD dwFlags), you can pass various flags, e.g. whether new settings should be saved in the registry.

The function returns DISP_CHANGE_SUCCESSFUL if display mode was successfully changed and one of other DISP_CHANGE_* constants if it failed.

To restore original display mode, call the function like this:

ChangeDisplaySettingsEx(targetDeviceName, NULL, NULL, 0, NULL);

Unfortunately, display mode changed in the way described here is not automatically restored after user switches to some other application (e.g. using Alt+Tab), like in DirectX fullscreen mode, but you can handle it yourself. Good news is that if you pass CDS_FULLSCREEN flag to ChangeDisplaySettingsEx, the previous mode is automatically restored by the system when your application exits or crashes.

Comments (0) | Tags: windows graphics | Author: Adam Sawicki | Share

Older entries >

STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2017 Adam Sawicki
Copyright © 2004-2017 Adam Sawicki