Skip to content

Commit

Permalink
Merge pull request #6 from cezbloch/linux_compilation
Browse files Browse the repository at this point in the history
Linux compilation
  • Loading branch information
cezbloch authored Nov 9, 2024
2 parents 825f58f + 92e93f4 commit 4ffc90d
Show file tree
Hide file tree
Showing 25 changed files with 322 additions and 123 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/cmake_single_platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: CMake on a single platform

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}} --verbose
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@
/packages
/.idea
/examples/OpenCL/IntelBitonicSort/BitonicSort/.vs/BitonicSort_2015/v15

# Linux
build/

# VS Code
.vscode/
41 changes: 41 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.10)
project(Shaderator)
#project(recipe-07 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


include(GNUInstallDirs)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})


# defines targets and sources
add_subdirectory(Shaderator)

# Include directories for Shaderator
target_include_directories(Shaderator
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/glm
)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

# Add an option to build tests
option(BUILD_TESTS "Build Shaderator tests" ON)

# enable testing and define tests
if(BUILD_TESTS)
enable_testing()
add_subdirectory(ShaderatorTests)
add_subdirectory(examples)
endif()
85 changes: 4 additions & 81 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,84 +1,7 @@
Some elements of this software are derived from or make use of material
that is subject to the terms of The Happy Bunny License (Modified MIT License).
The The Happy Bunny License (Modified MIT License) in question is shown below:
Copyright (c) 2024 Cezary Bloch

================================================================================
OpenGL Mathematics (GLM)
--------------------------------------------------------------------------------
GLM is licensed under The Happy Bunny License and MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

================================================================================
The Happy Bunny License (Modified MIT License)
--------------------------------------------------------------------------------
Copyright (c) 2005 - 2014 G-Truc Creation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

Restrictions:
By making use of the Software for military purposes, you choose to make a
Bunny unhappy.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

================================================================================
The MIT License
--------------------------------------------------------------------------------
Copyright (c) 2005 - 2014 G-Truc Creation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Some elements of this software are derived from or make use of material
that is subject to the terms of The MIT License (MIT).
The MIT License (MIT) in question is shown below:

The MIT License (MIT)

Copyright (c) 2017 Microsoft Corp

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
80 changes: 65 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[![Build Status](https://potrecs.visualstudio.com/_apis/public/build/definitions/76cd276e-183c-4a57-9255-523bf379583d/2/badge)](https://potrecs.visualstudio.com/Shaderator/_build/index?definitionId=2)

# What is this?
Shaderator is a productivity library intended to speed up complex Compute Shader development. It also provides means to Unit Tests shader code offering protection against regressions. Click on the image below to see the Lighting Talk from ACCU 2018 Conference.

Expand All @@ -8,21 +6,81 @@ Shaderator is a productivity library intended to speed up complex Compute Shader
# What problem does it solve?
Due to the nature of GPUs shaders are hard to debug. Back in the day developer wrote one, executed a batch and hoped for the best that the result is correct. Kernel function is usually executed hundreds of thousand times writing data to output buffer which can only be looked up when the Dispatch finished. This tool compiles .hlsl shader code to C++ and enables developer to leverage full Visual Studio debugging functionality to quickly find problems in the code.

# Getting started with debugging
# Setup

If you use VS Code install recommended extensions from

```configs/recommended_extensions.json```

## Linux

Install compiler and build tools

```sudo apt-get install -y cmake build-essential gdb```

# Building

Shaderators uses CMake to setup and run the build process.

## Linux

Run the following commands to build:

```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON ..
make
```

CMake will download the neccessary dependencies like GoogleTests.

# Unit testing

To execute unit tests run from command line run

```ctests --verbose```

When using VS Code and all the recommended extensions were installed, then tests should be visible in the 'Test Explorer UI'.


# Examples

There are several examples in folder ```examples``` how to write a test for you shaders/kernels. The idea is not leave the production code as much untouched as possible, but it's not always possible. Sometimes variables or data types need to be wrapped in a ```Shaderator``` macros.

You also need to write an ```executor``` which will handle input and exectution of your specific kernel.

There are examples for:
- Direct Compute HLSL
- OpenGL GLSL
- OpenCL C

Functionality for your specific kernel may be missing and would need to be added. If that is the case please submit an issue or feature request on github.

# FAQ

## Will this work with any shader?
Not yet, the project is in it's early phase, however it should work with many shaders. If there is interest, support for more HLSL language features will be added.
At the moment matrices are not supported yet.

# Problems or feedback

Submit any issues on github. Feel free to contact the author directly with information available on github.


# (old instructions) Windows - Getting started with debugging

NOTE: This instructions are from year 2018 and serve as reference. Running Shaderator on Windows has not been tried since then.

1. Open Shaderator.sln in VS 2017
2. Build solution (better choose Debug configuration to see more variables under debugger)
3. Set ComputeShaderSort11 in examples folder as startup project (right click on the project in Visual Studio and select "Set as StartUp Project")
4. Put breakpoint anywhere in ComputeShaderSort11.hlsl shader file
5. Press F5 to Debug

![](http://oi65.tinypic.com/358dwm1.jpg)

VS will start regular debugging session and you will be able to debug the .hlsl shader code as C++ code. You can see all variables, can add them to watch, pin or look-up values when hovering the mouse.
CPU shader is obviously very slow. The intention is to provide tools for faster Computer Shader development.

![](http://oi67.tinypic.com/1zp6rvc.jpg)

If you have Visual Assist X installed debugging experience may be reduced.

# Getting started with Unit Tests
Expand All @@ -37,11 +95,3 @@ If you have Visual Assist X installed debugging experience may be reduced.

* Windows 10
* Visual Studio 2017

# Will this work with any shader?
Not yet, the project is in it's early phase, however it should work with many shaders. If there is interest, support for more HLSL language features will be added.
At the moment matrices are not supported yet.

# Problems or feedback

Please e-mail me at cez dot bloch at gmail dot com, you can also find email on my github profile.
33 changes: 33 additions & 0 deletions Shaderator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
add_library(Shaderator "")

target_sources(Shaderator
PRIVATE
cpp_functions.cpp
Engine.cpp
CpuTimeMeasurement.cpp
opencl_support.cpp
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/access_counting_container.h
${CMAKE_CURRENT_LIST_DIR}/Barrier.h
${CMAKE_CURRENT_LIST_DIR}/cpp_include.h
${CMAKE_CURRENT_LIST_DIR}/element.h
${CMAKE_CURRENT_LIST_DIR}/Engine.h
${CMAKE_CURRENT_LIST_DIR}/CpuTimeMeasurement.h
${CMAKE_CURRENT_LIST_DIR}/glsl_include.h
${CMAKE_CURRENT_LIST_DIR}/hlsl_include.h
${CMAKE_CURRENT_LIST_DIR}/OpenCLEngine.h
${CMAKE_CURRENT_LIST_DIR}/opencl_support.h
${CMAKE_CURRENT_LIST_DIR}/opencl_types.h
${CMAKE_CURRENT_LIST_DIR}/thread_joiner.h
${CMAKE_CURRENT_LIST_DIR}/shaderator.h
${CMAKE_CURRENT_LIST_DIR}/shader_types.h
${CMAKE_CURRENT_LIST_DIR}/texture_2d.h
${CMAKE_CURRENT_LIST_DIR}/thread_pool.h
${CMAKE_CURRENT_LIST_DIR}/threadsafe_queue.h

)

target_include_directories(Shaderator
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
2 changes: 1 addition & 1 deletion Shaderator/OpenCLEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Shaderator { namespace OpenCL {
public:
using Kernel = std::function<void(Args...)>;

Engine::Engine(Kernel main, ClearGroupSharedVariables clear_function, uint3 numThreads)
Engine(Kernel main, ClearGroupSharedVariables clear_function, uint3 numThreads)
: kernel_(main)
, clear_groupshared_variables_(clear_function)
, threads_amount_in_group_(numThreads)
Expand Down
2 changes: 1 addition & 1 deletion Shaderator/access_counting_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AccessCountingContainer

void reset_access_counts()
{
std::memset(&access_counts_[0], 0, (sizeof uint) * size_.x * size_.y);
std::memset(&access_counts_[0], 0, sizeof(uint) * size_.x * size_.y);
for (auto& el : data_) {
el.reset_count();
}
Expand Down
24 changes: 18 additions & 6 deletions Shaderator/cpp_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
#include "cpp_include.h"
#include "Barrier.h"
#include "windows.h"
//#include "windows.h"
#include <atomic>
//#include <cassert>


static std::unique_ptr<Barrier> g_GroupMemoryBarrierWithGroupSync;

void ShaderInterlockedOr(int& dest, int value)
// void ShaderInterlockedOr(int& dest, int value)
// {
// InterlockedOr(reinterpret_cast<long*>(&dest), value);
// }

// void ShaderInterlockedAnd(int& dest, int value)
// {
// InterlockedAnd(reinterpret_cast<long*>(&dest), value);
// }

void ShaderInterlockedOr(std::atomic<int>& dest, int value)
{
InterlockedOr(reinterpret_cast<long*>(&dest), value);
dest.fetch_or(value, std::memory_order_seq_cst);
}

void ShaderInterlockedAnd(int& dest, int value)
void ShaderInterlockedAnd(std::atomic<int>& dest, int value)
{
InterlockedAnd(reinterpret_cast<long*>(&dest), value);
dest.fetch_and(value, std::memory_order_seq_cst);
}

void ShaderAssert(bool expression)
Expand Down Expand Up @@ -96,7 +108,7 @@ int compareInts(int x, int y)

// From OpenCL 1.2 Specification:
// "For vector types, the relational operators shall return 0 if the specified
// relation is false and 1(i.e.all bits set) if the specified relation is true."
// relation is false and 1(i.e.all bits set) if the specified relation is true."
int4 operator<(int4 v1, int4 v2)
{
int4 result;
Expand Down
3 changes: 3 additions & 0 deletions Shaderator/opencl_support.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <thread>

#include "opencl_support.h"
#include "cpp_include.h"


std::mutex g_thread_descriptions_mutex;
std::map<std::thread::id, ThreadDescription> g_thread_descriptions;

Expand Down
Loading

0 comments on commit 4ffc90d

Please sign in to comment.