mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Make pipelines bound state
This commit is contained in:
parent
4462a8cc99
commit
166243e0fd
8 changed files with 65 additions and 61 deletions
|
@ -141,7 +141,7 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
|
|||
} else {
|
||||
sampler = samplerLinear;
|
||||
}
|
||||
thin3d->SetSamplerStates(0, 1, &sampler);
|
||||
thin3d->BindSamplerStates(0, 1, &sampler);
|
||||
thin3d->SetDepthStencilState(depth);
|
||||
thin3d->SetRasterState(rasterNoCull);
|
||||
thin3d->SetScissorRect(0, 0, dstwidth, dstheight);
|
||||
|
@ -242,7 +242,8 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {
|
|||
};
|
||||
|
||||
texColor->SetMatrix4x4("WorldViewProj", identity4x4);
|
||||
thin3d->DrawIndexed(Primitive::TRIANGLE_LIST, texColor, vformat, vdata, idata, 6, 0);
|
||||
thin3d->BindPipeline(texColor);
|
||||
thin3d->DrawIndexed(Primitive::TRIANGLE_LIST, vformat, vdata, idata, 6, 0);
|
||||
}
|
||||
|
||||
void SoftGPU::CopyDisplayToOutput()
|
||||
|
|
|
@ -66,7 +66,7 @@ void DrawBuffer::Shutdown() {
|
|||
}
|
||||
|
||||
void DrawBuffer::Begin(Draw::Pipeline *program, DrawBufferPrimitiveMode dbmode) {
|
||||
shaderSet_ = program;
|
||||
pipeline_ = program;
|
||||
count_ = 0;
|
||||
mode_ = dbmode;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ void DrawBuffer::End() {
|
|||
|
||||
void DrawBuffer::Flush(bool set_blend_state) {
|
||||
using namespace Draw;
|
||||
if (!shaderSet_) {
|
||||
if (!pipeline_) {
|
||||
ELOG("No program set!");
|
||||
return;
|
||||
}
|
||||
|
@ -85,14 +85,14 @@ void DrawBuffer::Flush(bool set_blend_state) {
|
|||
if (count_ == 0)
|
||||
return;
|
||||
|
||||
shaderSet_->SetMatrix4x4("WorldViewProj", drawMatrix_.getReadPtr());
|
||||
|
||||
pipeline_->SetMatrix4x4("WorldViewProj", drawMatrix_.getReadPtr());
|
||||
t3d_->BindPipeline(pipeline_);
|
||||
if (vbuf_) {
|
||||
vbuf_->SubData((const uint8_t *)verts_, 0, sizeof(Vertex) * count_);
|
||||
int offset = 0;
|
||||
t3d_->Draw(mode_ == DBMODE_NORMAL ? Primitive::TRIANGLE_LIST : Primitive::LINE_LIST, shaderSet_, vformat_, vbuf_, count_, offset);
|
||||
t3d_->Draw(mode_ == DBMODE_NORMAL ? Primitive::TRIANGLE_LIST : Primitive::LINE_LIST, vformat_, vbuf_, count_, offset);
|
||||
} else {
|
||||
t3d_->DrawUP(mode_ == DBMODE_NORMAL ? Primitive::TRIANGLE_LIST : Primitive::LINE_LIST, shaderSet_, vformat_, (const void *)verts_, count_);
|
||||
t3d_->DrawUP(mode_ == DBMODE_NORMAL ? Primitive::TRIANGLE_LIST : Primitive::LINE_LIST, vformat_, (const void *)verts_, count_);
|
||||
}
|
||||
count_ = 0;
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ private:
|
|||
Draw::DrawContext *t3d_;
|
||||
Draw::Buffer *vbuf_;
|
||||
Draw::InputLayout *vformat_;
|
||||
Draw::Pipeline *shaderSet_;
|
||||
Draw::Pipeline *pipeline_;
|
||||
|
||||
Vertex *verts_;
|
||||
int count_;
|
||||
|
|
|
@ -470,7 +470,7 @@ public:
|
|||
|
||||
// Bound state objects. Too cumbersome to add them all as parameters to Draw.
|
||||
virtual void SetBlendState(BlendState *state) = 0;
|
||||
virtual void SetSamplerStates(int start, int count, SamplerState **state) = 0;
|
||||
virtual void BindSamplerStates(int start, int count, SamplerState **state) = 0;
|
||||
virtual void SetDepthStencilState(DepthStencilState *state) = 0;
|
||||
virtual void SetRasterState(RasterState *state) = 0;
|
||||
|
||||
|
@ -483,10 +483,12 @@ public:
|
|||
virtual void SetScissorRect(int left, int top, int width, int height) = 0;
|
||||
virtual void SetViewports(int count, Viewport *viewports) = 0;
|
||||
|
||||
virtual void BindPipeline(Pipeline *pipeline) = 0;
|
||||
|
||||
// TODO: Add more sophisticated draws with buffer offsets, and multidraws.
|
||||
virtual void Draw(Primitive prim, Pipeline *pipeline, InputLayout *format, Buffer *vdata, int vertexCount, int offset) = 0;
|
||||
virtual void DrawIndexed(Primitive prim, Pipeline *pipeline, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) = 0;
|
||||
virtual void DrawUP(Primitive prim, Pipeline *pipeline, InputLayout *format, const void *vdata, int vertexCount) = 0;
|
||||
virtual void Draw(Primitive prim, InputLayout *format, Buffer *vdata, int vertexCount, int offset) = 0;
|
||||
virtual void DrawIndexed(Primitive prim, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) = 0;
|
||||
virtual void DrawUP(Primitive prim, InputLayout *format, const void *vdata, int vertexCount) = 0;
|
||||
|
||||
// Render pass management. Default implementations here.
|
||||
virtual void Begin(bool clear, uint32_t colorval, float depthVal, int stencilVal) {
|
||||
|
|
|
@ -470,12 +470,6 @@ public:
|
|||
D3D9BlendState *bs = static_cast<D3D9BlendState *>(state);
|
||||
bs->Apply(device_);
|
||||
}
|
||||
void SetSamplerStates(int start, int count, SamplerState **states) override {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
D3D9SamplerState *s = static_cast<D3D9SamplerState *>(states[start + i]);
|
||||
s->Apply(device_, start + i);
|
||||
}
|
||||
}
|
||||
void SetDepthStencilState(DepthStencilState *state) override {
|
||||
Thin3DDX9DepthStencilState *bs = static_cast<Thin3DDX9DepthStencilState *>(state);
|
||||
bs->Apply(device_);
|
||||
|
@ -486,14 +480,23 @@ public:
|
|||
}
|
||||
|
||||
void BindTextures(int start, int count, Texture **textures) override;
|
||||
void BindSamplerStates(int start, int count, SamplerState **states) override {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
D3D9SamplerState *s = static_cast<D3D9SamplerState *>(states[start + i]);
|
||||
s->Apply(device_, start + i);
|
||||
}
|
||||
}
|
||||
void BindPipeline(Pipeline *pipeline) {
|
||||
curPipeline_ = (D3D9Pipeline *)pipeline;
|
||||
}
|
||||
|
||||
// Raster state
|
||||
void SetScissorRect(int left, int top, int width, int height) override;
|
||||
void SetViewports(int count, Viewport *viewports) override;
|
||||
|
||||
void Draw(Primitive prim, Pipeline *pipeline, InputLayout *format, Buffer *vdata, int vertexCount, int offset) override;
|
||||
void DrawIndexed(Primitive prim, Pipeline *pipeline, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) override;
|
||||
void DrawUP(Primitive prim, Pipeline *shaderSet, InputLayout *format, const void *vdata, int vertexCount) override;
|
||||
void Draw(Primitive prim, InputLayout *format, Buffer *vdata, int vertexCount, int offset) override;
|
||||
void DrawIndexed(Primitive prim, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) override;
|
||||
void DrawUP(Primitive prim, InputLayout *format, const void *vdata, int vertexCount) override;
|
||||
void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal);
|
||||
|
||||
std::string GetInfoString(InfoField info) const override {
|
||||
|
@ -517,6 +520,7 @@ private:
|
|||
D3DADAPTER_IDENTIFIER9 identifier_;
|
||||
D3DCAPS9 caps_;
|
||||
char shadeLangVersion_[64];
|
||||
D3D9Pipeline *curPipeline_;
|
||||
};
|
||||
|
||||
D3D9Context::D3D9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx)
|
||||
|
@ -703,35 +707,32 @@ void D3D9Pipeline::Apply(LPDIRECT3DDEVICE9 device) {
|
|||
pshader->Apply(device);
|
||||
}
|
||||
|
||||
void D3D9Context::Draw(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
|
||||
void D3D9Context::Draw(Primitive prim, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
|
||||
Thin3DDX9Buffer *vbuf = static_cast<Thin3DDX9Buffer *>(vdata);
|
||||
Thin3DDX9VertexFormat *fmt = static_cast<Thin3DDX9VertexFormat *>(format);
|
||||
D3D9Pipeline *ss = static_cast<D3D9Pipeline*>(shaderSet);
|
||||
|
||||
vbuf->BindAsVertexBuf(device_, fmt->GetStride(), offset);
|
||||
ss->Apply(device_);
|
||||
curPipeline_->Apply(device_);
|
||||
fmt->Apply(device_);
|
||||
device_->DrawPrimitive(primToD3D9[(int)prim], offset, vertexCount / 3);
|
||||
}
|
||||
|
||||
void D3D9Context::DrawIndexed(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
|
||||
void D3D9Context::DrawIndexed(Primitive prim, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
|
||||
Thin3DDX9Buffer *vbuf = static_cast<Thin3DDX9Buffer *>(vdata);
|
||||
Thin3DDX9Buffer *ibuf = static_cast<Thin3DDX9Buffer *>(idata);
|
||||
Thin3DDX9VertexFormat *fmt = static_cast<Thin3DDX9VertexFormat *>(format);
|
||||
D3D9Pipeline *ss = static_cast<D3D9Pipeline*>(shaderSet);
|
||||
|
||||
ss->Apply(device_);
|
||||
curPipeline_->Apply(device_);
|
||||
fmt->Apply(device_);
|
||||
vbuf->BindAsVertexBuf(device_, fmt->GetStride(), offset);
|
||||
ibuf->BindAsIndexBuf(device_);
|
||||
device_->DrawIndexedPrimitive(primToD3D9[(int)prim], 0, 0, vertexCount, 0, vertexCount / primCountDivisor[(int)prim]);
|
||||
}
|
||||
|
||||
void D3D9Context::DrawUP(Primitive prim, Pipeline *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
|
||||
void D3D9Context::DrawUP(Primitive prim, InputLayout *format, const void *vdata, int vertexCount) {
|
||||
Thin3DDX9VertexFormat *fmt = static_cast<Thin3DDX9VertexFormat *>(format);
|
||||
D3D9Pipeline *ss = static_cast<D3D9Pipeline*>(shaderSet);
|
||||
|
||||
ss->Apply(device_);
|
||||
curPipeline_->Apply(device_);
|
||||
fmt->Apply(device_);
|
||||
device_->DrawPrimitiveUP(primToD3D9[(int)prim], vertexCount / 3, vdata, fmt->GetStride());
|
||||
}
|
||||
|
|
|
@ -421,7 +421,7 @@ public:
|
|||
s->Apply();
|
||||
}
|
||||
|
||||
void SetSamplerStates(int start, int count, SamplerState **states) override {
|
||||
void BindSamplerStates(int start, int count, SamplerState **states) override {
|
||||
if (samplerStates_.size() < (size_t)(start + count)) {
|
||||
samplerStates_.resize(start + count);
|
||||
}
|
||||
|
@ -471,11 +471,14 @@ public:
|
|||
}
|
||||
|
||||
void BindTextures(int start, int count, Texture **textures) override;
|
||||
void BindPipeline(Pipeline *pipeline) {
|
||||
curPipeline_ = (OpenGLPipeline *)pipeline;
|
||||
}
|
||||
|
||||
// TODO: Add more sophisticated draws.
|
||||
void Draw(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) override;
|
||||
void DrawIndexed(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) override;
|
||||
void DrawUP(Primitive prim, Pipeline *shaderSet, InputLayout *format, const void *vdata, int vertexCount) override;
|
||||
void Draw(Primitive prim, InputLayout *format, Buffer *vdata, int vertexCount, int offset) override;
|
||||
void DrawIndexed(Primitive prim, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) override;
|
||||
void DrawUP(Primitive prim, InputLayout *format, const void *vdata, int vertexCount) override;
|
||||
void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override;
|
||||
|
||||
std::string GetInfoString(InfoField info) const override {
|
||||
|
@ -510,6 +513,7 @@ public:
|
|||
}
|
||||
|
||||
std::vector<OpenGLSamplerState *> samplerStates_;
|
||||
OpenGLPipeline *curPipeline_;
|
||||
};
|
||||
|
||||
OpenGLContext::OpenGLContext() {
|
||||
|
@ -932,51 +936,48 @@ void OpenGLPipeline::Unapply() {
|
|||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void OpenGLContext::Draw(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
|
||||
OpenGLPipeline *ss = static_cast<OpenGLPipeline *>(shaderSet);
|
||||
void OpenGLContext::Draw(Primitive prim, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
|
||||
OpenGLBuffer *vbuf = static_cast<OpenGLBuffer *>(vdata);
|
||||
OpenGLVertexFormat *fmt = static_cast<OpenGLVertexFormat *>(format);
|
||||
|
||||
vbuf->Bind();
|
||||
fmt->Apply();
|
||||
ss->Apply();
|
||||
curPipeline_->Apply();
|
||||
|
||||
glDrawArrays(primToGL[(int)prim], offset, vertexCount);
|
||||
|
||||
ss->Unapply();
|
||||
curPipeline_->Unapply();
|
||||
fmt->Unapply();
|
||||
}
|
||||
|
||||
void OpenGLContext::DrawIndexed(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
|
||||
OpenGLPipeline *ss = static_cast<OpenGLPipeline *>(shaderSet);
|
||||
void OpenGLContext::DrawIndexed(Primitive prim, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
|
||||
OpenGLBuffer *vbuf = static_cast<OpenGLBuffer *>(vdata);
|
||||
OpenGLBuffer *ibuf = static_cast<OpenGLBuffer *>(idata);
|
||||
OpenGLVertexFormat *fmt = static_cast<OpenGLVertexFormat *>(format);
|
||||
|
||||
vbuf->Bind();
|
||||
fmt->Apply();
|
||||
ss->Apply();
|
||||
curPipeline_->Apply();
|
||||
// Note: ibuf binding is stored in the VAO, so call this after binding the fmt.
|
||||
ibuf->Bind();
|
||||
|
||||
glDrawElements(primToGL[(int)prim], vertexCount, GL_UNSIGNED_INT, (const void *)(size_t)offset);
|
||||
|
||||
ss->Unapply();
|
||||
curPipeline_->Unapply();
|
||||
fmt->Unapply();
|
||||
}
|
||||
|
||||
void OpenGLContext::DrawUP(Primitive prim, Pipeline *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
|
||||
OpenGLPipeline *ss = static_cast<OpenGLPipeline *>(shaderSet);
|
||||
void OpenGLContext::DrawUP(Primitive prim, InputLayout *format, const void *vdata, int vertexCount) {
|
||||
OpenGLVertexFormat *fmt = static_cast<OpenGLVertexFormat *>(format);
|
||||
|
||||
fmt->Apply(vdata);
|
||||
ss->Apply();
|
||||
curPipeline_->Apply();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glDrawArrays(primToGL[(int)prim], 0, vertexCount);
|
||||
|
||||
ss->Unapply();
|
||||
curPipeline_->Unapply();
|
||||
fmt->Unapply();
|
||||
}
|
||||
|
||||
|
|
|
@ -441,14 +441,16 @@ public:
|
|||
|
||||
void SetViewports(int count, Viewport *viewports) override;
|
||||
|
||||
void BindSamplerStates(int start, int count, SamplerState **state) override;
|
||||
void BindTextures(int start, int count, Texture **textures) override;
|
||||
|
||||
void SetSamplerStates(int start, int count, SamplerState **state) override;
|
||||
void BindPipeline(Pipeline *pipeline) override {
|
||||
curPipeline_ = (VKPipeline *)pipeline;
|
||||
}
|
||||
|
||||
// TODO: Add more sophisticated draws.
|
||||
void Draw(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, int vertexCount, int offset) override;
|
||||
void DrawIndexed(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) override;
|
||||
void DrawUP(Primitive prim, Pipeline *shaderSet, InputLayout *format, const void *vdata, int vertexCount) override;
|
||||
void Draw(Primitive prim, InputLayout *format, Buffer *vdata, int vertexCount, int offset) override;
|
||||
void DrawIndexed(Primitive prim, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) override;
|
||||
void DrawUP(Primitive prim, InputLayout *format, const void *vdata, int vertexCount) override;
|
||||
|
||||
void Clear(int mask, uint32_t colorval, float depthVal, int stencilVal) override;
|
||||
|
||||
|
@ -584,7 +586,7 @@ RasterState *VKContext::CreateRasterState(const RasterStateDesc &desc) {
|
|||
return new VKRasterState(vulkan_, desc);
|
||||
}
|
||||
|
||||
void VKContext::SetSamplerStates(int start, int count, SamplerState **state) {
|
||||
void VKContext::BindSamplerStates(int start, int count, SamplerState **state) {
|
||||
for (int i = start; i < start + count; i++) {
|
||||
boundSamplers_[i] = (VKSamplerState *)state[i];
|
||||
}
|
||||
|
@ -1102,11 +1104,10 @@ inline VkPrimitiveTopology PrimToVK(Primitive prim) {
|
|||
}
|
||||
}
|
||||
|
||||
void VKContext::Draw(Primitive prim, Pipeline *pipeline, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
|
||||
void VKContext::Draw(Primitive prim, InputLayout *format, Buffer *vdata, int vertexCount, int offset) {
|
||||
ApplyDynamicState();
|
||||
|
||||
curPrim_ = PrimToVK(prim);
|
||||
curPipeline_ = (VKPipeline *)pipeline;
|
||||
curVertexFormat_ = (VKVertexFormat *)format;
|
||||
Thin3DVKBuffer *vbuf = static_cast<Thin3DVKBuffer *>(vdata);
|
||||
|
||||
|
@ -1125,11 +1126,10 @@ void VKContext::Draw(Primitive prim, Pipeline *pipeline, InputLayout *format, Bu
|
|||
vkCmdDraw(cmd_, vertexCount, 1, offset, 0);
|
||||
}
|
||||
|
||||
void VKContext::DrawIndexed(Primitive prim, Pipeline *shaderSet, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
|
||||
void VKContext::DrawIndexed(Primitive prim, InputLayout *format, Buffer *vdata, Buffer *idata, int vertexCount, int offset) {
|
||||
ApplyDynamicState();
|
||||
|
||||
curPrim_ = PrimToVK(prim);
|
||||
curPipeline_ = (VKPipeline *)shaderSet;
|
||||
curVertexFormat_ = (VKVertexFormat *)format;
|
||||
|
||||
Thin3DVKBuffer *ibuf = static_cast<Thin3DVKBuffer *>(idata);
|
||||
|
@ -1154,11 +1154,10 @@ void VKContext::DrawIndexed(Primitive prim, Pipeline *shaderSet, InputLayout *fo
|
|||
vkCmdDrawIndexed(cmd_, vertexCount, 1, 0, offset, 0);
|
||||
}
|
||||
|
||||
void VKContext::DrawUP(Primitive prim, Pipeline *shaderSet, InputLayout *format, const void *vdata, int vertexCount) {
|
||||
void VKContext::DrawUP(Primitive prim, InputLayout *format, const void *vdata, int vertexCount) {
|
||||
ApplyDynamicState();
|
||||
|
||||
curPrim_ = PrimToVK(prim);
|
||||
curPipeline_ = (VKPipeline *)shaderSet;
|
||||
curVertexFormat_ = (VKVertexFormat *)format;
|
||||
|
||||
VkBuffer vulkanVbuf, vulkanUBObuf;
|
||||
|
|
|
@ -47,7 +47,7 @@ void UIContext::Init(Draw::DrawContext *thin3d, Draw::Pipeline *uipipe, Draw::Pi
|
|||
|
||||
void UIContext::Begin() {
|
||||
thin3d_->SetBlendState(blendNormal_);
|
||||
thin3d_->SetSamplerStates(0, 1, &sampler_);
|
||||
thin3d_->BindSamplerStates(0, 1, &sampler_);
|
||||
thin3d_->SetDepthStencilState(depth_);
|
||||
thin3d_->SetRasterState(rasterNoCull_);
|
||||
thin3d_->BindTexture(0, uitexture_);
|
||||
|
@ -56,7 +56,7 @@ void UIContext::Begin() {
|
|||
|
||||
void UIContext::BeginNoTex() {
|
||||
thin3d_->SetBlendState(blendNormal_);
|
||||
thin3d_->SetSamplerStates(0, 1, &sampler_);
|
||||
thin3d_->BindSamplerStates(0, 1, &sampler_);
|
||||
thin3d_->SetRasterState(rasterNoCull_);
|
||||
UIBegin(ui_pipeline_notex_);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue