-
-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
258 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
----------------------------------------------------------------------------- | ||
This source file is part of OGRE | ||
(Object-oriented Graphics Rendering Engine) | ||
For the latest info, see http://www.ogre3d.org/ | ||
Copyright (c) 2000-2014 Torus Knot Software Ltd | ||
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. | ||
----------------------------------------------------------------------------- | ||
*/ | ||
|
||
#ifndef __SPIRVGpuProgramManager_H__ | ||
#define __SPIRVGpuProgramManager_H__ | ||
|
||
#include "OgreGL3PlusPrerequisites.h" | ||
#include "OgreHighLevelGpuProgramManager.h" | ||
#include "OgreGLSLShader.h" | ||
|
||
namespace Ogre { | ||
|
||
class _OgreGL3PlusExport SPIRVShader : public GLSLShader | ||
{ | ||
public: | ||
SPIRVShader(ResourceManager* creator, const String& name, ResourceHandle handle, const String& group, bool isManual, | ||
ManualResourceLoader* loader); | ||
virtual ~SPIRVShader(); | ||
|
||
const String& getLanguage(void) const; | ||
protected: | ||
void loadFromSource(); | ||
}; | ||
|
||
class _OgreGL3PlusExport SPIRVShaderFactory: public HighLevelGpuProgramFactory | ||
{ | ||
public: | ||
SPIRVShaderFactory(); | ||
~SPIRVShaderFactory(); | ||
/// Get the name of the language this factory creates shaders for. | ||
const String& getLanguage(void) const; | ||
/// Create an instance of GLSLProgram. | ||
HighLevelGpuProgram* create(ResourceManager* creator, | ||
const String& name, ResourceHandle handle, | ||
const String& group, bool isManual, ManualResourceLoader* loader); | ||
void destroy(HighLevelGpuProgram* prog); | ||
}; | ||
|
||
} //namespace Ogre | ||
|
||
#endif //__GLGpuProgramManager_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
----------------------------------------------------------------------------- | ||
This source file is part of OGRE | ||
(Object-oriented Graphics Rendering Engine) | ||
For the latest info, see http://www.ogre3d.org/ | ||
Copyright (c) 2000-2014 Torus Knot Software Ltd | ||
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. | ||
----------------------------------------------------------------------------- | ||
*/ | ||
|
||
#include "OgreSPIRVShaderFactory.h" | ||
#include "OgreLogManager.h" | ||
#include "OgreGLSLExtSupport.h" | ||
|
||
|
||
namespace Ogre { | ||
|
||
static GLenum getGLShaderType(GpuProgramType programType) | ||
{ | ||
switch (programType) | ||
{ | ||
case GPT_VERTEX_PROGRAM: | ||
return GL_VERTEX_SHADER; | ||
case GPT_HULL_PROGRAM: | ||
return GL_TESS_CONTROL_SHADER; | ||
case GPT_DOMAIN_PROGRAM: | ||
return GL_TESS_EVALUATION_SHADER; | ||
case GPT_GEOMETRY_PROGRAM: | ||
return GL_GEOMETRY_SHADER; | ||
case GPT_FRAGMENT_PROGRAM: | ||
return GL_FRAGMENT_SHADER; | ||
case GPT_COMPUTE_PROGRAM: | ||
return GL_COMPUTE_SHADER; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
SPIRVShader::SPIRVShader(ResourceManager* creator, const String& name, ResourceHandle handle, const String& group, | ||
bool isManual, ManualResourceLoader* loader) | ||
: GLSLShader(creator, name, handle, group, isManual, loader) | ||
{ | ||
if (createParamDictionary("SPIRVGpuProgram")) | ||
{ | ||
setupBaseParamDictionary(); | ||
} | ||
} | ||
|
||
SPIRVShader::~SPIRVShader() | ||
{ | ||
// have to call this here reather than in Resource destructor | ||
// since calling virtual methods in base destructors causes crash | ||
unloadHighLevel(); | ||
} | ||
|
||
const String& SPIRVShader::getLanguage(void) const | ||
{ | ||
static String language = "spirv"; | ||
return language; | ||
} | ||
|
||
void SPIRVShader::loadFromSource(void) | ||
{ | ||
OGRE_CHECK_GL_ERROR(mGLShaderHandle = glCreateShader(getGLShaderType(mType))); | ||
|
||
OGRE_CHECK_GL_ERROR(glShaderBinary(1, &mGLShaderHandle, GL_SHADER_BINARY_FORMAT_SPIR_V, mSource.data(), mSource.size())); | ||
|
||
OGRE_CHECK_GL_ERROR(glSpecializeShader(mGLShaderHandle, "main", 0, NULL, NULL)); | ||
|
||
// Check for compile errors | ||
int compiled = 0; | ||
OGRE_CHECK_GL_ERROR(glGetShaderiv(mGLShaderHandle, GL_COMPILE_STATUS, &compiled)); | ||
|
||
if (compiled) return; | ||
|
||
String compileInfo = getObjectInfo(mGLShaderHandle); | ||
|
||
OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, compileInfo); | ||
} | ||
|
||
SPIRVShaderFactory::SPIRVShaderFactory() | ||
{ | ||
|
||
} | ||
|
||
SPIRVShaderFactory::~SPIRVShaderFactory() | ||
{ | ||
|
||
} | ||
|
||
const String& SPIRVShaderFactory::getLanguage(void) const | ||
{ | ||
static String language = "spirv"; | ||
return language; | ||
} | ||
|
||
HighLevelGpuProgram* SPIRVShaderFactory::create(ResourceManager* creator, const String& name, ResourceHandle handle, | ||
const String& group, bool isManual, ManualResourceLoader* loader) | ||
{ | ||
return OGRE_NEW SPIRVShader(creator, name, handle, group, isManual, loader); | ||
} | ||
|
||
void SPIRVShaderFactory::destroy(HighLevelGpuProgram* prog) { delete prog; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#version 430 | ||
|
||
layout(location = 0) uniform sampler2D RT; | ||
layout(location = 0) in vec2 oUv0; | ||
|
||
layout(location = 0) out vec4 fragColor; | ||
|
||
void main() | ||
{ | ||
vec3 greyscale = vec3(dot(texture(RT, oUv0).rgb, vec3(0.3, 0.59, 0.11))); | ||
fragColor = vec4(greyscale, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
To compile these shaders install `glslangValidator` and run `compile.sh <shader>`. | ||
|
||
Then reference them in `BlackAndWhite.material` and `StdQuad_vp.program` by e.g. modifying the GLSL declaration as | ||
|
||
``` | ||
fragment_program Ogre/Compositor/B&W_GLSL_FP spirv | ||
{ | ||
source GrayScale.frag.spv | ||
} | ||
``` | ||
|
||
to mix SPIRV and GLSL shaders, `RSC_GLSL_SSO_REDECLARE` must be enabled. |
16 changes: 16 additions & 0 deletions
16
Samples/Media/materials/programs/SPIRV/StdQuad_Tex2a_vp.vert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#version 430 | ||
|
||
layout(location = 1) uniform mat4 worldViewProj; | ||
|
||
layout(location = 0) in vec4 vertex; | ||
layout(location = 8) in vec2 uv0; | ||
|
||
layout(location = 0) out vec2 oUv0; | ||
|
||
void main() | ||
{ | ||
// uniforms are not yet passed correctly | ||
// however here worldViewProj would be identity anyway | ||
gl_Position = /*worldViewProj */ vertex; | ||
oUv0 = uv0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
glslangValidator --client opengl100 $1 -o $1.spv |