Giter Site home page Giter Site logo

dragonjoker / ashes Goto Github PK

View Code? Open in Web Editor NEW
358.0 17.0 19.0 500.78 MB

Drop-in replacement for Vulkan shared library, for older hardware compatibility

Home Page: https://dragonjoker.github.io/Ashes/

License: MIT License

CMake 2.91% C 0.09% C++ 95.61% GLSL 0.53% Lua 0.71% Batchfile 0.07% Shell 0.03% Objective-C++ 0.05%
cpp17 vulkan opengl direct3d11

ashes's People

Contributors

aviallon avatar dragonjoker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ashes's Issues

Error model

In base, no exceptions must be raised, at all.
This implies returning an error code, wherever it is needed.

Image and buffer memory

Create MemoryRequirements and DeviceMemory in RendererLib.
This will require the effective creation of an OpenGL image/buffer storage when the call is made to bindMemory.

Fail to build

on Arch linux

CMake Error at CMakeLists.txt:189 (add_subdirectory):
  add_subdirectory given source "Templates" which is not an existing
  directory.


CMake Error at CMakeLists.txt:193 (add_subdirectory):
  add_subdirectory given source "Test" which is not an existing directory.


CMake Error at CMakeLists.txt:197 (add_subdirectory):
  add_subdirectory given source "Samples" which is not an existing directory.


-- Configuring incomplete, errors occurred!
See also "/home/arthapz/Dev/repos/Ashes/build/CMakeFiles/CMakeOutput.log".

roadmap?

I have been keeping an eye on your project, do you have a roadmap to where you are heading?

OpenGL SwapChain

The OpenGL swapchain is limited, and this limit impacts the API structure (see SwapChain::createDepthStencil).
I must make it work like a Vulkan swapchain, hence I need to implement it as a FBO.
It will also allow to work with the swapchain images as with any other one.

It will help for #34

Common text shader language across renderers.

Rationale

The various renderers use slightly different shader languages: SPIR-V, GLSL#150, GLSL#420, and HLSL (sm5).
Convertion to SPIR-V can be (and actually is) handled using glslang and libSPIRV.
For text shaders, I'd like to have a common language, that would be parsed inside each specific renderer.

Details

I think a good starting point could be GLSL with Vulkan extensions (for push constants, which are handled as simple uniforms in OpenGL renderers, and as constant buffers in Direct3D11 renderer).
I would add some kind of annotation using #pragma preprocessor directive, to help the renderers' parsers to make the appropriate replacements.

Example

Let's start with the following annotated GLSL#420 vertex shader:

// Here, layout can remain as is, since it can be removed completely for GLSL#150,
// and replaced by a matching cbuffer in HLSL (except for 'set', which is another problem).
layout( set=0, binding=1 ) uniform Matrix
{
	mat4 mtxProjection;
};

// The vertex shader inputs need a change, since D3D11 needs semantics
// (even if their names aren't important).
in VertexInput
{
	#pragma semantic_name POSITION
	#pragma semantic_index 0
	layout( location = 0 ) vec4 position;
	#pragma semantic_name TEXCOORD
	#pragma semantic_index 0
	layout( location = 1 ) vec2 texcoord;
};

// This one can be removed from D3D11 renderer's parser, and remain as is for others.
// It will also be used in D3D11 renderer's parser to define the SV_POSITION holder.
out gl_PerVertex
{
	vec4 gl_Position;
};

// The vertex shader inputs need a change, since D3D11 needs semantics
// (even if their names aren't important).
out VertexOutput
{
	#pragma semantic_name POSITION
	#pragma semantic_index 0
	layout( location = 0 ) vec3 vtx_position;
	#pragma semantic_name TEXCOORD
	#pragma semantic_index 0
	layout( location = 1 ) vec2 vtx_texcoord;
}

// The main function will certainly need some rework inside the D3D parser,
// to be able to return what is needed, and to have what is need in entry.
void main()
{
	// This specific line may be a problem (I'll explain later).
	// Note that `ashesScalePosition` is the only Ashes intrinsic,
	// which allows the renderer to transform the position
	// to make it correct for it's own clip space.
	gl_Position = mtxProjection * ashesScalePosition( position );
	vtx_position = vec3( gl_Position );
	vtx_texcoord = texcoord;
	// In HLSL, we'll need a return statement.
}

The generated GLSL#150 would look like this (not a lot of changes, except for the layout specifier which is removed from the uniform buffer declaration):

uniform Matrix
{
	mat4 mtxProjection;
};

in VertexInput
{
	layout( location = 0 ) vec4 position;
	layout( location = 1 ) vec2 texcoord;
};

out gl_PerVertex
{
	vec4 gl_Position;
};

out VertexOutput
{
	layout( location = 0 ) vec3 vtx_position;
	layout( location = 1 ) vec2 vtx_texcoord;
};

void main()
{
	gl_Position = mtxProjection * ashesScalePosition( position );
	vtx_position = vec3( gl_Position );
	vtx_texcoord = texcoord;
}

The generated HLSL would (obviously) be very different:

cbuffer Matrix: register(b1)
{
	float4x4 mtxProjection;
};

struct VertexInput
{
	float4 position: POSITION;
	float2 texcoord: TEXCOORD;
};

struct VertexOutput
{
	float4 gl_Position: SV_POSITION;
	float3 vtx_position: POSITION;
	float2 vtx_texcoord: TEXCOORD;
};


VertexOutput main( in VertexInput input )
{
	VertexOutput output;
	output.gl_Position = mul( mtxProjection, ashesScalePosition( input.position ) );
	output.vtx_position = vec3( output.gl_Position );
	output.vtx_texcoord = input.texcoord;
	return output;
}

Problems

As far as I can see, this can be done without too much hard work.
Some points need attention though.

Matrix multiplication
In GLSL it is handled using multiplication operator *, while in HLSL it is handled using the intrinsic function mul.
I suggest using mul in the common language, and the parsers would either provide the function, or replace it with multiplication operator (can be complex, since there can be anything, in the function call arguments).

Types
They'll need to be #defined or completely replaced by the parser.

Intrinsics
Similar issue as types, they'll either need to be #defined or completely replaced by the parser.

set layout
This one is IMO a big issue, and it is unsolvable: in Vulkan we can specify the same binding, as long as the sets are different:

layout( set = 0, binding = 0 ) uniform Glop
{
  //whatever
};
layout( set = 1, binding = 0 ) uniform Meow
{
  //whatever else
};

This is perfectly valid with Vulkan, but impossible in other renderers.
It will probably be a limitation for users, when using Ashes.

Conclusion

I'm open to any suggestion that would help :).

Implement command Copy Buffer To Image in D3D11Renderer

This concept is completely alien to Direct3D 11.
Either you give your image its data at creation, or through texture copy/blit.
So, since in Vulkan you can't give an image its data at creation, I must copy from another texture.
Two cases:

  • The texture memory was created as device local => I can't map the texture to RAM.
    I need to have/create a staging texture, for this case (a cache of staging textures ?).
  • The texture memory was created as host visible => I can map it to RAM.

What I'll do first, is the naive approach:

  • Map buffer to RAM
  • Map texture to RAM (staging or host visible destination)
  • Copy buffer mapped data to texture mapped data
  • Unmap all
    If the texture is device local, an additional step is needed:
  • Copy staging texture to destination texture

The only remaining question now is about the staging texture...

One more bit to #34

Metal renderer.

I don't have any Apple device, hence I can't do it by myself, feel free to start working on it :P

Remove GeometryBuffers

It will need specific processing in OpenGL, to be able to generate the VAO when the draw commands are issued, and initialisation of this VAO must happen when the command buffer is submitted to a queue.

C API for Ashes

With all these moves to improve compliance with vulkan.h, I will make Ashes a drop in replacement to Vulkan.

The first approach is an automatic one: you load Ashes shared library instead of Vulkan's, and you're done. The API selection will be done on first call of vkGetInstanceProcAddr.

The second approach is a manual one: additionally, you can ask for the list of loaded plugins, through a call to the function int ashEnumeratePlugins( uint32_t * count , AshPluginDescription * plugins );
It works as Vulkan ones : if plugins is set to NULL, count will then contain the number of loaded plugins.
AshPluginDescription is defined as follows:

typedef struct AshPluginDescription
{
  const char * name;
  const char * description;
  PFN_vkGetInstanceProcAddr getInstanceProcAddr;
} AshPluginDescription;

Some changes to this definition may be done, but the idea remains the same.
The struct and the function will be declared in ashes.h

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.