Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading of depth textures/buffers in ODR. #2652

Merged
merged 4 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/cc/gl/formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool getDepthStencilFormat(int d, int s, uint32_t& depth, uint32_t& stencil) {
stencil = GL_DEPTH24_STENCIL8;
return true;
case 32:
depth = GL_DEPTH24_STENCIL8;
depth = GL_DEPTH32F_STENCIL8;
stencil = GL_DEPTH32F_STENCIL8;
return true;
}
Expand Down
11 changes: 6 additions & 5 deletions gapis/api/gles/api/egl.api
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,12 @@ cmd EGLImageKHR eglCreateImageKHR(EGLDisplay display,
eglImage.Extra = info
for i in 0 .. max!u32(info.LayerCount, 1) {
image := new!Image(
Width: as!GLsizei(info.Width),
Height: as!GLsizei(info.Height),
SizedFormat: sf,
DataFormat: sfInfo.UnsizedFormat,
DataType: sfInfo.DataType,
Width: as!GLsizei(info.Width),
Height: as!GLsizei(info.Height),
SizedFormat: sf,
InternalFormat: sf,
DataFormat: sfInfo.UnsizedFormat,
DataType: sfInfo.DataType,
)
size := uncompressedImageSize(image.Width, image.Height, image.DataFormat, image.DataType)
image.Data = make!u8(size)
Expand Down
2 changes: 1 addition & 1 deletion gapis/api/gles/api/image_format.api
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ sub GLenum GetSizedFormatFromTuple(GLenum unsizedFormat, GLenum type) {
@if(Extension.GL_OES_depth_texture)
case GL_DEPTH_COMPONENT: switch type {
case GL_UNSIGNED_SHORT: GL_DEPTH_COMPONENT16
case GL_UNSIGNED_INT: GL_DEPTH_COMPONENT32
case GL_UNSIGNED_INT: GL_DEPTH_COMPONENT24
default: GL_NONE
}
@if(Extension.GL_OES_packed_depth_stencil)
Expand Down
8 changes: 8 additions & 0 deletions gapis/api/gles/api/textures_and_samplers.api
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ class Image {
// (sizedFormat, GL_NONE) - Compressed data.
@unused GLenum DataFormat
@unused GLenum DataType

// The internal format as specified by the application. It may be
// the same as SizedFormat, if the application requested a sized
// format, but may be unsized and different from SizedFormat, or
// GL_NONE for compressed textures and non texture images.
@unused GLenum InternalFormat
}

@internal
Expand Down Expand Up @@ -446,6 +452,7 @@ sub void TexImage(TexImageFlags flags,
Samples: samples,
FixedSampleLocations: fixedsamplelocations,
SizedFormat: sfBox.SizedFormat,
InternalFormat: sized_format,
DataFormat: data_format,
DataType: data_type))
}
Expand Down Expand Up @@ -1031,6 +1038,7 @@ cmd void glGenerateMipmap(GLenum target) {
Width: max!GLsizei(1, width),
Height: max!GLsizei(1, height),
SizedFormat: base.SizedFormat,
InternalFormat: base.InternalFormat,
DataFormat: base.DataFormat,
DataType: base.DataType)
// Set state first so that the command below knowns image size.
Expand Down
4 changes: 2 additions & 2 deletions gapis/api/gles/gles.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ func GetFramebufferAttachmentInfoByID(
}

fbai, err := s.getFramebufferAttachmentInfo(thread, fb, glAtt)
if fbai.format == 0 {
if fbai.sizedFormat == 0 {
return api.FramebufferAttachmentInfo{}, fmt.Errorf("No format set")
}
if err != nil {
return api.FramebufferAttachmentInfo{}, err
}
fmt, ty := getUnsizedFormatAndType(fbai.format)
fmt, ty := getUnsizedFormatAndType(fbai.sizedFormat)
f, err := getImageFormat(fmt, ty)
if err != nil {
return api.FramebufferAttachmentInfo{}, err
Expand Down
8 changes: 6 additions & 2 deletions gapis/api/gles/read_depth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// current read framebuffer into an new framebuffer (which is left bound as the
// read framebuffer upon exit) as the color attachment in R32F format, allowing
// it to be read via glReadPixels.
func copyDepthToColorGLES(ctx context.Context, dID api.CmdID, thread uint64, s *api.GlobalState, out transform.Writer, t *tweaker, format GLenum, width, height int32) {
func copyDepthToColorGLES(ctx context.Context, dID api.CmdID, thread uint64, s *api.GlobalState, out transform.Writer, t *tweaker, fbai fbai, width, height int32) {
const (
aScreenCoordsLocation AttributeLocation = 0
aScreenCoords = "aScreenCoords"
Expand Down Expand Up @@ -71,7 +71,11 @@ func copyDepthToColorGLES(ctx context.Context, dID api.CmdID, thread uint64, s *
t.glBindTexture_2D(ctx, tex)
out.MutateAndWrite(ctx, dID, cb.GlTexParameteri(GLenum_GL_TEXTURE_2D, GLenum_GL_TEXTURE_MIN_FILTER, GLint(GLenum_GL_NEAREST)))
out.MutateAndWrite(ctx, dID, cb.GlTexParameteri(GLenum_GL_TEXTURE_2D, GLenum_GL_TEXTURE_MAG_FILTER, GLint(GLenum_GL_NEAREST)))
out.MutateAndWrite(ctx, dID, cb.GlTexStorage2D(GLenum_GL_TEXTURE_2D, 1, format, ws, hs))
if fbai.internalFormat != GLenum_GL_NONE && fbai.internalFormat != fbai.sizedFormat {
out.MutateAndWrite(ctx, dID, cb.GlTexImage2D(GLenum_GL_TEXTURE_2D, 0, GLint(fbai.internalFormat), ws, hs, 0, fbai.format, fbai.ty, memory.Nullptr))
} else {
out.MutateAndWrite(ctx, dID, cb.GlTexStorage2D(GLenum_GL_TEXTURE_2D, 1, fbai.sizedFormat, ws, hs))
}
t.glBindFramebuffer_Draw(ctx, fb)
out.MutateAndWrite(ctx, dID, cb.GlFramebufferTexture2D(GLenum_GL_DRAW_FRAMEBUFFER, GLenum_GL_DEPTH_ATTACHMENT, GLenum_GL_TEXTURE_2D, tex, 0))
out.MutateAndWrite(ctx, dID, cb.GlBlitFramebuffer(0, 0, wi, hi, 0, 0, wi, hi, GLbitfield_GL_DEPTH_BUFFER_BIT, GLenum_GL_NEAREST))
Expand Down
10 changes: 5 additions & 5 deletions gapis/api/gles/read_framebuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func postFBData(ctx context.Context,
res(nil, &service.ErrDataUnavailable{Reason: messages.ErrFramebufferUnavailable()})
return
}
if fbai.format == 0 {
if fbai.sizedFormat == 0 {
log.W(ctx, "Failed to read framebuffer after cmd %v: no image format", id)
res(nil, &service.ErrDataUnavailable{Reason: messages.ErrFramebufferUnavailable()})
return
Expand All @@ -134,7 +134,7 @@ func postFBData(ctx context.Context,
defer t.revert(ctx)
t.glBindFramebuffer_Read(ctx, fb)

unsizedFormat, ty := getUnsizedFormatAndType(fbai.format)
unsizedFormat, ty := getUnsizedFormatAndType(fbai.sizedFormat)

imgFmt, err := getImageFormat(unsizedFormat, ty)
if err != nil {
Expand Down Expand Up @@ -227,7 +227,7 @@ func postFBData(ctx context.Context,
}

mutateAndWriteEach(ctx, out, dID,
cb.GlRenderbufferStorage(GLenum_GL_RENDERBUFFER, fbai.format, GLsizei(inW), GLsizei(inH)),
cb.GlRenderbufferStorage(GLenum_GL_RENDERBUFFER, fbai.sizedFormat, GLsizei(inW), GLsizei(inH)),
cb.GlFramebufferRenderbuffer(GLenum_GL_DRAW_FRAMEBUFFER, attachment, GLenum_GL_RENDERBUFFER, renderbufferID),
cb.GlBlitFramebuffer(0, 0, GLint(inW), GLint(inH), 0, 0, GLint(inW), GLint(inH), bufferBits, GLenum_GL_NEAREST),
)
Expand Down Expand Up @@ -264,15 +264,15 @@ func postFBData(ctx context.Context,
}

mutateAndWriteEach(ctx, out, dID,
cb.GlRenderbufferStorage(GLenum_GL_RENDERBUFFER, fbai.format, GLsizei(outW), GLsizei(outH)),
cb.GlRenderbufferStorage(GLenum_GL_RENDERBUFFER, fbai.sizedFormat, GLsizei(outW), GLsizei(outH)),
cb.GlFramebufferRenderbuffer(GLenum_GL_DRAW_FRAMEBUFFER, attachment, GLenum_GL_RENDERBUFFER, renderbufferID),
cb.GlBlitFramebuffer(0, 0, GLint(inW), GLint(inH), 0, 0, GLint(outW), GLint(outH), bufferBits, sampling),
)
t.glBindFramebuffer_Read(ctx, framebufferID)
}

if hasDepth && version.IsES {
copyDepthToColorGLES(ctx, dID, thread, s, out, t, fbai.format, inW, inH)
copyDepthToColorGLES(ctx, dID, thread, s, out, t, fbai, inW, inH)
}

if needFBQuery {
Expand Down
15 changes: 9 additions & 6 deletions gapis/api/gles/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import (

// fbai is the result getFramebufferAttachmentInfo.
type fbai struct {
width uint32
height uint32
format GLenum // sized
multisampled bool
width uint32
height uint32
sizedFormat GLenum
internalFormat GLenum // These are GL_NONE, unless the attachement is a texture
format GLenum // that was initialized with a buffer of this internal
ty GLenum // format, format and type.
multisampled bool
}

func attachmentToEnum(a api.FramebufferAttachment) (GLenum, error) {
Expand Down Expand Up @@ -93,15 +96,15 @@ func (s *State) getFramebufferAttachmentInfo(thread uint64, fb FramebufferId, at
t.ID(), a.TextureLevel(), a.TextureLayer())
}
multisampled := l.Samples() > 0
return fbai{uint32(l.Width()), uint32(l.Height()), l.SizedFormat(), multisampled}, nil
return fbai{uint32(l.Width()), uint32(l.Height()), l.SizedFormat(), l.InternalFormat(), l.DataFormat(), l.DataType(), multisampled}, nil
case GLenum_GL_RENDERBUFFER:
r := a.Renderbuffer()
l := r.Image()
if l.IsNil() {
return fbai{}, fmt.Errorf("Renderbuffer %v does not have any image date", r.ID())
}
multisampled := l.Samples() > 0
return fbai{uint32(l.Width()), uint32(l.Height()), l.SizedFormat(), multisampled}, nil
return fbai{uint32(l.Width()), uint32(l.Height()), l.SizedFormat(), GLenum_GL_NONE, GLenum_GL_NONE, GLenum_GL_NONE, multisampled}, nil
default:
return fbai{}, fmt.Errorf("Unknown framebuffer attachment type %T", a.Type())
}
Expand Down