mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-13 21:29:40 +00:00
More renaming to match
This commit is contained in:
parent
cce1ee332b
commit
3de4a38527
@ -62,7 +62,7 @@ SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *_thin3D)
|
||||
components.push_back(VertexComponent("TexCoord0", SEM_TEXCOORD0, DataFormat::R32G32_FLOAT, 12));
|
||||
components.push_back(VertexComponent("Color0", SEM_COLOR0, DataFormat::R8G8B8A8_UNORM, 20));
|
||||
|
||||
Shader *vshader = thin3d->GetVshaderPreset(VS_TEXTURE_COLOR_2D);
|
||||
ShaderModule *vshader = thin3d->GetVshaderPreset(VS_TEXTURE_COLOR_2D);
|
||||
vformat = thin3d->CreateVertexFormat(components, 24, vshader);
|
||||
|
||||
vdata = thin3d->CreateBuffer(24 * 4, BufferUsageFlag::DYNAMIC | BufferUsageFlag::VERTEXDATA);
|
||||
@ -75,7 +75,7 @@ SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *_thin3D)
|
||||
fb.data = Memory::GetPointer(0x44000000); // TODO: correct default address?
|
||||
depthbuf.data = Memory::GetPointer(0x44000000); // TODO: correct default address?
|
||||
|
||||
T3DRasterStateDesc rasterDesc{};
|
||||
RasterStateDesc rasterDesc{};
|
||||
rasterNoCull = thin3d->CreateRasterState(rasterDesc);
|
||||
|
||||
framebufferDirty_ = true;
|
||||
|
@ -46,7 +46,7 @@ void DrawBuffer::Init(Draw::DrawContext *t3d) {
|
||||
components.push_back(VertexComponent("TexCoord0", SEM_TEXCOORD0, DataFormat::R32G32_FLOAT, 12));
|
||||
components.push_back(VertexComponent("Color0", SEM_COLOR0, DataFormat::R8G8B8A8_UNORM, 20));
|
||||
|
||||
Shader *vshader = t3d_->GetVshaderPreset(VS_TEXTURE_COLOR_2D);
|
||||
ShaderModule *vshader = t3d_->GetVshaderPreset(VS_TEXTURE_COLOR_2D);
|
||||
|
||||
vformat_ = t3d_->CreateVertexFormat(components, 24, vshader);
|
||||
if (vformat_->RequiresBuffer()) {
|
||||
|
@ -148,11 +148,11 @@ static const char * const vulkan_vsTexCol =
|
||||
|
||||
|
||||
void DrawContext::CreatePresets() {
|
||||
vsPresets_[VS_TEXTURE_COLOR_2D] = CreateShader(ShaderStage::VERTEX, glsl_vsTexCol, hlslVsTexCol, vulkan_vsTexCol);
|
||||
vsPresets_[VS_COLOR_2D] = CreateShader(ShaderStage::VERTEX, glsl_vsCol, hlslVsCol, vulkan_vsCol);
|
||||
vsPresets_[VS_TEXTURE_COLOR_2D] = CreateShaderModule(ShaderStage::VERTEX, glsl_vsTexCol, hlslVsTexCol, vulkan_vsTexCol);
|
||||
vsPresets_[VS_COLOR_2D] = CreateShaderModule(ShaderStage::VERTEX, glsl_vsCol, hlslVsCol, vulkan_vsCol);
|
||||
|
||||
fsPresets_[FS_TEXTURE_COLOR_2D] = CreateShader(ShaderStage::FRAGMENT, glsl_fsTexCol, hlslFsTexCol, vulkan_fsTexCol);
|
||||
fsPresets_[FS_COLOR_2D] = CreateShader(ShaderStage::FRAGMENT, glsl_fsCol, hlslFsCol, vulkan_fsCol);
|
||||
fsPresets_[FS_TEXTURE_COLOR_2D] = CreateShaderModule(ShaderStage::FRAGMENT, glsl_fsTexCol, hlslFsTexCol, vulkan_fsTexCol);
|
||||
fsPresets_[FS_COLOR_2D] = CreateShaderModule(ShaderStage::FRAGMENT, glsl_fsCol, hlslFsCol, vulkan_fsCol);
|
||||
|
||||
ssPresets_[SS_TEXTURE_COLOR_2D] = CreateShaderSet(vsPresets_[VS_TEXTURE_COLOR_2D], fsPresets_[FS_TEXTURE_COLOR_2D]);
|
||||
ssPresets_[SS_COLOR_2D] = CreateShaderSet(vsPresets_[VS_COLOR_2D], fsPresets_[FS_COLOR_2D]);
|
||||
|
@ -318,21 +318,6 @@ public:
|
||||
virtual bool RequiresBuffer() = 0;
|
||||
};
|
||||
|
||||
class Shader : public RefCountedObject {
|
||||
public:
|
||||
};
|
||||
|
||||
class ShaderSet : public RefCountedObject {
|
||||
public:
|
||||
// TODO: Make some faster way of doing these. Support uniform buffers (and fake them on GL 2.0?)
|
||||
virtual void SetVector(const char *name, float *value, int n) = 0;
|
||||
virtual void SetMatrix4x4(const char *name, const float value[16]) = 0;
|
||||
};
|
||||
|
||||
class RasterState : public RefCountedObject {
|
||||
public:
|
||||
};
|
||||
|
||||
enum class ShaderStage {
|
||||
VERTEX,
|
||||
FRAGMENT,
|
||||
@ -351,6 +336,22 @@ enum class ShaderLanguage {
|
||||
HLSL_D3D11,
|
||||
};
|
||||
|
||||
class ShaderModule : public RefCountedObject {
|
||||
public:
|
||||
virtual ShaderStage GetStage() const = 0;
|
||||
};
|
||||
|
||||
class ShaderSet : public RefCountedObject {
|
||||
public:
|
||||
// TODO: Make some faster way of doing these. Support uniform buffers (and fake them on GL 2.0?)
|
||||
virtual void SetVector(const char *name, float *value, int n) = 0;
|
||||
virtual void SetMatrix4x4(const char *name, const float value[16]) = 0;
|
||||
};
|
||||
|
||||
class RasterState : public RefCountedObject {
|
||||
public:
|
||||
};
|
||||
|
||||
struct DepthStencilStateDesc {
|
||||
bool depthTestEnabled;
|
||||
bool depthWriteEnabled;
|
||||
@ -411,7 +412,7 @@ enum class Facing {
|
||||
CW,
|
||||
};
|
||||
|
||||
struct T3DRasterStateDesc {
|
||||
struct RasterStateDesc {
|
||||
CullMode cull;
|
||||
Facing facing;
|
||||
};
|
||||
@ -425,10 +426,10 @@ public:
|
||||
virtual DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) = 0;
|
||||
virtual BlendState *CreateBlendState(const BlendStateDesc &desc) = 0;
|
||||
virtual SamplerState *CreateSamplerState(const SamplerStateDesc &desc) = 0;
|
||||
virtual RasterState *CreateRasterState(const T3DRasterStateDesc &desc) = 0;
|
||||
virtual RasterState *CreateRasterState(const RasterStateDesc &desc) = 0;
|
||||
virtual Buffer *CreateBuffer(size_t size, uint32_t usageFlags) = 0;
|
||||
virtual ShaderSet *CreateShaderSet(Shader *vshader, Shader *fshader) = 0;
|
||||
virtual InputLayout *CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) = 0;
|
||||
virtual ShaderSet *CreateShaderSet(ShaderModule *vshader, ShaderModule *fshader) = 0;
|
||||
virtual InputLayout *CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, ShaderModule *vshader) = 0;
|
||||
|
||||
virtual Texture *CreateTexture() = 0; // To be later filled in by ->LoadFromFile or similar.
|
||||
virtual Texture *CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) = 0;
|
||||
@ -438,12 +439,12 @@ public:
|
||||
Texture *CreateTextureFromFileData(const uint8_t *data, int size, ImageFileType fileType);
|
||||
|
||||
// Note that these DO NOT AddRef so you must not ->Release presets unless you manually AddRef them.
|
||||
Shader *GetVshaderPreset(VertexShaderPreset preset) { return fsPresets_[preset]; }
|
||||
Shader *GetFshaderPreset(FragmentShaderPreset preset) { return vsPresets_[preset]; }
|
||||
ShaderModule *GetVshaderPreset(VertexShaderPreset preset) { return fsPresets_[preset]; }
|
||||
ShaderModule *GetFshaderPreset(FragmentShaderPreset preset) { return vsPresets_[preset]; }
|
||||
ShaderSet *GetShaderSetPreset(ShaderSetPreset preset) { return ssPresets_[preset]; }
|
||||
|
||||
// The implementation makes the choice of which shader code to use.
|
||||
virtual Shader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) = 0;
|
||||
virtual ShaderModule *CreateShaderModule(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) = 0;
|
||||
|
||||
// Bound state objects. Too cumbersome to add them all as parameters to Draw.
|
||||
virtual void SetBlendState(BlendState *state) = 0;
|
||||
@ -485,8 +486,8 @@ public:
|
||||
protected:
|
||||
void CreatePresets();
|
||||
|
||||
Shader *vsPresets_[VS_MAX_PRESET];
|
||||
Shader *fsPresets_[FS_MAX_PRESET];
|
||||
ShaderModule *vsPresets_[VS_MAX_PRESET];
|
||||
ShaderModule *fsPresets_[FS_MAX_PRESET];
|
||||
ShaderSet *ssPresets_[SS_MAX_PRESET];
|
||||
|
||||
int targetWidth_;
|
||||
|
@ -249,10 +249,10 @@ private:
|
||||
int stride_;
|
||||
};
|
||||
|
||||
class D3D9Shader : public Shader {
|
||||
class D3D9ShaderModule : public ShaderModule {
|
||||
public:
|
||||
D3D9Shader(ShaderStage stage) : stage_(stage), vshader_(NULL), pshader_(NULL), constantTable_(NULL) {}
|
||||
~D3D9Shader() {
|
||||
D3D9ShaderModule(ShaderStage stage) : stage_(stage), vshader_(NULL), pshader_(NULL), constantTable_(NULL) {}
|
||||
~D3D9ShaderModule() {
|
||||
if (vshader_)
|
||||
vshader_->Release();
|
||||
if (pshader_)
|
||||
@ -270,6 +270,7 @@ public:
|
||||
}
|
||||
void SetVector(LPDIRECT3DDEVICE9 device, const char *name, float *value, int n);
|
||||
void SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const float value[16]);
|
||||
ShaderStage GetStage() const override { return stage_; }
|
||||
|
||||
private:
|
||||
ShaderStage stage_;
|
||||
@ -281,8 +282,8 @@ private:
|
||||
class D3D9ShaderSet : public ShaderSet {
|
||||
public:
|
||||
D3D9ShaderSet(LPDIRECT3DDEVICE9 device) : device_(device) {}
|
||||
D3D9Shader *vshader;
|
||||
D3D9Shader *pshader;
|
||||
D3D9ShaderModule *vshader;
|
||||
D3D9ShaderModule *pshader;
|
||||
void Apply(LPDIRECT3DDEVICE9 device);
|
||||
void SetVector(const char *name, float *value, int n) { vshader->SetVector(device_, name, value, n); pshader->SetVector(device_, name, value, n); }
|
||||
void SetMatrix4x4(const char *name, const float value[16]) { vshader->SetMatrix4x4(device_, name, value); } // pshaders don't usually have matrices
|
||||
@ -455,13 +456,13 @@ public:
|
||||
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc);
|
||||
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
|
||||
SamplerState *CreateSamplerState(const SamplerStateDesc &desc) override;
|
||||
RasterState *CreateRasterState(const T3DRasterStateDesc &desc) override;
|
||||
RasterState *CreateRasterState(const RasterStateDesc &desc) override;
|
||||
Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override;
|
||||
ShaderSet *CreateShaderSet(Shader *vshader, Shader *fshader) override;
|
||||
InputLayout *CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) override;
|
||||
ShaderSet *CreateShaderSet(ShaderModule *vshader, ShaderModule *fshader) override;
|
||||
InputLayout *CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, ShaderModule *vshader) override;
|
||||
Texture *CreateTexture() override;
|
||||
Texture *CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override;
|
||||
Shader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
ShaderModule *CreateShaderModule(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
|
||||
// Bound state objects. Too cumbersome to add them all as parameters to Draw.
|
||||
void SetBlendState(BlendState *state) {
|
||||
@ -532,8 +533,8 @@ D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, ID
|
||||
D3D9Context::~D3D9Context() {
|
||||
}
|
||||
|
||||
Shader *D3D9Context::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
D3D9Shader *shader = new D3D9Shader(stage);
|
||||
ShaderModule *D3D9Context::CreateShaderModule(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
D3D9ShaderModule *shader = new D3D9ShaderModule(stage);
|
||||
if (shader->Compile(device_, hlsl_source)) {
|
||||
return shader;
|
||||
} else {
|
||||
@ -542,14 +543,14 @@ Shader *D3D9Context::CreateShader(ShaderStage stage, const char *glsl_source, co
|
||||
}
|
||||
}
|
||||
|
||||
ShaderSet *D3D9Context::CreateShaderSet(Shader *vshader, Shader *fshader) {
|
||||
ShaderSet *D3D9Context::CreateShaderSet(ShaderModule *vshader, ShaderModule *fshader) {
|
||||
if (!vshader || !fshader) {
|
||||
ELOG("ShaderSet requires both a valid vertex and a fragment shader: %p %p", vshader, fshader);
|
||||
return NULL;
|
||||
}
|
||||
D3D9ShaderSet *shaderSet = new D3D9ShaderSet(device_);
|
||||
shaderSet->vshader = static_cast<D3D9Shader *>(vshader);
|
||||
shaderSet->pshader = static_cast<D3D9Shader *>(fshader);
|
||||
shaderSet->vshader = static_cast<D3D9ShaderModule *>(vshader);
|
||||
shaderSet->pshader = static_cast<D3D9ShaderModule *>(fshader);
|
||||
return shaderSet;
|
||||
}
|
||||
|
||||
@ -561,7 +562,7 @@ DepthStencilState *D3D9Context::CreateDepthStencilState(const DepthStencilStateD
|
||||
return ds;
|
||||
}
|
||||
|
||||
InputLayout *D3D9Context::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
|
||||
InputLayout *D3D9Context::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, ShaderModule *vshader) {
|
||||
Thin3DDX9VertexFormat *fmt = new Thin3DDX9VertexFormat(device_, components, stride);
|
||||
return fmt;
|
||||
}
|
||||
@ -589,7 +590,7 @@ SamplerState *D3D9Context::CreateSamplerState(const SamplerStateDesc &desc) {
|
||||
return samps;
|
||||
}
|
||||
|
||||
RasterState *D3D9Context::CreateRasterState(const T3DRasterStateDesc &desc) {
|
||||
RasterState *D3D9Context::CreateRasterState(const RasterStateDesc &desc) {
|
||||
D3D9RasterState *rs = new D3D9RasterState();
|
||||
rs->cullMode = D3DCULL_NONE;
|
||||
if (desc.cull == CullMode::NONE) {
|
||||
@ -766,7 +767,7 @@ void D3D9Context::SetViewports(int count, Viewport *viewports) {
|
||||
device_->SetViewport(&vp);
|
||||
}
|
||||
|
||||
bool D3D9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source) {
|
||||
bool D3D9ShaderModule::Compile(LPDIRECT3DDEVICE9 device, const char *source) {
|
||||
LPD3DXMACRO defines = NULL;
|
||||
LPD3DXINCLUDE includes = NULL;
|
||||
DWORD flags = 0;
|
||||
@ -815,14 +816,14 @@ bool D3D9Shader::Compile(LPDIRECT3DDEVICE9 device, const char *source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void D3D9Shader::SetVector(LPDIRECT3DDEVICE9 device, const char *name, float *value, int n) {
|
||||
void D3D9ShaderModule::SetVector(LPDIRECT3DDEVICE9 device, const char *name, float *value, int n) {
|
||||
D3DXHANDLE handle = constantTable_->GetConstantByName(NULL, name);
|
||||
if (handle) {
|
||||
constantTable_->SetFloatArray(device, handle, value, n);
|
||||
}
|
||||
}
|
||||
|
||||
void D3D9Shader::SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const float value[16]) {
|
||||
void D3D9ShaderModule::SetMatrix4x4(LPDIRECT3DDEVICE9 device, const char *name, const float value[16]) {
|
||||
D3DXHANDLE handle = constantTable_->GetConstantByName(NULL, name);
|
||||
if (handle) {
|
||||
constantTable_->SetFloatArray(device, handle, value, 16);
|
||||
|
@ -254,12 +254,29 @@ private:
|
||||
size_t knownSize_;
|
||||
};
|
||||
|
||||
GLuint ShaderStageToOpenGL(ShaderStage stage) {
|
||||
switch (stage) {
|
||||
case ShaderStage::VERTEX: return GL_VERTEX_SHADER;
|
||||
case ShaderStage::COMPUTE: return GL_COMPUTE_SHADER;
|
||||
case ShaderStage::EVALUATION: return GL_TESS_EVALUATION_SHADER;
|
||||
case ShaderStage::CONTROL: return GL_TESS_CONTROL_SHADER;
|
||||
case ShaderStage::GEOMETRY: return GL_GEOMETRY_SHADER;
|
||||
case ShaderStage::FRAGMENT:
|
||||
default:
|
||||
return GL_FRAGMENT_SHADER;
|
||||
}
|
||||
}
|
||||
|
||||
// Not registering this as a resource holder, instead ShaderSet is registered. It will
|
||||
// invoke Compile again to recreate the shader then link them together.
|
||||
class OpenGLShader : public Shader {
|
||||
class OpenGLShaderModule : public ShaderModule {
|
||||
public:
|
||||
OpenGLShader(ShaderStage stage) : shader_(0), type_(0) {
|
||||
type_ = stage == ShaderStage::FRAGMENT ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER;
|
||||
OpenGLShaderModule(ShaderStage stage) : stage_(stage), shader_(0) {
|
||||
glstage_ = ShaderStageToOpenGL(stage);
|
||||
}
|
||||
|
||||
~OpenGLShaderModule() {
|
||||
glDeleteShader(shader_);
|
||||
}
|
||||
|
||||
bool Compile(const char *source);
|
||||
@ -271,25 +288,25 @@ public:
|
||||
void Unset() {
|
||||
shader_ = 0;
|
||||
}
|
||||
|
||||
~OpenGLShader() {
|
||||
glDeleteShader(shader_);
|
||||
ShaderStage GetStage() const override {
|
||||
return stage_;
|
||||
}
|
||||
|
||||
private:
|
||||
ShaderStage stage_;
|
||||
GLuint shader_;
|
||||
GLuint type_;
|
||||
GLuint glstage_;
|
||||
bool ok_;
|
||||
std::string source_; // So we can recompile in case of context loss.
|
||||
};
|
||||
|
||||
bool OpenGLShader::Compile(const char *source) {
|
||||
bool OpenGLShaderModule::Compile(const char *source) {
|
||||
source_ = source;
|
||||
shader_ = glCreateShader(type_);
|
||||
shader_ = glCreateShader(glstage_);
|
||||
|
||||
std::string temp;
|
||||
// Add the prelude on automatically for fragment shaders.
|
||||
if (type_ == GL_FRAGMENT_SHADER) {
|
||||
if (glstage_ == GL_FRAGMENT_SHADER) {
|
||||
temp = std::string(glsl_fragment_prelude) + source;
|
||||
source = temp.c_str();
|
||||
}
|
||||
@ -306,7 +323,7 @@ bool OpenGLShader::Compile(const char *source) {
|
||||
infoLog[len] = '\0';
|
||||
glDeleteShader(shader_);
|
||||
shader_ = 0;
|
||||
ILOG("%s Shader compile error:\n%s", type_ == GL_FRAGMENT_SHADER ? "Fragment" : "Vertex", infoLog);
|
||||
ILOG("%s Shader compile error:\n%s", glstage_ == GL_FRAGMENT_SHADER ? "Fragment" : "Vertex", infoLog);
|
||||
}
|
||||
ok_ = success != 0;
|
||||
return ok_;
|
||||
@ -373,8 +390,8 @@ public:
|
||||
Link();
|
||||
}
|
||||
|
||||
OpenGLShader *vshader;
|
||||
OpenGLShader *fshader;
|
||||
OpenGLShaderModule *vshader;
|
||||
OpenGLShaderModule *fshader;
|
||||
|
||||
private:
|
||||
GLuint program_;
|
||||
@ -389,10 +406,10 @@ public:
|
||||
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
|
||||
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
|
||||
SamplerState *CreateSamplerState(const SamplerStateDesc &desc) override;
|
||||
RasterState *CreateRasterState(const T3DRasterStateDesc &desc) override;
|
||||
RasterState *CreateRasterState(const RasterStateDesc &desc) override;
|
||||
Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override;
|
||||
ShaderSet *CreateShaderSet(Shader *vshader, Shader *fshader) override;
|
||||
InputLayout *CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) override;
|
||||
ShaderSet *CreateShaderSet(ShaderModule *vshader, ShaderModule *fshader) override;
|
||||
InputLayout *CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, ShaderModule *vshader) override;
|
||||
Texture *CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override;
|
||||
Texture *CreateTexture() override;
|
||||
|
||||
@ -435,7 +452,7 @@ public:
|
||||
rs->Apply();
|
||||
}
|
||||
|
||||
Shader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
ShaderModule *CreateShaderModule(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
|
||||
void SetScissorEnabled(bool enable) override {
|
||||
if (enable) {
|
||||
@ -514,7 +531,7 @@ OpenGLContext::~OpenGLContext() {
|
||||
samplerStates_.clear();
|
||||
}
|
||||
|
||||
InputLayout *OpenGLContext::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
|
||||
InputLayout *OpenGLContext::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, ShaderModule *vshader) {
|
||||
OpenGLVertexFormat *fmt = new OpenGLVertexFormat();
|
||||
fmt->components_ = components;
|
||||
fmt->stride_ = stride;
|
||||
@ -754,7 +771,7 @@ SamplerState *OpenGLContext::CreateSamplerState(const SamplerStateDesc &desc) {
|
||||
return samps;
|
||||
}
|
||||
|
||||
RasterState *OpenGLContext::CreateRasterState(const T3DRasterStateDesc &desc) {
|
||||
RasterState *OpenGLContext::CreateRasterState(const RasterStateDesc &desc) {
|
||||
OpenGLRasterState *rs = new OpenGLRasterState();
|
||||
if (desc.cull == CullMode::NONE) {
|
||||
rs->cullEnable = GL_FALSE;
|
||||
@ -787,7 +804,7 @@ Buffer *OpenGLContext::CreateBuffer(size_t size, uint32_t usageFlags) {
|
||||
return new OpenGLBuffer(size, usageFlags);
|
||||
}
|
||||
|
||||
ShaderSet *OpenGLContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
|
||||
ShaderSet *OpenGLContext::CreateShaderSet(ShaderModule *vshader, ShaderModule *fshader) {
|
||||
if (!vshader || !fshader) {
|
||||
ELOG("ShaderSet requires both a valid vertex and a fragment shader: %p %p", vshader, fshader);
|
||||
return NULL;
|
||||
@ -795,8 +812,8 @@ ShaderSet *OpenGLContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
|
||||
OpenGLShaderSet *shaderSet = new OpenGLShaderSet();
|
||||
vshader->AddRef();
|
||||
fshader->AddRef();
|
||||
shaderSet->vshader = static_cast<OpenGLShader *>(vshader);
|
||||
shaderSet->fshader = static_cast<OpenGLShader *>(fshader);
|
||||
shaderSet->vshader = static_cast<OpenGLShaderModule *>(vshader);
|
||||
shaderSet->fshader = static_cast<OpenGLShaderModule *>(fshader);
|
||||
if (shaderSet->Link()) {
|
||||
return shaderSet;
|
||||
} else {
|
||||
@ -819,8 +836,8 @@ void OpenGLContext::BindTextures(int start, int count, Texture **textures) {
|
||||
}
|
||||
|
||||
|
||||
Shader *OpenGLContext::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
OpenGLShader *shader = new OpenGLShader(stage);
|
||||
ShaderModule *OpenGLContext::CreateShaderModule(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
OpenGLShaderModule *shader = new OpenGLShaderModule(stage);
|
||||
if (shader->Compile(glsl_source)) {
|
||||
return shader;
|
||||
} else {
|
||||
|
@ -165,7 +165,7 @@ public:
|
||||
|
||||
class VKRasterState : public RasterState {
|
||||
public:
|
||||
VKRasterState(VulkanContext *vulkan, const T3DRasterStateDesc &desc) {
|
||||
VKRasterState(VulkanContext *vulkan, const RasterStateDesc &desc) {
|
||||
cullFace = desc.cull;
|
||||
frontFace = desc.facing;
|
||||
}
|
||||
@ -219,36 +219,52 @@ private:
|
||||
size_t dataSize_;
|
||||
};
|
||||
|
||||
VkShaderStageFlagBits StageToVulkan(ShaderStage stage) {
|
||||
switch (stage) {
|
||||
case ShaderStage::VERTEX: return VK_SHADER_STAGE_VERTEX_BIT;
|
||||
case ShaderStage::GEOMETRY: return VK_SHADER_STAGE_GEOMETRY_BIT;
|
||||
case ShaderStage::COMPUTE: return VK_SHADER_STAGE_COMPUTE_BIT;
|
||||
case ShaderStage::EVALUATION: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
|
||||
case ShaderStage::CONTROL: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
|
||||
default:
|
||||
case ShaderStage::FRAGMENT: return VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
// Not registering this as a resource holder, instead ShaderSet is registered. It will
|
||||
// invoke Compile again to recreate the shader then link them together.
|
||||
class VKShader : public Shader {
|
||||
class VKShaderModule : public ShaderModule {
|
||||
public:
|
||||
VKShader(ShaderStage stage) : module_(VK_NULL_HANDLE), ok_(false) {
|
||||
stage_ = stage == ShaderStage::FRAGMENT ? VK_SHADER_STAGE_FRAGMENT_BIT : VK_SHADER_STAGE_VERTEX_BIT;
|
||||
VKShaderModule(ShaderStage stage) : module_(VK_NULL_HANDLE), ok_(false), stage_(stage) {
|
||||
vkstage_ = StageToVulkan(stage);
|
||||
}
|
||||
bool Compile(VulkanContext *vulkan, const char *source);
|
||||
const std::string &GetSource() const { return source_; }
|
||||
~VKShader() {
|
||||
~VKShaderModule() {
|
||||
if (module_) {
|
||||
vkDestroyShaderModule(device_, module_, nullptr);
|
||||
}
|
||||
}
|
||||
VkShaderModule Get() const { return module_; }
|
||||
ShaderStage GetStage() const override {
|
||||
return stage_;
|
||||
}
|
||||
|
||||
private:
|
||||
VkDevice device_;
|
||||
VkShaderModule module_;
|
||||
VkShaderStageFlagBits stage_;
|
||||
VkShaderStageFlagBits vkstage_;
|
||||
bool ok_;
|
||||
ShaderStage stage_;
|
||||
std::string source_; // So we can recompile in case of context loss.
|
||||
};
|
||||
|
||||
bool VKShader::Compile(VulkanContext *vulkan, const char *source) {
|
||||
bool VKShaderModule::Compile(VulkanContext *vulkan, const char *source) {
|
||||
// We'll need this to free it later.
|
||||
device_ = vulkan->GetDevice();
|
||||
this->source_ = source;
|
||||
std::vector<uint32_t> spirv;
|
||||
if (!GLSLtoSPV(stage_, source, spirv)) {
|
||||
if (!GLSLtoSPV(vkstage_, source, spirv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -339,8 +355,8 @@ public:
|
||||
return uboSize_;
|
||||
}
|
||||
|
||||
VKShader *vshader;
|
||||
VKShader *fshader;
|
||||
VKShaderModule *vshader;
|
||||
VKShaderModule *fshader;
|
||||
|
||||
private:
|
||||
uint8_t *ubo_;
|
||||
@ -393,10 +409,13 @@ public:
|
||||
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
|
||||
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
|
||||
Buffer *CreateBuffer(size_t size, uint32_t usageFlags) override;
|
||||
ShaderSet *CreateShaderSet(Shader *vshader, Shader *fshader) override;
|
||||
InputLayout *CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) override;
|
||||
InputLayout *CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, ShaderModule *vshader) override;
|
||||
SamplerState *CreateSamplerState(const SamplerStateDesc &desc) override;
|
||||
RasterState *CreateRasterState(const T3DRasterStateDesc &desc) override;
|
||||
RasterState *CreateRasterState(const RasterStateDesc &desc) override;
|
||||
ShaderSet *CreateShaderSet(ShaderModule *vshader, ShaderModule *fshader) override;
|
||||
// The implementation makes the choice of which shader code to use.
|
||||
ShaderModule *CreateShaderModule(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
|
||||
Texture *CreateTexture(TextureType type, DataFormat format, int width, int height, int depth, int mipLevels) override;
|
||||
Texture *CreateTexture() override;
|
||||
|
||||
@ -418,9 +437,6 @@ public:
|
||||
curRasterState_ = s;
|
||||
}
|
||||
|
||||
// The implementation makes the choice of which shader code to use.
|
||||
Shader *CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) override;
|
||||
|
||||
void SetScissorEnabled(bool enable) override {
|
||||
scissorEnabled_ = enable;
|
||||
scissorDirty_ = true;
|
||||
@ -572,7 +588,7 @@ SamplerState *VKContext::CreateSamplerState(const SamplerStateDesc &desc) {
|
||||
return new VKSamplerState(vulkan_, desc);
|
||||
}
|
||||
|
||||
RasterState *VKContext::CreateRasterState(const T3DRasterStateDesc &desc) {
|
||||
RasterState *VKContext::CreateRasterState(const RasterStateDesc &desc) {
|
||||
return new VKRasterState(vulkan_, desc);
|
||||
}
|
||||
|
||||
@ -964,7 +980,7 @@ void VKContext::DirtyDynamicState() {
|
||||
viewportDirty_ = true;
|
||||
}
|
||||
|
||||
InputLayout *VKContext::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, Shader *vshader) {
|
||||
InputLayout *VKContext::CreateVertexFormat(const std::vector<VertexComponent> &components, int stride, ShaderModule *vshader) {
|
||||
VKVertexFormat *fmt = new VKVertexFormat();
|
||||
fmt->components_ = components;
|
||||
fmt->stride_ = stride;
|
||||
@ -1022,7 +1038,7 @@ Buffer *VKContext::CreateBuffer(size_t size, uint32_t usageFlags) {
|
||||
return new Thin3DVKBuffer(size, usageFlags);
|
||||
}
|
||||
|
||||
ShaderSet *VKContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
|
||||
ShaderSet *VKContext::CreateShaderSet(ShaderModule *vshader, ShaderModule *fshader) {
|
||||
if (!vshader || !fshader) {
|
||||
ELOG("ShaderSet requires both a valid vertex and a fragment shader: %p %p", vshader, fshader);
|
||||
return NULL;
|
||||
@ -1030,8 +1046,8 @@ ShaderSet *VKContext::CreateShaderSet(Shader *vshader, Shader *fshader) {
|
||||
VKShaderSet *shaderSet = new VKShaderSet();
|
||||
vshader->AddRef();
|
||||
fshader->AddRef();
|
||||
shaderSet->vshader = static_cast<VKShader *>(vshader);
|
||||
shaderSet->fshader = static_cast<VKShader *>(fshader);
|
||||
shaderSet->vshader = static_cast<VKShaderModule *>(vshader);
|
||||
shaderSet->fshader = static_cast<VKShaderModule *>(fshader);
|
||||
if (shaderSet->Link()) {
|
||||
return shaderSet;
|
||||
} else {
|
||||
@ -1046,8 +1062,8 @@ void VKContext::BindTextures(int start, int count, Texture **textures) {
|
||||
}
|
||||
}
|
||||
|
||||
Shader *VKContext::CreateShader(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
VKShader *shader = new VKShader(stage);
|
||||
ShaderModule *VKContext::CreateShaderModule(ShaderStage stage, const char *glsl_source, const char *hlsl_source, const char *vulkan_source) {
|
||||
VKShaderModule *shader = new VKShaderModule(stage);
|
||||
if (shader->Compile(vulkan_, vulkan_source)) {
|
||||
return shader;
|
||||
} else {
|
||||
|
@ -29,7 +29,7 @@ void UIContext::Init(Draw::DrawContext *thin3d, Draw::ShaderSet *uishader, Draw:
|
||||
blendNormal_ = thin3d_->CreateBlendState({ true, BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA });
|
||||
sampler_ = thin3d_->CreateSamplerState({ TextureFilter::LINEAR, TextureFilter::LINEAR, TextureFilter::LINEAR });
|
||||
depth_ = thin3d_->CreateDepthStencilState({ false, false, Comparison::LESS });
|
||||
T3DRasterStateDesc desc;
|
||||
RasterStateDesc desc;
|
||||
desc.cull = CullMode::NONE;
|
||||
desc.facing = Facing::CCW;
|
||||
rasterNoCull_ = thin3d_->CreateRasterState(desc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user